Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();

        CustomEditorUtility.DrawTitle(t.name.Replace("POW_", ""));

        CustomEditorUtility.QuickSerializeObject("cooldown", serializedObject);

        EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel);

        SerializedProperty actions = serializedObject.FindProperty("actions");

        for (int i = 0; i < actions.arraySize; i++)
        {
            EditorGUILayout.BeginVertical("box");
            SerializedProperty action = actions.GetArrayElementAtIndex(i);

            EditorGUILayout.BeginHorizontal();
            if (i < t.actions.Count)
            {
                t.actions[i].enabled = EditorGUILayout.Toggle(t.actions[i].enabled);
            }
            CustomEditorUtility.QuickSerializeRelative("delay", action);
            if (CustomEditorUtility.RemoveButton())
            {
                Undo.RecordObject(t, "Remove");
                t.actions.RemoveAt(i);
            }
            EditorGUILayout.EndHorizontal();

            CustomEditorUtility.QuickSerializeRelative("action", action);
            EditorGUILayout.EndVertical();
        }

        if (CustomEditorUtility.AddButton())
        {
            Undo.RecordObject(t, "Add");
            t.actions.Add(new PowerActionSettings());
        }

        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(t);
            Repaint();
        }
        serializedObject.ApplyModifiedProperties();
    }
Ejemplo n.º 2
0
    private void DrawSinglePool(int i, SerializedProperty pools)
    {
        if (i < m.pools.Count)
        {
            Color      defaultCol = GUI.color;
            GameObject prefab     = m.pools[i].prefab;
            string     name       = "Pool " + i;
            bool       hasPrefab  = prefab != null;
            bool       hasEntity  = true;

            EditorGUILayout.BeginVertical("box");

            if (hasPrefab)
            {
                hasEntity = prefab.GetComponentInChildren <Entity>();
                name     += ": " + prefab.name;
                if (!hasEntity)
                {
                    GUI.color = Color.red;
                }

                //if (elem) name += ": Level element";
            }

            else
            {
                GUI.color = Color.yellow;
                name     += ": No prefab ";
            }

            EditorGUILayout.BeginHorizontal();

            EditorGUI.indentLevel += 1;
            m.pools[i].foldout     = EditorGUILayout.Foldout(m.pools[i].foldout, name, EditorStyles.foldoutHeader);

            GUI.color              = defaultCol;
            EditorGUI.indentLevel -= 1;
            if (GUILayout.Button("x", GUILayout.MaxWidth(50)))
            {
                if (m.pools[i].parent)
                {
                    Undo.DestroyObjectImmediate(m.pools[i].parent.gameObject);
                }
                Undo.RecordObject(m, "Remove Pool");
                m.pools.RemoveAt(i);
            }
            EditorGUILayout.EndHorizontal();
            if (i < m.pools.Count)
            {
                if (m.pools[i].foldout)
                {
                    EditorGUILayout.Space();

                    SerializedProperty arrayElement = pools.GetArrayElementAtIndex(i);
                    CustomEditorUtility.QuickSerializeRelative("prefab", arrayElement);


                    if (hasPrefab)
                    {
                        if (!hasEntity)
                        {
                            EditorGUILayout.BeginHorizontal();

                            EditorGUILayout.HelpBox("Error : The specified prefab is not an entity. Please add an entity script on it.", MessageType.Error);
                            if (GUILayout.Button("Fix"))
                            {
                                Undo.AddComponent(prefab, typeof(Entity));
                                //prefab.AddComponent<Entity>();
                            }

                            EditorGUILayout.EndHorizontal();
                        }

                        else
                        {
                            CustomEditorUtility.QuickSerializeRelative("amount", arrayElement);
                            GUI.enabled = false;
                            CustomEditorUtility.QuickSerializeRelative("parent", arrayElement);
                            CustomEditorUtility.QuickSerializeRelative("entities", arrayElement);
                            GUI.enabled = true;

                            EditorGUILayout.Space();

                            int currentlyActive = m.UpdateCurrentlyActive(i);

                            Rect r     = EditorGUILayout.BeginVertical();
                            int  usage = Mathf.CeilToInt(m.pools[i].usage * 100);
                            EditorGUI.ProgressBar(r, m.pools[i].usage, "Current usage of the pool: " + usage.ToString("F2") + "% (" + currentlyActive + " out of " + m.pools[i].entities.Count + ")");
                            GUILayout.Space(18);
                            EditorGUILayout.EndVertical();
                        }
                    }

                    else
                    {
                        EditorGUILayout.HelpBox("Please assign a prefab.", MessageType.Warning);
                    }
                }
            }

            EditorGUILayout.EndVertical();
        }
    }