Exemple #1
0
    // Draw inspector gui
    public void OnInspectorGUI(Action onValueChanged)
    {
        if (m_component == null)
        {
            m_component = new SerializedComponent("Attaching Components");
        }

        if (m_component.IsInvalidated)
        {
            m_component.Restore();
        }

        var newAttachPolicy = (AttachPolicy)EditorGUILayout.EnumFlagsField("Attach Policy", m_attachPolicy);

        if (newAttachPolicy != m_attachPolicy)
        {
            m_attachPolicy = newAttachPolicy;
            onValueChanged();
        }

        var newNameFormat = EditorGUILayout.TextField("Name Pattern", m_nameFormat);

        if (newNameFormat != m_nameFormat)
        {
            m_nameFormat = newNameFormat;
            onValueChanged();
        }

        EditorGUI.BeginChangeCheck();

        m_component.OnInspectorGUI();

        if (EditorGUI.EndChangeCheck())
        {
            m_component.Save();
            onValueChanged();
        }

        GUILayout.Space(10f);
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

        using (new EditorGUILayout.HorizontalScope()) {
            m_selectedIndex = EditorGUILayout.Popup("Component", m_selectedIndex, ComponentMenuUtility.GetComponentNames());

            using (new EditorGUI.DisabledScope(m_selectedIndex < 0)) {
                if (GUILayout.Button("Add", GUILayout.Width(40)))
                {
                    var type = ComponentMenuUtility.GetComponentTypes()[m_selectedIndex];

                    var c = m_component.AddComponent(type);
                    if (c != null)
                    {
                        m_component.Save();
                        onValueChanged();
                    }
                }
            }
        }
    }
Exemple #2
0
    // Draw inspector gui
    public void OnInspectorGUI(Action onValueChanged)
    {
        if (m_component == null)
        {
            m_component = new SerializedComponent();
        }

        if (m_component.IsInvalidated)
        {
            m_component.Restore();
            m_component.SyncAttachedComponents();

            if (m_goEditor == null)
            {
                m_goEditor = Editor.CreateEditor(m_component.InternalGameObject);
            }
        }

        var newAttachPolicy = (AttachPolicy)EditorGUILayout.EnumFlagsField("Attach Policy", m_attachPolicy);

        if (newAttachPolicy != m_attachPolicy)
        {
            m_attachPolicy = newAttachPolicy;
            onValueChanged();
        }

        var newNameFormat = EditorGUILayout.TextField("Name Pattern", m_nameFormat);

        if (newNameFormat != m_nameFormat)
        {
            m_nameFormat = newNameFormat;
            onValueChanged();
        }

        EditorGUI.BeginChangeCheck();

        m_goEditor.DrawHeader();

        GUILayout.Space(8f);

        EditorGUILayout.HelpBox("You can use {ParentName} variable for GameObject's naming.", MessageType.Info);

        GUILayout.Space(4f);

        // reset label Width ()
        EditorGUIUtility.labelWidth = 0;

        m_activePolicy        = (GameObjectPropertyPolicy)EditorGUILayout.EnumPopup("Active Flag", m_activePolicy);
        m_tagPolicy           = (GameObjectPropertyPolicy)EditorGUILayout.EnumPopup("Tag", m_tagPolicy);
        m_layerPolicy         = (GameObjectPropertyPolicy)EditorGUILayout.EnumPopup("Layer", m_layerPolicy);
        m_staticPolicy        = (GameObjectPropertyPolicy)EditorGUILayout.EnumPopup("Static Flags", m_staticPolicy);
        m_componentSyncPolicy = (ComponentSyncPolicy)EditorGUILayout.EnumPopup("Extra Component", m_componentSyncPolicy);

        GUILayout.Space(8f);

        m_component.OnInspectorGUI();

        if (EditorGUI.EndChangeCheck())
        {
            m_component.Save();
            onValueChanged();
        }

        GUILayout.Space(10f);
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

        using (new EditorGUILayout.HorizontalScope()) {
            m_selectedIndex = EditorGUILayout.Popup("Component", m_selectedIndex, ComponentMenuUtility.GetComponentNames());

            using (new EditorGUI.DisabledScope(m_selectedIndex < 0)) {
                if (GUILayout.Button("Add", GUILayout.Width(40)))
                {
                    var type = ComponentMenuUtility.GetComponentTypes()[m_selectedIndex];

                    var c = m_component.AddComponent(type);
                    if (c != null)
                    {
                        // addition of some component implicitly adds other component by RequireComponent attribute,
                        // so ensure to track everything added.
                        m_component.SyncAttachedComponents();
                        m_component.Save();
                        onValueChanged();
                    }
                }
            }
        }
    }
Exemple #3
0
    // Draw inspector gui
    public void OnInspectorGUI(Action onValueChanged)
    {
        if (m_component == null)
        {
            m_component = new SerializedComponent();
        }

        if (m_component.IsInvalidated)
        {
            m_component.Restore();
        }

        #if UNITY_2017_3_OR_NEWER
        var newAttachPolicy = (AttachPolicy)EditorGUILayout.EnumFlagsField("Attach Policy", m_attachPolicy);
        #else
        var newAttachPolicy = (AttachPolicy)EditorGUILayout.EnumMaskField("Attach Policy", m_attachPolicy);
        #endif
        if (newAttachPolicy != m_attachPolicy)
        {
            m_attachPolicy = newAttachPolicy;
            onValueChanged();
        }

        var newNameFormat = EditorGUILayout.TextField("Name Pattern", m_nameFormat);
        if (newNameFormat != m_nameFormat)
        {
            m_nameFormat = newNameFormat;
            onValueChanged();
        }

        using (new EditorGUILayout.HorizontalScope()) {
            m_selectedIndex = EditorGUILayout.Popup("Component", m_selectedIndex, ComponentMenuUtility.GetComponentNames());

            using (new EditorGUI.DisabledScope(m_selectedIndex < 0)) {
                if (GUILayout.Button("Add", GUILayout.Width(40)))
                {
                    var type = ComponentMenuUtility.GetComponentTypes()[m_selectedIndex];

                    var c = m_component.AddComponent(type);
                    if (c != null)
                    {
                        m_component.Save();
                        onValueChanged();
                    }
                }
            }
        }

        EditorGUI.BeginChangeCheck();

        SerializedComponent.ComponentInfo removingItem = null;

        foreach (var info in m_component.Components)
        {
            if (info.Editor != null)
            {
                DrawComponentHeader(info);
                GUILayout.BeginHorizontal();
                GUILayout.Space(16f);
                GUILayout.BeginVertical();
                info.Editor.DrawDefaultInspector();
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                using (new EditorGUILayout.HorizontalScope()) {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Remove", GUILayout.Width(60)))
                    {
                        removingItem = info;
                    }
                }
            }
        }

        if (removingItem != null)
        {
            m_component.RemoveComponent(removingItem);
        }

        if (EditorGUI.EndChangeCheck())
        {
            m_component.Save();
            onValueChanged();
        }
    }