示例#1
0
    void CreateNode(Transform t, Node msg, bool is_dont_destroy_onload)
    {
        GameObject o = new GameObject(msg.name);

        o.transform.SetParent(t);
        o.SetActive(msg.active);
        DumpObj dump = o.AddComponent <DumpObj>();

        dump.Init(msg.active, OnStateChange, OnBehaviorChange);

        if (is_dont_destroy_onload)
        {
            DontDestroyOnLoad(o);
        }

        foreach (var item in msg.list)
        {
            if (item.is_component)
            {
                dump.AddComp(item.name, item.active);
            }
            else
            {
                CreateNode(o.transform, item, false);
            }
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        int size = _list_components.arraySize;

        for (int i = 0; i < size; i++)
        {
            SerializedProperty obj             = _list_components.GetArrayElementAtIndex(i);
            SerializedProperty name_property   = obj.FindPropertyRelative("name");
            SerializedProperty active_property = obj.FindPropertyRelative("active");

            bool pre_state = active_property.boolValue;
            active_property.boolValue = EditorGUILayout.Toggle(name_property.stringValue, active_property.boolValue);

            if (pre_state != active_property.boolValue)
            {
                DumpObj dump = (DumpObj)serializedObject.targetObject;
                dump.OnBehaviorChange(name_property.stringValue, active_property.boolValue);
            }
        }

        serializedObject.ApplyModifiedProperties();
    }