示例#1
0
    void OnGUI()
    {
        // OnGUI is called even when the game is not playing. This allows us to create functionality that updates in editor mode

        this.Repaint();         // refresh the popup window

        // Create a text field for the name of the prefab we want to make. Assign tileName to the string that's in the name text field.
        tileName = EditorGUILayout.TextField("Tile Name", tileName);
        GUILayout.Space(10);         // create some space on the window. Allows us to space out our ui elements

        // create a tag field that allows the user to specify the type of terrain this tile should be. Assign terrainTag string to the chosen tag.
        terrainTag = EditorGUILayout.TagField("Terrain/Building type", terrainTag);

        GUILayout.Space(10);

        // create a sprite field. Allows user to select a sprite to use for the tile. Assign tileSprite to this object
        tileSprite = EditorGUILayout.ObjectField("Sprite", tileSprite, typeof(Sprite), true);

        if (GUILayout.Button("Accept"))
        {
            // Create Accept button. When user presses this button, we want to call our ScriptableObjectUtility to create a prefab.
            ScriptableObjectUtility.CreateTile(tileName, terrainTag, tileSprite);
            this.Close();             // close window
        }
        else if (GUILayout.Button("Cancel"))
        {
            this.Close();
        }
    }