Ejemplo n.º 1
0
        private void Reset()
        {
            foreach (var property in properties)
            {
                TweenDataHolder.pool.PutObject(property.Value);
            }

            properties.Clear();

            prev    = null;
            next    = null;
            chain   = null;
            target  = null;
            manager = null;

            _startHandler         = null;
            _startParamHandler    = null;
            _updateHandler        = null;
            _updateParamHandler   = null;
            _completeHandler      = null;
            _completeParamHandler = null;
            _easing                = null;
            _targetAsIReusable     = null;
            _targetAsIActiveObject = null;
        }
Ejemplo n.º 2
0
    /**
     * 生成对象
     * */
    public GameObject Spawn()
    {
        GameObject obj = null;      //池中对象

        foreach (GameObject o in subPool)
        {//判断是否激活:
            if (o != null && o.activeSelf == false)
            {
                obj = o;
            }
        }

        if (obj == null)
        {                                                                  //第一次和池子中没有的时候
            obj = GameObject.Instantiate(m_Pref, cache, new Quaternion()); //创建新对象
            subPool.Add(obj);                                              //入池
        }

        obj.SetActive(true);        //激活对象

        //通过接口重用:
        IReusable ir = obj.GetComponent <IReusable>();

        if (ir != null)
        {
            ir.Spawn();
        }
        return(obj);
    }
Ejemplo n.º 3
0
    public static T GetObjectFromPool <T>(IReusable obj) where T : Object
    {
        if (!I.reusePool.ContainsKey(obj.ObjectID) || I.reusePool[obj.ObjectID].Count == 0)
        {
            return(null);
        }

        return((T)I.reusePool[obj.ObjectID].Dequeue());
    }
Ejemplo n.º 4
0
 /**
  * 收回对象
  * */
 public void UnSpawn(GameObject obj)
 {
     //需要收回的对象存在于池中:
     if (subPool.Contains(obj))
     {//通过接口重用:
         IReusable ir = obj.GetComponent <IReusable>();
         if (ir != null)
         {
             ir.UnSpawn();
         }
         obj.SetActive(false);
     }
 }
Ejemplo n.º 5
0
        internal void Initialize(TweenManager manager, object target)
        {
            this.manager = manager;
            this.target  = target;

            _duration = Mathf.Min(this.manager.defaultDuration, 1);
            _elapsed  = 0;

            _targetAsIActiveObject = target as IActiveObject;
            _targetAsIReusable     = target as IReusable;
            _targetVersion         = (_targetAsIReusable != null) ? _targetAsIReusable.version : 0;

            isActive    = false;
            isCompleted = false;
            isRemoved   = false;
        }
Ejemplo n.º 6
0
    public static void AddToReusePool(IReusable obj)
    {
        if (!obj.Poolable)
        {
            Destroy(obj.GetObject); // Unpoolable, let GC have this one.
        }
        if (I.reusePool == null)
        {
            I.reusePool = new Dictionary <int, Queue <IReusable> >();
        }

        if (!I.reusePool.ContainsKey(obj.ObjectID))
        {
            I.reusePool.Add(obj.ObjectID, new Queue <IReusable>());
        }

        I.reusePool[obj.ObjectID].Enqueue(obj);
    }
Ejemplo n.º 7
0
    public static T CreateObject <T>(T original) where T : Object
    {
        IReusable res    = (IReusable)original;
        T         newObj = null;

        if (res != null)
        {
            newObj = GetObjectFromPool <T>(res);
        }

        if (!newObj)
        {
            newObj = Instantiate(original);
            res    = (IReusable)newObj;
            if (res != null)
            {
                res.ObjectID = original.GetInstanceID();
            }
        }

        return(newObj);
    }
Ejemplo n.º 8
0
 public void MethodTwo(IReusable reuse)
 {
     this._reuse = reuse;
     _reuse.doSomething();
 }