示例#1
0
 internal void Render(AIInspectorState state)
 {
     for (int i = 0; i < fieldCategories.Length; i++)
     {
         fieldCategories[i].Render(state, dependencyChecker);
     }
 }
示例#2
0
        public sealed override void RenderField(AIInspectorState state)
        {
            // solution found in EditorGUILayout.Vector4Field in UnityEditor namespace (decompiled)
            var controlRect = EditorGUILayout.GetControlRect(true, 32f, EditorStyles.numberField);

            _vector4Arr[0] = _curValue.x;
            _vector4Arr[1] = _curValue.y;
            _vector4Arr[2] = _curValue.z;
            _vector4Arr[3] = _curValue.w;

            controlRect.height = 16f;
            GUI.Label(EditorGUI.IndentedRect(controlRect), _label, EditorStyles.label);
            controlRect.y += 16f;

            EditorGUI.BeginChangeCheck();
            EditorGUI.indentLevel += 1;
            EditorGUI.MultiFloatField(controlRect, _labelsArr, _vector4Arr);
            EditorGUI.indentLevel -= 1;

            if (EditorGUI.EndChangeCheck())
            {
                _curValue.x = _vector4Arr[0];
                _curValue.y = _vector4Arr[1];
                _curValue.z = _vector4Arr[2];
                _curValue.w = _vector4Arr[3];

                UpdateValue(_curValue, state);
            }
        }
示例#3
0
        private bool DrawEditorItem(EditorItem item, AIInspectorState state)
        {
            var result = false;

            // Item Header
            EditorGUILayout.BeginHorizontal(SharedStyles.BuiltIn.listItemHeader);

            EditorGUILayout.LabelField(item.name, SharedStyles.BuiltIn.normalText);

            if (GUILayout.Button(SharedStyles.deleteTooltip, SharedStyles.BuiltIn.deleteButtonSmall))
            {
                result = true;

                // We do not want the button click itself to count as a change. Since no other changes are expected when a button click is encountered, we can just set it to false.
                GUI.changed = false;
            }

            EditorGUILayout.EndHorizontal();

            // Item fields
            item.Render(state);
            EditorGUILayout.Separator();

            //warning on duplicate key
            if (((IKeyedItem)item.item).isDuplicate)
            {
                EditorGUILayout.HelpBox("Duplicate Key", MessageType.Error);
            }

            return(result);
        }
示例#4
0
        protected override void DoRemove(int removeIdx, AIInspectorState state)
        {
            var item = _list[removeIdx];

            _list.RemoveAt(removeIdx);
            state.currentAIUI.undoRedo.Do(new ListFieldRemoveOperation(_list, removeIdx, item));
        }
示例#5
0
 public sealed override void RenderField(AIInspectorState state)
 {
     var val = EditorGUILayout.FloatField(_label, _curValue, EditorStyles.numberField);
     if (val != _curValue)
     {
         UpdateValue(val, state);
     }
 }
示例#6
0
        public sealed override void RenderField(AIInspectorState state)
        {
            var val = (double)EditorGUILayout.FloatField(_label, Convert.ToSingle(_curValue), EditorStyles.numberField);

            if (val != _curValue)
            {
                UpdateValue(val, state);
            }
        }
示例#7
0
        private void HandleVisualizerRemove(AIInspectorState state, int idx)
        {
            var visualizers = GetVisualizers(state);

            foreach (var cv in visualizers)
            {
                cv.children.RemoveAt(idx);
            }
        }
示例#8
0
        protected void HandleVisualizerAdd(AIInspectorState state, object item)
        {
            var visualizers = GetVisualizers(state);

            foreach (var cv in visualizers)
            {
                cv.Add(item);
            }
        }
示例#9
0
        private void HandleVisualizerReorder(AIInspectorState state, int fromIdx, int toIdx)
        {
            var visualizers = GetVisualizers(state);

            foreach (var cv in visualizers)
            {
                cv.children.Reorder(fromIdx, toIdx);
            }
        }
示例#10
0
        public sealed override void RenderField(AIInspectorState state)
        {
            var val = (short)EditorGUILayout.IntSlider(_label, _curValue, short.MinValue, short.MaxValue);

            if (val != _curValue)
            {
                UpdateValue(val, state);
            }
        }
        public sealed override void RenderField(AIInspectorState state)
        {
            var val = EditorGUILayout.EnumMaskField(_label, _curValue);

            if (!val.Equals(_curValue))
            {
                UpdateValue(val, state);
            }
        }
示例#12
0
        public override void RenderField(AIInspectorState state)
        {
            var val = EditorGUILayout.CurveField(_label, _curValue);

            if (val != _curValue)
            {
                UpdateValue(val, state);
            }
        }
示例#13
0
        public sealed override void RenderField(AIInspectorState state)
        {
            var  stringVal = EditorGUILayout.TextField(_label, _curValue.ToString(), EditorStyles.textField);
            char val       = stringVal.Length > 0 ? stringVal[0] : '\0';

            if (val != _curValue)
            {
                UpdateValue(val, state);
            }
        }
示例#14
0
        protected override void DoAdd(object item, AIInspectorState state)
        {
            var arr = (Array)_list;
            var tmp = Array.CreateInstance(_itemType, arr.Length + 1);

            Array.Copy(arr, 0, tmp, 0, arr.Length);
            tmp.SetValue(item, arr.Length);
            _setter(tmp);

            state.currentAIUI.undoRedo.Do(new ArrayFieldAddOperation(tmp, _setter, item));
        }
示例#15
0
        internal void Render(AIInspectorState state, DependencyChecker dependencyChecker)
        {
            EditorGUILayout.Separator();

            bool hasCategory = !string.IsNullOrEmpty(this.name);

            if (hasCategory)
            {
                if (_shownFields == null)
                {
                    _shownFields = new List <IEditorField>(fields.Length);
                }
                else
                {
                    _shownFields.Clear();
                }

                for (int i = 0; i < fields.Length; i++)
                {
                    var f = fields[i];
                    if (dependencyChecker.AreDependenciesSatisfied(f.memberName))
                    {
                        _shownFields.Add(f);
                    }
                }

                if (_shownFields.Count == 0)
                {
                    return;
                }

                EditorGUILayout.LabelField(this.name, EditorStyles.label);
                EditorGUI.indentLevel += 1;

                foreach (var f in _shownFields)
                {
                    f.RenderField(state);
                }

                EditorGUI.indentLevel -= 1;
            }
            else
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    var f = fields[i];
                    if (dependencyChecker.AreDependenciesSatisfied(f.memberName))
                    {
                        fields[i].RenderField(state);
                    }
                }
            }
        }
示例#16
0
        public void RenderField(AIInspectorState state)
        {
            var evt      = Event.current;
            var mousePos = evt.mousePosition;
            var boxStyle = new GUIStyle("Box");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(_label);
            EditorGUILayout.Separator();
            if (GUILayout.Button(SharedStyles.addTooltip, SharedStyles.BuiltIn.addButtonSmall))
            {
                AddNew(mousePos, state);
            }

            EditorGUILayout.EndHorizontal();

            var count = _editorItems.Count;

            if (count == 0)
            {
                return;
            }

            EditorGUILayout.BeginVertical(boxStyle);

            var removeIdx = -1;

            for (int i = 0; i < count; i++)
            {
                EditorGUILayout.BeginVertical();
                if (DrawEditorItem(_editorItems[i], state))
                {
                    removeIdx = i;
                }

                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.EndVertical();

            if (removeIdx >= 0 && DisplayHelper.ConfirmDelete("item"))
            {
                var item = (IKeyedItem)_editorItems[removeIdx].item;
                _dictionary.Remove(item.key);
                _editorItems.RemoveAt(removeIdx);
                state.MarkDirty();
            }
        }
示例#17
0
        protected override void DoRemove(int removeIdx, AIInspectorState state)
        {
            var item = _list[removeIdx];

            var arr = (Array)_list;
            var tmp = Array.CreateInstance(_itemType, arr.Length - 1);

            Array.Copy(arr, 0, tmp, 0, removeIdx);
            if (removeIdx < tmp.Length)
            {
                Array.Copy(arr, removeIdx + 1, tmp, removeIdx, tmp.Length - removeIdx);
            }

            _setter(tmp);

            state.currentAIUI.undoRedo.Do(new ArrayFieldRemoveOperation(tmp, _setter, removeIdx, item));
        }
示例#18
0
        public sealed override void RenderField(AIInspectorState state)
        {
            EditorGUILayout.LabelField(_label, EditorStyles.label);
            EditorGUI.indentLevel += 1;

            _center = EditorGUILayout.Vector3Field("Center", _center);
            _size   = EditorGUILayout.Vector3Field("Size", _size);

            EditorGUI.indentLevel -= 1;

            var val = new Bounds(_center, _size);

            if (val != _curValue)
            {
                UpdateValue(val, state);
            }
        }
示例#19
0
        //Functionality specific to Composite Visualizers
        private IEnumerable <ICompositeVisualizer> GetVisualizers(AIInspectorState state)
        {
            if (!VisualizationManager.isVisualizing)
            {
                yield break;
            }

            var isCompositeQualifier = (_owner is ICompositeScorer) && (_owner is IQualifier);
            var isCompositeAction    = _owner is CompositeAction;

            if (!isCompositeQualifier && !isCompositeAction)
            {
                yield break;
            }

            var ui = state.currentAIUI;

            if (ui == null)
            {
                yield break;
            }

            var clientsToUpdate = AIManager.GetAIClients(ui.ai.id);

            int count = clientsToUpdate.Count;

            for (int i = 0; i < count; i++)
            {
                var ai = clientsToUpdate[i].ai as UtilityAIVisualizer;
                if (ai != null)
                {
                    if (isCompositeQualifier)
                    {
                        yield return(ai.FindQualifierVisualizer((IQualifier)_owner) as ICompositeVisualizer);
                    }
                    else
                    {
                        yield return(ai.FindActionVisualizer((IAction)_owner) as ICompositeVisualizer);
                    }
                }
            }
        }
示例#20
0
        public override void RenderField(AIInspectorState state)
        {
            if (string.IsNullOrEmpty(_aiName))
            {
                _nameLabel.text = "None";
            }
            else
            {
                _nameLabel.text = _aiName;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 60f;
            EditorGUILayout.LabelField(_label, _nameLabel);
            EditorGUIUtility.labelWidth = 0f;

            if (GUILayout.Button("...", EditorStyling.Skinned.fixedButton))
            {
                GUI.changed = false;

                var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                AISelectorWindow.Get(
                    screenPos,
                    (ai) =>
                {
                    var newVal = (ai == null) ? Guid.Empty : new Guid(ai.aiId);
                    if (_curValue != newVal)
                    {
                        if (newVal == state.currentAIUI.ai.id)
                        {
                            EditorUtility.DisplayDialog("Invalid AI", "You cannot execute an AI from within itself.", "OK");
                            return;
                        }

                        _aiName = (ai == null) ? null : ai.name;
                        UpdateValue(newVal, state);
                    }
                });
            }

            EditorGUILayout.EndHorizontal();
        }
示例#21
0
        private void AddNew(Vector2 mousePos, AIInspectorState state)
        {
            if (_dictionary == null)
            {
                var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary <,>).MakeGenericType(_keyType, _valueType));
                _setter(dict);
            }

            if (_itemCreator == null)
            {
                _itemCreator = new ItemConstructor(_dictionary, _keyType, _valueType);
            }

            var itemWrapper = _itemCreator.Conctruct();

            _editorItems.Add(ReflectMaster.Reflect(itemWrapper));

            // We do not want the button click itself to count as a change.. same as above.
            GUI.changed = false;
        }
        public sealed override void RenderField(AIInspectorState state)
        {
            var val = _curValue;

            var layers       = UnityEditorInternal.InternalEditorUtility.layers;
            var layerNumbers = new int[layers.Length];

            for (int i = 0; i < layers.Length; i++)
            {
                layerNumbers[i] = LayerMask.NameToLayer(layers[i]);
            }

            int maskWithoutEmpty = 0;

            for (int i = 0; i < layerNumbers.Length; i++)
            {
                if (((1 << layerNumbers[i]) & val.value) > 0)
                {
                    maskWithoutEmpty |= (1 << i);
                }
            }

            maskWithoutEmpty = EditorGUILayout.MaskField(_label, maskWithoutEmpty, layers);

            int mask = 0;

            for (int i = 0; i < layerNumbers.Length; i++)
            {
                if ((maskWithoutEmpty & (1 << i)) > 0)
                {
                    mask |= (1 << layerNumbers[i]);
                }

                val.value = mask;
            }

            if (val != _curValue)
            {
                UpdateValue(val, state);
            }
        }
示例#23
0
        private bool DrawEditorItem(EditorItem item, AIInspectorState state, bool spaceForHandle)
        {
            var result = false;

            // Item Header
            EditorGUILayout.BeginHorizontal(spaceForHandle ? SharedStyles.BuiltIn.listItemHeaderIndented : SharedStyles.BuiltIn.listItemHeader);

            var cbd = item.item as ICanBeDisabled;

            if (cbd != null)
            {
                var isDisabled = !EditorGUILayout.ToggleLeft(item.name, !cbd.isDisabled, cbd.isDisabled ? EditorStyling.Skinned.disabledText : SharedStyles.BuiltIn.normalText);
                if (isDisabled != cbd.isDisabled)
                {
                    cbd.isDisabled = isDisabled;
                    state.currentAIUI.undoRedo.Do(new DisableOperation(cbd));
                }
            }
            else
            {
                EditorGUILayout.LabelField(item.name, SharedStyles.BuiltIn.normalText);
            }

            if (GUILayout.Button(SharedStyles.deleteTooltip, SharedStyles.BuiltIn.deleteButtonSmall))
            {
                result = true;

                // We do not want the button click itself to count as a change. Since no other changes are expected when a button click is encountered, we can just set it to false.
                GUI.changed = false;
            }

            EditorGUILayout.EndHorizontal();

            // Item fields
            item.Render(state);
            EditorGUILayout.Separator();

            return(result);
        }
示例#24
0
        protected void UpdateValue(T newValue, AIInspectorState state)
        {
            state.currentAIUI.undoRedo.Do(new EditorFieldOperation <T>(_owner, _member, _curValue, newValue));
            state.MarkDirty();

            _curValue = newValue;

            var prop = _member as PropertyInfo;

            if (prop != null)
            {
                prop.SetValue(_owner, newValue, null);
            }
            else
            {
                var field = _member as FieldInfo;
                if (field != null)
                {
                    field.SetValue(_owner, newValue);
                }
            }
        }
示例#25
0
        public void RenderField(AIInspectorState state)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(_label);

            if (GUILayout.Button(SharedStyles.changeSelectionTooltip, SharedStyles.BuiltIn.changeButtonSmall))
            {
                Action <Type> cb = (selectedType) =>
                {
                    if (_itemType.IsGenericType && selectedType.IsGenericType)
                    {
                        var genArgs = _itemType.GetGenericArguments();
                        selectedType = selectedType.GetGenericTypeDefinition().MakeGenericType(genArgs);
                    }

                    var old = _item;
                    _item       = Activator.CreateInstance(selectedType);
                    _editorItem = ReflectMaster.Reflect(_item);
                    _setter(_item);

                    state.currentAIUI.undoRedo.Do(new CustomEditorFieldOperation(old, _item, _setter));
                    state.MarkDirty();
                };

                //We do not want the button click itself to count as a change.. same as above.
                GUI.changed = false;

                var screenPos = EditorGUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                AIEntitySelectorWindow.Get(screenPos, _itemType, cb);
            }

            EditorGUILayout.EndHorizontal();

            bool doDelete = false;

            if (_item != null)
            {
                EditorGUILayout.BeginVertical("Box");
                EditorGUILayout.BeginHorizontal(SharedStyles.BuiltIn.listItemHeader);
                EditorGUILayout.LabelField(_editorItem.name, SharedStyles.BuiltIn.normalText);
                if (GUILayout.Button(SharedStyles.deleteTooltip, SharedStyles.BuiltIn.deleteButtonSmall))
                {
                    GUI.changed = false;

                    if (DisplayHelper.ConfirmDelete("item"))
                    {
                        doDelete = true;
                    }
                }

                EditorGUILayout.EndHorizontal();

                _editorItem.Render(state);
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Separator();

            //We do the delete outside any layout stuff to ensure we don't get weird warnings.
            if (doDelete)
            {
                state.currentAIUI.undoRedo.Do(new CustomEditorFieldOperation(_item, null, _setter));
                _setter(null);
                _item       = null;
                _editorItem = null;
                state.MarkDirty();
            }
        }
示例#26
0
 protected abstract void DoAdd(object item, AIInspectorState state);
示例#27
0
 protected override void DoAdd(object item, AIInspectorState state)
 {
     _list.Add(item);
     state.currentAIUI.undoRedo.Do(new ListFieldAddOperation(_list, item));
 }
示例#28
0
        public void RenderField(AIInspectorState state)
        {
            var evt      = Event.current;
            var mousePos = evt.mousePosition;
            var boxStyle = new GUIStyle("Box");

            if (_reorderable && _dragging)
            {
                // don't let the mouse affect the X position of the rect being dragged
                mousePos.x = _draggedRect.x;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(_label);
            EditorGUILayout.Separator();
            if (GUILayout.Button(SharedStyles.addTooltip, SharedStyles.BuiltIn.addButtonSmall))
            {
                AddNew(mousePos, state);
            }

            EditorGUILayout.EndHorizontal();

            var count = _editorItems.Count;

            if (count == 0)
            {
                return;
            }

            EditorGUILayout.BeginVertical(boxStyle);

            var removeIdx = -1;

            if (!_reorderable || count <= 1)
            {
                for (int i = 0; i < count; i++)
                {
                    // if list is not reorderable, just draw items
                    EditorGUILayout.BeginVertical();
                    if (DrawEditorItem(_editorItems[i], state, false))
                    {
                        removeIdx = i;
                    }

                    EditorGUILayout.EndVertical();
                }
            }
            else
            {
                // Reorderable list
                int drawIdx = 0;
                for (int i = 0; i < count; i++)
                {
                    if (_dragging && _draggingIndex == drawIdx)
                    {
                        drawIdx++;
                    }

                    Rect dragHandle;
                    Rect itemRect;
                    if (i == _dropIndex)
                    {
                        dragHandle = new Rect();
                        itemRect   = EditorGUILayout.BeginVertical();
                        GUILayout.Space(_dragRectHeight);
                        EditorGUILayout.EndVertical();
                    }
                    else
                    {
                        itemRect = EditorGUILayout.BeginVertical();
                        var item = _editorItems[drawIdx++];
                        if (DrawEditorItem(item, state, true))
                        {
                            removeIdx = i;
                        }

                        EditorGUILayout.EndVertical();

                        dragHandle = DrawDragHandle();
                    }

                    if (evt.button == MouseButton.left && evt.isMouse)
                    {
                        if (!_dragging)
                        {
                            if (dragHandle.Contains(mousePos) && evt.type == EventType.MouseDrag)
                            {
                                _dragging      = true;
                                _draggingIndex = _dropIndex = i;
                                _draggedRect   = itemRect;
                                _dragOffsetY   = itemRect.y - mousePos.y;
                                break;
                            }
                        }
                        else
                        {
                            if (itemRect.Contains(mousePos))
                            {
                                _dropIndex = i;
                                break;
                            }
                        }
                    }
                }

                if (_dragging && evt.type == EventType.MouseUp)
                {
                    if (_draggingIndex != _dropIndex)
                    {
                        _list.Reorder(_draggingIndex, _dropIndex);
                        _editorItems.Reorder(_draggingIndex, _dropIndex);
                        state.currentAIUI.undoRedo.Do(new ReorderOperation(_draggingIndex, _dropIndex, _list));
                        state.MarkDirty();

                        if (Application.isPlaying)
                        {
                            HandleVisualizerReorder(state, _draggingIndex, _dropIndex);
                        }
                    }

                    _dragging  = false;
                    _dropIndex = _draggingIndex = -1;
                }
            }

            EditorGUILayout.EndVertical();

            if (removeIdx >= 0 && DisplayHelper.ConfirmDelete("item"))
            {
                DoRemove(removeIdx, state);
                _editorItems.RemoveAt(removeIdx);
                state.MarkDirty();

                if (Application.isPlaying)
                {
                    HandleVisualizerRemove(state, removeIdx);
                }
            }

            if (_reorderable && _dragging)
            {
                if (evt.type == EventType.Layout || evt.type == EventType.Repaint)
                {
                    GUI.Box(new Rect(_draggedRect.x, mousePos.y + _dragOffsetY, _draggedRect.width, _dragRectHeight), _editorItems[_draggingIndex].name, boxStyle);
                    AIInspectorEditor.instance.Repaint();
                }
            }
        }
示例#29
0
        private void AddNew(Vector2 mousePos, AIInspectorState state)
        {
            if (_isSimpleType)
            {
                if (_list == null)
                {
                    _setter(CreateList());
                }

                if (_simpleItemCreator == null)
                {
                    _simpleItemCreator = new SimpleItemConstructor(_list, _itemType);
                }

                var item = Activator.CreateInstance(_itemType);
                DoAdd(item, state);

                var itemWrapper = _simpleItemCreator.Conctruct(_list.Count - 1, item);
                _editorItems.Add(ReflectMaster.Reflect(itemWrapper));
                return;
            }

            Action <Type[]> cb = (selectedTypes) =>
            {
                if (_list == null)
                {
                    _setter(CreateList());
                }

                using (state.currentAIUI.undoRedo.bulkOperation)
                {
                    for (int i = 0; i < selectedTypes.Length; i++)
                    {
                        var selectedType = selectedTypes[i];
                        if (_itemType.IsGenericType && selectedType.IsGenericType)
                        {
                            var genArgs = _itemType.GetGenericArguments();
                            selectedType = selectedType.GetGenericTypeDefinition().MakeGenericType(genArgs);
                        }

                        var item = Activator.CreateInstance(selectedType);
                        DoAdd(item, state);
                        _editorItems.Add(ReflectMaster.Reflect(item));

                        if (Application.isPlaying)
                        {
                            HandleVisualizerAdd(state, item);
                        }
                    }

                    state.MarkDirty();
                }
            };

            // We do not want the button click itself to count as a change.. same as above.
            GUI.changed = false;

            var screenPos = EditorGUIUtility.GUIToScreenPoint(mousePos);

            AIEntitySelectorWindow.Get(screenPos, _itemType, cb);
        }
示例#30
0
 public abstract void RenderField(AIInspectorState state);