示例#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.
        unitName = EditorGUILayout.TextField("Tile Name", unitName);
        GUILayout.Space(10);         // create some space on the window. Allows us to space out our ui elements

        index    = EditorGUILayout.Popup("Unit Type", index, unitTypes);
        unitType = unitTypes[index];

        GUILayout.Space(10);

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

        GUILayout.Space(10);

        if (GUILayout.Button("Accept"))
        {
            // Create Accept button. When user presses this button, we want to call our ScriptableObjectUtility to create a prefab.
            ScriptableObjectUtility.CreateUnit(unitName, unitType, unitSprite);
            this.Close();             // close window
        }
        else if (GUILayout.Button("Cancel"))
        {
            this.Close();
        }
    }
    void OnGUI()

    {
        _name = EditorGUILayout.TextField("Name", _name);
        _hp   = EditorGUILayout.FloatField("HP", _hp);
        _atk  = EditorGUILayout.FloatField("ATK", _atk);
        _def  = EditorGUILayout.FloatField("DEF", _def);
        _spd  = EditorGUILayout.FloatField("SPD", _spd);


        if (_name == null)
        {
            _name = "Default";
        }
        if (_hp < 0)
        {
            _hp = 0;
        }
        if (_atk < 0)
        {
            _atk = 0;
        }
        if (_def < 0)
        {
            _def = 0;
        }
        if (_spd < 0)
        {
            _spd = 0;
        }
        if (_int < 0)
        {
            _int = 0;
        }
        if (_acc < 0)
        {
            _acc = 0;
        }



        if (GUILayout.Button("Create unit"))
        {
            ScriptableObjectUtility.CreateUnit <Unit>(_name, _acc, _atk, _def, _hp, _int, _spd);
        }
    }