Пример #1
0
        private void ApplyTerrainDataScalability(TerrainData targetData, TerrainScalabilitySetting setting)
        {
            targetData.baseMapResolution = (int)setting.overrideBaseTextureRes;
            targetData.SetBaseMapDirty();

            if ((int)setting.overrideControlTextureRes < targetData.alphamapResolution)
            {
                float[,,] sourceAlphamap = targetData.GetAlphamaps(0, 0, targetData.alphamapResolution, targetData.alphamapResolution);
                int targetRes   = (int)setting.overrideControlTextureRes;
                int divideRatio = targetData.alphamapResolution / targetRes;

                float[,,] newAlphaMap = new float[targetRes, targetRes, sourceAlphamap.GetLength(2)];
                for (int i = 0; i < targetRes; i++)
                {
                    for (int j = 0; j < targetRes; j++)
                    {
                        int coll = i * divideRatio;
                        int row  = j * divideRatio;
                        for (int k = 0; k < sourceAlphamap.GetLength(2); k++)
                        {
                            newAlphaMap[i, j, k] = sourceAlphamap[coll, row, k];
                        }
                    }
                }

                targetData.alphamapResolution = targetRes;
                targetData.SetAlphamaps(0, 0, newAlphaMap);
            }
            else
            {
                Debug.LogWarning("[Terrrain Scalability Manager] The control texture override value is higher or equal than the base one, update it is not required");
            }

            ManageTreesDensity(setting, targetData);
        }
Пример #2
0
        public static void OnPostProcessScene()
        {
            if (BuildPipeline.isBuildingPlayer)
            {
                foreach (var tsm in FindObjectsOfType <TerrainScalabilityManager>())
                {
                    if (tsm.m_TargetTerrain == null)
                    {
                        continue;
                    }

                    TerrainScalabilitySetting targetSetting = tsm.GetPlatformSetting();
                    if (targetSetting == null)
                    {
                        continue;
                    }

                    TerrainData backedData = tsm.GetScaledTerrainData(out bool alreadyInDatabase);

                    if (!alreadyInDatabase)
                    {
                        tsm.ApplyTerrainDataScalability(backedData, targetSetting);
                    }

                    tsm.SetTerrainData(backedData);
                    tsm.ApplyTerrainScalability(targetSetting);
                }
            }
        }
Пример #3
0
        private void Awake()
        {
            TerrainScalabilitySetting targetSetting = GetPlatformSetting();

            if (targetSetting != null)
            {
                SetTerrainData(GetScaledTerrainData(out bool alreadyInDatabase));
                ApplyTerrainDataScalability(m_TargetTerrain.terrainData, targetSetting);
                ApplyTerrainScalability(targetSetting);
            }
        }
Пример #4
0
        /// <summary>
        /// Removes trees depending trees scalability settings
        /// </summary>
        /// <param name="scalabilitySetting"></param>
        private void ManageTreesDensity(TerrainScalabilitySetting scalabilitySetting, TerrainData terrainData)
        {
            List <TreeInstance> remainingInstances = new List <TreeInstance>();

            TreeInstance[] treeInstances = terrainData.treeInstances;

            for (int i = 0; i < treeInstances.Length; i++)
            {
                TreeInstance ti = treeInstances[i];

                TreeScalabilitySetting setting = null;

                foreach (var treeScalability in scalabilitySetting.treeScalabilities)
                {
                    if (treeScalability.prototypeId == ti.prototypeIndex)
                    {
                        setting = treeScalability;
                        break;
                    }
                }

                if (setting != null)
                {
                    float randomValue = RandomFloat(new Vector2((float)i, setting.seed));
                    if (randomValue <= setting.amount)
                    {
                        remainingInstances.Add(ti);
                    }
                }
                else
                {
                    remainingInstances.Add(ti);
                }
            }

            terrainData.treeInstances = remainingInstances.ToArray();
        }
Пример #5
0
        private void ApplyTerrainScalability(TerrainScalabilitySetting setting)
        {
            if (setting.overridenPixelError >= 0f)
            {
                m_TargetTerrain.heightmapPixelError = setting.overridenPixelError;
            }

            if (setting.overridenBaseMapDist >= 0f)
            {
                m_TargetTerrain.basemapDistance = setting.overridenBaseMapDist;
            }

            if (setting.overrideDetailDistance >= 0f)
            {
                m_TargetTerrain.detailObjectDistance = setting.overrideDetailDistance;
            }

            if (setting.overrideDetailDensity >= 0f)
            {
                m_TargetTerrain.detailObjectDensity = setting.overrideDetailDensity;
            }

            if (setting.overrideTreeDistance >= 0f)
            {
                m_TargetTerrain.treeDistance = setting.overrideTreeDistance;
            }

            if (setting.overrideBillboardStart >= 0f)
            {
                m_TargetTerrain.treeBillboardDistance = setting.overrideBillboardStart;
            }

            if (setting.overrideFadeLength >= 0f)
            {
                m_TargetTerrain.treeCrossFadeLength = setting.overrideFadeLength;
            }
        }