Beispiel #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label = EditorGUI.BeginProperty(position, label, property);

            if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                Dictionary <string, NPCTypeInfo> npcTypeDic = RTSEditorHelper.GetNPCTypes();

                index = npcTypeDic.Values.ToList().IndexOf(property.objectReferenceValue as NPCTypeInfo);

                if (index < 0) //make sure the index value is always valid
                {
                    index = 0;
                }

                index = EditorGUI.Popup(position, label.text, index, npcTypeDic.Keys.ToArray());

                property.objectReferenceValue = npcTypeDic[npcTypeDic.Keys.ToArray()[index]] as Object;
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use [NPCType] with object reference fields.");
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label = EditorGUI.BeginProperty(position, label, property);

            Dictionary <string, ResourceTypeInfo> resourceTypeDic = RTSEditorHelper.GetResourceTypes();

            if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                index = resourceTypeDic.Values.ToList().IndexOf(property.objectReferenceValue as ResourceTypeInfo);
            }
            else if (property.propertyType == SerializedPropertyType.String)
            {
                index = resourceTypeDic.Keys.ToList().IndexOf(property.stringValue);
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use [ResourceType] with object reference or string fields.");
                return;
            }

            if (index < 0) //make sure the index value is always valid
            {
                index = 0;
            }

            index = EditorGUI.Popup(position, label.text, index, resourceTypeDic.Keys.ToArray());

            if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                property.objectReferenceValue = resourceTypeDic[resourceTypeDic.Keys.ToArray()[index]] as Object;
            }
            else if (property.propertyType == SerializedPropertyType.String)
            {
                property.stringValue = resourceTypeDic.Keys.ToArray()[index];
            }
        }
Beispiel #3
0
        protected virtual void ListTabSettings(SerializedObject so, string title, string listProperty, bool singleTab = false)
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(title, titleGUIStyle);
            EditorGUILayout.Space();

            EditorGUILayout.HelpBox("Navigate, add or remove elements using the buttons below", MessageType.Info);
            EditorGUILayout.Space();

            int count = so.FindProperty(listProperty).arraySize;

            if (GUILayout.Button("Add (Count: " + count.ToString() + ")"))
            {
                so.FindProperty(listProperty).InsertArrayElementAtIndex(count);

                elementID = count;
                count++;
            }

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("<<"))
                {
                    RTSEditorHelper.Navigate(ref elementID, -1, count);
                }
                if (GUILayout.Button(">>"))
                {
                    RTSEditorHelper.Navigate(ref elementID, 1, count);
                }
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.Space();

            //making sure there are elements to begin with:
            if (count > 0)
            {
                //element to display:
                string elementPath = $"{listProperty}.Array.data[{elementID}]";

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Element ID: " + elementID.ToString(), titleGUIStyle);
                EditorGUILayout.Space();

                if (singleTab) //if we only have one single tab,
                {
                    GeneralElementSettings(so, elementPath);
                }
                else
                {
                    titleGUIStyle.alignment = TextAnchor.MiddleLeft;
                    titleGUIStyle.fontStyle = FontStyle.Bold;

                    EditorGUI.BeginChangeCheck();

                    tabID = GUILayout.Toolbar(tabID, new string[] { "General Settings", "Custom Settings", "Events" });

                    switch (tabID)
                    {
                    case 0:
                        tabName = "General Settings";
                        break;

                    case 1:
                        tabName = "Custom Settings";
                        break;

                    case 2:
                        tabName = "Events";
                        break;

                    default:
                        break;
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        so.ApplyModifiedProperties();
                        GUI.FocusControl(null);
                    }

                    EditorGUILayout.Space();

                    switch (tabName)
                    {
                    case "General Settings":
                        GeneralElementSettings(so, elementPath);
                        break;

                    case "Custom Settings":
                        CustomElementSettings(so, elementPath);
                        break;

                    case "Events":
                        ElementEventsSettings(so, elementPath);

                        break;

                    default:
                        break;
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.Space();
                if (GUILayout.Button("Delete"))
                {
                    so.FindProperty($"{listProperty}").DeleteArrayElementAtIndex(elementID);
                    if (elementID > 0)
                    {
                        RTSEditorHelper.Navigate(ref elementID, -1, count);
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There are no elements, create one using the button above.", MessageType.Warning);
            }
        }
Beispiel #4
0
 public void OnEnable()
 {
     target_SO = new SerializedObject(target as NPCTypeInfo);
     RTSEditorHelper.GetNPCTypes(true, target as NPCTypeInfo);
 }