コード例 #1
0
        private void CreateTerrain()
        {
            var parent = (GameObject) Instantiate(new GameObject("Terrain"));

             parent.transform.position = new Vector3(0, 0, 0);

             for (int x = 1; x <= tileAmount.x; x++)
             {
            for (int y = 1; y <= tileAmount.y; y++)
            {
               var terrainData = new TerrainData();
               alphabet = (Alphabet) x;
               string name = alphabet + "-" + y;
               terrainData.size = new Vector3(width/16f,
                  height,
                  lenght/16f);

               terrainData.baseMapResolution = baseTextureReolution;
               terrainData.heightmapResolution = heightmapResoltion;
               terrainData.alphamapResolution = controlTextureResolution;
               terrainData.SetDetailResolution(detailResolution, detailResolutionPerPatch);
               terrainData.name = name;
               GameObject terrain = Terrain.CreateTerrainGameObject(terrainData);
               terrain.name = name;
               terrain.transform.parent = parent.transform;
               terrain.transform.position = new Vector3(lenght*(x - 1), 0, width*(y - 1));
               AssetDatabase.CreateAsset(terrainData, "Assets/" + path + name + ".asset");
            }
             }
        }
コード例 #2
0
 private static void Noise(float[,] heights, TerrainData terrain)
 {
   for (int index1 = 0; index1 < heights.GetLength(0); ++index1)
   {
     for (int index2 = 0; index2 < heights.GetLength(1); ++index2)
       heights[index1, index2] += Random.value * 0.01f;
   }
 }
コード例 #3
0
 private static void WobbleStuff(float[,] heights, TerrainData terrain)
 {
   for (int index1 = 0; index1 < heights.GetLength(0); ++index1)
   {
     for (int index2 = 0; index2 < heights.GetLength(1); ++index2)
       heights[index1, index2] = (float) (((double) heights[index1, index2] + 1.0) / 2.0);
   }
 }
コード例 #4
0
 public static void Smooth(TerrainData terrain)
 {
     int heightmapWidth = terrain.heightmapWidth;
     int heightmapHeight = terrain.heightmapHeight;
     float[,] heights = terrain.GetHeights(0, 0, heightmapWidth, heightmapHeight);
     Smooth(heights, terrain);
     terrain.SetHeights(0, 0, heights);
 }
コード例 #5
0
    UnityEngine.TerrainData GenerateTerrain(UnityEngine.TerrainData terrainData)
    {
        terrainData.heightmapResolution = width + 1;
        terrainData.size = new Vector3(width, depth, height);
        terrainData.SetHeights(0, 0, GenerateHeights());

        return(terrainData);
    }
コード例 #6
0
		private static void Noise(float[,] heights, TerrainData terrain)
		{
			for (int i = 0; i < heights.GetLength(0); i++)
			{
				for (int j = 0; j < heights.GetLength(1); j++)
				{
					heights[i, j] += UnityEngine.Random.value * 0.01f;
				}
			}
		}
コード例 #7
0
 private static void WobbleStuff(float[,] heights, TerrainData terrain)
 {
     for (int i = 0; i < heights.GetLength(0); i++)
     {
         for (int j = 0; j < heights.GetLength(1); j++)
         {
             heights[i, j] = (heights[i, j] + 1f) / 2f;
         }
     }
 }
コード例 #8
0
 private static void Noise(float[,] heights, TerrainData terrain)
 {
     for (int i = 0; i < heights.GetLength(0); i++)
     {
         for (int j = 0; j < heights.GetLength(1); j++)
         {
             float single1 = heights[i, j];
             single1[0] += Random.value * 0.01f;
         }
     }
 }
コード例 #9
0
 public static void Flatten(TerrainData terrain, float height)
 {
   int heightmapWidth = terrain.heightmapWidth;
   float[,] heights = new float[terrain.heightmapHeight, heightmapWidth];
   for (int index1 = 0; index1 < heights.GetLength(0); ++index1)
   {
     for (int index2 = 0; index2 < heights.GetLength(1); ++index2)
       heights[index1, index2] = height;
   }
   terrain.SetHeights(0, 0, heights);
 }
コード例 #10
0
        void Start()
        {
            terrainData = Terrain.terrainData;
            terrainPos = Terrain.transform.position;

            foreach (PhysSoundMaterial mat in SoundMaterials)
            {
                if (!compDic.ContainsKey(mat.MaterialTypeKey))
                    compDic.Add(mat.MaterialTypeKey, new PhysSoundComposition(mat.MaterialTypeKey));
            }
        }
コード例 #11
0
ファイル: TerrainManager.cs プロジェクト: Szejp/SurvivalGame
        private void Awake()
        {
            Instance = FindObjectOfType <TerrainManager>();

            ActiveTerrain = FindObjectOfType <UnityEngine.Terrain>();

            Data = ActiveTerrain.terrainData;

            IsInitialized = true;

            SaveTerrainData();
        }
コード例 #12
0
 public static void Flatten(TerrainData terrain, float height)
 {
     int heightmapWidth = terrain.heightmapWidth;
     float[,] heights = new float[terrain.heightmapHeight, heightmapWidth];
     for (int i = 0; i < heights.GetLength(0); i++)
     {
         for (int j = 0; j < heights.GetLength(1); j++)
         {
             heights[i, j] = height;
         }
     }
     terrain.SetHeights(0, 0, heights);
 }
コード例 #13
0
 public static void Smooth(float[,] heights, TerrainData terrain)
 {
   float[,] numArray = heights.Clone() as float[,];
   int length1 = heights.GetLength(1);
   int length2 = heights.GetLength(0);
   for (int index1 = 1; index1 < length2 - 1; ++index1)
   {
     for (int index2 = 1; index2 < length1 - 1; ++index2)
     {
       float num = (0.0f + numArray[index1, index2] + numArray[index1, index2 - 1] + numArray[index1, index2 + 1] + numArray[index1 - 1, index2] + numArray[index1 + 1, index2]) / 5f;
       heights[index1, index2] = num;
     }
   }
 }
コード例 #14
0
		private static void CreateTerrain(MenuCommand menuCommand)
		{
			TerrainData terrainData = new TerrainData();
			terrainData.heightmapResolution = 1025;
			terrainData.size = new Vector3(1000f, 600f, 1000f);
			terrainData.heightmapResolution = 512;
			terrainData.baseMapResolution = 1024;
			terrainData.SetDetailResolution(1024, terrainData.detailResolutionPerPatch);
			AssetDatabase.CreateAsset(terrainData, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset"));
			GameObject gameObject = Terrain.CreateTerrainGameObject(terrainData);
			GameObjectUtility.SetParentAndAlign(gameObject, menuCommand.context as GameObject);
			Selection.activeObject = gameObject;
			Undo.RegisterCreatedObjectUndo(gameObject, "Create terrain");
		}
コード例 #15
0
		public static void Flatten(TerrainData terrain, float height)
		{
			int heightmapWidth = terrain.heightmapWidth;
			int heightmapHeight = terrain.heightmapHeight;
			float[,] array = new float[heightmapHeight, heightmapWidth];
			for (int i = 0; i < array.GetLength(0); i++)
			{
				for (int j = 0; j < array.GetLength(1); j++)
				{
					array[i, j] = height;
				}
			}
			terrain.SetHeights(0, 0, array);
		}
コード例 #16
0
ファイル: TerrainMenus.cs プロジェクト: randomize/VimConfig
 private static void CreateTerrain(MenuCommand menuCommand)
 {
     TerrainData asset = new TerrainData {
         heightmapResolution = 0x401,
         size = new Vector3(1000f, 600f, 1000f),
         heightmapResolution = 0x200,
         baseMapResolution = 0x400
     };
     asset.SetDetailResolution(0x400, asset.detailResolutionPerPatch);
     AssetDatabase.CreateAsset(asset, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset"));
     GameObject child = Terrain.CreateTerrainGameObject(asset);
     GameObjectUtility.SetParentAndAlign(child, menuCommand.context as GameObject);
     Selection.activeObject = child;
     Undo.RegisterCreatedObjectUndo(child, "Create terrain");
 }
コード例 #17
0
 internal static void RemoveSplatTexture(TerrainData terrainData, int index)
 {
   Undo.RegisterCompleteObjectUndo((Object) terrainData, "Remove texture");
   int alphamapWidth = terrainData.alphamapWidth;
   int alphamapHeight = terrainData.alphamapHeight;
   float[,,] alphamaps = terrainData.GetAlphamaps(0, 0, alphamapWidth, alphamapHeight);
   int length1 = alphamaps.GetLength(2);
   int length2 = length1 - 1;
   float[,,] map = new float[alphamapHeight, alphamapWidth, length2];
   for (int index1 = 0; index1 < alphamapHeight; ++index1)
   {
     for (int index2 = 0; index2 < alphamapWidth; ++index2)
     {
       for (int index3 = 0; index3 < index; ++index3)
         map[index1, index2, index3] = alphamaps[index1, index2, index3];
       for (int index3 = index + 1; index3 < length1; ++index3)
         map[index1, index2, index3 - 1] = alphamaps[index1, index2, index3];
     }
   }
   for (int index1 = 0; index1 < alphamapHeight; ++index1)
   {
     for (int index2 = 0; index2 < alphamapWidth; ++index2)
     {
       float num1 = 0.0f;
       for (int index3 = 0; index3 < length2; ++index3)
         num1 += map[index1, index2, index3];
       if ((double) num1 >= 0.01)
       {
         float num2 = 1f / num1;
         for (int index3 = 0; index3 < length2; ++index3)
           map[index1, index2, index3] *= num2;
       }
       else
       {
         for (int index3 = 0; index3 < length2; ++index3)
           map[index1, index2, index3] = index3 != 0 ? 0.0f : 1f;
       }
     }
   }
   SplatPrototype[] splatPrototypes = terrainData.splatPrototypes;
   SplatPrototype[] splatPrototypeArray = new SplatPrototype[splatPrototypes.Length - 1];
   for (int index1 = 0; index1 < index; ++index1)
     splatPrototypeArray[index1] = splatPrototypes[index1];
   for (int index1 = index + 1; index1 < length1; ++index1)
     splatPrototypeArray[index1 - 1] = splatPrototypes[index1];
   terrainData.splatPrototypes = splatPrototypeArray;
   terrainData.SetAlphamaps(0, 0, map);
 }
コード例 #18
0
    static int set_terrainData(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.TerrainCollider obj  = (UnityEngine.TerrainCollider)o;
            UnityEngine.TerrainData     arg0 = (UnityEngine.TerrainData)ToLua.CheckObject(L, 2, typeof(UnityEngine.TerrainData));
            obj.terrainData = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index terrainData on a nil value"));
        }
    }
コード例 #19
0
    static int get_terrainData(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.TerrainCollider obj = (UnityEngine.TerrainCollider)o;
            UnityEngine.TerrainData     ret = obj.terrainData;
            ToLua.PushSealed(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index terrainData on a nil value"));
        }
    }
コード例 #20
0
        /// <summary>
        /// 设置拆分块信息
        /// </summary>
        /// <param name="iKey">Key:地形所在Gameobject的InstanceID</param>
        /// <param name="iData">地形数据</param>
        /// <param name="iSlicingCount">切分尺寸(x&z方向均等分,且为2的N次幂)</param>
        /// <param name="iStaticOnly">仅处理静态物体</param>
        /// <param name="iTerrainChunks">Chunk拆分数据</param>
        public void AddChunkInfo(
            int iKey, UnityEngine.TerrainData iData,
            int iSlicingCount, bool iStaticOnly,
            TerrainChunkData[] iTerrainChunks)
        {
            TerrainSplitInfo terrainChunk;

            if (ConfInfo.TryGetValue(iKey, out terrainChunk))
            {
                return;
            }
            terrainChunk = new TerrainSplitInfo();
            // 初始化
            terrainChunk.Init(
                iData, iSlicingCount,
                iTerrainChunks);
            ConfInfo.Add(iKey, terrainChunk);
        }
コード例 #21
0
        public void CreateTerrain()
        {
            Data = new TerrainData();
            Data.heightmapResolution = Settings.HeightmapResolution;
            Data.alphamapResolution = Settings.AlphamapResolution;
            Data.SetHeights(0, 0, Heightmap);
            ApplyTextures(Data);

            Data.size = new Vector3(Settings.Length, Settings.Height, Settings.Length);
            var newTerrainGameObject = Terrain.CreateTerrainGameObject(Data);
            newTerrainGameObject.transform.position = new Vector3(Position.X * Settings.Length, 0, Position.Z * Settings.Length);

            Terrain = newTerrainGameObject.GetComponent<Terrain>();
            Terrain.heightmapPixelError = 8;
            Terrain.materialType = UnityEngine.Terrain.MaterialType.Custom;
            Terrain.materialTemplate = Settings.TerrainMaterial;
            Terrain.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
            Terrain.Flush();
        }
コード例 #22
0
        /// <summary>
        /// 初始化
        ///   备注:
        ///     这里我们切分长宽按等比例切分.既长和宽方向切分同等数量
        ///     且高度地图的分辨率只能是2的N次幂加1,所以切分个数也必须为2的N次幂
        /// </summary>
        /// <param name="iData">地形数据</param>
        /// <param name="iSlicingCount">切分尺寸(x&z方向均等分,且为2的N次幂)</param>
        /// <param name="iTerrainChunks">Chunk拆分数据</param>
        public void Init(
            UnityEngine.TerrainData iData, int iSlicingCount,
            TerrainChunkData[] iTerrainChunks)
        {
            if (null == iData)
            {
                return;
            }
            if (0 >= iSlicingCount)
            {
                return;
            }

            // 查分数量(SlicingCount x SlicingCount)
            SlicingCount = iSlicingCount;

            // 追加chunk信息
            AddChunks(iTerrainChunks);
        }
コード例 #23
0
 public static void Smooth(float[,] heights, TerrainData terrain)
 {
     float[,] numArray = heights.Clone() as float[,];
     int length = heights.GetLength(1);
     int num2 = heights.GetLength(0);
     for (int i = 1; i < (num2 - 1); i++)
     {
         for (int j = 1; j < (length - 1); j++)
         {
             float num5 = 0f;
             num5 += numArray[i, j];
             num5 += numArray[i, j - 1];
             num5 += numArray[i, j + 1];
             num5 += numArray[i - 1, j];
             num5 += numArray[i + 1, j];
             num5 /= 5f;
             heights[i, j] = num5;
         }
     }
 }
コード例 #24
0
		public static void Smooth(float[,] heights, TerrainData terrain)
		{
			float[,] array = heights.Clone() as float[,];
			int length = heights.GetLength(1);
			int length2 = heights.GetLength(0);
			for (int i = 1; i < length2 - 1; i++)
			{
				for (int j = 1; j < length - 1; j++)
				{
					float num = 0f;
					num += array[i, j];
					num += array[i, j - 1];
					num += array[i, j + 1];
					num += array[i - 1, j];
					num += array[i + 1, j];
					num /= 5f;
					heights[i, j] = num;
				}
			}
		}
コード例 #25
0
		private static void ResizeDetailResolution(TerrainData terrainData, int resolution, int resolutionPerPatch)
		{
			if (resolution == terrainData.detailResolution)
			{
				List<int[,]> list = new List<int[,]>();
				for (int i = 0; i < terrainData.detailPrototypes.Length; i++)
				{
					list.Add(terrainData.GetDetailLayer(0, 0, terrainData.detailWidth, terrainData.detailHeight, i));
				}
				terrainData.SetDetailResolution(resolution, resolutionPerPatch);
				for (int j = 0; j < list.Count; j++)
				{
					terrainData.SetDetailLayer(0, 0, j, list[j]);
				}
			}
			else
			{
				terrainData.SetDetailResolution(resolution, resolutionPerPatch);
			}
		}
コード例 #26
0
ファイル: TreePainter.cs プロジェクト: randomize/VimConfig
 public static void MassPlaceTrees(TerrainData terrainData, int numberOfTrees, bool randomTreeColor, bool keepExistingTrees)
 {
     int length = terrainData.treePrototypes.Length;
     if (length == 0)
     {
         Debug.Log("Can't place trees because no prototypes are defined");
     }
     else
     {
         Undo.RegisterCompleteObjectUndo(terrainData, "Mass Place Trees");
         TreeInstance[] sourceArray = new TreeInstance[numberOfTrees];
         int num2 = 0;
         while (num2 < sourceArray.Length)
         {
             TreeInstance instance = new TreeInstance {
                 position = new Vector3(UnityEngine.Random.value, 0f, UnityEngine.Random.value)
             };
             if (terrainData.GetSteepness(instance.position.x, instance.position.z) < 30f)
             {
                 instance.color = !randomTreeColor ? Color.white : GetTreeColor();
                 instance.lightmapColor = Color.white;
                 instance.prototypeIndex = UnityEngine.Random.Range(0, length);
                 instance.heightScale = GetTreeHeight();
                 instance.widthScale = !lockWidthToHeight ? GetTreeWidth() : instance.heightScale;
                 instance.rotation = GetTreeRotation();
                 sourceArray[num2++] = instance;
             }
         }
         if (keepExistingTrees)
         {
             TreeInstance[] treeInstances = terrainData.treeInstances;
             TreeInstance[] destinationArray = new TreeInstance[treeInstances.Length + sourceArray.Length];
             Array.Copy(treeInstances, 0, destinationArray, 0, treeInstances.Length);
             Array.Copy(sourceArray, 0, destinationArray, treeInstances.Length, sourceArray.Length);
             sourceArray = destinationArray;
         }
         terrainData.treeInstances = sourceArray;
         terrainData.RecalculateTreePositions();
     }
 }
コード例 #27
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.TerrainData terrainData = (UnityEngine.TerrainData)value;
     float [,,] alphamaps = terrainData.GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight);
     float [,] heights    = terrainData.GetHeights(0, 0, terrainData.heightmapResolution, terrainData.heightmapResolution);
     writer.WriteProperty("alphamaps", alphamaps);
     writer.WriteProperty("heights", heights);
     writer.WriteProperty("heightmapResolution", terrainData.heightmapResolution);
     writer.WriteProperty("size", terrainData.size);
     writer.WriteProperty("thickness", terrainData.thickness);
     writer.WriteProperty("wavingGrassStrength", terrainData.wavingGrassStrength);
     writer.WriteProperty("wavingGrassAmount", terrainData.wavingGrassAmount);
     writer.WriteProperty("wavingGrassSpeed", terrainData.wavingGrassSpeed);
     writer.WriteProperty("wavingGrassTint", terrainData.wavingGrassTint);
     writer.WriteProperty("detailPrototypes", terrainData.detailPrototypes);
     writer.WriteProperty("treeInstances", terrainData.treeInstances);
     writer.WriteProperty("treePrototypes", terrainData.treePrototypes);
     writer.WriteProperty("alphamapResolution", terrainData.alphamapResolution);
     writer.WriteProperty("baseMapResolution", terrainData.baseMapResolution);
     writer.WriteProperty("splatPrototypes", terrainData.splatPrototypes);
     writer.WriteProperty("name", terrainData.name);
     writer.WriteProperty("hideFlags", terrainData.hideFlags);
 }
コード例 #28
0
ファイル: ProceduralTerrain.cs プロジェクト: TheMunro/noise
        public void CreateTerrain()
        {
            var data = new TerrainData();
            data.alphamapResolution = Settings.AlphaMapResolution;
            data.heightmapResolution = Settings.HeightMapResolution;

            var heightmap = GetHeightmap();
            data.SetHeights(0, 0, heightmap);
            ApplyTextures(data);

            data.size = new Vector3(Settings.Length, Settings.Height, Settings.Length);

            var terrain = Terrain.CreateTerrainGameObject(data);
            terrain.transform.position = new Vector3(-0.5f * Settings.Length, 0, -0.5f * Settings.Length);

            _terrain = terrain.GetComponent<Terrain>();
            _terrain.heightmapPixelError = 8;
            _terrain.materialType = Terrain.MaterialType.Custom;
            _terrain.materialTemplate = Settings.TerrainMaterial;
            _terrain.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;

            _terrain.Flush();
        }
コード例 #29
0
ファイル: Terrain.cs プロジェクト: CarlosHBC/UnityDecompiled
 public static extern GameObject CreateTerrainGameObject(TerrainData assignTerrain);
コード例 #30
0
 private void ResizeDetailResolution(TerrainData terrainData, int resolution, int resolutionPerPatch)
 {
   if (resolution == terrainData.detailResolution)
   {
     List<int[,]> numArrayList = new List<int[,]>();
     for (int layer = 0; layer < terrainData.detailPrototypes.Length; ++layer)
       numArrayList.Add(terrainData.GetDetailLayer(0, 0, terrainData.detailWidth, terrainData.detailHeight, layer));
     terrainData.SetDetailResolution(resolution, resolutionPerPatch);
     for (int layer = 0; layer < numArrayList.Count; ++layer)
       terrainData.SetDetailLayer(0, 0, layer, numArrayList[layer]);
   }
   else
     terrainData.SetDetailResolution(resolution, resolutionPerPatch);
 }
コード例 #31
0
ファイル: ProceduralTerrain.cs プロジェクト: TheMunro/noise
        private void ApplyTextures(TerrainData data)
        {
            var flatSplat = new SplatPrototype();
            var steepSplat = new SplatPrototype();

            flatSplat.texture = Settings.FlatTexture;
            steepSplat.texture = Settings.SteepTexture;

            data.splatPrototypes = new []
            {
                flatSplat,
                steepSplat
            };

            data.RefreshPrototypes();

            var splatMap = new float[data.alphamapResolution, data.alphamapResolution, 2];

            for (var z = 0; z < data.alphamapHeight; z++)
            {
                for (var x = 0; x < data.alphamapWidth; x++)
                {
                    var normalizedX = (float)x / (data.alphamapWidth - 1);
                    var normalizedZ = (float)z / (data.alphamapHeight - 1);

                    var steepness = data.GetSteepness(normalizedX, normalizedZ) * Settings.SteepnessTextureMultiplier;
                    var steepnessNormalized = Mathf.Clamp(steepness, 0, 1f);

                    splatMap[z, x, 0] = 1f - steepnessNormalized;
                    splatMap[z, x, 1] = steepnessNormalized;
                }
            }

            data.SetAlphamaps(0, 0, splatMap);
        }
コード例 #32
0
 internal void Internal_Create([Writable] TerrainData terrainData)
 {
     throw new NotImplementedException("なにこれ");
 }
コード例 #33
0
 public static bool CheckTreeDistance(TerrainData terrainData, Vector3 position, int treeIndex, float distanceBias)
 {
     return INTERNAL_CALL_CheckTreeDistance(terrainData, ref position, treeIndex, distanceBias);
 }
コード例 #34
0
 private static extern int INTERNAL_CALL_RemoveTrees(TerrainData self, ref Vector2 position, float radius, int prototypeIndex);
コード例 #35
0
 private static extern void INTERNAL_CALL_SetTreeInstance(TerrainData self, int index, ref TreeInstance instance);
コード例 #36
0
ファイル: TerrainData.cs プロジェクト: zzrx79/UnityDecompiled
 private static extern void INTERNAL_CALL_GetInterpolatedNormal(TerrainData self, float x, float y, out Vector3 value);
コード例 #37
0
ファイル: GridEditor.cs プロジェクト: thetobinator/udg2
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Grid Width:");
            var oldWidth = grid.width;
            grid.width = EditorGUILayout.IntSlider(grid.width, 0, 100);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Grid height:");
            var oldHeight = grid.height;
            grid.height = EditorGUILayout.IntSlider(grid.height, 0, 100);
            GUILayout.EndHorizontal();

            if (grid.width != oldWidth || grid.height != oldHeight)
            {
                grid.GenerateMaps(false);
            }

            ShowEdit();

            for (int i = 0; i < grid.streets.Count; i++)
            {
                if (grid.streets[grid.streets.Count - 1].Count > 1)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Street" + (i + 1) + ": ");

                    if (GUILayout.Button("Select"))
                    {
                        for (int j = 0; j < grid.selectedStreet.Count; j++)
                            grid.selectedStreet[j] = false;
                        grid.selectedStreet[i] = true;
                    }
                    if (GUILayout.Button("Deselect"))
                        grid.selectedStreet[i] = false;
                    if (GUILayout.Button("Delete"))
                    {
                        grid.streets.RemoveAt(i);
                        grid.selectedStreet.RemoveAt(i);
                        if (grid.selectedStreet.Count > i)
                            grid.selectedStreet[i] = false;
                    }
                    GUILayout.EndHorizontal();
                }
            }

            //select number of building types and add building prefabs
            showBuildingTypes = EditorGUILayout.Foldout(showBuildingTypes, "Show Building Types");

            if (showBuildingTypes)
            {
                GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(true));

                EditorGUILayout.Space();
                AddTypesOfPrefabs("House Types", grid.housePrefab);

                EditorGUILayout.Space();
                AddTypesOfPrefabs("Skyscraper Types", grid.skyscraperPrefab);

                GUILayout.EndVertical();
            }

            EditorGUILayout.Space();
            //select number of building types and add building prefabs
            showTreeTypes = EditorGUILayout.Foldout(showTreeTypes, "Show Building Types");

            if (showTreeTypes)
            {
                GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(true));

                AddTypesOfPrefabs("ConeTree Types", grid.conetreePrefab);

                EditorGUILayout.Space();
                AddTypesOfPrefabs("WoodTree Types", grid.woodtreePrefab);

                GUILayout.EndVertical();
            }

            if (GUILayout.Button("Reset Map", GUILayout.Height(30)))
            {
                grid.showGrid = true;
                redoStack = new LinkedList<GridCreator.CellType[,]>();
                undoStack = new LinkedList<GridCreator.CellType[,]>();
                grid.GenerateMaps(true);
                current = (GridCreator.CellType[,])grid.worldMap.Clone();
                undoStack.AddLast(new LinkedListNode<GridCreator.CellType[,]>(grid.worldMap));
            }

            if (GUILayout.Button("Generate City", GUILayout.Height(30)))
            {
                if (!grid.showGrid)
                    Debug.Log("Please build grid to generete");
                else
                {
                    grid.showGrid = false;
                    TerrainData terrainData = new TerrainData();
                    GameObject city = Terrain.CreateTerrainGameObject(terrainData);
                    city.transform.position = Vector3.zero;
                    city.AddComponent<CityPopulator>();
                    city.GetComponent<CityPopulator>().citysize = terrainData.size;
                    city.GetComponent<CityPopulator>().Populate(grid);
                }
            }

            if (GUILayout.Button("Done", GUILayout.Height(30)))
            {
                GameObject city = GameObject.Find("Terrain");

                if (city == null)
                    Debug.Log("Please generate map before");
                else
                {
                    city.GetComponent<CityPopulator>().ClearFromScripts();
                    PrefabCreator.CreatePrefab(city.gameObject);
                }
            }
            GUI.enabled = true;

            SceneView.RepaintAll();

            if (GUI.changed)
            {
                grid.firstTimeBuild = true;
            }
        }
コード例 #38
0
ファイル: TerrainData.cs プロジェクト: zzrx79/UnityDecompiled
 private static extern void INTERNAL_CALL_GetTreeInstance(TerrainData self, int index, out TreeInstance value);
コード例 #39
0
 private static int INTERNAL_CALL_RemoveTrees(TerrainData self, ref Vector2 position, float radius, int prototypeIndex)
 {
     throw new NotImplementedException("なにこれ");
 }
コード例 #40
0
ファイル: TerrainData.cs プロジェクト: yaoya/UnityDecompiled
 public TerrainData()
 {
     TerrainData.Internal_Create(this);
 }
コード例 #41
0
 public static extern GameObject CreateTerrainGameObject(TerrainData assignTerrain);
コード例 #42
0
ファイル: TerrainData.cs プロジェクト: qipa/UnityDecompiled-2
 internal int RemoveTrees(Vector2 position, float radius, int prototypeIndex)
 {
     return(TerrainData.INTERNAL_CALL_RemoveTrees(this, ref position, radius, prototypeIndex));
 }
    /// <summary>
    /// Preprocess the terrain to clamp down on the number of splat maps which have weights on each control point. First pass
    /// limits the number of weights to the specified amount per control point. Since each rendered pixel is a blend of 4 possible
    /// control points, this still means a given pixel may need up to 4 weights even if the control point is clamped to 1 weight.
    /// In the second pass, we check all of the neighoring pixels to see if they have different weights- if they do, we clamp
    /// down to one less weight on this control point. The idea here is to create some extra headroom for the blend, but since
    /// you can still need 4 blend weights in some cases, there is no perfect solution to this issue when running with less than
    /// 4 blend weights. It does, however, greatly help when running under those constraints.
    ///
    /// </summary>
    /// <param name="bt">Bt.</param>
    /// <param name="maxWeights">Max weights.</param>
    /// <param name="secondPass">If set to <c>true</c> second pass.</param>
    public static void WeightLimitTerrain(MicroSplatTerrain bt, int maxWeights, bool secondPass = false)
    {
        Terrain t = bt.GetComponent <Terrain>();

        if (t == null)
        {
            return;
        }
        UnityEngine.TerrainData td = t.terrainData;
        if (td == null)
        {
            return;
        }

        int w = td.alphamapWidth;
        int h = td.alphamapHeight;
        int l = td.alphamapLayers;

        Undo.RegisterCompleteObjectUndo(t, "Weight Limit Terrain");

        var splats = td.GetAlphamaps(0, 0, w, h);

        float[]           data         = new float[16];
        List <WeightPair> sorted       = new List <WeightPair>();
        List <int>        validIndexes = new List <int>();

        for (int x = 0; x < w; ++x)
        {
            for (int y = 0; y < h; ++y)
            {
                // gather all weights
                for (int i = 0; i < l; ++i)
                {
                    data[i] = splats[x, y, i];
                }

                sorted.Clear();
                for (int i = 0; i < 16; ++i)
                {
                    var wp = new WeightPair();
                    wp.index  = i;
                    wp.weight = data[i];
                    sorted.Add(wp);
                }

                sorted.Sort((w0, w1) => w1.weight.CompareTo(w0.weight));

                // remove lower weights
                int allowedWeights = maxWeights;
                while (sorted.Count > allowedWeights)
                {
                    sorted.RemoveAt(sorted.Count - 1);
                }

                // generate valid index list
                validIndexes.Clear();
                for (int i = 0; i < sorted.Count; ++i)
                {
                    if (sorted[i].weight > 0)
                    {
                        validIndexes.Add(sorted[i].index);
                    }
                }
                // figure out if our neighbors have weights which we don't have- if so, clamp down harder to make room for blending..
                // if not, allow us to blend fully. We do this in a second pass so that small weights are reduced before we make
                // this decision..

                if (secondPass)
                {
                    for (int xm = -1; xm < 2; ++xm)
                    {
                        for (int ym = -1; ym < 2; ++ym)
                        {
                            int nx = x + xm;
                            int ny = y + ym;
                            if (nx >= 0 && ny >= 0 && nx < w && ny < y)
                            {
                                for (int layer = 0; layer < l; ++layer)
                                {
                                    float weight = splats[nx, ny, layer];
                                    if (weight > 0 && !validIndexes.Contains(layer))
                                    {
                                        allowedWeights = maxWeights - 1;
                                    }
                                }
                            }
                        }
                    }
                    while (sorted.Count > allowedWeights)
                    {
                        sorted.RemoveAt(sorted.Count - 1);
                    }
                    // generate valid index list
                    validIndexes.Clear();
                    for (int i = 0; i < sorted.Count; ++i)
                    {
                        if (sorted[i].weight > 0)
                        {
                            validIndexes.Add(sorted[i].index);
                        }
                    }
                }


                // clear non-valid indexes

                for (int j = 0; j < 16; ++j)
                {
                    if (!validIndexes.Contains(j))
                    {
                        data[j] = 0;
                    }
                }


                // now normalize weights so that they total one on each pixel

                float total = 0;
                for (int j = 0; j < 16; ++j)
                {
                    total += data[j];
                }
                float scale = 1.0f / total;
                for (int j = 0; j < 16; ++j)
                {
                    data[j] *= scale;
                }


                // now map back to splat data array
                for (int i = 0; i < l; ++i)
                {
                    splats[x, y, i] = data[i];
                }
            }
        }

        td.SetAlphamaps(0, 0, splats);
    }
コード例 #44
0
        /// <summary>
        /// Promote data to live terrain.
        /// This must be called after other processing complete.
        /// </summary>
        public void PromoteTerrainData()
        {
            // Basemap not used and is just pushed far away
            const float basemapDistance = 10000f;

            // Ensure TerrainData is created
            Terrain terrain = GetComponent<Terrain>();
            if (terrain.terrainData == null)
            {
                // Calculate width and length of terrain in world units
                float terrainSize = (MapsFile.WorldMapTerrainDim * MeshReader.GlobalScale);

                // Setup terrain data
                // Must set terrainData.heightmapResolution before size (thanks Nystul!)
                TerrainData terrainData = new TerrainData();
                terrainData.name = "TerrainData";
                terrainData.heightmapResolution = heightmapResolution;
                terrainData.size = new Vector3(terrainSize, TerrainHelper.maxTerrainHeight, terrainSize);
                terrainData.SetDetailResolution(detailResolution, resolutionPerPatch);
                terrainData.alphamapResolution = detailResolution;
                terrainData.baseMapResolution = detailResolution;

                // Apply terrain data
                terrain.terrainData = terrainData;
                terrain.GetComponent<TerrainCollider>().terrainData = terrainData;
                terrain.basemapDistance = basemapDistance;
            }

            // Promote tileMap
            tileMapTexture.SetPixels32(TileMap);
            tileMapTexture.Apply(false);

            // Promote material
            terrain.materialTemplate = terrainMaterial;
            terrain.materialType = Terrain.MaterialType.Custom;

            // Promote heights
            Vector3 size = terrain.terrainData.size;
            terrain.terrainData.size = new Vector3(size.x, TerrainHelper.maxTerrainHeight * TerrainScale, size.z);
            terrain.terrainData.SetHeights(0, 0, heights);

            // Raise event
            RaiseOnPromoteTerrainDataEvent(terrain.terrainData);
        }
コード例 #45
0
        /// <summary>
        /// Caches quick references and initializes the quadtree.
        /// </summary>
        /// <remarks>
        /// This method is invoked by Unity.
        /// </remarks>
        private void Start()
        {
            this.diagonalLengthOver2 = this.DiagonalLength * 0.5f;

            this.terrain = this.GetComponent<Terrain>();
            this.data = terrain.terrainData;

            var boundaries = new Rect(
                this.terrain.transform.position.x,
                this.terrain.transform.position.z,
                this.data.size.x,
                this.data.size.z
                );
            this.trees = new Quadtree<TreeInstance>(boundaries);
            foreach (var instance in this.data.treeInstances)
            {
                this.AddTree(instance);
            }
        }
コード例 #46
0
 private static void INTERNAL_CALL_SetTreeInstance(TerrainData self, int index, ref TreeInstance instance)
 {
     throw new NotImplementedException("なにこれ");
 }
コード例 #47
0
 extern private static void Internal_Create([Writable] TerrainData terrainData);
コード例 #48
0
 /// <summary>
 /// Read the data using the reader.
 /// </summary>
 /// <param name="reader">Reader.</param>
 public override object Read(ISaveGameReader reader)
 {
     UnityEngine.TerrainData terrainData = new UnityEngine.TerrainData();
     ReadInto(terrainData, reader);
     return(terrainData);
 }
コード例 #49
0
 protected virtual void RaiseOnPromoteTerrainDataEvent(TerrainData terrainData)
 {
     if (OnPromoteTerrainData != null)
         OnPromoteTerrainData(this, terrainData);
 }
コード例 #50
0
        /// <summary>
        /// Read the data into the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="reader">Reader.</param>
        public override void ReadInto(object value, ISaveGameReader reader)
        {
            UnityEngine.TerrainData terrainData = (UnityEngine.TerrainData)value;
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "alphamaps":
                    terrainData.SetAlphamaps(0, 0, reader.ReadProperty <float [, , ]> ());
                    break;

                case "heights":
                    terrainData.SetHeights(0, 0, reader.ReadProperty <float [, ]> ());
                    break;

                case "heightmapResolution":
                    terrainData.heightmapResolution = reader.ReadProperty <System.Int32> ();
                    break;

                case "size":
                    terrainData.size = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "thickness":
                    terrainData.thickness = reader.ReadProperty <System.Single> ();
                    break;

                case "wavingGrassStrength":
                    terrainData.wavingGrassStrength = reader.ReadProperty <System.Single> ();
                    break;

                case "wavingGrassAmount":
                    terrainData.wavingGrassAmount = reader.ReadProperty <System.Single> ();
                    break;

                case "wavingGrassSpeed":
                    terrainData.wavingGrassSpeed = reader.ReadProperty <System.Single> ();
                    break;

                case "wavingGrassTint":
                    terrainData.wavingGrassTint = reader.ReadProperty <UnityEngine.Color> ();
                    break;

                case "detailPrototypes":
                    terrainData.detailPrototypes = reader.ReadProperty <UnityEngine.DetailPrototype []> ();
                    break;

                case "treeInstances":
                    terrainData.treeInstances = reader.ReadProperty <UnityEngine.TreeInstance []> ();
                    break;

                case "treePrototypes":
                    terrainData.treePrototypes = reader.ReadProperty <UnityEngine.TreePrototype []> ();
                    break;

                case "alphamapResolution":
                    terrainData.alphamapResolution = reader.ReadProperty <System.Int32> ();
                    break;

                case "baseMapResolution":
                    terrainData.baseMapResolution = reader.ReadProperty <System.Int32> ();
                    break;

                case "splatPrototypes":
                    terrainData.splatPrototypes = reader.ReadProperty <UnityEngine.SplatPrototype []> ();
                    break;

                case "name":
                    terrainData.name = reader.ReadProperty <System.String> ();
                    break;

                case "hideFlags":
                    terrainData.hideFlags = reader.ReadProperty <UnityEngine.HideFlags> ();
                    break;
                }
            }
        }
コード例 #51
0
 [FreeFunction]                                                          // 0x00000001801186A0-0x00000001801186D0
 private static void Internal_Create([Writable] /* 0x00000001800D4E50-0x00000001800D4E60 */ TerrainData terrainData)
 {
 }                                                                                                                              // 0x0000000180ADD580-0x0000000180ADD5C0
コード例 #52
0
ファイル: TerrainData.cs プロジェクト: zzrx79/UnityDecompiled
 internal extern void Internal_Create([Writable] TerrainData terrainData);
コード例 #53
0
        private void ApplyTextures(TerrainData terrainData)
        {
            var flatSplat = new SplatPrototype();
            var steepSplat = new SplatPrototype();

            flatSplat.texture = Settings.FlatTexture;
            steepSplat.texture = Settings.SteepTexture;

            terrainData.splatPrototypes = new SplatPrototype[]
            {
                flatSplat,
                steepSplat
            };

            terrainData.RefreshPrototypes();

            var splatMap = new float[terrainData.alphamapResolution, terrainData.alphamapResolution, 2];

            for (var zRes = 0; zRes < terrainData.alphamapHeight; zRes++)
            {
                for (var xRes = 0; xRes < terrainData.alphamapWidth; xRes++)
                {
                    var normalizedX = (float)xRes / (terrainData.alphamapWidth - 1);
                    var normalizedZ = (float)zRes / (terrainData.alphamapHeight - 1);

                    var steepness = terrainData.GetSteepness(normalizedX, normalizedZ);
                    var steepnessNormalized = Mathf.Clamp(steepness / 1.5f, 0, 1f);

                    splatMap[zRes, xRes, 0] = 1f - steepnessNormalized;
                    splatMap[zRes, xRes, 1] = steepnessNormalized;
                }
            }

            terrainData.SetAlphamaps(0, 0, splatMap);
        }
コード例 #54
0
ファイル: TerrainData.cs プロジェクト: qipa/UnityDecompiled-2
 public void SetTreeInstance(int index, TreeInstance instance)
 {
     TerrainData.INTERNAL_CALL_SetTreeInstance(this, index, ref instance);
 }