Пример #1
0
    Editor GetComponentEditor(GameObject obj, string createText, string destroyText, ref GamePrefabComponentEditor componentEditor)
    {
        System.Type componentType = componentEditor.componentType;
        Component   comp          = obj.GetComponent(componentType);

        if (!comp)
        {
            if (GUILayout.Button(createText))
            {
                comp = obj.AddComponent(componentType);
            }
        }
        else
        {
            if (GUILayout.Button(destroyText))
            {
                DestroyImmediate(comp);
                componentEditor.DestroyEditor();
            }
        }

        if (componentEditor.component != comp)
        {
            componentEditor.DestroyEditor();
            componentEditor.CreateEditor(comp);
        }

        return(componentEditor.editor);
    }
Пример #2
0
    Editor GetForcedComponentEditor(GameObject obj, ref GamePrefabComponentEditor componentEditor)
    {
        System.Type componentType = componentEditor.componentType;
        Component   comp          = obj.GetComponent(componentType);

        if (!comp)
        {
            comp = obj.AddComponent(componentType);
        }

        if (componentEditor.component != comp)
        {
            componentEditor.DestroyEditor();
            componentEditor.CreateEditor(comp);
        }

        return(componentEditor.editor);
    }