コード例 #1
0
    //coroutine which waits for 'time' seconds before deactivating the instance
    IEnumerator DespawnInTime(PoolTimeObject timeObject)
    {
        //cache instance to deactivate
        GameObject instance = timeObject.instance;

        if (instance == null)
        {
            yield break;
        }

        //wait for defined seconds
        float timer = Time.time + timeObject.time;

        while (instance.activeInHierarchy && Time.time < timer)
        {
            yield return(null);
        }

        //the instance got deactivated in between already
        if (!instance.activeInHierarchy)
        {
            yield break;
        }
        //despawn it now
        Despawn(instance);
    }
コード例 #2
0
ファイル: Pool.cs プロジェクト: HigherLevelGames/GATETutor
    //similiar to Despawn(), but also yields for 'PoolTimeObject.time' seconds
    //started by Despawn(instance, time) above
    IEnumerator DespawnInTime(PoolTimeObject timeObject)
    {
        //cache instance to deactivate
        GameObject instance = timeObject.instance;

        //wait for defined seconds
        yield return(new WaitForSeconds(timeObject.time));

        //loop through all pool options of this component
        for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
        {
            PoolOptions poolOptions = this._PoolOptions[cnt];
            //seach in active instances for this instance
            if (poolOptions.active.Contains(instance))
            {
                //in case it was unparented during runtime, reparent it now
                if (instance.transform.parent != container)
                {
                    instance.transform.parent = container;
                }

                //let Deactivate() of PoolOption disable this instance
                poolOptions.Deactivate(instance);

                //remove instance from our active list of this component
                this._AllActive.Remove(instance);
            }
        }
    }
コード例 #3
0
    ////根据时间将GameObject设置回不被激活
    public void DeSpawn(GameObject instance, float time)
    {
        //create new class PoolTimeObject to keep track of the instance
        PoolTimeObject timeObject = new PoolTimeObject();

        //assign time and instance variable of this class
        timeObject.instance = instance;
        timeObject.time     = time;

        //start timed deactivation using the created properties
        StartCoroutine(DespawnInTime(timeObject));
    }
コード例 #4
0
ファイル: Pool.cs プロジェクト: HigherLevelGames/GATETutor
    //timed deactivation of an instance
    public void Despawn(GameObject instance, float time)
    {
        //ahead: we need to start a coroutine which waits for 'time' seconds
        //and then deactivates the instance, but StartCoroutine() nor Invoke()
        //takes 2 parameters, so we use an own class to store these values

        //create new class PoolTimeObject
        PoolTimeObject timeObject = new PoolTimeObject();

        //assign time and instance variable of this class
        timeObject.instance = instance;
        timeObject.time     = time;

        //start timed deactivation and pass in the created PoolTimeObject class
        StartCoroutine("DespawnInTime", timeObject);
    }
コード例 #5
0
    IEnumerator DespawnInTime(PoolTimeObject timeObject)
    {
        GameObject instance = timeObject.instance;

        float timer = Time.time + timeObject.time;

        while (instance.activeInHierarchy && Time.time < timer)
        {
            yield return(null);
        }

        if (!instance.activeInHierarchy)
        {
            yield break;
        }
        DeSpawn(instance);
    }
コード例 #6
0
ファイル: Pool.cs プロジェクト: patte88/Monsters-Incoming
    //timed deactivation of an instance
    public void Despawn(GameObject instance, float time)
    {
        //ahead: we need to start a coroutine which waits for 'time' seconds
        //and then deactivates the instance, but StartCoroutine() nor Invoke()
        //takes 2 parameters, so we use an own class to store these values

        //create new class PoolTimeObject
        PoolTimeObject timeObject = new PoolTimeObject();
        //assign time and instance variable of this class
        timeObject.instance = instance;
        timeObject.time = time;

        //start timed deactivation and pass in the created PoolTimeObject class
        StartCoroutine("DespawnInTime", timeObject);
    }
コード例 #7
0
ファイル: Pool.cs プロジェクト: patte88/Monsters-Incoming
    //similiar to Despawn(), but also yields for 'PoolTimeObject.time' seconds
    //started by Despawn(instance, time) above
    IEnumerator DespawnInTime(PoolTimeObject timeObject)
    {
        //cache instance to deactivate
        GameObject instance = timeObject.instance;
        //wait for defined seconds
        yield return new WaitForSeconds(timeObject.time);

        //loop through all pool options of this component
        for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
        {
            PoolOptions poolOptions = this._PoolOptions[cnt];
            //seach in active instances for this instance
            if (poolOptions.active.Contains(instance))
            {
                //in case it was unparented during runtime, reparent it now
                if (instance.transform.parent != container)
                    instance.transform.parent = container;

                //let Deactivate() of PoolOption disable this instance
                poolOptions.Deactivate(instance);

                //remove instance from our active list of this component
                this._AllActive.Remove(instance);
            }
        }
    }