private void DrawActionUI(ActionView actionView)
        {
            HeaderHandler headerRects;

            if (EditorApplication.isPlaying)
            {
                headerRects = HeaderHandler.GetHeaderRects(0);
            }
            else
            {
                headerRects = HeaderHandler.GetHeaderRects(2);

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

                if (GUI.Button(headerRects.Next, EditorStyling.changeTypeTooltip, SharedStyles.BuiltIn.changeButtonSmall))
                {
                    ShowChangeTypeMenu(actionView.action, (newAction) => _state.currentAIUI.ReplaceAction(actionView.parent, newAction));
                }
            }

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

            EditorGUILayout.Separator();

            DrawViewSharedUI(actionView);

            EditorGUILayout.Separator();

            _state.editedItem.Render(_state);
        }
        private static ActionView ReadActionView(StageElement ave, QualifierView parent)
        {
            var connectorType = ave.AttributeValueOrDefault <string>(AttributeName.ConnectorType, null);

            ActionView av;

            if (connectorType == ConnectorType.Selector)
            {
                av = new SelectorActionView();
            }
            else if (connectorType == ConnectorType.AILink)
            {
                av = new AILinkActionView();
            }
            else if (connectorType == ConnectorType.Composite)
            {
                av = new CompositeActionView();
            }
            else
            {
                av = new ActionView();
            }

            av.name        = ave.ValueOrDefault <string>(ElementName.Name, null);
            av.description = ave.ValueOrDefault <string>(ElementName.Description, null);
            av.parent      = parent;

            return(av);
        }
示例#3
0
        internal ActionView SetAction(ActionView av, QualifierView parent, bool recordUndo = true)
        {
            if (av.parent != null && !object.ReferenceEquals(av.parent, parent))
            {
                throw new InvalidOperationException("Cannot add an action that already has a parent Qualifier.");
            }

            var oldAction = parent.actionView;

            av.parent = parent;
            parent.qualifier.action = av.action;
            parent.actionView       = av;

            if (av.isSelectable)
            {
                Select(parent.parent, parent, av);
            }

            this.isDirty = true;

            if (recordUndo)
            {
                if (oldAction != null)
                {
                    _undoRedo.Do(new SetActionOperation(this, oldAction, av));
                }
                else
                {
                    _undoRedo.Do(new SetActionOperation(this, av));
                }
            }

            return(av);
        }
示例#4
0
        internal void ReplaceAction(QualifierView qv, IAction replacement, bool recordUndo = true)
        {
            var av = qv.actionView;

            if (av == null)
            {
                return;
            }

            if (recordUndo)
            {
                _undoRedo.Do(new ReplaceActionOperation(this, av.action, replacement, qv));

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

            if (av is CompositeActionView && !(replacement is CompositeAction))
            {
                var tmp = new ActionView();
                tmp.parent      = qv;
                tmp.name        = av.name;
                tmp.description = av.description;
                av            = tmp;
                qv.actionView = av;
            }
            else if (!(av is CompositeActionView) && replacement is CompositeAction)
            {
                var tmp = new CompositeActionView();
                tmp.parent      = qv;
                tmp.name        = av.name;
                tmp.description = av.description;
                av            = tmp;
                qv.actionView = av;
            }
            else if (av is IConnectorActionView)
            {
                //For replacement of other connector views we need to reset to a normal ActionView.
                //Since it is not possible to replace an action with a connector, we don't handle the reverse.
                var tmp = new ActionView();
                tmp.parent      = qv;
                tmp.name        = av.name;
                tmp.description = av.description;
                av            = tmp;
                qv.actionView = av;
            }

            av.action           = replacement;
            qv.qualifier.action = replacement;

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

            this.isDirty = true;
        }
示例#5
0
        private void ResetSingleSelection(bool resfreshState)
        {
            _currentAILink    = null;
            _currentSelector  = null;
            _currentQualifier = null;
            _currentAction    = null;

            if (resfreshState)
            {
                this.inspectorState.Refresh();
            }
        }
示例#6
0
        internal void Select(AILinkView alv)
        {
            _currentAILink = alv;
            _selectedViews.Clear();
            if (alv != null)
            {
                _selectedViews.Add(alv);
            }

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

            this.inspectorState.Refresh();
        }
示例#7
0
        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();
        }
        internal static string Serialize(ActionView action)
        {
            var aiPart = new StageElement(ElementName.AIPart);
            var uiPart = new StageElement(ElementName.UIPart);
            var root   = new StageElement(ElementName.ActionSnippet, aiPart, uiPart);

            root.AddTextAttribute(AttributeName.SnippetType, ElementName.ActionSnippet);

            var aiItem = SerializationMaster.Stage(ElementName.Action, action.action);

            aiPart.Add(aiItem);

            var viewItem = WriteActionView(action);

            uiPart.Add(viewItem);

            return(SerializationMaster.Serialize(root));
        }
示例#9
0
        internal void RemoveAction(ActionView av, bool recordUndo = true)
        {
            if (av == _currentAction)
            {
                _currentAction = null;
                this.inspectorState.Refresh();
            }

            var parent = av.parent;

            parent.qualifier.action = null;
            parent.actionView       = null;
            this.isDirty            = true;

            if (recordUndo)
            {
                _undoRedo.Do(new RemoveActionOperation(this, av));
            }
        }
示例#10
0
        internal ActionView SetAction(Type actionType, QualifierView parent)
        {
            if (actionType == null || parent == null)
            {
                return(null);
            }

            if (parent.actionView != null)
            {
                var action = Activator.CreateInstance(actionType) as IAction;
                if (action != null)
                {
                    ReplaceAction(parent, action, true);
                    return(parent.actionView);
                }
            }

            var av = ActionView.Create(actionType, parent);

            return(SetAction(av, parent));
        }
        private static StageElement WriteActionView(ActionView av)
        {
            var ae = new StageElement(ElementName.ActionView);

            ae.AddTextValue(ElementName.Name, av.name);
            ae.AddTextValue(ElementName.Description, av.description);

            if (av is SelectorActionView)
            {
                ae.AddAttribute(AttributeName.ConnectorType, ConnectorType.Selector);
            }
            else if (av is AILinkActionView)
            {
                ae.AddAttribute(AttributeName.ConnectorType, ConnectorType.AILink);
            }
            else if (av is CompositeActionView)
            {
                ae.AddAttribute(AttributeName.ConnectorType, ConnectorType.Composite);
            }

            return(ae);
        }
示例#12
0
        internal bool Connect(QualifierView qv, TopLevelView targetView)
        {
            ActionView av = null;

            var sv = targetView as SelectorView;

            if (sv != null)
            {
                if (sv.selector.IsConnectedTo(qv.parent.selector))
                {
                    EditorUtility.DisplayDialog("Invalid Action", "Circular connections are not allowed.", "Ok");
                    return(false);
                }

                //Composite actions may also act as selectors as the last step
                var cav = qv.actionView as CompositeActionView;
                if (cav != null)
                {
                    var ca           = (CompositeAction)cav.action;
                    var newConnector = new SelectorAction(sv.selector);

                    _undoRedo.Do(new ConnectCompositeOperation(cav, ca.connectorAction, newConnector));
                    ca.connectorAction = newConnector;
                    cav.targetView     = null;
                    return(true);
                }

                av = new SelectorActionView
                {
                    targetSelector = sv,
                    action         = new SelectorAction(sv.selector),
                    parent         = qv
                };
            }

            var lv = targetView as AILinkView;

            if (lv != null)
            {
                var cav = qv.actionView as CompositeActionView;
                if (cav != null)
                {
                    var ca           = (CompositeAction)cav.action;
                    var newConnector = new AILinkAction(lv.aiId);

                    _undoRedo.Do(new ConnectCompositeOperation(cav, ca.connectorAction, newConnector));
                    ca.connectorAction = newConnector;
                    cav.targetView     = null;
                    return(true);
                }

                av = new AILinkActionView
                {
                    targetAI = lv,
                    action   = new AILinkAction(lv.aiId),
                    parent   = qv
                };
            }

            if (av != null)
            {
                SetAction(av, qv);
                return(true);
            }

            return(false);
        }