/// <summary> /// Creates A new scenario. /// </summary> /// <returns> /// return the Created GameObject Attached a New Scenario Node. /// </returns> static public GameObject CreateANewScenario(string scenarioName, bool startAndPlay) { // GameObject vinoObj = GetViNoObject(); GameObject scenarioObj = GameObject.Find(scenarioName); if (scenarioObj == null) { scenarioObj = new GameObject(scenarioName); // scenarioObj.transform.parent = vinoObj.transform; scenarioObj.AddComponent <ScenarioNode>(); } // if a New ScenarioNode is Played at Start , Other ScenarioNode objects of all the are Not Played at Start. if (startAndPlay) { ScenarioNode[] snodes = GameObject.FindObjectsOfType(typeof(ScenarioNode)) as ScenarioNode[]; for (int i = 0; i < snodes.Length; i++) { snodes[i].m_PlayAtStart = false; } } GameObject startObj = new GameObject("START"); ViNode startNode = startObj.AddComponent <ViNode>(); startObj.transform.parent = scenarioObj.transform; ScenarioNode scenarioNode = scenarioObj.GetComponent <ScenarioNode>(); scenarioNode.startNode = startNode; scenarioNode.m_PlayAtStart = startAndPlay; return(scenarioObj); }
public void ReIndexChildren() { ViNode[] nodes = GetComponentsInChildren <ViNode>(); if (nodes != null) { int index = 0; GameObject nodeObj = null; for (int i = 0; i < nodes.Length; i++) { ViNode node = nodes[i]; if (node.name.Equals(name) || node.gameObject == nodeObj) { continue; // Dont Rename MySelf. } nodeObj = nodes[i].gameObject; // Extract 1_Dialog to "1_" and "Dialog". string[] strs = node.name.Split("_"[0]); if (strs.Length > 1) { node.name = (index).ToString() + "_" + strs[1]; } else { node.name = (index).ToString() + "_" + node.name; } index++; } } }
/// <summary> /// Play From a Node. /// </summary> public void PlayFrom(ViNode node) { CheckInstance(); string tag = node.GetNodeTag(node.name); VM.Instance.RunWithTag(tag); }
static public void CreateViNodeOfMenu( ) { Transform parentNodeTra = (Selection.activeGameObject != null) ? Selection.activeGameObject.transform : null; ViNode node = ViNoToolUtil.AddViNodeGameObject <ViNode>("ViNode", parentNodeTra); EditorGUIUtility.PingObject(node.gameObject); }
public void SetChild(ViNode childNode) { if (childNode == null) { return; } Transform thisTra = transform; int childCount = this.transform.GetChildCount(); int index = childCount - 1; childNode.name = index + "_" + childNode.name; childNode.transform.parent = thisTra; }
public override void ToScenarioScript(ref System.Text.StringBuilder sb) { if (units != null && units.Length > 0) { for (int i = 0; i < units.Length; i++) { ViNode target = units[i].targetNode; string targetStr = target.GetNodeTag(target.name); sb.Append("[link target=*" + targetStr + "]" + units[i].text + "[endlink][r]"); // This is KiriKiri Script. sb.Append(System.Environment.NewLine); } sb.Append("[s]"); sb.Append(System.Environment.NewLine); } }
static public void CreateSelectionsNodeOfMenu( ) { ISelectionsCtrl sel = GameObject.FindObjectOfType(typeof(ISelectionsCtrl)) as ISelectionsCtrl; if (sel == null) { DrawObjectsTab.CreateGUISelectionsCtrl(); } Transform parentNodeTra = (Selection.activeGameObject != null) ? Selection.activeGameObject.transform : null; SelectionsNode node = ViNoToolUtil.AddViNodeGameObject <SelectionsNode>("Selections", parentNodeTra); ViNode childNode1 = ViNoToolUtil.AddViNodeGameObject <ViNode>("Selected1", node.transform); ViNode childNode2 = ViNoToolUtil.AddViNodeGameObject <ViNode>("Selected2", node.transform); DialogPartNode dlg1 = CreateDialogNode("name", "Selected 1"); //ViNoToolUtil.AddViNodeGameObject<DialogPartNode>( "Dialog" , childNode1.transform ); dlg1.transform.parent = childNode1.transform; DialogPartNode dlg2 = CreateDialogNode("name", "Selected 2"); //ViNoToolUtil.AddViNodeGameObject<DialogPartNode>( "Dialog" , childNode2.transform ); dlg2.transform.parent = childNode2.transform; node.units = new SelectionsNode.SelectUnit [2]; node.units[0] = new SelectionsNode.SelectUnit(); node.units[0].targetNode = childNode1; node.units[0].text = "Selection 1"; node.units[0].index = 0; node.units[1] = new SelectionsNode.SelectUnit(); node.units[1].targetNode = childNode2; node.units[1].text = "Selection 2"; node.units[1].index = 1; EditorGUIUtility.PingObject(node.gameObject); }
/// <summary> /// Play From a Node. /// </summary> public void PlayFrom( ViNode node ) { CheckInstance(); string tag = node.GetNodeTag( node.name ); VM.Instance.RunWithTag( tag ); }
public static void OnGUI_ViNode( ViNode node , bool drawChildList , bool showNextNode ) { GUICommon.DrawLineSpace( 7f , 7f ); bool hasViNode = false; if( drawChildList ){ Color savedCol = GUI.color; GUI.color = Color.green; // node.startAndActive = EditorGUILayout.Toggle( "Start and Active" , node.startAndActive ); // EditorGUILayout.LabelField( "ViNode List" , GUILayout.Width( 200f ) ); int childCount= node.transform.GetChildCount(); for( int i=0;i<childCount;i++){ Transform childTra = node.transform.GetChild( i ); ViNode vinode = childTra.GetComponent<ViNode>(); if( vinode != null ){ hasViNode = true; Undo.RegisterUndo( childTra.gameObject , "active" + childTra.name ); EditorGUILayout.BeginHorizontal(); // bool t = EditorGUILayout.Toggle( childTra.gameObject.activeInHierarchy , GUILayout.Width( 10f) ); // Toggle active. if( GUILayout.Button( i.ToString () , GUILayout.Width ( 20f ) ) ){ childTra.gameObject.SetActive( ! childTra.gameObject.activeInHierarchy ); } // Need to be fixed. #if false if( GUILayout.Button( "up" , GUILayout.Width ( 35f ) ) ){ childTra.name = childTra.name.Replace( i + "_" , ( i + 1 ) + "_" ); Transform parantTra = childTra.parent; childTra.parent = null; childTra.parent = parantTra; Transform childTra2 = node.transform.GetChild( i + 1 ); childTra2.name = childTra2.name.Replace( ( i + 1 ) + "_" , i + "_" ); parantTra = childTra2.parent; childTra2.parent = null; childTra2.parent = parantTra; } if( GUILayout.Button( "dwn" , GUILayout.Width ( 35f ) ) ){ childTra.name = childTra.name.Replace( i + "_" , ( i - 1 ) + "_" ); Transform childTra2 = node.transform.GetChild( i - 1 ); childTra2.name = childTra2.name.Replace( ( i - 1 ) + "_" , i + "_" ); Transform parantTra = childTra2.parent; childTra2.parent = null; childTra2.parent = parantTra; } #endif GUI.enabled = childTra.gameObject.activeInHierarchy; if( GUILayout.Button ( childTra.name ) ){ EditorGUIUtility.PingObject( childTra.gameObject ); if( Application.isPlaying ){ VM.Instance.GoToLabel( vinode.GetNodeLabel() ); } } GUI.enabled = true; EditorGUILayout.EndHorizontal (); } } GUI.color = savedCol; } if( hasViNode ){ EditorGUILayout.LabelField( "When execution order is not right in Children," ); EditorGUILayout.LabelField( "Please push RefreshChildren button to fix." ); EditorGUILayout.BeginHorizontal(); if( GUILayout.Button( "RefreshChildren" ) ){ node.RefreshChildren(); } if( GUILayout.Button( "ReIndexChildren" ) ){ ViNode[] childNodes = node.GetComponentsInChildren<ViNode>(); Undo.RegisterUndo( childNodes , "ReIndexChildren" ); node.ReIndexChildren (); } EditorGUILayout.EndHorizontal(); } GUICommon.DrawLineSpace( 5f , 5f ); }
// private SerializedProperty soundDataProp = null; static private void CompileAndSaveAsBinaryFile(string fileName, ScenarioNode scenario) { ByteCodes btcodes = scenario.Compile(); ViNode.SaveByteCodesToFile(fileName, btcodes.GetCode()); }
// --------------- public Methods --------------------------------------. public void AddNode <T>(ViNode aNode) where T : ViNode { aNode.transform.parent = transform; }
public override void OnInspectorGUI(){ ViNode node = target as ViNode; NodeGUI.OnGUI_ViNode( node , true , true ); }
static public void OnGUI_ViNode(ViNode node, bool drawChildList, bool showNextNode) { GUICommon.DrawLineSpace(7f, 7f); bool hasViNode = false; if (drawChildList) { Color savedCol = GUI.color; GUI.color = Color.green; // node.startAndActive = EditorGUILayout.Toggle( "Start and Active" , node.startAndActive ); // EditorGUILayout.LabelField( "ViNode List" , GUILayout.Width( 200f ) ); int childCount = node.transform.GetChildCount(); for (int i = 0; i < childCount; i++) { Transform childTra = node.transform.GetChild(i); ViNode vinode = childTra.GetComponent <ViNode>(); if (vinode != null) { hasViNode = true; Undo.RegisterUndo(childTra.gameObject, "active" + childTra.name); EditorGUILayout.BeginHorizontal(); // bool t = EditorGUILayout.Toggle( childTra.gameObject.activeInHierarchy , GUILayout.Width( 10f) ); // Toggle active. if (GUILayout.Button(i.ToString(), GUILayout.Width(20f))) { childTra.gameObject.SetActive(!childTra.gameObject.activeInHierarchy); } // Need to be fixed. #if false if (GUILayout.Button("up", GUILayout.Width(35f))) { childTra.name = childTra.name.Replace(i + "_", (i + 1) + "_"); Transform parantTra = childTra.parent; childTra.parent = null; childTra.parent = parantTra; Transform childTra2 = node.transform.GetChild(i + 1); childTra2.name = childTra2.name.Replace((i + 1) + "_", i + "_"); parantTra = childTra2.parent; childTra2.parent = null; childTra2.parent = parantTra; } if (GUILayout.Button("dwn", GUILayout.Width(35f))) { childTra.name = childTra.name.Replace(i + "_", (i - 1) + "_"); Transform childTra2 = node.transform.GetChild(i - 1); childTra2.name = childTra2.name.Replace((i - 1) + "_", i + "_"); Transform parantTra = childTra2.parent; childTra2.parent = null; childTra2.parent = parantTra; } #endif GUI.enabled = childTra.gameObject.activeInHierarchy; if (GUILayout.Button(childTra.name)) { EditorGUIUtility.PingObject(childTra.gameObject); if (Application.isPlaying) { VM.Instance.GoToLabel(vinode.GetNodeLabel()); } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); } } GUI.color = savedCol; } if (hasViNode) { EditorGUILayout.LabelField("When execution order is not right in Children,"); EditorGUILayout.LabelField("Please push RefreshChildren button to fix."); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("RefreshChildren")) { node.RefreshChildren(); } if (GUILayout.Button("ReIndexChildren")) { ViNode[] childNodes = node.GetComponentsInChildren <ViNode>(); Undo.RegisterUndo(childNodes, "ReIndexChildren"); node.ReIndexChildren(); } EditorGUILayout.EndHorizontal(); } GUICommon.DrawLineSpace(5f, 5f); }