Пример #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            itemsListProp.isExpanded = EditorGUILayout.Foldout(itemsListProp.isExpanded, new GUIContent("Items list"), true);
            if (itemsListProp.isExpanded)
            {
                EditorGUI.indentLevel++;
                itemsListProp.arraySize = EditorGUILayout.IntField(new GUIContent("Size"), itemsListProp.arraySize);
                for (int i = 0; i < itemsListProp.arraySize; i++)
                {
                    EditorGUILayout.ObjectField(itemsListProp.GetArrayElementAtIndex(i), new GUIContent($"Item {i}"));
                }
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Separator();

            EditorGUILayout.PropertyField(strIdProp);

            EditorGUILayout.PropertyField(idProp);

            if (GUILayout.Button("Open Editor"))
            {
                ItemDataEditorWindow.Open((ItemGroup)target);
            }

            serializedObject.ApplyModifiedProperties();
        }
Пример #2
0
        public static bool OpenEditor(int instanceId, int line)
        {
            ItemGroup obj = EditorUtility.InstanceIDToObject(instanceId) as ItemGroup;

            if (obj != null)
            {
                ItemDataEditorWindow.Open(obj);
                return(true);
            }
            return(false);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.PropertyField(position, property);

            var buttonRect = new Rect(position.x, position.y, 170, position.height);

            if (property.objectReferenceValue != null)
            {
                if (GUI.Button(buttonRect, new GUIContent("Open Editor of " + label.text)))
                {
                    ItemDataEditorWindow.Open(property.objectReferenceValue as ItemGroup);
                }
            }

            //base.OnGUI(position, property, label);
        }
        public static void Open(ItemGroup dataObject)
        {
            ItemDataEditorWindow window = GetWindow <ItemDataEditorWindow>("Item Group Editor");

            window.serializedObject = new SerializedObject(dataObject);
        }
Пример #5
0
        void OnGUI()
        {
            EditorGUILayout.BeginVertical("Toolbar", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(500));
            GUILayout.BeginArea(new Rect((Screen.width / 2) - 250, 1, 500, 18));

            selected = GUILayout.Toolbar(selected, new string[3] {
                "Inventory", "InventoryUI", "Debug"
            });

            GUILayout.EndArea();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            if (selected == 0)
            {
                EditorGUILayout.LabelField("Inventories");
                for (int i = 0; i < InventoryController.inventories.Count; i++)
                {
                    var a = InventoryController.inventories[i];
                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField($"{a.key} (id: {a.id})");
                    EditorGUILayout.EnumFlagsField(a.interactiable);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.LabelField($"Size: {a.SlotAmount}");

                    MakeHeader();

                    for (int j = 0; j < a.slots.Count; j++)
                    {
                        Slot s = a.slots[j];

                        EditorGUILayout.BeginHorizontal();
                        var rect = GUILayoutUtility.GetRect(100, 18);
                        rect.x     += 10;
                        rect.width -= 20;
                        HR(rect);

                        if (s.HasItem)
                        {
                            EditorGUI.LabelField(rect, new GUIContent(" Has Item   ", EditorGUIUtility.IconContent("TestPassed").image));
                        }
                        else
                        {
                            EditorGUI.LabelField(rect, new GUIContent(" Hasn't Item ", EditorGUIUtility.IconContent("TestFailed").image));
                        }

                        rect.x += 100;

                        DrawLine(rect, 18);

                        if (s.item != null)
                        {
                            var soRect = rect;
                            soRect.height = 16;
                            EditorGUI.LabelField(soRect, new GUIContent(s.item.itemName, EditorGUIUtility.IconContent("ScriptableObject Icon").image));
                            rect.x += 100;
                            DrawLine(rect, 18);
                            EditorGUI.LabelField(rect, s.amount.ToString());
                            rect.x += 80;
                            DrawLine(rect, 18);
                            EditorGUI.LabelField(rect, $"{s.durability} | {s.item.hasDurability}");
                            rect.x += 110;
                            DrawLine(rect, 18);
                        }
                        else
                        {
                            EditorGUI.LabelField(rect, "None");
                            rect.x += 100;
                            DrawLine(rect, 18);
                            rect.x += 80;
                            DrawLine(rect, 18);
                            rect.x += 110;
                            DrawLine(rect, 18);
                        }
                        EditorGUI.LabelField(rect, s.isProductSlot.ToString());
                        rect.x += 100;
                        DrawLine(rect, 18);

                        var auxRect = rect;
                        auxRect.height = 16;
                        auxRect.width  = 130;
                        GUIContent content = new GUIContent(s.whitelist == null ? "" : s.whitelist.strId, EditorGUIUtility.IconContent("ScriptableObject Icon").image);
                        if (GUI.Button(auxRect, s.whitelist == null ? new GUIContent("None") : content))
                        {
                            if (s.whitelist != null)
                            {
                                ItemDataEditorWindow.Open(s.whitelist);
                            }
                        }

                        rect.x += 140;
                        DrawLine(rect, 18);

                        auxRect        = rect;
                        auxRect.width  = 130;
                        auxRect.height = 16;
                        content        = new GUIContent(s.ItemInstance == null ? "" : s.ItemInstance.itemName, EditorGUIUtility.IconContent("ScriptableObject Icon").image);
                        if (GUI.Button(auxRect, s.ItemInstance == null ? new GUIContent("None") : content) && s.ItemInstance != null)
                        {
                            ItemInstanceInspector window = GetWindow <ItemInstanceInspector>("Item Inspector");
                            window.Show();
                            window.itemTarget = s.ItemInstance;
                        }

                        EditorGUILayout.EndHorizontal();
                    }

                    EditorGUILayout.EndVertical();
                }
            }
            else if (selected == 1)
            {
                EditorGUILayout.LabelField("InventoriesUI");
                if (!Application.isPlaying)
                {
                    EditorGUILayout.LabelField("This only works in play mode");
                }
                for (int i = 0; i < InventoryController.inventoriesUI.Count; i++)
                {
                    InventoryUI ui  = InventoryController.inventoriesUI[i];
                    var         obj = new SerializedObject(ui);
                    obj.Update();
                    var prop = obj.GetIterator().Copy();
                    EditorGUILayout.Separator();
                    HR(GUILayoutUtility.GetRect(100, 18));
                    if (prop.NextVisible(true))
                    {
                        do
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.PropertyField(prop);
                            EditorGUI.EndDisabledGroup();
                        } while (prop.NextVisible(false));
                    }
                }
            }
            else if (selected == 2)
            {
                EditorGUILayout.LabelField("Debugging");

                if (Application.isPlaying)
                {
                    var          bf      = BindingFlags.Public | BindingFlags.Static;
                    var          mt      = MemberTypes.Method;
                    MemberInfo[] members = typeof(InventoryController).FindMembers(mt, bf, (MemberInfo mi, object search) => true, null);

                    foreach (MemberInfo mi in members)
                    {
                        var method = mi as MethodInfo;
                        if (GUILayout.Button(method.Name))
                        {
                            MethodExecutor window = GetWindow <MethodExecutor>("Invoker");
                            window.Show();
                            window.mi          = method;
                            window.param       = new List <object>();
                            window.obj         = null;
                            window.returnValue = null;
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("This tool should only be used in play mode");
                }
            }

            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }