コード例 #1
0
 void Rewind()
 {
     if (pointsInTime.Count > 0)
     {
         PointInTime pointInTime = pointsInTime[0];
         transform.position = pointInTime.position;
         transform.rotation = pointInTime.rotation;
         pointsInTime.RemoveAt(0);
     }
     else
     {
         Timebody tb = GetComponent <Timebody>();
         finishedRewinding = true;
         Destroy(tb);
     }
 }
コード例 #2
0
    /// <summary>The actual process to get combat torn down</summary>
    private IEnumerator TeardownCombat()
    {
        canStartCombat = false;
        canStopCombat  = false;

        RewindTime();

        foreach (GameObject r in rigidbodyObjects)
        {
            Timebody tb = r.GetComponent <Timebody>();
            RewindTime -= tb.RewindTime;
        }

        bc.enabled = false;

        while (!Timebody.finishedRewinding)
        {
            yield return(null);
        }

        foreach (GameObject o in clonedCombatObjects)
        {
            Destroy(o);
        }

        foreach (GameObject o in combatObjects)
        {
            if (o.GetComponent <Rigidbody>())
            {
                o.GetComponent <Rigidbody>().isKinematic = false;
            }
        }

        foreach (GameObject o in rightObjects)
        {
            Destroy(o);
        }

        brainOfCamera.enabled = false;

        foreach (GameObject e in entityObjects)
        {
            e.transform.position = beforeArenaLocation + (e.transform.position - transform.position);
        }

        yield return(new WaitForSeconds(0.1f));

        brainOfCamera.enabled = true;

        transform.position = beforeArenaLocation;

        clonedCombatObjects = null;
        combatObjects       = new List <GameObject>();
        entityObjects       = new List <GameObject>();
        rightObjects        = null;
        allSlicedObjects    = null;
        rigidbodyObjects    = null;

        canStartCombat = true;
        canStopCombat  = false;
    }
コード例 #3
0
    /// <summary>The actual process to get combat setup</summary>
    private IEnumerator SetupCombat()
    {
        Stopwatch totalTime = new Stopwatch();

        totalTime.Start();

        canStartCombat = false;
        canStopCombat  = false;

        transform.position = startLocation;

        beforeArenaLocation = transform.position;
        yield return(new WaitForSeconds(.1f)); //Give objects enough time to trigger OnTriggerEnter()

        bc.enabled = true;
        yield return(new WaitForSeconds(.1f)); //Give objects enough time to trigger OnTriggerEnter()

        //Clone objects to new location
        CloneAndMoveObjectsToArena();

        yield return(new WaitForSeconds(.1f));

        brainOfCamera.enabled = true;

        //transform.position = combatArenaLocation;

        rightObjects     = new List <GameObject>();
        allSlicedObjects = new List <GameObject>();
        rigidbodyObjects = new List <GameObject>();

        //Slice the objects
        SliceObjects();

        //Take a brief pause to give everything a chance to update
        yield return(new WaitForSeconds(.1f));

        foreach (GameObject g in clonedCombatObjects)
        {
            if (g.GetComponent <Rigidbody>())
            {
                //Debug.Log("Found one! " + g.name);
                rigidbodyObjects.Add(g);
                Destroy(g.GetComponent <Rigidbody>());
            }
        }

        //Add mesh colliders BACK to all environmental objects
        foreach (GameObject m in allSlicedObjects)
        {
            m.AddComponent <MeshCollider>();
            m.GetComponent <MeshCollider>().convex = true;
        }

        //Take a brief pause to give everything a chance to update
        yield return(new WaitForSeconds(.1f));

        //Add rigidbody components BACK to all specified objects
        foreach (GameObject r in rigidbodyObjects)
        {
            r.AddComponent <Rigidbody>();
            r.GetComponent <Rigidbody>().drag        = dragOfNewObject;
            r.GetComponent <Rigidbody>().angularDrag = angularDragOfNewObject;
            r.AddComponent <Timebody>();
            Timebody tb = r.GetComponent <Timebody>();
            RewindTime += tb.RewindTime;
        }

        //Take a brief pause to give everything a chance to update
        yield return(new WaitForSeconds(.1f));

        //Explode all objects outside the arena
        foreach (GameObject o in rightObjects)
        {
            o.GetComponent <Rigidbody>().AddExplosionForce(explosStrength, transform.position, explosRad, explosUpForce, ForceMode.Impulse);
        }

        canStartCombat = false;
        canStopCombat  = true;

        totalTime.Stop();

        UnityEngine.Debug.Log("Total time: " + totalTime.Elapsed);
        //yield return new WaitForSeconds(3f);

        //StartCoroutine(EndCombat());
    }