Beispiel #1
0
 public void OnDisable()
 {
     if (masksApplied)
     {
         VSProOps.FlushTextures(package, terrainRect);
     }
     masksApplied = false;
 }
Beispiel #2
0
        //public void OnEnable ()  //VSPro has got to run OnEnable first (objects only)
        public void Start()
        {
            if (package == null)
            {
                return;
            }

            if (!masksApplied)
            {
                VSProOps.SetTextures(system, package, textures, maskGroupNums, terrainRect);
            }
            masksApplied = true;
        }
Beispiel #3
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();
        }
Beispiel #4
0
            public void Apply(Terrain terrain)
            {
                //updating system
                VegetationSystemPro copySystem = null;                  //we'll need it to set up tile

                if (copyVS)
                {
                    copySystem = VSProOps.GetCopyVegetationSystem(terrain);
                    if (copySystem == null)
                    {
                        copySystem = VSProOps.CopyVegetationSystem(srcSystem, terrain.transform.parent);
                    }
                    VSProOps.UpdateCopySystem(copySystem, terrain, package, srcSystem);
                }

                else
                {
                    VSProOps.UpdateSourceSystem(srcSystem, terrain);
                }

                //applying
                Texture2D[] textures = WriteTextures(null, colors);
                VSProOps.SetTextures(
                    copyVS ? copySystem : srcSystem,
                    package, textures, maskGroupNums, terrain.GetWorldRect());

                //tile obj (serialization and disable purpose)
                Transform     tileTfm = terrain.transform.parent;
                VSProMapsTile vsTile  = tileTfm.GetComponent <VSProMapsTile>();

                if (vsTile == null)
                {
                    vsTile = tileTfm.gameObject.AddComponent <VSProMapsTile>();
                }
                vsTile.system        = copyVS ? copySystem : srcSystem;
                vsTile.package       = package;
                vsTile.terrainRect   = terrain.GetWorldRect();
                vsTile.textures      = textures;
                vsTile.maskGroupNums = maskGroupNums;
                vsTile.masksApplied  = true;
            }
Beispiel #5
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);
        }