Ejemplo n.º 1
0
        void Awake()
        {
            m_terrainCreator = GameObject.FindObjectOfType <EPMPolyTerrainCreator>();

            m_terrainCreator.Init();
            m_terrainCreator.ImportData();
            GameObject terrianRoot = m_terrainCreator.CreateTerrain();

            for (int i = 0; i < terrianRoot.transform.childCount; i++)
            {
                terrianRoot.transform.GetChild(i).gameObject.AddComponent <MeshCollider>();
            }
        }
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(sectionStyle);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("TerrainName:");
            m_creator.g_customData.terrainName = EditorGUILayout.TextField(m_creator.g_customData.terrainName);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("TerrainWidth:");
            m_creator.g_customData.terrainWidth = EditorGUILayout.IntField(m_creator.g_customData.terrainWidth, GUILayout.MinWidth(100));
            GUILayout.Label("TerrainLength:");
            m_creator.g_customData.terrainLength = EditorGUILayout.IntField(m_creator.g_customData.terrainLength, GUILayout.MinWidth(100));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("RowSplit:");
            m_creator.g_customData.rowSplit = EditorGUILayout.IntField(m_creator.g_customData.rowSplit, GUILayout.MinWidth(100));
            GUILayout.Label("ColumnSplit:");
            m_creator.g_customData.columnSplit = EditorGUILayout.IntField(m_creator.g_customData.columnSplit, GUILayout.MinWidth(100));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Random Seed:", GUILayout.Width(100));
            m_creator.g_customData.seed = EditorGUILayout.IntField(m_creator.g_customData.seed, GUILayout.Width(100));
            if (GUILayout.Button("R", GUILayout.Width(20)))
            {
                UnityEngine.Random.InitState(System.DateTime.Now.Millisecond);
                m_creator.g_customData.seed = UnityEngine.Random.Range(0, 1000000);
                m_creator.CreateTerrain();
            }
            GUILayout.Label("SeaLevel:");
            m_creator.g_customData.seaLevel = EditorGUILayout.FloatField((float)m_creator.g_customData.seaLevel, GUILayout.MinWidth(100));
            EditorGUILayout.EndHorizontal();

            DrawDataReadWrite();
            EditorGUILayout.EndVertical();


            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(sectionStyle);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("OBJECTS SECTION:");
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Visual Editor"))
            {
                EPMDrawMapWindow.CreateWindow(m_creator);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel++;
            for (int i = 0; i < 7; i++)
            {
                DrawPointListSection(i);
            }
            EditorGUI.indentLevel--;
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("CLEAR All OBJECTS", GUILayout.Width(150)))
            {
                if (EditorUtility.DisplayDialog("Caution!", "All the objects data will be cleard.", "OK", "Cancel"))
                {
                    m_creator.g_customData.roadLists.Clear();
                    m_creator.g_customData.riverLists.Clear();
                    m_creator.g_customData.hillLists.Clear();
                    m_creator.g_customData.mountainLists.Clear();
                    m_creator.g_customData.sandGroundLists.Clear();
                    m_creator.g_customData.soilGroundLists.Clear();
                    m_creator.g_customData.islandLists.Clear();
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();


            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(sectionStyle);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("HEIGHT SECTION");
            EditorGUILayout.EndHorizontal();

            for (int i = 0; i < m_creator.g_customData.heightSamplerList.Count; i++)
            {
                DrawSingleHeightSampler(i);
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add New Sampler", GUILayout.Width(150)))
            {
                m_creator.g_customData.heightSamplerList.Add(new EPMPolyTerrainCreator.HeightSampleData());
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();



            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(sectionStyle);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("TWIST SECTION");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            m_creator.g_customData.twistSeed = EditorGUILayout.IntField("Twist Seed:", m_creator.g_customData.twistSeed, GUILayout.Width(300));
            if (GUILayout.Button("R", GUILayout.Width(20)))
            {
                UnityEngine.Random.InitState(System.DateTime.Now.Millisecond);
                m_creator.g_customData.twistSeed = UnityEngine.Random.Range(0, 1000000);
                m_creator.CreateTerrain();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            m_creator.g_customData.twistNum = EditorGUILayout.IntField("Number:", m_creator.g_customData.twistNum, GUILayout.Width(300));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            m_creator.g_customData.twistStrength = EditorGUILayout.FloatField("Strength:", (float)m_creator.g_customData.twistStrength, GUILayout.Width(300));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("CreateTerrain"))
            {
                m_creator.CreateTerrain();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();



            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(sectionStyle);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("COLOR SECTION:");
            EditorGUILayout.EndHorizontal();
            foreach (EPMPoint.PointType pt in System.Enum.GetValues(typeof(EPMPoint.PointType)))
            {
                DrawSingleTypeColor(pt);
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(sectionStyle);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("ExportTerrain"))
            {
                m_creator.ExportTerrain();
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }