Esempio n. 1
0
    //--------- 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]);
        }
    }
Esempio n. 2
0
    //--------- 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);
    }
Esempio n. 3
0
    //--------- 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);
    }
    //--------- 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();
        }
    }
    //--------- 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]);
        }
    }
Esempio n. 6
0
 void Start()
 {
     iScript = GetComponent<iMove>();
     hoScript = GetComponent<hoMove>();
     thisObject = transform;
 }
Esempio n. 7
0
    //--------- 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();
        }
    }
Esempio n. 8
0
 void Start()
 {
     iScript    = GetComponent <iMove>();
     hoScript   = GetComponent <hoMove>();
     thisObject = transform;
 }