public IGPUAnim Instantiate(GameObject prefab, Vector3 pos, Quaternion rot)
 {
     if (supportsInstancing)
     {
         GPUAnimGroup group = null;
         GroupDic.TryGetValue(prefab.name, out group);
         if (group == null)
         {
             GameObject o = GameObject.Instantiate(prefab, transform);
             o.name = prefab.name;
             GPUAnimation gpuAnim = o.GetComponentInChildren <GPUAnimation> ();
             gpuAnim._gameObject = o;
             group = new GPUAnimGroup(gpuAnim);
             GroupDic.Add(o.name, group);
             o.SetActive(false);
             // DestroyImmediate (o);
         }
         var animObj = new GPUAnimObj(pos, rot);
         group.AddObject(animObj);
         return(animObj as IGPUAnim);
     }
     else
     {
         GameObject   o       = GameObject.Instantiate(prefab, pos, rot);
         GPUAnimation gpuAnim = o.GetComponentInChildren <GPUAnimation> ();
         // if (!gpuAnim) return o.GetComponent<GPUAnim_> ();
         gpuAnim._gameObject = o;
         return(gpuAnim as IGPUAnim);
     }
 }
        public void CombineBatch(InstancingBatch batch)
        {
            if (MAXBATCHCOUNT - visibleCount < batch.visibleCount)
            {
                return;
            }
            GPUAnimObj visible   = null;
            GPUAnimObj invisible = null;
            int        n         = batch.visibleCount;

            while (n > 0)
            {
                visible = batch.objs[0];
                if (visibleCount < objs.Count)
                {
                    invisible = objs[visibleCount];
                }
                else
                {
                    invisible = null;
                }
                batch.RemoveObject(visible);
                this.RemoveObject(invisible);
                visible._isVisible = true;
                AddObject(visible);
                batch.AddObject(invisible);
                n--;
            }
            batch.SetValid(false);
            group.combineList.Remove(this);
            group.combineList.Remove(batch);
        }
Ejemplo n.º 3
0
 public void RemoveObject(GPUAnimObj o)
 {
     if (!objs.Contains(o))
     {
         return;
     }
     o.manager.RemoveObject(o);
     objs.Remove(o);
 }
 public void ShowObject(GPUAnimObj o)
 {
     SwapObj(o._index, visibleCount);
     o._needUpdateProperty  = true;
     o._needUpdateTransform = true;
     o._isVisible           = true;
     visibleCount++;
     if (visibleCount >= MAXBATCHCOUNT / 2)
     {
         group.combineList.Remove(this);
     }
     isValid = true;
 }
 public void RemoveObject(GPUAnimObj o)
 {
     if (o == null || !objs.Contains(o))
     {
         return;
     }
     if (o._isVisible)
     {
         HideObject(o);
     }
     SwapObj(o._index, objs.Count - 1);
     objs.RemoveAt(objs.Count - 1);
     isfull = false;
 }
Ejemplo n.º 6
0
        public void AddObject(GPUAnimObj o)
        {
            objs.Add(o);
            o.group   = this;
            o._bounds = mesh.bounds;             //to do :calculat the real bounds
            // o.bounds = new Bounds (o.position, new Vector3 (0.1f, 0.1f, 0.1f));
            o._bounds.center = o.position;
            var batch = batches.Find((x) => !x.isfull);

            if (batch == null)
            {
                batch = new InstancingBatch(this);
                batches.Add(batch);
            }
            batch.AddObject(o);
        }
        public void HideObject(GPUAnimObj o)
        {
            int idx = o._index;

            SwapObj(o._index, visibleCount - 1);
            objs[idx]._needUpdateProperty  = true;
            objs[idx]._needUpdateTransform = true;
            o._isVisible = false;
            visibleCount--;
            if (visibleCount == 0)
            {
                isValid = false;
                return;                 //不可见则不参与合批
            }
            if (!group.combineList.Contains(this) && visibleCount < MAXBATCHCOUNT / 2)
            {
                group.combineList.Add(this);
            }
        }
 public void AddObject(GPUAnimObj o)
 {
     if (o == null)
     {
         return;
     }
     objs.Add(o);
     o.manager  = this;
     o.property = property;
     o._index   = objs.Count - 1;
     if (o._isVisible)
     {
         ShowObject(o);
     }
     if (objs.Count >= MAXBATCHCOUNT)
     {
         isfull = true;
     }
 }