Example #1
0
        void AddBatcherToQueue(Batchable batchable)
        {
            if (batchable.GetMesh() == null)
            {
                return;
            }
            bool added = false;

            for (int i = 0; i < combineQueues.Count; i++)
            {
                if (combineQueues[i].Add(batchable))
                {
                    added = true;
                    batchable.DeactivateRenderer();
                    break;
                }
            }

            if (!added)
            {
                batchable.DeactivateRenderer();
                combineQueues.Add(new CombineChildQueue(transform, batchable.GetMaterials()));
                combineQueues[combineQueues.Count - 1].Add(batchable);
            }
        }
Example #2
0
        void GetBatchers()
        {
            List <Batchable> batchableList = new List <Batchable>();

            if (includeParent)
            {
                Batchable batchable = GetComponent <Batchable>();
                if (batchable == null)
                {
                    batchable = gameObject.AddComponent <Batchable>();
                }
                batchableList.Add(batchable);
            }
            List <Transform> children = new List <Transform>();

            Dreamteck.SceneUtility.GetChildrenRecursively(transform, ref children);
            for (int i = 1; i < children.Count; i++)
            {
                Batchable batchable = children[i].GetComponent <Batchable>();
                if (batchable != null)
                {
                    batchableList.Add(batchable);
                }
            }
            batchables = batchableList.ToArray();
        }
Example #3
0
 public override void OnUnpack()
 {
     base.OnUnpack();
     if (batchables.Length > 0)
     {
         for (int i = 0; i < batchables.Length; i++)
         {
             batchables[i].Unpack();
         }
     }
     else
     {
         List <Transform> children = new List <Transform>();
         SceneUtility.GetChildrenRecursively(transform, ref children);
         for (int i = 0; i < children.Count; i++)
         {
             if (i == 0 && !includeParent)
             {
                 continue;
             }
             Batchable batchable = children[i].GetComponent <Batchable>();
             if (batchable != null)
             {
                 batchable.Unpack();
             }
         }
     }
 }
Example #4
0
 public override void OnPack()
 {
     base.OnPack();
     if (mode == Mode.Cached)
     {
         GetBatchers();
         for (int i = 0; i < batchables.Length; i++)
         {
             batchables[i].Pack();
         }
     }
     else
     {
         List <Transform> children = new List <Transform>();
         SceneUtility.GetChildrenRecursively(transform, ref children);
         for (int i = 0; i < children.Count; i++)
         {
             if (i == 0 && !includeParent)
             {
                 continue;
             }
             Batchable batchable = children[i].GetComponent <Batchable>();
             if (batchable != null)
             {
                 batchable.Pack();
             }
         }
         batchables = new Batchable[0];
     }
 }
Example #5
0
 internal bool Add(Batchable batcher)
 {
     if (!CanAddBatcher(batcher))
     {
         return(false);
     }
     vertexCount += batcher.GetMesh().vertexCount;
     batchers.Add(batcher);
     return(true);
 }
Example #6
0
 private bool CanAddBatcher(Batchable batcher)
 {
     if (batcher.GetMesh().vertexCount + vertexCount > 65000)
     {
         return(false);
     }
     for (int i = 0; i < materials.Length; i++)
     {
         if (materials[i] != batcher.GetMaterials()[i])
         {
             return(false);
         }
     }
     return(true);
 }
Example #7
0
 protected override IEnumerator BuildAsync()
 {
     if (mode == Mode.Dynamic)
     {
         GetBatchers();
     }
     if (includeParent)
     {
         Batchable parentBatchable = GetComponent <Batchable>();
         if (parentBatchable == null)
         {
             parentBatchable = gameObject.AddComponent <Batchable>();
         }
         parentBatchable.UpdateImmediate();
         AddBatcherToQueue(parentBatchable);
     }
     for (int i = 0; i < batchables.Length; i++)
     {
         if (batchables[i] == null)
         {
             continue;
         }
         if (!batchables[i].gameObject.activeInHierarchy)
         {
             continue;
         }
         AddBatcherToQueue(batchables[i]);
     }
     combinedMeshes = new Mesh[combineQueues.Count];
     for (int i = 0; i < combineQueues.Count; i++)
     {
         combinedMeshes[i] = combineQueues[i].Combine("Combined " + i);
         yield return(null);
     }
     combineQueues.Clear();
 }