Ejemplo n.º 1
0
        public static void UpdateSourceSystem(VegetationSystemPro srcSystem, Terrain terrain)
        {
            //erasing legacy settings on copyVS change
            //returning extents after using per-terrain systems
            VegetationSystemPro copySystem = VSProOps.GetCopyVegetationSystem(terrain);

            if (srcSystem.VegetationSystemBounds.extents.x < 1)
            {
                srcSystem.VegetationSystemBounds = new Bounds(
                    terrain.transform.position + terrain.terrainData.size / 2,
                    terrain.terrainData.size * 3.4f);
                srcSystem.RefreshVegetationSystem();
            }

            if (copySystem != null &&
                srcSystem.PersistentVegetationStorage != null &&
                srcSystem.PersistentVegetationStorage.PersistentVegetationStoragePackage == copySystem.PersistentVegetationStorage.PersistentVegetationStoragePackage)
            {
                srcSystem.PersistentVegetationStorage.InitializePersistentStorage();
            }

            if (copySystem != null)
            {
                GameObject.DestroyImmediate(copySystem.gameObject);
            }

            //unityterrain
            UnityTerrain unityTerrain = terrain.GetComponent <UnityTerrain>();             //VS Pro component added to terrain

            if (unityTerrain == null)
            {
                unityTerrain = VSProOps.AddUnityTerrain(terrain);
            }
            unityTerrain.TerrainPosition = terrain.transform.position;

            if (srcSystem != null && !srcSystem.VegetationStudioTerrainList.Contains(unityTerrain))                //check if already added since AddTerrain is long operation
            {
                srcSystem.AddTerrain(terrain.gameObject);
            }

            //refresh system (takes >100 ms)
            UnityEngine.Profiling.Profiler.BeginSample("VegetationSystemPro.RefreshVegetationSystem");
            srcSystem.RefreshVegetationSystem();
            UnityEngine.Profiling.Profiler.EndSample();
        }
Ejemplo n.º 2
0
        public static VegetationSystemPro UpdateCopySystem(VegetationSystemPro copySystem, Terrain terrain, VegetationPackagePro package, VegetationSystemPro srcSystem)
        {
            Transform tileTfm = terrain.transform.parent;

            //erasing legacy settings on copyVS change
            //checking if src system has any extents, and resetting them - otherwise refreshing clone systems will take too long
            if (srcSystem.VegetationSystemBounds.extents.x > 1)
            {
                srcSystem.VegetationSystemBounds = new Bounds(Vector3.zero, Vector3.zero);
                srcSystem.RefreshVegetationSystem();
            }
            if (srcSystem.VegetationStudioTerrainObjectList.Count != 0)
            {
                srcSystem.RemoveAllTerrains();
            }

            //unityterrain
            UnityTerrain unityTerrain = terrain.GetComponent <UnityTerrain>();             //VS Pro component added to terrain

            if (unityTerrain == null)
            {
                unityTerrain = VSProOps.AddUnityTerrain(terrain);
            }
            unityTerrain.TerrainPosition = terrain.transform.position;

            //resetting clone package just in case
            if (copySystem.VegetationPackageProList.Count == 0 || copySystem.VegetationPackageProList[0] != package)
            {
                copySystem.VegetationPackageProList.Clear();
                copySystem.AddVegetationPackage(package);
            }

            //reset bounds
            copySystem.AutomaticBoundsCalculation = false;
            copySystem.VegetationSystemBounds     = new Bounds(           //or use unityTerrain.TerrainBounds;
                terrain.terrainData.bounds.center + terrain.transform.position,
                terrain.terrainData.bounds.extents * 2);

            //add terrain
            if (copySystem.VegetationStudioTerrainObjectList.Count != 1 || copySystem.VegetationStudioTerrainObjectList[0] != terrain.gameObject)
            {
                if (copySystem.VegetationStudioTerrainObjectList.Count != 0)
                {
                    copySystem.RemoveAllTerrains();
                }
                copySystem.AddTerrain(terrain.gameObject);                  //will call RefreshVegetationStudioTerrains and RefreshVegetationStudioTerrains
            }

            //clearing storage
            if (copySystem.PersistentVegetationStorage.PersistentVegetationStoragePackage == null)
            {
                copySystem.PersistentVegetationStorage.PersistentVegetationStoragePackage = ScriptableObject.CreateInstance <PersistentVegetationStoragePackage>();                //new PersistentVegetationStoragePackage(); //changed on feedback from forum
            }
            //clearing is done in apply

            //refresh system (takes >100 ms)
            UnityEngine.Profiling.Profiler.BeginSample("VegetationSystemPro.RefreshVegetationSystem");
//			copySystem.RefreshVegetationSystem();
            if (copySystem != null)             //re-initializing
            {
                copySystem.enabled = false;
                copySystem.enabled = true;                 //to call private OnEnable
            }

            UnityEngine.Profiling.Profiler.EndSample();

            return(copySystem);
        }