//Prepare
        public void CheckAddComponent(Chunk chunk)
        {
                        #if VEGETATION_STUDIO
            Profiler.BeginSample("VS Prepare");

            //adding the main vegetation object
            VegetationStudioManager.AddVegetationStudioManagerToScene();

            //checking if all packs for all of the generators are the same
            if (packageShared == null)
            {
                packageShared = package;
            }
            else
            {
                package = packageShared;
            }

            //finding/creating vegetation system component
            VegetationSystem vetSys = chunk.terrain.gameObject.GetComponentInChildren <VegetationSystem>();
            if (vetSys == null)
            {
                vetSys = VegetationStudioManager.AddVegetationSystemToTerrain(chunk.terrain, package, createPersistentVegetationStoragePackage: true);
            }
            if (vetSys.VegetationPackageList.Count == 0)
            {
                vetSys.VegetationPackageList.Add(package);
            }
            if (vetSys.VegetationPackageList.Count == 1 && vetSys.VegetationPackageList[0] == null)
            {
                vetSys.VegetationPackageList[0] = package;
            }
            if (!vetSys.VegetationPackageList.Contains(package))
            {
                vetSys.VegetationPackageList.Add(package);
            }

            if (!vetSys.InitDone)
            {
                vetSys.SetupVegetationSystem();
                vetSys.RefreshVegetationPackage();
            }
            cellSize = vetSys.CellSize;


            //saving per-chunk storage (to access it from thread)
            PersistentVegetationStorage storage = vetSys.gameObject.GetComponent <PersistentVegetationStorage>();
            if (!vetStorComponents.ContainsKey(chunk.rect))
            {
                vetStorComponents.Add(chunk.rect, null);
            }
            vetStorComponents[chunk.rect] = storage;

            Profiler.EndSample();
                        #endif
        }
        public static void SetupTerrain(Terrain terrain, ref VegetationPackage package, out VegetationSystem system, out PersistentVegetationStorage storage)
        {
            var vetSystems          = GetVegetationSystemsForTerrain(terrain);
            VegetationSystem vetSys = null;

            for (var i = 0; i < vetSystems.Count; ++i)
            {
                var candidate = vetSystems[i];
                if (candidate.CurrentVegetationPackage == package)
                {
                    vetSys = candidate;
                    break;
                }
            }

            if (vetSys == null)
            {
                vetSys = VegetationStudioManager.AddVegetationSystemToTerrain(terrain, package, createPersistentVegetationStoragePackage: true);
            }
            if (package != null)
            {
                if (vetSys.VegetationPackageList.Count == 0)
                {
                    vetSys.VegetationPackageList.Add(package);
                }
                if (vetSys.VegetationPackageList.Count == 1 && vetSys.VegetationPackageList[0] == null)
                {
                    vetSys.VegetationPackageList[0] = package;
                }
                if (!vetSys.VegetationPackageList.Contains(package))
                {
                    vetSys.VegetationPackageList.Add(package);
                }
            }
            if (!vetSys.InitDone)
            {
                vetSys.SetupVegetationSystem();
                vetSys.RefreshVegetationPackage();
            }
            vetSys.SetSleepMode(false);
            package = vetSys.CurrentVegetationPackage;
            system  = vetSys;
            storage = vetSys.GetComponent <PersistentVegetationStorage>();
        }
Exemple #3
0
    //v1 just deletes all and rebakes
    //void ReBakeAllStorage()
    //{
    //    ClearAllVegetationSystems();

    //    if (_usePrefab)
    //    {
    //        SetupFromPrefab();
    //    }
    //    else
    //    {
    //        SetupFromVegetationPackage();
    //    }

    //}



    void AddAdditionalPackage()
    {
        // do a rebake of existing persistent storage packages.
        // Not quite working as expected - adds additional VegetationPackages to the VegetationSystem component, rather than replacing the existing one
        // Also, buggy?... seems to work first time but not on subsequent rebakes (baked storage ends up empty).


        // take care of storage (path)
        _assetsPath = RemoveTrailingSlash(_assetsPath); // ensures that there isn't an ending slash

        if (!AssetDatabase.IsValidFolder(_assetsPath))
        {
            if (_debugToLog)
            {
                Debug.Log("Asset path is invalid. Creating your folders");
            }
            CreateAssetFolders();
        }

        ClearAllStorageInPath();



        if (_vegetationPackage == null)
        {
            Debug.LogWarning("You need to assign a vegetation package");
            EditorUtility.DisplayDialog("No Vegetation Package",
                                        "You need to drag and drop a vegetation package into the utility window", "OK");
            return;
        }
        if (_forceItemsEnabled)     // Make sure all Vegetation is enabled on Vegetation Package
        {
            SetAllItemsToRuntimeSpawn();
        }


        var terrains = _rootObject ? _rootObject.GetComponentsInChildren <Terrain>() : GameObject.FindObjectsOfType <Terrain>();
        int totalNum = terrains.Length;
        int counter  = 0;

        foreach (Terrain terrain in terrains)
        {
            counter++;
            if (_addPersistentStorage)
            {
                // first check if a Vegetation System already exists
                VegetationSystem _vegetationSystem = terrain.gameObject.GetComponentInChildren <VegetationSystem>();
                if (_vegetationSystem == null)
                {     // add if not already there
                    _vegetationSystem = VegetationStudioManager.AddVegetationSystemToTerrain(terrain, _vegetationPackage, true);
                    if (_debugToLog)
                    {
                        Debug.Log("Rebaking: Added missing VS to " + terrain.name + " (" + counter + " of " + totalNum + ")");
                    }
                }
                else
                {
                    if (_debugToLog)
                    {
                        Debug.Log("Rebaking VS already existed on " + terrain.name + " (" + counter + " of " + totalNum + ")");
                    }
                    _vegetationSystem.AddVegetationPackage(_vegetationPackage, true);
                }

                if (_debugToLog)
                {
                    Debug.Log("Adding Persistent Storage " + terrain.name + " (" + counter + " of " + totalNum + ")");
                }
                DoAddPersistentStorage(_vegetationSystem);
            }
            else
            {
                // just add a Vegetation System
                VegetationStudioManager.AddVegetationSystemToTerrain(terrain, _vegetationPackage);
            }
        }


        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    }
Exemple #4
0
    void SetupFromVegetationPackage()
    {
        _assetsPath = RemoveTrailingSlash(_assetsPath); // ensures that there isn't an ending slash

        if (!AssetDatabase.IsValidFolder(_assetsPath))
        {
            if (_debugToLog)
            {
                Debug.Log("Asset path is invalid. Creating your folders");
            }
            CreateAssetFolders();
        }


        if (_forceItemsEnabled) // Make sure all Vegetation is enabled on Vegetation Package
        {
            SetAllItemsToRuntimeSpawn();
        }

        if (_autoBake) // if going to rebake then delete any existing packages
        {
            ClearAllStorageInPath();
        }

        var terrains = _rootObject ? _rootObject.GetComponentsInChildren <Terrain>() : GameObject.FindObjectsOfType <Terrain>();
        int totalNum = terrains.Length;
        int counter  = 0;

        foreach (Terrain terrain in terrains)
        {
            counter++;
            if (_addPersistentStorage)
            {
                if (_debugToLog)
                {
                    Debug.Log("---------------------------------------------------------------");
                }
                // first check if a Vegetation System already exists
                VegetationSystem _vegetationSystem = terrain.gameObject.GetComponentInChildren <VegetationSystem>();
                if (_vegetationSystem != null)
                {
                    DestroyImmediate(_vegetationSystem.gameObject);
                }
                // add
                _vegetationSystem = VegetationStudioManager.AddVegetationSystemToTerrain(terrain, _vegetationPackage, true);

                if (_debugToLog)
                {
                    Debug.Log("Added VS to " + terrain.name + " (" + counter + " of " + totalNum + ")");
                }


                if (_debugToLog)
                {
                    Debug.Log("Adding Persistent Storage " + terrain.name + " (" + counter + " of " + totalNum + ")");
                }
                DoAddPersistentStorage(_vegetationSystem);
            }
            else
            {
                VegetationStudioManager.AddVegetationSystemToTerrain(terrain, _vegetationPackage); // just add a Vegetation System
            }
        }
        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    }