/// <summary> /// Turns a JSON-formatted Twine node into a GameObject with all the relevant data in a TwineNode component. /// </summary> /// <returns>GameObject of single node.</returns> /// <param name="nodeJSON">A Twine Node, in JSON format</param> public static GameObject MakeGameObjectFromStoryNode(JSONNode nodeJSON) { #if UNITY_EDITOR GameObject nodeGameObject = new GameObject(nodeJSON["name"]); nodeGameObject.AddComponent <TwineNode> (); // Save additional Twine data on a Twine component TwineNode twineNode = nodeGameObject.GetComponent <TwineNode> (); twineNode.pid = nodeJSON["pid"]; twineNode.name = nodeJSON["name"]; twineNode.tags = GetDequotedStringArrayFromJsonArray(nodeJSON["tags"]); twineNode.content = GetVisibleText(nodeJSON["text"]); string[] variableExpressions = GetVariableExpressions(nodeJSON["text"]); ActivateVariableExpressions(variableExpressions, twineNode); // Upon creation of this node, ensure that it is a decision node if it has // the decision tag: // Vice versa for condition node twineNode.isDecisionNode = (twineNode.tags != null && twineNode.tags.Contains(PRAIRIE_DECISION_TAG)); twineNode.isConditionNode = (twineNode.tags != null && twineNode.tags.Contains(PRAIRIE_CONDITION_TAG)); // Start all twine nodes as deactivated at first: twineNode.Deactivate(); return(nodeGameObject); #endif }
/// <summary> /// Turns a JSON-formatted Twine node into a GameObject with all the relevant data in a TwineNode component. /// </summary> /// <returns>GameObject of single node.</returns> /// <param name="storyNode">A Twine Node, in JSON format</param> public static GameObject MakeGameObjectFromStoryNode(JSONNode storyNode) { #if UNITY_EDITOR GameObject nodeGameObject = new GameObject(storyNode["name"]); nodeGameObject.AddComponent <TwineNode> (); // Save additional Twine data on a Twine component TwineNode twineNode = nodeGameObject.GetComponent <TwineNode> (); twineNode.pid = storyNode["pid"]; twineNode.name = storyNode["name"]; twineNode.tags = GetDequotedStringArrayFromJsonArray(storyNode["tags"]); twineNode.content = RemoveTwineLinks(storyNode["text"]); // Upon creation of this node, ensure that it is a decision node if it has // the decision tag: twineNode.isDecisionNode = (twineNode.tags != null && twineNode.tags.Contains(PRAIRIE_DECISION_TAG)); // Start all twine nodes as deactivated at first: twineNode.Deactivate(); return(nodeGameObject); #endif }