コード例 #1
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();
        }
コード例 #2
0
        public void OnGUI()
        {
            if (itemTarget == null)
            {
                return;
            }
            EditorGUILayout.LabelField(itemTarget.itemName);

            MemberTypes  mt = MemberTypes.Field | MemberTypes.Property | MemberTypes.Method;
            BindingFlags bf = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic;

            MemberInfo[] members = itemTarget.GetType().FindMembers(mt, bf, (MemberInfo mi, object search) => true, null);

            EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            scrollPosItem = EditorGUILayout.BeginScrollView(scrollPosItem);
            foreach (MemberInfo mi in members)
            {
                var rect = GUILayoutUtility.GetRect(100, 20);
                rect.x     += 10;
                rect.width -= 20;
                InventoryControllerWindow.HR(rect);
                EditorGUI.LabelField(rect, mi.Name);
                rect.x += 200;
                InventoryControllerWindow.DrawLine(rect, 20);
                rect.width -= 205;
                rect.height = 18;
                try
                {
                    switch (mi.MemberType)
                    {
                    case MemberTypes.Field:
                        HandleField(mi as FieldInfo, rect);
                        break;

                    case MemberTypes.Property:
                        var prop = (mi as PropertyInfo).GetValue(itemTarget);
                        if (prop == null)
                        {
                            break;
                        }
                        EditorGUI.LabelField(rect, (mi as PropertyInfo).GetValue(itemTarget).ToString());
                        break;

                    case MemberTypes.Method:
                        var method = (mi as MethodInfo);
                        if (method == null)
                        {
                            break;
                        }
                        if (GUI.Button(rect, (mi as MethodInfo).Name))
                        {
                            MethodExecutor window = GetWindow <MethodExecutor>("Invoker");
                            window.Show();
                            window.mi          = method;
                            window.param       = new List <object>();
                            window.obj         = itemTarget;
                            window.returnValue = null;
                        }
                        break;
                    }
                }
                catch (Exception) { }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }