// Token: 0x060006FF RID: 1791 RVA: 0x0002DF9C File Offset: 0x0002C39C private void DrawExample1() { GUI.Label(new Rect(10f, 10f, 20f, 20f), "1:"); string name = "Walker (Path1)"; string text = "Path1 (Instantiation)"; Vector3 position = new Vector3(-25f, 0f, 10f); if (!this.example1.done && GUI.Button(new Rect(30f, 10f, 100f, 20f), "Instantiate")) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.example1.walkerPrefab, position, Quaternion.identity); gameObject.name = name; GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(this.example1.pathPrefab, position, Quaternion.identity); gameObject2.name = text; WaypointManager.AddPath(gameObject2); gameObject.GetComponent <splineMove>().SetPath(WaypointManager.Paths[text]); this.example1.done = true; } if (this.example1.done && GUI.Button(new Rect(30f, 10f, 100f, 20f), "Destroy")) { UnityEngine.Object.Destroy(GameObject.Find(name)); UnityEngine.Object.Destroy(GameObject.Find(text)); WaypointManager.Paths.Remove(text); this.example1.done = false; } }
//--------- this short example method visualizes: ---------\\ //*instantiate a walker object and a path at runtime, //*add path reference to our WaypointManager so other have access to it //*set path container of path instantiated in method above ("RuntimePath1") and start moving //*change path at runtime - switch from "RuntimePath1" to "RuntimePath2" void Example2() { GUI.Label(new Rect(10, 60, 120, 30), "Example 2"); if (!walkerObj2 && GUI.Button(new Rect(10, 85, 130, 25), "Instantiate Objects")) { //instantiate walker prefab walkerObj2 = (GameObject)Instantiate(walkerPrefab, position3.position, Quaternion.identity); walkerObj2.name = "Soldier@" + System.DateTime.Now.TimeOfDay; //instantiate path prefab newPath2 = (GameObject)Instantiate(pathPrefab, position3.position, Quaternion.identity); //rename the path to ensure it is unique newPath2.name = "RuntimePath@" + System.DateTime.Now.TimeOfDay; //add newly instantiated path to the WaypointManager dictionary WaypointManager.AddPath(newPath2); } if (walkerObj2 && !walkeriM2 && GUI.Button(new Rect(140, 85, 130, 25), "Start Movement")) { //get iMove component of this walker object, here we cache it once walkeriM2 = walkerObj2.GetComponent <iMove>(); //set path container to path instantiated above - access WaypointManager dictionary //and start movement on new path walkeriM2.SetPath(WaypointManager.Paths[newPath2.name]); } //change instantiated path position from position1 to position2 or vice versa if (newPath1 && newPath2 && GUI.Button(new Rect(10, 85, 130, 25), "Switch Path")) { //set moveToPath boolean of instantiated walker to true, //so on calling SetPath() it does not appear at the new path but walks to it instead if (!walkeriM2) { walkeriM2 = walkerObj2.GetComponent <iMove>(); } walkeriM2.moveToPath = true; //set path container from newPath1 to newPath2 or vice versa //- access WaypointManager dictionary and start movement on new path if (walkeriM2.pathContainer == WaypointManager.Paths[newPath1.name]) { walkeriM2.SetPath(WaypointManager.Paths[newPath2.name]); } else { walkeriM2.SetPath(WaypointManager.Paths[newPath1.name]); } //you could call also that function within one line like this, //if you don't need to change other iMove properties: //walkeriM2.GetComponent<iMove>().SetPath(WaypointManager.Paths[newPath1.name]); //or //walkeriM2.SendMessage("SetPath", WaypointManager.Paths[newPath1.name]); } }
//recalculate path points void Awake() { WaypointManager.AddPath(gameObject); //do not recalculate automatically with runtime created paths if (bPoints == null || bPoints.Count == 0) { return; } CalculatePath(); }
//--------- this short example method visualizes: ---------\\ //*instantiate a walker object and a path at runtime //*add path reference to our WaypointManager so other have access to it //*set path container of this object and start moving //*reposition path (walker object automatically gets new waypoint positions) //*stop movement //*continue movement IEnumerator RuntimeInstantiation() { //instantiate walker prefab GameObject walkerObj = (GameObject)Instantiate(walkerPrefab, transform.position, Quaternion.identity); //instantiate path prefab GameObject newPath = (GameObject)Instantiate(pathPrefab, transform.position, Quaternion.identity); //rename the path to ensure it is unique newPath.name = "RuntimePath1"; //add newly instantiated path to the WaypointManager dictionary WaypointManager.AddPath(newPath); //get iMove component of this walker object iMove walkeriM = walkerObj.GetComponent <iMove>(); //set path container to path instantiated above - access WaypointManager dictionary //and start movement on new path walkeriM.SetPath(WaypointManager.Paths["RuntimePath1"]); Debug.Log("[RuntimeExample.cs] Ex1: Instantiated: " + newPath.name + " and " + walkerObj.name + " running."); //wait few seconds yield return(new WaitForSeconds(5)); //change instantiated path position so we can distinguish it from example two //get path transform and reposition it 10 z units further away newPath.transform.position += new Vector3(-20, 0, 0); Debug.Log("[RuntimeExample.cs] Ex1: Repositioned: " + newPath.name); //wait few seconds yield return(new WaitForSeconds(10)); //stop any movement and reset to first waypoint walkeriM.Reset(); //to only stop it instead, use //walkeriM.Stop(); Debug.Log("[RuntimeExample.cs] Ex1: Resetted: " + walkerObj.name); //wait few seconds yield return(new WaitForSeconds(10)); //set moveToPath boolean of instantiated walker to true, //so on calling StartMove() it does not appear at the next waypoint but walks to it instead walkeriM.moveToPath = true; //continue movement walkeriM.StartMove(); Debug.Log("[RuntimeExample.cs] Ex1: Continued movement on: " + newPath.name); }
//--------- this short example method visualizes: ---------\\ //*instantiate a walker object and a path at runtime, //*reposition path, but our walker object does not use it yet //*add path reference to our WaypointManager so other have access to it //*set path container of path instantiated in method above ("RuntimePath1") and start moving //*change path at runtime - switch from "RuntimePath1" to "RuntimePath2" IEnumerator ChangePathAtRuntime() { //instantiate walker prefab GameObject walkerObj = (GameObject)Instantiate(walkerPrefab, transform.position, Quaternion.identity); //instantiate path prefab GameObject newPath = (GameObject)Instantiate(pathPrefab, transform.position, Quaternion.identity); //rename the path to ensure it is unique newPath.name = "RuntimePath2"; //change instantiated path position so we can distinguish it from example one newPath.transform.position += new Vector3(24.5f, 0, 0); //add newly instantiated path to the WaypointManager dictionary WaypointManager.AddPath(newPath); //get iMove component of this walker object iMove walkeriM = walkerObj.GetComponent <iMove>(); //set half speed of this walker walkeriM.speed /= 2; //set path container to path instantiated in "RuntimeInstantiation()" //- access WaypointManager dictionary and start movement on new path walkeriM.SetPath(WaypointManager.Paths["RuntimePath1"]); Debug.Log("[RuntimeExample.cs] Ex2: Instantiated: " + newPath.name + " and " + walkerObj.name + " running on RuntimePath1."); //you could call that function within one line if you don't need to change other iMove properties: //walkerObj.GetComponent<iMove>().SetPath(WaypointManager.Paths["RuntimePath1"]); //or //walkerObj.SendMessage("SetPath", WaypointManager.Paths["RuntimePath1"]); //wait few seconds yield return(new WaitForSeconds(5)); //set moveToPath boolean of instantiated walker to true, //so on calling SetPath() it does not appear at the new path but walks to it instead walkeriM.moveToPath = true; //change path to the path instantiated in this method, //- switch from "RuntimePath1" to "RuntimePath2" walkeriM.SetPath(WaypointManager.Paths[newPath.name]); Debug.Log("[RuntimeExample.cs] Ex2: " + walkerObj.name + " changed path to: " + newPath.name); }
//Example 1: Path & Walker Instantiation void DrawExample1() { GUI.Label(new Rect(10, 10, 20, 20), "1:"); string walkerName = "Walker (Path1)"; string pathName = "Path1 (Instantiation)"; Vector3 pos = new Vector3(-25, 0, 10); //instantiation if (!example1.done && GUI.Button(new Rect(30, 10, 100, 20), "Instantiate")) { //instantiate walker prefab GameObject walker = (GameObject)Instantiate(example1.walkerPrefab, pos, Quaternion.identity); //rename walker to ensure it is unique walker.name = walkerName; //instantiate path prefab GameObject path = (GameObject)Instantiate(example1.pathPrefab, pos, Quaternion.identity); //rename path to ensure it is unique path.name = pathName; //add newly instantiated path to the WaypointManager dictionary WaypointManager.AddPath(path); //start movement on the new path walker.GetComponent <splineMove>().SetPath(WaypointManager.Paths[pathName]); //example only example1.done = true; } //destruction if (example1.done && GUI.Button(new Rect(30, 10, 100, 20), "Destroy")) { Destroy(GameObject.Find(walkerName)); Destroy(GameObject.Find(pathName)); WaypointManager.Paths.Remove(pathName); //example only example1.done = false; } }
void Awake() { WaypointManager.AddPath(gameObject); }
//--------- this short example visualizes: ---------\\ //*instantiate a walker object and a path at runtime //*add path reference to our WaypointManager so other have access to it //*set path container of this object and start moving //*reposition path (walker object automatically gets new waypoint positions) //*stop movement //*continue movement void Example1() { GUI.Label(new Rect(10, 5, 120, 30), "Example 1"); if (!walkerObj1 && GUI.Button(new Rect(10, 30, 130, 25), "Instantiate Objects")) { //instantiate walker prefab walkerObj1 = (GameObject)Instantiate(walkerPrefab, position1.position, Quaternion.identity); walkerObj1.name = "Soldier@" + System.DateTime.Now.TimeOfDay; //instantiate path prefab newPath1 = (GameObject)Instantiate(pathPrefab, position1.position, Quaternion.identity); //rename the path to ensure it is unique newPath1.name = "RuntimePath@" + System.DateTime.Now.TimeOfDay; //add newly instantiated path to the WaypointManager dictionary WaypointManager.AddPath(newPath1); } if (walkerObj1 && !walkeriM1 && GUI.Button(new Rect(140, 30, 130, 25), "Start Movement")) { //get iMove component of this walker object, here we cahce it once walkeriM1 = walkerObj1.GetComponent <iMove>(); //set path container to path instantiated above - access WaypointManager dictionary //and start movement on new path walkeriM1.SetPath(WaypointManager.Paths[newPath1.name]); } //change instantiated path position from position1 to position2 or vice versa if (newPath1 && GUI.Button(new Rect(10, 30, 130, 25), "Reposition Path")) { Transform path = newPath1.transform; if (path.position == position1.position) { path.position = position2.position; } else { path.position = position1.position; } } //stop and reset movement to the first waypoint if (walkerObj1 && walkeriM1 && GUI.Button(new Rect(140, 30, 130, 25), "Reset Walker")) { walkeriM1.Reset(); walkeriM1 = null; } //stop any movement for the time being if (walkerObj1 && walkeriM1 && GUI.Button(new Rect(270, 30, 100, 25), "Stop Walker")) { walkeriM1.Stop(); //don't call this method in hoMove if you want to resume the animation later, //call .Pause() and .Resume() instead } //continue movement if (walkerObj1 && walkeriM1 && GUI.Button(new Rect(370, 30, 100, 25), "Continue Walk")) { //set moveToPath boolean of instantiated walker to true, //so on calling StartMove() it does not appear at the next waypoint but walks to it instead walkeriM1.moveToPath = true; //continue movement walkeriM1.StartMove(); } }
//Auto-add to WaypointManager void Start() { WaypointManager.AddPath(gameObject); }