/// <summary> /// Updates the visuals of this BoxUI node and any higher up BoxUI nodes based on what the currently selected actionTreeNode is /// </summary> /// <param name="actionTreeNode"></param> public void OnChangeActionTreePosition(ExNovoActionTreeNode actionTreeNode) { if (actionTreeNode == null) { Hide(true /*hide recursively*/); return; } if (actionTreeNode.IsRoot) { Hide(false /*not recursive, show the rest of the tree*/); } else { ChangeVisuals(actionTreeNode.ActionName, actionTreeNode.Color); } if (Next1 != null) { Next1.OnChangeActionTreePosition(actionTreeNode.Child(1)); } if (Next2 != null) { Next2.OnChangeActionTreePosition(actionTreeNode.Child(2)); } if (Next3 != null) { Next3.OnChangeActionTreePosition(actionTreeNode.Child(3)); } }
private void Start() { // process json action tree if (JSONActionTree == null) { throw new MissingReferenceException("ExNovo controller requires an action tree json file"); } ActionTreeRoot = ExNovoActionTreeJSONReader.ReadTreeFromJSON(JSONActionTree.text); CurrentTreeNode = ActionTreeRoot; // initialize boxUI if (ExNovoBoxUIRoot == null) { throw new MissingReferenceException("Requies reference to root of ExNovoBoxUI"); } ExNovoBoxUIRoot.OnChangeActionTreePosition(CurrentTreeNode); // get reference to command runner ActionRunner = FindObjectOfType <ExNovoActionRunner>(); if (ActionRunner == null) { throw new MissingComponentException("No ActionRunner was found. Make sure there is one in the scene. ExNovo cannot run commands without it"); } // Get sound player ExNovoSoundPlayer = GetComponent <ExNovoSoundPlayer>(); if (ExNovoSoundPlayer == null) { throw new MissingComponentException(); } }
private static ExNovoActionTreeNode BuildXNVNode(JSONNode jsonNode, ExNovoActionTreeNode parentXNVNode) { Color nodeColor = parentXNVNode != null ? parentXNVNode.Color : Color.white; // set default color to the parent color in case this node doesnt have it's own color defined if (jsonNode["color"] != null) { ColorUtility.TryParseHtmlString(jsonNode["color"], out nodeColor); } return(new ExNovoActionTreeNode(jsonNode["name"], nodeColor, jsonNode["methodCall"], parentXNVNode)); }
/// <summary> /// Recursive method for building the action tree /// </summary> /// <param name="jsonNode">JSON representation of the current node</param> /// <param name="xnvNode">ExNovoActionTreeNode representation of the parent of the current node</param> private static void CreateChildNodes(JSONNode jsonNode, ExNovoActionTreeNode xnvNode) { foreach (JSONNode jsonChild in new JSONNode[] { jsonNode["next1"], jsonNode["next2"], jsonNode["next3"] }) { if (jsonChild != null) { var childXNVNode = BuildXNVNode(jsonChild, xnvNode); CreateChildNodes(jsonChild, childXNVNode); } } }
public ExNovoActionTreeNode(string name, Color color, string methodCallText, ExNovoActionTreeNode parent) { this.ActionName = name; this.Color = color; this.MethodCallText = methodCallText; this.Parent = parent; Children = new List <ExNovoActionTreeNode>(); if (parent != null) { parent.AddChildNode(this); } }
public void OnInputSelect(int selectNumber) { if (CurrentTreeNode.HasChild(selectNumber)) { CurrentTreeNode = CurrentTreeNode.Child(selectNumber); ExNovoBoxUIRoot.OnChangeActionTreePosition(CurrentTreeNode); ExNovoSoundPlayer.PlaySelectSound(selectNumber); } else { Debug.Log("Cannot traverse that way"); ExNovoSoundPlayer.PlayErrorSound(); } }
public void OnInputCancel() { if (CurrentTreeNode.IsRoot == false) { CurrentTreeNode = ActionTreeRoot; ExNovoBoxUIRoot.OnChangeActionTreePosition(CurrentTreeNode); ExNovoSoundPlayer.PlayCancelSound(); } else { Debug.Log("Cannot cancel here"); ExNovoSoundPlayer.PlayErrorSound(); } }
/// <summary> /// Reads the json string and converts it to a tree of ExNovoActionTreeNode /// </summary> /// <param name="jsonString">String containing the entire json action tree</param> /// <returns>The root to the ExNovoActionTreeNode tree</returns> public static ExNovoActionTreeNode ReadTreeFromJSON(string jsonString) { // read the content as json nodes //ActionTreeJSONNode jsonTree = ActionTreeJSONNode.CreateFromJSON(jsonString); var jsonTree = JSON.Parse(jsonString); // create the root xnv node ExNovoActionTreeNode rootXNVNode = BuildXNVNode(jsonTree, null); // create xnv nodes for the entire tree CreateChildNodes(jsonTree, rootXNVNode); return(rootXNVNode); }
public void OnInputConfirm() { try { if (CurrentTreeNode.IsRoot) { throw new System.InvalidOperationException("Cannot confirm at root"); } ActionRunner.RunMethodCallText(CurrentTreeNode.MethodCallText); ExNovoSoundPlayer.PlayConfirmSound(); } catch (System.Exception e) { ExNovoSoundPlayer.PlayErrorSound(); throw e; } finally { CurrentTreeNode = ActionTreeRoot; ExNovoBoxUIRoot.OnChangeActionTreePosition(CurrentTreeNode); } }
private void AddChildNode(ExNovoActionTreeNode childNode) { Children.Add(childNode); }