public override void EditItem(EquipmentType item)
        {
            base.EditItem(item);
            _equipmentHandlerDrawer = ReflectionDrawerUtility.BuildEditorHierarchy(ReflectionUtility.GetFieldInherited(item.GetType(), "equipmentHandler"), item);

            _restrictionList = new UnityEditorInternal.ReorderableList(selectedItem.blockTypes, typeof(int), false, true, true, true);
            _restrictionList.drawHeaderCallback  += rect => GUI.Label(rect, "Restrictions");
            _restrictionList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;
                rect.width -= 30;
                rect.x     += 30; // Some selection room

                if (index < 0 || index >= selectedItem.blockTypes.Length)
                {
                    return;
                }

                // Trying to block self, not allowed.
                if (selectedItem.blockTypes[index] == selectedItem)
                {
                    var t = rect;
                    t.width = 200;

                    GUI.backgroundColor = Color.red;
                    EditorGUI.LabelField(t, "Can't block self");

                    rect.x     += 205; // +5 for margin
                    rect.width -= 205;
                }

                ObjectPickerUtility.RenderObjectPickerForType(rect, string.Empty, selectedItem.blockTypes[index], typeof(EquipmentType),
                                                              (val) =>
                {
                    selectedItem.blockTypes[index] = (EquipmentType)val;
                });

                GUI.backgroundColor = Color.white;
            };
            _restrictionList.onAddCallback += list =>
            {
                var l = new List <EquipmentType>(selectedItem.blockTypes);
                l.Add(null);
                selectedItem.blockTypes = l.ToArray();
                list.list = selectedItem.blockTypes;

                window.Repaint();
            };
            _restrictionList.onRemoveCallback += list =>
            {
                // Remove the element itself
                var l = new List <EquipmentType>(selectedItem.blockTypes);
                l.RemoveAt(list.index);
                selectedItem.blockTypes = l.ToArray();
                list.list = selectedItem.blockTypes;

                window.Repaint();
            };
        }
        protected virtual void ValidateItem(T item)
        {
            var drawers = ReflectionDrawerUtility.BuildEditorHierarchy(item.GetType(), item);

            foreach (var drawer in drawers)
            {
                ValidateItem(item, drawer, false, false);
            }
        }
        private void UpdateIssuesFromType <T>(T t) where T : UnityEngine.Object
        {
            var drawers = ReflectionDrawerUtility.BuildEditorHierarchy(t.GetType(), t);

            foreach (var drawer in drawers)
            {
                UpdateIssueFromReflectionDrawerRecursive(drawer, t);
            }
        }
        private List<DrawerBase> GetMainDrawers()
        {
            var drawers = ReflectionDrawerUtility.BuildEditorHierarchy(target.GetType(), target).ToList();
            var editor = ReflectionDrawerUtility.TryGetCustomDrawer(null, target, null, -1, target.GetType()) as ChildrenValueDrawerBase;
            if (editor != null)
            {
                editor.children = drawers;
                return new List<DrawerBase>() { editor };
            }

            return drawers;
        }
Example #5
0
        private void Update(DialogueEditorWindow editor)
        {
            _editor     = editor;
            _nodeEditor = editor.selectedNodeEditors.FirstOrDefault();
            _edge       = editor.selectedEdges.FirstOrDefault();
            _edgeDrawers.Clear();

            if (_edge != null)
            {
                _edgeDrawers = ReflectionDrawerUtility.BuildEditorHierarchy(_edge.GetType(), _edge).ToList();
            }
        }
Example #6
0
        public virtual void Init(NodeBase node, DialogueEditorWindow editor)
        {
            this.node   = node;
            this.editor = editor;

            _childFields.Clear();

            drawers = ReflectionDrawerUtility.BuildEditorHierarchy(node.GetType(), node);
            foreach (var drawer in drawers)
            {
                _showInNodeDict[drawer] = drawer.fieldInfo.GetCustomAttributes(typeof(ShowInNodeAttribute), true).Length == 0;
            }
        }
        /// <summary>
        /// Validate all items and make sure they're set up correctly. If not render a warning icon in the crud list.
        /// </summary>
        private void ValidateItems()
        {
            foreach (var item in crudList)
            {
                if (item == null)
                {
                    continue;
                }

                var drawers = ReflectionDrawerUtility.BuildEditorHierarchy(item.GetType(), item);
                foreach (var drawer in drawers)
                {
                    var isValid = ValidateItem(item, drawer);
                    if (isValid == false)
                    {
                        break;
                    }
                }
            }
        }
        public override void Draw(Rect rect, DialogueEditorWindow editor)
        {
            // Little bit of caching..
            if (_lastDialogue != editor.dialogue || _isDirty)
            {
                _lastDialogue = editor.dialogue;
                _drawer       = ReflectionDrawerUtility.BuildEditorHierarchy(typeof(Dialogue).GetField("variables"), _lastDialogue);

                _isDirty = false;
            }

            _drawer.Draw(ref rect);

//            rect.y += EditorGUIUtility.singleLineHeight;
//            if (GUI.Button(rect, "Add generic type"))
//            {
//                var l = new List<Variable>(_lastDialogue.variables.Cast<Variable>());
//                l.Add(new Variable<Vector2>());
//                _lastDialogue.variables = l.ToArray();
//
//                _isDirty = true;
//            }
        }