Ejemplo n.º 1
0
        /// <summary>
        /// Can we get any more batches? and is the data exists?
        /// </summary>
        /// <param name="data">our materials data</param>
        /// <param name="shapeVertexCount">our current shape vertex count</param>
        /// <returns>instance of the batch data</returns>
        public BatchClass Batchable(Material[] data, int shapeVertexCount)
        {
            BatchClass current;

            for (int i = 0; i < renderesData.Count; i++)
            {
                current = renderesData[i];

                if (current.Containes(data) && !BatchUtility.isVertexOverLimit(current.totalVertexAmount + shapeVertexCount))
                {
                    return(current);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Batch buildings
        /// </summary>
        /// <param name="value">Batch the building ?</param>
        public virtual void Batch(bool value, BaseBuilding updatedBuilding, bool added)
        {
            if (UCSavingManager.IsLoading || !UCSettings.instance.UCBatchingEnabled)
            {
                return;
            }

            if (value)
            {
                Batch(false, updatedBuilding, added); // clear the old data

                if (initializedBatch && updatedBuilding != null)
                {
                    BatchUtility.UpdateBatchData(GetUpdatedBatchData(updatedBuilding, added), added, ref batchData);
                }
                else if (!initializedBatch)
                {
                    batchData = BatchUtility.CompileInitialBatchData(batchedFilters.ToArray(), true);
                }

                Mesh mesh;

                for (int i = 0; i < batchData.Count; i++)
                {
                    var go = new GameObject();
                    go.name               = "Group Batched Collider";
                    go.gameObject.layer   = LayersData.DefaultBuildingLayer;
                    go.transform.parent   = transform;
                    go.transform.position = transform.position;

                    var buildingBatch = go.AddComponent <BaseBuildingBatcher>();
                    buildingBatch.group = this;

                    mesh = new Mesh();

                    mesh.CombineMeshes(batchData[i].combineInstances.ToArray());

                    /* COLLIDER BATCHING CURRENTLY DISABLED.
                     * var meshCollider = go.AddComponent<MeshCollider>();
                     * meshCollider.sharedMesh = mesh;
                     */

                    if (batchData[i].Materials != null)
                    {
                        var renderer = go.AddComponent <MeshRenderer>();
                        var filter   = go.AddComponent <MeshFilter>();

                        filter.mesh        = mesh;
                        renderer.materials = batchData[i].Materials;
                    }

                    batchInstances.Add(go.transform);

                    if (OnBatchDoneEvent != null)
                    {
                        OnBatchDoneEvent(go, mesh);
                    }
                }

                initializedBatch = true;
            }
            else
            {
                for (int i = 0; i < batchInstances.Count; i++)
                {
                    if (batchInstances[i] != null)
                    {
                        Destroy(batchInstances[i].gameObject);
                    }
                }
                batchInstances.Clear();
            }

            if (OnGroupBatchedEvent != null)
            {
                OnGroupBatchedEvent(value);
            }
        }