Beispiel #1
0
        public void AddFoundObjectsToOctree()
        {
            if (foundObjects.Count > 0 || foundLodObjects.Count > 0)
            {
                octreeContainsObjects = true;
            }
            else
            {
                Debug.Log("No matching GameObjects with chosen search options are found for combining.");
                return;
            }

            foundMaterials.Clear();
            CalcOctreeSize(bounds);

            ObjectOctree.MaxCell.maxCellCount = 0;

            for (int i = 0; i < foundObjects.Count; i++)
            {
                CachedGameObject foundObject = foundObjects[i];
                AddFoundMaterials(foundObject.mr);

                Vector3 position = (searchOptions.objectCenter == ObjectCenter.TransformPosition ? foundObject.t.position : foundObject.mr.bounds.center);
                octree.AddObject(position, this, foundObject, 0, 0);
            }
            for (int i = 0; i < foundLodObjects.Count; i++)
            {
                CachedLodGameObject cachedLodGO = foundLodObjects[i];
                AddFoundMaterials(cachedLodGO.mr);
                octree.AddObject(cachedLodGO.center, this, cachedLodGO, cachedLodGO.lodCount, cachedLodGO.lodLevel);
            }

            foundMaterialsCount = foundMaterials.Count;
        }
Beispiel #2
0
        // ==========================================================================================================================

        void AddLodGroups(LODGroup[] lodGroups, bool useSearchOptions = true)
        {
            List <CachedLodGameObject> cachedLodRenderers = new List <CachedLodGameObject>();

            CachedGameObject cachedGODummy = null;

            for (int i = 0; i < lodGroups.Length; i++)
            {
                LODGroup lodGroup = lodGroups[i];

                bool validLodGroup;

                if (searchOptions.lodGroupSearchMode == SearchOptions.LODGroupSearchMode.LodGroup)
                {
                    validLodGroup = (ValidObject(lodGroup.transform, ObjectType.LodGroup, useSearchOptions, ref cachedGODummy) == 1);
                }
                else
                {
                    if (searchOptions.onlyActive && !lodGroup.gameObject.activeInHierarchy)
                    {
                        continue;
                    }
                    validLodGroup = true;
                }

                LOD[] lods           = lodGroup.GetLODs();
                int   lodParentIndex = lods.Length - 1;

                if (lodParentIndex <= 0)
                {
                    continue;
                }
                // Debug.Log(lods.Length);

                Vector3 center = Vector3.zero;

                int rendererCount = 0;

                for (int j = 0; j < lods.Length; j++)
                {
                    LOD lod = lods[j];

                    for (int k = 0; k < lod.renderers.Length; k++)
                    {
                        Renderer r = lod.renderers[k];

                        if (!r)
                        {
                            continue;
                        }

                        if (validLodGroup)
                        {
                            CachedGameObject cachedGO = null;

                            int result = ValidObject(r.transform, ObjectType.LodRenderer, useSearchOptions, ref cachedGO);

                            if (result == -1)
                            {
                                continue;
                            }
                            else if (result == -2)
                            {
                                cachedLodRenderers.Clear();
                                goto breakLoop;
                            }

                            cachedLodRenderers.Add(new CachedLodGameObject(cachedGO, lodParentIndex, j));
                            if (searchOptions.objectCenter == ObjectCenter.BoundsCenter)
                            {
                                center += cachedGO.mr.bounds.center;
                                rendererCount++;
                            }
                        }
                        uniqueLodObjects.Add(r.transform);
                    }
                }

breakLoop:

                if (cachedLodRenderers.Count > 0)
                {
                    if (searchOptions.objectCenter == ObjectCenter.BoundsCenter)
                    {
                        center /= rendererCount;
                    }
                    else
                    {
                        center = lodGroup.transform.position;
                    }

                    for (int j = 0; j < cachedLodRenderers.Count; j++)
                    {
                        CachedLodGameObject cachedLodGO = cachedLodRenderers[j];
                        cachedLodGO.center = center;
                        if (!hasFoundFirstObject)
                        {
                            bounds.center = cachedLodGO.mr.bounds.center; hasFoundFirstObject = true;
                        }
                        bounds.Encapsulate(cachedLodGO.mr.bounds);
                        foundLodObjects.Add(cachedLodGO);
                        lodParentHolders[lodParentIndex].found = true;
                        lodParentHolders[lodParentIndex].lods[cachedLodGO.lodLevel]++;
                    }

                    uniqueFoundLodGroups.Add(lodGroup);
                    cachedLodRenderers.Clear();
                }
            }

            foundLodGroups = new List <LODGroup>(uniqueFoundLodGroups);
        }
Beispiel #3
0
        public void ExecuteHandleObjects(bool active, HandleComponent handleOriginalObjects, HandleComponent handleOriginalLodGroups, bool includeColliders = true)
        {
            Methods.SetChildrenActive(transform, !active);

            if (handleOriginalObjects == HandleComponent.Disable)
            {
                if (includeColliders)
                {
                    SetOriginalCollidersActive(active);
                }

                for (int i = 0; i < foundObjects.Count; i++)
                {
                    CachedGameObject cachedGO = foundObjects[i];

                    if (cachedGO.mr)
                    {
                        cachedGO.mr.enabled = active;
                    }
                    else
                    {
                        Methods.ListRemoveAt(foundObjects, i--);
                    }
                }
                for (int i = 0; i < foundLodObjects.Count; i++)
                {
                    CachedLodGameObject cachedLodGO = foundLodObjects[i];

                    if (cachedLodGO.mr)
                    {
                        cachedLodGO.mr.enabled = active;
                    }
                    else
                    {
                        Methods.ListRemoveAt(foundLodObjects, i--);
                    }
                }
            }
            if (handleOriginalObjects == HandleComponent.Destroy)
            {
                for (int i = 0; i < foundColliders.Count; i++)
                {
                    Collider collider = foundColliders[i];
                    if (collider)
                    {
                        Destroy(collider);
                    }
                    else
                    {
                        Methods.ListRemoveAt(foundColliders, i--);
                    }
                }

                for (int i = 0; i < foundObjects.Count; i++)
                {
                    bool             remove   = false;
                    CachedGameObject cachedGO = foundObjects[i];
                    if (cachedGO.mf)
                    {
                        Destroy(cachedGO.mf);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (cachedGO.mr)
                    {
                        Destroy(cachedGO.mr);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (remove)
                    {
                        Methods.ListRemoveAt(foundObjects, i--);
                    }
                }

                for (int i = 0; i < foundLodObjects.Count; i++)
                {
                    bool             remove   = false;
                    CachedGameObject cachedGO = foundLodObjects[i];
                    if (cachedGO.mf)
                    {
                        Destroy(cachedGO.mf);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (cachedGO.mr)
                    {
                        Destroy(cachedGO.mr);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (remove)
                    {
                        Methods.ListRemoveAt(foundLodObjects, i--);
                    }
                }
            }

            if (handleOriginalLodGroups == HandleComponent.Disable)
            {
                for (int i = 0; i < foundLodGroups.Count; i++)
                {
                    LODGroup lodGroup = foundLodGroups[i];
                    if (lodGroup)
                    {
                        lodGroup.enabled = active;
                    }
                }
            }
            else if (handleOriginalLodGroups == HandleComponent.Destroy)
            {
                for (int i = 0; i < foundLodGroups.Count; i++)
                {
                    LODGroup lodGroup = foundLodGroups[i];
                    if (lodGroup != null)
                    {
                        Destroy(lodGroup);
                    }
                }
            }
        }