Browse Source

Rebuild the bound types list in all LuaBindings when scripts are renamed

master
Chris Gregan 9 years ago
parent
commit
ee79ce8d45
  1. 38
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs

38
Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs vendored

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.IO; using System.IO;
using UnityEditor.Callbacks;
namespace Fungus namespace Fungus
{ {
@ -160,11 +161,11 @@ namespace Fungus
ShowBindingMemberInfo(); ShowBindingMemberInfo();
// Update the bound types on every tick to make sure they're up to date. // Update the bound types on every tick to make sure they're up to date.
// This could be a bit heavy on performance if the bound object list is long, but // This could be a bit heavy on performance if the bound object list is long, but
// I couldn't get it to work reliably by only updating when the list has changed. // I couldn't get it to work reliably by only updating when the list has changed.
// This only happens when inspecting a Fungus Bindings component so I think it'll be ok. // This only happens when inspecting a Fungus Bindings component so I think it'll be ok.
PopulateBoundTypes(); PopulateBoundTypes(target as LuaBindings, serializedObject);
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
@ -354,13 +355,26 @@ namespace Fungus
return key; return key;
} }
[DidReloadScripts()]
protected static void DidReloadScripts()
{
LuaBindings[] luaBindingsList = GameObject.FindObjectsOfType<LuaBindings>();
foreach (LuaBindings luaBindings in luaBindingsList)
{
SerializedObject so = new SerializedObject(luaBindings);
so.Update();
PopulateBoundTypes(luaBindings, so);
so.ApplyModifiedProperties();
}
}
/// <summary> /// <summary>
/// Update the list of bound types on the LuaBindings object. /// Update the list of bound types on the LuaBindings object.
/// </summary> /// </summary>
protected virtual void PopulateBoundTypes() protected static void PopulateBoundTypes(LuaBindings luaBindings, SerializedObject so)
{ {
LuaBindings luaBindings = target as LuaBindings;
// Use a temp HashSet to store the list of types. // Use a temp HashSet to store the list of types.
// The final list is stored as a list of type strings. // The final list is stored as a list of type strings.
HashSet<System.Type> typeSet = new HashSet<System.Type>(); HashSet<System.Type> typeSet = new HashSet<System.Type>();
@ -378,9 +392,9 @@ namespace Fungus
AddAllSubTypes(typeSet, boundObject.component.GetType()); AddAllSubTypes(typeSet, boundObject.component.GetType());
} }
} }
// Store the final list of types in the luaBindings object // Store the final list of types in the luaBindings object
SerializedProperty boundTypesProp = serializedObject.FindProperty("boundTypes"); SerializedProperty boundTypesProp = so.FindProperty("boundTypes");
boundTypesProp.ClearArray(); boundTypesProp.ClearArray();
int index = 0; int index = 0;
foreach (System.Type t in typeSet) foreach (System.Type t in typeSet)
@ -396,7 +410,7 @@ namespace Fungus
/// Adds the type to the set of types, and then uses reflection to add /// Adds the type to the set of types, and then uses reflection to add
/// all public fields, properties and methods to the set of types. /// all public fields, properties and methods to the set of types.
/// </summary> /// </summary>
protected virtual void AddAllSubTypes(HashSet<System.Type> typeSet, System.Type t) protected static void AddAllSubTypes(HashSet<System.Type> typeSet, System.Type t)
{ {
AddSubType(typeSet, t); AddSubType(typeSet, t);
@ -438,7 +452,7 @@ namespace Fungus
/// Adds a single type to the type set. /// Adds a single type to the type set.
/// IEnumerable and IEnumerator types are handled specially. /// IEnumerable and IEnumerator types are handled specially.
/// </summary> /// </summary>
protected virtual void AddSubType(HashSet<System.Type> typeSet, System.Type t) protected static void AddSubType(HashSet<System.Type> typeSet, System.Type t)
{ {
// MoonSharp handles IEnumerator and IEnumerable types automatically, so just // MoonSharp handles IEnumerator and IEnumerable types automatically, so just
// register the generic type used. // register the generic type used.

Loading…
Cancel
Save