Beispiel #1
0
    void OnEnable()
    {
        list = new ReorderableList(serializedObject,
                                   serializedObject.FindProperty("bursts"),
                                   true, true, true, true);

        list.drawHeaderCallback = (Rect rect) =>
        {
            EditorGUI.LabelField(rect, "Bursts");
        };

        list.drawElementCallback =
            (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            rect.y += 2;

            EditorGUI.LabelField(new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight), "Direction");
            element.FindPropertyRelative("angle").floatValue = CustomGUI.Knob(new Rect(rect.x + 5, rect.y + EditorGUIUtility.singleLineHeight, 40, 40), element.FindPropertyRelative("angle").floatValue, element.FindPropertyRelative("spread").floatValue);
            EditorGUI.LabelField(new Rect(rect.x + 65, rect.y, 60, EditorGUIUtility.singleLineHeight), "Spread");
            element.FindPropertyRelative("spread").floatValue = EditorGUI.Slider(new Rect(rect.x + 65, rect.y + EditorGUIUtility.singleLineHeight, rect.width - 65 - 80, EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("spread").floatValue, 0, 360);
            EditorGUI.PropertyField(
                new Rect(rect.x + 65, rect.y + EditorGUIUtility.singleLineHeight * 2 + 4, rect.width - 65 - 80, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("prefab"), GUIContent.none);
            EditorGUI.LabelField(new Rect(rect.x + rect.width - 80, rect.y, 60, EditorGUIUtility.singleLineHeight), "Amount");
            EditorGUI.PropertyField(
                new Rect(rect.x + rect.width - 30, rect.y, 30, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("amount"), GUIContent.none);
        };

        list.elementHeight = EditorGUIUtility.singleLineHeight + 40 + 6;
    }
Beispiel #2
0
    void OnEnable()
    {
        list = new ReorderableList(serializedObject,
                                   serializedObject.FindProperty("charges"),
                                   true, true, true, true);

        list.drawHeaderCallback = (Rect rect) =>
        {
            EditorGUI.LabelField(rect, "Charges");
        };

        list.drawElementCallback =
            (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            rect.y += 2;

            EditorGUI.LabelField(new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight), "Direction");
            element.FindPropertyRelative("angle").floatValue = CustomGUI.Knob(new Rect(rect.x + 5, rect.y + EditorGUIUtility.singleLineHeight, 40, 40), element.FindPropertyRelative("angle").floatValue, false);
            EditorGUI.LabelField(new Rect(rect.x + 65, rect.y, 60, EditorGUIUtility.singleLineHeight), "Distance");
            element.FindPropertyRelative("distance").floatValue = EditorGUI.Slider(new Rect(rect.x + 65, rect.y + EditorGUIUtility.singleLineHeight, rect.width - 65 - 80, EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("distance").floatValue, 0, 10);
        };

        list.elementHeight = EditorGUIUtility.singleLineHeight + 40 + 6;
    }
Beispiel #3
0
    public override void OnInspectorGUI()
    {
        playable = (SpawnClip)this.target;

        if (playable.enemies == null)
        {
            playable.enemies = new List <Spawn>();
        }

        serializedObject.Update();

        EditorGUILayout.PropertyField(serializedObject.FindProperty("spawner"));

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
        if (GUILayout.Button("Add Pawn"))
        {
            Spawn sp = new Spawn();
            sp.position = UnityEngine.Random.insideUnitCircle;
            sp.col      = UnityEngine.Random.ColorHSV(0, 1, 1, 1, 1, 1, 0.5f, 0.6f);
            sp.angle    = 180;
            playable.enemies.Add(sp);
            serializedObject.ApplyModifiedProperties();
            serializedObject.Update();
        }

        for (int i = 0; i < playable.enemies.Count; i++)
        {
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Delete " + (char)('A' + (char)i), GUILayout.Width(60)))
            {
                playable.enemies.RemoveAt(i);
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
                break;
            }
            SerializedProperty enemy = serializedObject.FindProperty("enemies").GetArrayElementAtIndex(i);
            EditorGUILayout.ObjectField(enemy.FindPropertyRelative("enemy"), typeof(GameObject), GUIContent.none, GUILayout.Width(150));
            enemy.FindPropertyRelative("angle").intValue = (int)CustomGUI.Knob(enemy.FindPropertyRelative("angle").intValue, Color.red);
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical(GUILayout.MinWidth(150), GUILayout.Width(150));
        List <Vector2> pos   = playable.enemies.ConvertAll(getPos);
        List <int>     angle = playable.enemies.ConvertAll(getAngle);
        List <Color>   col   = playable.enemies.ConvertAll(getCol);

        EditorGUI.BeginChangeCheck();
        pos = CustomGUI.Grid(pos, angle, col, GUILayout.Width(150), GUILayout.Height(250));
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(playable, "Modify Spawn");
        }
        for (int i = 0; i < playable.enemies.Count; i++)
        {
            playable.enemies[i].position = new Vector2((pos[i].x - 75) / 75f, (pos[i].y - 125) / 125f);
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        serializedObject.ApplyModifiedProperties();

        showDefault = EditorGUILayout.Toggle("Show advanced configuration", showDefault);
        if (showDefault)
        {
            this.DrawDefaultInspector();
        }
    }