示例#1
0
        public static int VisibleProperties(this SerializedObject serializedObject, bool enterChildren = false)
        {
            var iterator = serializedObject.GetIterator();
            var next     = iterator.Next(true);

            if (!next)
            {
                return(0);
            }

            var num = 0;

            do
            {
                if (!FoCsEditor.IsPropertyHidden(iterator))
                {
                    ++num;
                }
            }while (iterator.NextVisible(enterChildren));

            return(num);
        }
        private bool DrawItemEditPanel(Item item)
        {
            using (FoCsEditor.Disposables.HorizontalScope(FoCsGUI.Styles.Toolbar, GUILayout.Height(16)))
                FoCsGUI.Layout.Label(string.Format("Editing: {0}", item.name), FoCsGUI.Styles.ToolbarButton, GUILayout.Height(16));


            using (var cc = FoCsEditor.Disposables.ChangeCheck())
            {
                FoCsGUI.GUIEvent <Texture> Icon;
                FoCsGUI.GUIEvent <string>  Name;
                FoCsGUI.GUIEvent <string>  Description;
                FoCsGUI.GUIEvent <int>     Value;
                FoCsGUI.GUIEvent <bool>    ShowInInventory;

                using (FoCsEditor.Disposables.LabelFieldSetWidth(200f))
                {
                    using (FoCsEditor.Disposables.HorizontalScope(GUILayout.Height(16 * 5), GUILayout.Height(16)))
                    {
                        FoCsGUI.Layout.GetControlRect(false, 16, GUILayout.Width(5));

                        using (FoCsEditor.Disposables.VerticalScope(GUILayout.Width(64)))
                        {
                            FoCsGUI.Layout.Label("Icon", GUILayout.Width(64));
                            Icon = FoCsGUI.Layout.ObjectField <Texture>(GUIContent.none, item.Icon, false, GUILayout.Width(64), GUILayout.Height(16 * 4));
                        }

                        using (FoCsEditor.Disposables.VerticalScope(GUILayout.ExpandWidth(true)))
                        {
                            FoCsGUI.Layout.Label();
                            Name            = FoCsGUI.Layout.TextField(new GUIContent("Name"), item.Name, GUILayout.Height(16));
                            Value           = FoCsGUI.Layout.IntField(new GUIContent("Value"), item.Value, GUILayout.Height(16));
                            ShowInInventory = FoCsGUI.Layout.ToggleField(new GUIContent("Show In Inventory"), item.ShowInInventory, GUILayout.Height(16));
                        }

                        using (FoCsEditor.Disposables.VerticalScope(GUILayout.Width(4)))
                        {
                            FoCsGUI.Layout.GetControlRect(false, GUILayout.Width(4));
                        }
                    }

                    using (FoCsEditor.Disposables.HorizontalScope())
                    {
                        using (FoCsEditor.Disposables.VerticalScope(GUILayout.ExpandHeight(true)))
                        {
                            FoCsGUI.Layout.Label("Description");
                            Description = FoCsGUI.Layout.TextArea(item.Description, GUILayout.Height(16 * 3));
                        }
                    }

                    using (FoCsEditor.Disposables.HorizontalScope(FoCsGUI.Styles.Toolbar, GUILayout.Height(FOOTER_HEIGHT)))
                    {
                        using (FoCsEditor.Disposables.ColorChanger(Color.red))
                        {
                            if (FoCsGUI.Layout.Button("Delete item: Warning this is an unrecoverable action. As it deletes the related Item Asset", FoCsGUI.Styles.ToolbarButton, GUILayout.Height(18)))
                            {
                                if (EditorUtility.DisplayDialog(string.Format("Delete Item:{0}", item.name), string.Format("Are you sure you want to delete Item:{0}\nAsset Name:{1}", item.Name, item.name), "Yes, Delete.", "No, Cancel."))
                                {
                                    AssetDatabase.DeleteAsset(FoCsEditor.AssetPath(item));
                                    RefreshAssets();
                                }
                            }
                        }
                    }
                }

                if (cc.changed)
                {
                    item.Icon            = Icon;
                    item.Name            = Name;
                    item.Description     = Description;
                    item.Value           = Value;
                    item.ShowInInventory = ShowInInventory;
                    EditorUtility.SetDirty(item);
                }
            }

            return(false);
        }