コード例 #1
0
    /// <summary>
    /// The Initializer for the <seealso cref="TransitionGUI"/>
    /// </summary>
    /// <param name="name"></param>
    /// <param name="from"></param>
    /// <param name="to"></param>
    public void InitTransitionGUI(ClickableElement parent, BaseNode from, BaseNode to, bool comesFromXML = false)
    {
        var foo = sender;

        this.identificator = UniqueID();

        this.transitionName = parent.elementNamer.AddName(identificator, "New Transition ");

        this.width  = baseWidth;
        this.height = baseHeight;

        this.fromNode = from;
        this.toNode   = to;

        this.rootPerception = CreateInstance <PerceptionGUI>();
        this.rootPerception.InitPerceptionGUI(perceptionType.Push);

        if (comesFromXML)
        {
            ((BehaviourNode)toNode).index = ((BehaviourNode)to).index;
        }
        else if (fromNode is BehaviourNode && ((((BehaviourNode)fromNode).type == behaviourType.Sequence && !((BehaviourNode)fromNode).isRandom) || ((BehaviourNode)fromNode).type == behaviourType.Selector))
        {
            ((BehaviourNode)toNode).index = ((BehaviourTree)parent).ChildrenCount((BehaviourNode)fromNode) + 1;
        }
    }
コード例 #2
0
    /// <summary>
    /// Creates a copy of this <see cref="FSM"/>
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public override GUIElement CopyElement(params object[] args)
    {
        ClickableElement parent = (ClickableElement)args[0];

        FSM result = CreateInstance <FSM>();

        result.identificator = this.identificator;
        result.elementNamer  = CreateInstance <UniqueNamer>();
        result.elementName   = this.elementName;
        result.parent        = parent;
        result.windowRect    = new Rect(this.windowRect);

        result.nodes       = this.nodes.Select(o => (BaseNode)o.CopyElement(result)).ToList();
        result.transitions = this.transitions.Select(o =>
                                                     (TransitionGUI)o.CopyElement(result.nodes.Find(n => n.identificator == o.fromNode.identificator),
                                                                                  result.nodes.Find(n => n.identificator == o.toNode.identificator))).ToList();

        foreach (StateNode elem in result.nodes)
        {
            if (elem.type == stateType.Entry)
            {
                result.SetAsEntry(elem);
            }
        }

        return(result);
    }
コード例 #3
0
    /// <summary>
    /// The Initializer for the <seealso cref="TransitionGUI"/> when it is being loaded from an XML
    /// </summary>
    /// <param name="name"></param>
    /// <param name="from"></param>
    /// <param name="to"></param>
    public void InitTransitionGUIFromXML(ClickableElement parent, BaseNode from, BaseNode to, string id, string name, PerceptionGUI rootPerception, bool isExit, float weight = 1.0f)
    {
        var foo = sender;

        this.identificator = id;

        this.transitionName = parent.elementNamer.AddName(identificator, name);

        this.width  = baseWidth;
        this.height = baseHeight;

        this.weight = weight;

        this.fromNode = from;
        this.toNode   = to;

        this.rootPerception = rootPerception;

        this.isExit = isExit;

        if (fromNode is BehaviourNode && ((((BehaviourNode)fromNode).type == behaviourType.Sequence && !((BehaviourNode)fromNode).isRandom) || ((BehaviourNode)fromNode).type == behaviourType.Selector))
        {
            ((BehaviourNode)toNode).index = ((BehaviourNode)to).index;
        }
    }
コード例 #4
0
ファイル: Logs.cs プロジェクト: Rodron/biomochis
    /// <summary>
    /// Transforms the <paramref name="warning"/> into a pre-defined message
    /// </summary>
    /// <param name="warning"></param>
    /// <param name="current"></param>
    /// <returns></returns>
    public static string WarningToString(Warning warning, ClickableElement current)
    {
        string prompt = "Warning at " + (current ? current.elementName : "unknown") + ": ";

        switch (warning)
        {
        case Warning.LeafIsRoot:
            prompt += "A Leaf Node cannot be the root of the Behaviour Tree";
            break;

        case Warning.NoFactors:
            prompt += "At least one Node does not have any Factors connected to it, meaning that line of Action will be ignored";
            break;

        case Warning.UnconnectedNode:
            prompt += "At least one State node is disconnected from the entry state, meaning it will be ignored";
            break;

        case Warning.WeightZero:
            prompt += "Having a Factor with a weight value of zero means it will be ignored";
            break;

        default:
            prompt += "Unknown warning :(";
            break;
        }

        return(prompt);
    }
コード例 #5
0
    /// <summary>
    /// The Initializer for the <seealso cref="FSM"/>
    /// </summary>
    /// <param name="editor"></param>
    /// <param name="parent"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    public void InitFSM(ClickableElement parent, float posx, float posy)
    {
        InitClickableElement();

        this.parent = parent;

        if (parent != null)
        {
            elementName = parent.elementNamer.AddName(identificator, "New FSM ");
        }
        else
        {
            elementName = editor.editorNamer.AddName(identificator, "New FSM ");
        }

        windowRect = new Rect(posx, posy, width, height);

        // Create the entry state
        StateNode entryNode = CreateInstance <StateNode>();

        entryNode.InitStateNode(this, stateType.Entry, 50, 50);

        if (entryNode != null)
        {
            AddEntryState(entryNode);
        }
    }
コード例 #6
0
ファイル: Logs.cs プロジェクト: Rodron/biomochis
    /// <summary>
    /// Transforms the <paramref name="error"/> into a pre-defined message
    /// </summary>
    /// <param name="error"></param>
    /// <returns></returns>
    public static string ErrorToString(Error error, ClickableElement current)
    {
        string prompt = "Error at " + (current ? current.elementName : "unknown") + ": ";

        switch (error)
        {
        case Error.NoEntryState:
            prompt += "You can't have a FSM without an Entry State";
            break;

        case Error.MoreThanOneRoot:
            prompt += "You can't have a BT with more than one Root";
            break;

        case Error.RepeatedName:
            prompt += "You can't have two elements with the same name";
            break;

        case Error.NoExitTransition:
            prompt += "You can't have a " + current.GetTypeString() + " inside a " + current.parent.GetTypeString() + " with no Exit Transition";
            break;

        default:
            prompt += "Unknown error :(";
            break;
        }

        return(prompt);
    }
コード例 #7
0
 /// <summary>
 /// UnCheck the checkbox in the UI.
 /// If the checkbox is already checked, it will try to click on the [ClickableElement] of this control, which make it UnCheck on the UI
 /// </summary>
 public void Uncheck()
 {
     if (IsChecked)
     {
         ClickableElement.WaitUntilElementCssDisplayed();
         ClickableElement.Click();
     }
 }
コード例 #8
0
    /// <summary>
    /// Creates and returns the <see cref="TransitionGUI"/> corresponding to this <see cref="XMLElement"/>
    /// </summary>
    /// <param name="from"></param>
    /// <param name="to"></param>
    /// <returns></returns>
    public TransitionGUI ToTransitionGUI(ClickableElement parent, BaseNode from, BaseNode to)
    {
        TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>();

        transition.InitTransitionGUIFromXML(parent, from, to, this.Id, this.name, this.perception.ToGUIElement(), this.isExit, this.weight);

        return(transition);
    }
コード例 #9
0
ファイル: Page.cs プロジェクト: jcopperman/UiMatic
 private static void ProcessClickables <TPage>(PropertyInfo prop, IDriver driver, TPage page)
 {
     if (prop.PropertyType == typeof(IClickable))
     {
         var      el = new ClickableElement(driver);
         Selector s  = GetSelector(prop, el);
         el.Selector = s;
         prop.SetValue(page, el);
     }
 }
コード例 #10
0
ファイル: ClickableElement.cs プロジェクト: Rodron/biomochis
    public ClickableElement GetMaxParent()
    {
        ClickableElement maxParent = this;

        while (maxParent.parent)
        {
            maxParent = maxParent.parent;
        }

        return(maxParent);
    }
コード例 #11
0
 /// <summary>
 /// The Initializer for the <seealso cref="BaseNode"/>
 /// </summary>
 public void InitBaseNode(ClickableElement parent, string id = null)
 {
     this.parent = parent;
     if (id == null)
     {
         identificator = UniqueID();
     }
     else
     {
         identificator = id;
     }
 }
コード例 #12
0
    /// <summary>
    /// Initializer for the <see cref="PopupWindow"/> when failed at exporting a <see cref="ClickableElement"/>
    /// </summary>
    /// <param name="focusElem"></param>
    /// <param name="type"></param>
    public static void InitExport(ClickableElement elem)
    {
        var foo = senderEditor;

        PopupType = typeOfPopup.FailedExport;

        exportingElem = elem;

        PopupWindow window = ScriptableObject.CreateInstance <PopupWindow>();

        window.titleContent = new GUIContent("Export");
        window.position     = new Rect(senderEditor.position.center.x - width / 2, senderEditor.position.center.y - height / 2, width, height);

        window.ShowModalUtility();
    }
コード例 #13
0
    /// <summary>
    /// The Initializer for the <seealso cref="UtilitySystem"/>
    /// </summary>
    /// <param name="editor"></param>
    /// <param name="parent"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    /// <param name="id"></param>
    public void InitUtilitySystem(ClickableElement parent, float posx, float posy)
    {
        InitClickableElement();

        this.parent = parent;

        if (parent != null)
        {
            elementName = parent.elementNamer.AddName(identificator, "New US ");
        }
        else
        {
            elementName = editor.editorNamer.AddName(identificator, "New US ");
        }

        windowRect = new Rect(posx, posy, width, height);
    }
コード例 #14
0
    /// <summary>
    /// The Initializer for the <seealso cref="FSM"/> when it is being loaded from XML
    /// </summary>
    /// <param name="editor"></param>
    /// <param name="parent"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    public void InitFSMFromXML(ClickableElement parent, float posx, float posy, string id, string name)
    {
        InitClickableElement(id);

        this.parent = parent;

        if (parent != null)
        {
            elementName = parent.elementNamer.AddName(identificator, name);
        }
        else
        {
            elementName = editor.editorNamer.AddName(identificator, name);
        }

        windowRect = new Rect(posx, posy, width, height);
    }
コード例 #15
0
    /// <summary>
    /// Creates the <see cref="BehaviourNode"/> corresponding to this <see cref="XMLElement"/>
    /// </summary>
    /// <param name="selectedNode"></param>
    /// <param name="currentTree"></param>
    /// <param name="currentElement"></param>
    public void ToBehaviourNode(BaseNode selectedNode, BehaviourTree currentTree, ClickableElement currentElement)
    {
        switch (this.elemType)
        {
        case nameof(FSM):
            this.ToFSM(currentElement, selectedNode);
            break;

        case nameof(BehaviourTree):
            this.ToBehaviourTree(currentElement, selectedNode);
            break;

        case nameof(UtilitySystem):
            this.ToUtilitySystem(currentElement, selectedNode);
            break;

        case nameof(BehaviourNode):
            BehaviourNode nodeBT = ScriptableObject.CreateInstance <BehaviourNode>();
            nodeBT.InitBehaviourNodeFromXML(currentTree, (behaviourType)Enum.Parse(typeof(behaviourType), this.secondType), this.windowPosX, this.windowPosY, this.Id, this.name, this.delayTime, this.Nloops, this.isRandom, this.isInfinite, this.index);

            currentTree.nodes.Add(nodeBT);

            if (selectedNode)
            {
                TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>();
                transition.InitTransitionGUI(currentTree, selectedNode, nodeBT, true);

                currentTree.transitions.Add(transition);
            }
            else
            {
                nodeBT.isRoot = true;
            }

            foreach (XMLElement childState in this.nodes)
            {
                childState.ToBehaviourNode(nodeBT, currentTree, currentTree);
            }
            break;

        default:
            Debug.LogError("Wrong content in saved data");
            break;
        }
    }
        private void RenderClickableElement(ClickableElement clickableElement)
        {
            GUIContent buttonGuiContent;

            if (!string.IsNullOrEmpty(clickableElement.IconName))
            {
                buttonGuiContent = new GUIContent($" {clickableElement.Text}", EditorGUIUtility.IconContent(clickableElement.IconName).image);
            }
            else
            {
                buttonGuiContent = new GUIContent(clickableElement.Text);
            }

            if (GUILayout.Button(buttonGuiContent, GUILayout.ExpandWidth(true)))
            {
                clickableElement.OnClick(this);
            }
        }
コード例 #17
0
    /// <summary>
    /// The Initializer for the <seealso cref="StateNode"/> when it is being loaded from an XML
    /// </summary>
    /// <param name="typeNumber"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    public void InitStateNodeFromXML(ClickableElement parent, stateType type, float posx, float posy, string id, string name, ClickableElement subElem = null)
    {
        InitBaseNode(parent, id);

        if (subElem != null)
        {
            this.subElem = subElem;
            nodeName     = this.subElem.elementName;
            windowRect   = new Rect(posx, posy, ClickableElement.width, ClickableElement.height);
        }
        else
        {
            nodeName   = parent.elementNamer.AddName(id, name);
            windowRect = new Rect(posx, posy, width, height);
        }

        this.type = type;
    }
コード例 #18
0
ファイル: BehaviourNode.cs プロジェクト: Rodron/biomochis
    /// <summary>
    /// The Initializer for the <seealso cref="BehaviourNode"/>
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="typeNumber"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    /// <param name="subElem"></param>
    public void InitBehaviourNode(ClickableElement parent, behaviourType type, float posx, float posy, ClickableElement subElem = null, string id = null)
    {
        InitBaseNode(parent, id);

        this.type = type;

        if (subElem != null)
        {
            this.subElem = subElem;
            nodeName     = this.subElem.elementName;
            windowRect   = new Rect(posx, posy, ClickableElement.width, ClickableElement.height);
        }
        else
        {
            nodeName   = parent.elementNamer.AddName(identificator, "New " + type + " Node ");
            windowRect = new Rect(posx, posy, width, height);
        }
    }
コード例 #19
0
ファイル: UtilityNode.cs プロジェクト: Rodron/biomochis
    /// <summary>
    /// The Initializer for the <seealso cref="UtilityNode"/> when it is being loaded from an XML
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="typeNumber"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    /// <param name="subElem"></param>
    public void InitUtilityNodeFromXML(ClickableElement parent, utilityType type, fusionType fusionType, curveType curveType,
                                       float posx, float posy, string id, string name, float variableMax, float variableMin, float slope, float exp, float displX, float displY, List <Vector2> points, ClickableElement subElem = null)
    {
        InitBaseNode(parent, id);

        var foo = editor;

        this.type       = type;
        this.fusionType = fusionType;
        this.curveType  = curveType;

        if (subElem != null)
        {
            this.subElem = subElem;
            nodeName     = this.subElem.elementName;
            windowRect   = new Rect(posx, posy, ClickableElement.width, ClickableElement.height);
        }
        else
        {
            nodeName = parent.elementNamer.AddName(id, name);

            if (type == utilityType.Fusion)
            {
                windowRect = new Rect(posx, posy, width, height * 1.7f);
            }
            else if (type == utilityType.Curve)
            {
                baseHeight = height * 1.5f;
                windowRect = new Rect(posx, posy, width, baseHeight);
            }
            else
            {
                windowRect = new Rect(posx, posy, width, height);
            }
        }

        this.variableMax = variableMax;
        this.variableMin = variableMin;
        this.slope       = slope;
        this.exp         = exp;
        this.displX      = displX;
        this.displY      = displY;
        this.points      = points;
    }
コード例 #20
0
    /// <summary>
    /// Creates a copy of this <see cref="StateNode"/>
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public override GUIElement CopyElement(params object[] args)
    {
        ClickableElement parent = (ClickableElement)args[0];

        StateNode result = CreateInstance <StateNode>();

        result.identificator = this.identificator;
        result.nodeName      = this.nodeName;
        result.parent        = parent;
        result.windowRect    = new Rect(this.windowRect);
        result.type          = this.type;

        if (this.subElem)
        {
            result.subElem = (ClickableElement)this.subElem.CopyElement(parent);
        }

        return(result);
    }
コード例 #21
0
ファイル: UtilityNode.cs プロジェクト: Rodron/biomochis
    /// <summary>
    /// The Initializer for the <seealso cref="UtilityNode"/>
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="typeNumber"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    /// <param name="subElem"></param>
    public void InitUtilityNode(ClickableElement parent, utilityType type, float posx, float posy, ClickableElement subElem = null, string id = null)
    {
        InitBaseNode(parent, id);

        var foo = editor;

        this.type = type;

        if (subElem != null)
        {
            this.subElem = subElem;
            nodeName     = this.subElem.elementName;
            windowRect   = new Rect(posx, posy, ClickableElement.width, ClickableElement.height);
        }
        else
        {
            string nameToAdd = "New " + type;
            if (type != utilityType.Variable)
            {
                nameToAdd += " Node ";
            }
            nodeName = parent.elementNamer.AddName(identificator, nameToAdd);

            if (type == utilityType.Fusion)
            {
                windowRect = new Rect(posx, posy, width, height * 1.7f);
            }
            else if (type == utilityType.Curve)
            {
                baseHeight = height * 1.5f;
                windowRect = new Rect(posx, posy, width, baseHeight);
            }
            else
            {
                windowRect = new Rect(posx, posy, width, height);
            }
        }

        points = new List <Vector2>()
        {
            new Vector2(0, 0)
        };
    }
コード例 #22
0
    /// <summary>
    /// Creates a copy of this <see cref="UtilitySystem"/>
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public override GUIElement CopyElement(params object[] args)
    {
        ClickableElement parent = (ClickableElement)args[0];

        UtilitySystem result = CreateInstance <UtilitySystem>();

        result.identificator = this.identificator;
        result.elementNamer  = CreateInstance <UniqueNamer>();
        result.elementName   = this.elementName;
        result.parent        = parent;
        result.windowRect    = new Rect(this.windowRect);

        result.nodes       = this.nodes.Select(o => (BaseNode)o.CopyElement(result)).ToList();
        result.transitions = this.transitions.Select(o =>
                                                     (TransitionGUI)o.CopyElement(result.nodes.Find(n => n.identificator == o.fromNode.identificator),
                                                                                  result.nodes.Find(n => n.identificator == o.toNode.identificator))).ToList();

        return(result);
    }
コード例 #23
0
ファイル: BehaviourNode.cs プロジェクト: Rodron/biomochis
    /// <summary>
    /// The Initializer for the <seealso cref="BehaviourNode"/> when it is being loaded from an XML
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="typeNumber"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    /// <param name="subElem"></param>
    public void InitBehaviourNodeFromXML(ClickableElement parent, behaviourType type, float posx, float posy, string id, string name, float delayTime, int Nloops, bool isRandom, bool isInfinite, int index, ClickableElement subElem = null)
    {
        InitBaseNode(parent, id);

        this.type = type;

        if (subElem != null)
        {
            this.subElem = subElem;
            nodeName     = this.subElem.elementName;
            windowRect   = new Rect(posx, posy, ClickableElement.width, ClickableElement.height);
        }
        else
        {
            nodeName   = parent.elementNamer.AddName(id, name);
            windowRect = new Rect(posx, posy, width, height);
        }

        this.delayTime  = delayTime;
        this.Nloops     = Nloops;
        this.isRandom   = isRandom;
        this.isInfinite = isInfinite;
        this.index      = index;
    }
コード例 #24
0
    /// <summary>
    /// Creates and returns the <see cref="FSM"/> corresponding to this <see cref="XMLElement"/>
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="selectedNode"></param>
    /// <returns></returns>
    public UtilitySystem ToUtilitySystem(ClickableElement parent, BaseNode selectedNode = null)
    {
        UtilitySystem utilSystem = ScriptableObject.CreateInstance <UtilitySystem>();

        utilSystem.InitUtilitySystemFromXML(parent, this.windowPosX, this.windowPosY, this.Id, this.name);

        foreach (XMLElement node in this.nodes)
        {
            switch (node.elemType)
            {
            case nameof(FSM):
                node.ToFSM(utilSystem, null);
                break;

            case nameof(BehaviourTree):
                node.ToBehaviourTree(utilSystem, null);
                break;

            case nameof(UtilitySystem):
                node.ToUtilitySystem(utilSystem, null);
                break;

            case nameof(UtilityNode):
                UtilityNode state = node.ToUtilityNode(utilSystem);

                utilSystem.nodes.Add(state);
                break;

            default:
                Debug.LogError("Wrong content in saved data");
                break;
            }
        }

        foreach (XMLElement trans in this.transitions)
        {
            BaseNode node1 = utilSystem.nodes.Where(n => n.identificator == trans.fromId || n.subElem?.identificator == trans.fromId).FirstOrDefault();
            BaseNode node2 = utilSystem.nodes.Where(n => n.identificator == trans.toId || n.subElem?.identificator == trans.toId).FirstOrDefault();
            if (node1 != null && node2 != null)
            {
                utilSystem.transitions.Add(trans.ToTransitionGUI(utilSystem, node1, node2));
            }
        }

        if (parent)
        {
            switch (parent.GetType().ToString())
            {
            case nameof(FSM):
                StateNode state = ScriptableObject.CreateInstance <StateNode>();
                state.InitStateNodeFromXML(parent, stateType.Unconnected, utilSystem.windowRect.position.x, utilSystem.windowRect.position.y, this.Id, this.name, utilSystem);

                if (this.secondType.Equals(stateType.Entry.ToString()))
                {
                    ((FSM)parent).AddEntryState(state);
                }
                else
                {
                    parent.nodes.Add(state);
                }
                break;

            case nameof(BehaviourTree):
                BehaviourNode node = ScriptableObject.CreateInstance <BehaviourNode>();
                node.InitBehaviourNode(parent, behaviourType.Leaf, utilSystem.windowRect.x, utilSystem.windowRect.y, utilSystem);

                parent.nodes.Add(node);

                if (selectedNode != null)
                {
                    TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>();
                    transition.InitTransitionGUI(parent, selectedNode, node);

                    parent.transitions.Add(transition);

                    selectedNode = node;
                }
                break;

            case nameof(UtilitySystem):
                UtilityNode utilNode = ScriptableObject.CreateInstance <UtilityNode>();
                utilNode.InitUtilityNode(parent, utilityType.Action, utilSystem.windowRect.position.x, utilSystem.windowRect.position.y, utilSystem);

                parent.nodes.Add(utilNode);
                break;
            }
        }

        return(utilSystem);
    }