miepzerino
2025-03-29 ad79d9ca49274cc660fc2030a071b24314f0f210
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using UnityEditor;
using UnityEngine;
 
namespace Flexalon.Editor
{
    [CustomEditor(typeof(FlexalonComponent)), CanEditMultipleObjects]
    public class FlexalonComponentEditor : UnityEditor.Editor
    {
        public static void Create<T>(string name, Object context) where T : MonoBehaviour
        {
            FlexalonEditor.Create();
            var go = new GameObject(name);
            Undo.RegisterCreatedObjectUndo(go, "Create " + name);
 
            if (context is GameObject)
            {
                go.transform.SetParent((context as GameObject).transform, false);
            }
 
            Flexalon.AddComponent<T>(go);
            Selection.activeGameObject = go;
        }
 
        protected void ForceUpdateButton()
        {
            if (GUILayout.Button("Force Update"))
            {
                foreach (var target in targets)
                {
                    ForceUpdate(target as FlexalonComponent);
                }
            }
        }
 
        protected void ApplyModifiedProperties()
        {
            if (serializedObject.ApplyModifiedProperties())
            {
                foreach (var target in targets)
                {
                    Record(target as FlexalonComponent);
                    (target as FlexalonComponent).MarkDirty();
                }
 
                Flexalon.GetOrCreate().UpdateDirtyNodes();
            }
        }
 
        protected void Record(FlexalonComponent script)
        {
            Undo.RecordObject(script, "Record Component Edit");
            PrefabUtility.RecordPrefabInstancePropertyModifications(script);
 
            if (script.Node != null && script.Node.Result)
            {
                Undo.RecordObject(script.Node.Result, "Record Component Edit");
                PrefabUtility.RecordPrefabInstancePropertyModifications(script.Node.Result);
            }
 
            Flexalon.RecordFrameChanges = true;
        }
 
        protected void MarkDirty(FlexalonComponent script)
        {
            script.MarkDirty();
            Flexalon.GetOrCreate().UpdateDirtyNodes();
        }
 
        protected void ForceUpdate(FlexalonComponent script)
        {
            Record(script);
            script.ForceUpdate();
        }
    }
}