Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        var entity = (RegisterAsEntity)target;

        EditorGUILayout.BeginHorizontal(GUI.skin.box);
        entity.PoolName = EditorGUILayout.TextField("Pool Name:", entity.PoolName);
        EditorGUILayout.EndHorizontal();

        if (entity.Components != null)
        {
            EditorGUILayout.Space();
            foreach (var component in entity.Components)
            {
                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.BeginHorizontal();
                var foldoutState = DrawFoldout(component);
                if (PopupButtonClicked())
                {
                    DisplayComponentMenu(entity, component);
                }
                EditorGUILayout.EndHorizontal();
                if (foldoutState)
                {
                    DrawComponent(entity.gameObject, component);
                }
                EditorGUILayout.EndVertical();
            }
            if (AddComponentButtonClicked())
            {
                BuildEntityWindow.Show(entity.gameObject, entity.Components);
            }
        }

        if (GUI.changed)
        {
            Undo.RecordObject(entity, "Entity Editor Modify");
            EditorUtility.SetDirty(entity);
            EditorSceneManager.MarkSceneDirty(entity.gameObject.scene);
        }
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        var entity = (PrototypeSettings)target;

        EditorGUILayout.BeginHorizontal(GUI.skin.box);
        entity.Name = EditorGUILayout.TextField("Name:", entity.Name);
        EditorGUILayout.EndHorizontal();

        if (entity.Components != null)
        {
            EditorGUILayout.LabelField("Components:");
            foreach (var component in entity.Components)
            {
                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.BeginHorizontal();
                var foldoutState = DrawFoldout(component);
                if (PopupButtonClicked())
                {
                    DisplayComponentMenu(entity, component);
                }
                EditorGUILayout.EndHorizontal();
                if (foldoutState)
                {
                    DrawComponent(component);
                }
                EditorGUILayout.EndVertical();
            }
            if (AddComponentButtonClicked())
            {
                BuildEntityWindow.Show(null, entity.Components, EntityWindowTabs.Components);
            }
        }

        if (GUI.changed)
        {
            Undo.RecordObject(entity, "Entity Editor Modify");
            EditorUtility.SetDirty(entity);
        }
    }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        var blueprint = (BlueprintSettings)target;

        EditorGUILayout.BeginHorizontal(GUI.skin.box);
        blueprint.Name = EditorGUILayout.TextField("Name:", blueprint.Name);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal(GUI.skin.box);
        blueprint.Object = EditorGUILayout.ObjectField("Object:", blueprint.Object, typeof(GameObject), true) as GameObject;
        EditorGUILayout.EndHorizontal();

        if (blueprint.Components != null)
        {
            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Components:");
            if (AddComponentButtonClicked())
            {
                BuildEntityWindow.Show(null, blueprint.Components, EntityWindowTabs.Components);
            }
            EditorGUILayout.EndHorizontal();
            foreach (var component in blueprint.Components)
            {
                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.BeginHorizontal();
                var foldoutState = DrawFoldout(component);
                if (PopupButtonClicked())
                {
                    DisplayComponentMenu(blueprint, component);
                }
                EditorGUILayout.EndHorizontal();
                if (foldoutState)
                {
                    DrawComponent(blueprint.Object, component);
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (blueprint.Object != null && GUILayout.Button("Apply", GUILayout.Height(20f), GUILayout.Width(80f)))
        {
            var entity = blueprint.Object.GetComponent <RegisterAsEntity>() ?? blueprint.Object.AddComponent <RegisterAsEntity>();
            entity.Components = blueprint.Components;

            // add component wrappers to gameObject
            if (blueprint.Components != null)
            {
                foreach (var entityComponent in blueprint.Components.Where(x => x.WrapperType != null))
                {
                    if (blueprint.Object.GetComponent(entityComponent.WrapperType) == null)
                    {
                        blueprint.Object.AddComponent(entityComponent.WrapperType);
                    }
                }
            }
        }

        // todo auto update on data change
        if (GUILayout.Button("Generate", GUILayout.Height(20f), GUILayout.Width(80f)))
        {
            var gen = new BlueprintGenerator("Game/Blueprints/", blueprint);
            gen.Generate();
            AssetDatabase.Refresh();
        }
        EditorGUILayout.EndHorizontal();

        if (GUI.changed)
        {
            Undo.RecordObject(blueprint, "Entity Editor Modify");
            EditorUtility.SetDirty(blueprint);
        }
    }