コード例 #1
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal SelectorView AddSelector(Vector2 position, Type selectorType, bool recordUndo = true)
        {
            var viewRect = this.canvas.SnapToGrid(new Rect(position.x, position.y, 200f * this.canvas.zoom, 0f));
            var sv       = SelectorView.Create(selectorType, this, viewRect);

            this.canvas.views.Add(sv);

            _ai.AddSelector(sv.selector);

            if (_ai.rootSelector == null)
            {
                _ai.rootSelector = sv.selector;
            }

            Select(sv, null, null);

            this.isDirty = true;

            if (recordUndo && !sv.isRoot)
            {
                _undoRedo.Do(new AddSelectorOperation(this, sv));
            }

            return(sv);
        }
コード例 #2
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal void ReplaceDefaultQualifier(QualifierView newDefault, SelectorView parent, bool recordUndo = true)
        {
            if (!newDefault.isDefault)
            {
                throw new ArgumentException("Qualifier must be a Default Qualifier.", "newDefault");
            }

            if (newDefault.parent != null && !object.ReferenceEquals(newDefault.parent, parent))
            {
                throw new InvalidOperationException("Cannot add a qualifier that already has a parent Selector.");
            }

            if (recordUndo)
            {
                _undoRedo.Do(new ReplaceDefaultQualifierOperation(this, parent.defaultQualifierView, newDefault, parent));
            }

            newDefault.parent                = parent;
            parent.defaultQualifierView      = newDefault;
            parent.selector.defaultQualifier = (IDefaultQualifier)newDefault.qualifier;

            Select(parent, newDefault, null);

            this.isDirty = true;
        }
コード例 #3
0
        internal SelectorLayout(SelectorView selectorView, float windowTop, ScaleSettings scaling)
            : base(selectorView, windowTop, scaling)
        {
            _selectorView = selectorView;

            float leftMost  = _localViewRange.xMin;
            float rightMost = _localViewRange.xMax;

            _dragArea = new XRange(leftMost, scaling.dragHandleWidth);
            leftMost += scaling.dragHandleWidth;

            rightMost  -= scaling.anchorAreaWidth;
            _anchorArea = new XRange(rightMost, scaling.anchorAreaWidth);
            _toggleArea = new XRange(rightMost, scaling.toggleAreaWidth);

            if (EditorApplication.isPlaying)
            {
                var remainder      = rightMost - leftMost;
                var scoreAreaWidth = remainder * 0.25f;

                rightMost -= scoreAreaWidth;
                _scoreArea = new XRange(rightMost, scoreAreaWidth);
            }

            _contentArea = new XRange(leftMost, rightMost - leftMost);
        }
コード例 #4
0
        private static SelectorView ReadSelectorView(StageElement sve, AIUI parent)
        {
            var sv = new SelectorView
            {
                name        = sve.ValueOrDefault <string>(ElementName.Name),
                description = sve.ValueOrDefault <string>(ElementName.Description),
                viewArea    = sve.ValueOrDefault <Rect>(ElementName.ViewArea),
                parent      = parent
            };

            var defQv = sve.Element(ElementName.DefaultQualifier);

            sv.defaultQualifierView = defQv != null?ReadQualifierView(defQv, sv) : new QualifierView
            {
                parent = sv
            };

            var qualifierViews = sve.Elements(ElementName.QualifierView);

            foreach (var qve in qualifierViews)
            {
                var qv = ReadQualifierView(qve, sv);
                sv.qualifierViews.Add(qv);
            }

            return(sv);
        }
コード例 #5
0
        private static StageElement WriteSelectorView(SelectorView sv)
        {
            var sve = new StageElement(
                ElementName.SelectorView,
                SerializationMaster.Stage(ElementName.ViewArea, sv.viewArea));

            sve.AddTextValue(ElementName.Name, sv.name);
            sve.AddTextValue(ElementName.Description, sv.description);

            var qualifierViews = sv.qualifierViews;
            int qvCount        = qualifierViews.Count;

            for (int i = 0; i < qvCount; i++)
            {
                var qv = WriteQualifierView(qualifierViews[i]);

                sve.Add(qv);
            }

            var defQv = WriteQualifierView(sv.defaultQualifierView);

            sve.Add(defQv);

            return(sve);
        }
コード例 #6
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        private IEnumerable <ActionView> GetReferencingActions(SelectorView sv)
        {
            foreach (var selectorView in this.canvas.selectorViews)
            {
                if (selectorView == sv)
                {
                    // no need to check the one being removed
                    continue;
                }

                var qualifierViews  = selectorView.qualifierViews;
                var qualifiersCount = qualifierViews.Count;
                for (int j = 0; j < qualifiersCount; j++)
                {
                    var qualifierView  = qualifierViews[j];
                    var actionView     = qualifierView.actionView as SelectorActionView;
                    var compActionView = qualifierView.actionView as CompositeActionView;
                    if (actionView != null)
                    {
                        var action = (SelectorAction)actionView.action;
                        if (object.ReferenceEquals(action.selector, sv.selector))
                        {
                            yield return(actionView);
                        }
                    }
                    else if (compActionView != null)
                    {
                        var action = compActionView.connectorAction as SelectorAction;
                        if (action != null && object.ReferenceEquals(action.selector, sv.selector))
                        {
                            yield return(compActionView);
                        }
                    }
                }

                var defaultQualifier    = selectorView.defaultQualifierView;
                var selectorActionView  = defaultQualifier.actionView as SelectorActionView;
                var compositeActionView = defaultQualifier.actionView as CompositeActionView;
                if (selectorActionView != null)
                {
                    var action = (SelectorAction)selectorActionView.action;
                    if (object.ReferenceEquals(action.selector, sv.selector))
                    {
                        yield return(selectorActionView);
                    }
                }
                else if (compositeActionView != null)
                {
                    var action = compositeActionView.connectorAction as SelectorAction;
                    if (action != null && object.ReferenceEquals(action.selector, sv.selector))
                    {
                        yield return(compositeActionView);
                    }
                }
            }
        }
コード例 #7
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal QualifierView AddQualifier(Type qualifierType, SelectorView parent, bool recordUndo = true)
        {
            if (qualifierType == null || parent == null)
            {
                return(null);
            }

            var qv = QualifierView.Create(qualifierType);

            return(AddQualifier(qv, parent));
        }
コード例 #8
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        private void ResetSingleSelection(bool resfreshState)
        {
            _currentAILink    = null;
            _currentSelector  = null;
            _currentQualifier = null;
            _currentAction    = null;

            if (resfreshState)
            {
                this.inspectorState.Refresh();
            }
        }
コード例 #9
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal bool RemoveSelector(SelectorView sv, bool recordUndo = true)
        {
            if (_ai.rootSelector == sv.selector)
            {
                EditorUtility.DisplayDialog("Invalid Action", "You cannot remove the root selector.\nTo remove the selected selector please assign another selector as the root first.", "Ok");
                return(false);
            }

            if (sv == _currentSelector)
            {
                _currentSelector = null;
                this.inspectorState.Refresh();
            }

            RemoveTopLevelViewOperation undoOp = null;

            if (recordUndo)
            {
                undoOp = new RemoveSelectorOperation(this, sv);
                _undoRedo.Do(undoOp);
            }

            var refActions = GetReferencingActions(sv);

            foreach (var av in refActions)
            {
                if (recordUndo)
                {
                    undoOp.LogReferencingActionRemoval(av);
                }

                //References from composite actions must be treated differently
                var cav = av as CompositeActionView;
                if (cav != null)
                {
                    ResetConnection(cav, false);
                }
                else
                {
                    RemoveAction(av, false);
                }
            }

            this.canvas.views.Remove(sv);
            _ai.RemoveSelector(sv.selector);
            _selectedViews.Remove(sv);
            this.isDirty = true;

            return(true);
        }
コード例 #10
0
        private void DrawSelectorUI(SelectorView selectorView)
        {
            var isRoot = selectorView.isRoot;

            HeaderHandler headerRects;

            if (EditorApplication.isPlaying)
            {
                headerRects = HeaderHandler.GetHeaderRects(0);
            }
            else
            {
                if (isRoot)
                {
                    headerRects = HeaderHandler.GetHeaderRects(1);
                }
                else
                {
                    headerRects = HeaderHandler.GetHeaderRects(3);

                    if (GUI.Button(headerRects.Next, SharedStyles.deleteTooltip, SharedStyles.BuiltIn.deleteButtonSmall))
                    {
                        GUI.changed = false;
                        _state.currentAIUI.RemoveSelected();
                        return;
                    }

                    if (GUI.Button(headerRects.Next, EditorStyling.setRootTooltip, EditorStyling.Skinned.setRootButtonSmall))
                    {
                        _state.currentAIUI.SetRoot(selectorView.selector);
                    }
                }

                if (GUI.Button(headerRects.Next, EditorStyling.changeTypeTooltip, SharedStyles.BuiltIn.changeButtonSmall))
                {
                    ShowChangeTypeMenu(selectorView.selector, (newSelector) => _state.currentAIUI.ReplaceSelector(selectorView, newSelector));
                }
            }

            GUI.Label(headerRects.Next, string.Concat(_state.editedItem.name, (isRoot ? " (ROOT) " : string.Empty), " | APEX AI"), EditorStyling.Skinned.inspectorTitle);

            EditorGUILayout.Separator();

            DrawViewSharedUI(selectorView);

            EditorGUILayout.Separator();

            _state.editedItem.Render(_state);
        }
コード例 #11
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal void Select(SelectorView sv, QualifierView qv, ActionView av)
        {
            _currentAILink = null;

            _currentSelector = sv;
            _selectedViews.Clear();
            if (sv != null)
            {
                _selectedViews.Add(sv);
            }

            _currentQualifier = qv;
            _currentAction    = av;
            this.inspectorState.Refresh();
        }
コード例 #12
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal void Select(AILinkView alv)
        {
            _currentAILink = alv;
            _selectedViews.Clear();
            if (alv != null)
            {
                _selectedViews.Add(alv);
            }

            _currentSelector  = null;
            _currentQualifier = null;
            _currentAction    = null;

            this.inspectorState.Refresh();
        }
コード例 #13
0
        private static QualifierView ReadQualifierView(StageElement qve, SelectorView parent)
        {
            var qv = new QualifierView
            {
                name        = qve.ValueOrDefault <string>(ElementName.Name, null),
                description = qve.ValueOrDefault <string>(ElementName.Description, null),
                parent      = parent
            };

            var ave = qve.Element(ElementName.ActionView);

            if (ave != null)
            {
                qv.actionView = ReadActionView(ave, qv);
            }

            return(qv);
        }
コード例 #14
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal void ReplaceSelector(SelectorView sv, Selector replacement, bool recordUndo = true)
        {
            //First get a hold of ref actions, we need to do this before we change the selector reference
            var refActions = GetReferencingActions(sv).ToArray();

            if (!_ai.ReplaceSelector(sv.selector, replacement))
            {
                return;
            }

            if (recordUndo)
            {
                _undoRedo.Do(new ReplaceSelectorOperation(this, sv.selector, replacement, sv));

                //We don't want to clone during undo/redo as the cloning is recorded
                TryClone(sv.selector, replacement);
            }

            sv.selector = replacement;

            foreach (var av in refActions)
            {
                var sa = av.action as SelectorAction;

                if (sa == null)
                {
                    var cav = av as CompositeActionView;
                    if (cav != null)
                    {
                        sa = cav.connectorAction as SelectorAction;
                    }
                }

                if (sa != null)
                {
                    sa.selector = replacement;
                }
            }

            //Need to refresh editor
            this.inspectorState.Refresh();

            this.isDirty = true;
        }
コード例 #15
0
        internal static SelectorView Create(Type selectorType, AIUI parent, Rect viewArea)
        {
            if (!selectorType.IsSubclassOf(typeof(Selector)))
            {
                throw new ArgumentException("The proposed type is not a Selector.", "selectorType");
            }

            var sv = new SelectorView(viewArea);

            sv.parent               = parent;
            sv.selector             = Activator.CreateInstance(selectorType) as Selector;
            sv.defaultQualifierView = new QualifierView
            {
                qualifier = sv.selector.defaultQualifier,
                parent    = sv
            };

            return(sv);
        }
コード例 #16
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal QualifierView AddQualifier(QualifierView qv, SelectorView parent, bool recordUndo = true)
        {
            if (qv.parent != null && !object.ReferenceEquals(qv.parent, parent))
            {
                throw new InvalidOperationException("Cannot add a qualifier that already has a parent Selector.");
            }

            qv.parent = parent;
            parent.qualifierViews.Add(qv);
            parent.selector.qualifiers.Add(qv.qualifier);

            Select(parent, qv, null);

            this.isDirty = true;

            if (recordUndo)
            {
                _undoRedo.Do(new AddQualifierOperation(this, qv));
            }

            return(qv);
        }
コード例 #17
0
ファイル: AIUI.cs プロジェクト: xwf20050250/Apex-Game-Tools
        internal void MultiSelectView(TopLevelView view)
        {
            if (!_selectedViews.Contains(view))
            {
                _selectedViews.Add(view);
            }
            else
            {
                _selectedViews.Remove(view);
            }

            if (_selectedViews.Count == 1)
            {
                view             = _selectedViews[0];
                _currentSelector = view as SelectorView;
                _currentAILink   = view as AILinkView;
            }
            else
            {
                ResetSingleSelection(false);
            }

            this.inspectorState.Refresh();
        }