/// <summary> /// Updates all non modified properties in the prototype hierarchy. Works in reverse. /// </summary> public void UpdatePrototypeHierachy() { Stack <PrototypeObject> stack = new Stack <PrototypeObject>(); PrototypeObject prototype = serializedObject.FindProperty("prototype").objectReferenceValue as PrototypeObject; while (prototype != null) { stack.Push(prototype); if (prototype == prototype.prototype) { break; } prototype = prototype.prototype; } if (stack.Count == 0) { return; } while (stack.Count > 0) { SerializedPrototypeEditor serializedObjectEditor = new SerializedPrototypeEditor(new SerializedObject(stack.Pop())); serializedObjectEditor.UpdateNonModifiedProperties(); } prototypeSerialized.Update(); }
/// <summary> /// Updates all prototypes in Assets/. /// </summary> public static void UpdateAllPrototypes() { foreach (string assetGUID in AssetDatabase.FindAssets("t:Prototype")) { SerializedPrototypeEditor serializedPrototypeEditor = new SerializedPrototypeEditor(new SerializedObject(AssetDatabase.LoadAssetAtPath <PrototypeObject>(AssetDatabase.GUIDToAssetPath(assetGUID)))); serializedPrototypeEditor.UpdatePrototypeHierachy(); serializedPrototypeEditor.serializedObject.ApplyModifiedProperties(); } }
void OnDisable() { SerializedPrototypeEditor.UpdateAllPrototypes(); }
void OnEnable() { serializedPrototypeObject = new SerializedPrototypeEditor(serializedObject); serializedPrototypeObject.UpdatePrototypeHierachy(); }