Exemple #1
0
        private void DrawNeighboringGUI()
        {
            string label = "Neighboring";
            string id    = "polaris-v2-neighboring";

            GenericMenu menu = new GenericMenu();

            menu.AddItem(
                new GUIContent("Reset"),
                false,
                () => { ResetNeighboring(); });
            menu.AddItem(
                new GUIContent("Connect"),
                false,
                () => { GStylizedTerrain.ConnectAdjacentTiles(); });

            isNeighboringFoldoutExpanded = GEditorCommon.Foldout(label, false, id, () =>
            {
                EditorGUI.BeginChangeCheck();
                terrain.AutoConnect    = EditorGUILayout.Toggle("Auto Connect", terrain.AutoConnect);
                terrain.GroupId        = EditorGUILayout.DelayedIntField("Group Id", terrain.GroupId);
                terrain.TopNeighbor    = EditorGUILayout.ObjectField("Top Neighbor", terrain.TopNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;
                terrain.BottomNeighbor = EditorGUILayout.ObjectField("Bottom Neighbor", terrain.BottomNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;
                terrain.LeftNeighbor   = EditorGUILayout.ObjectField("Left Neighbor", terrain.LeftNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;
                terrain.RightNeighbor  = EditorGUILayout.ObjectField("Right Neighbor", terrain.RightNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;

                if (EditorGUI.EndChangeCheck())
                {
                    if (terrain.TopNeighbor != null || terrain.BottomNeighbor != null || terrain.LeftNeighbor != null || terrain.RightNeighbor != null)
                    {
                        GAnalytics.Record(GAnalytics.MULTI_TERRAIN, true);
                    }
                }
            }, menu);
        }
        private void FinishingUp()
        {
#if UNITY_EDITOR
            GCommonGUI.ProgressBar("Finishing Up", "Matching geometry...", 1f);
#endif
            GStylizedTerrain.ConnectAdjacentTiles();
            GStylizedTerrain.MatchEdges(-1);
            Root.gameObject.SetActive(false);
#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif
        }
Exemple #3
0
        private void DuringSceneGUI(SceneView sv)
        {
            DrawDebugGUI();

            if (terrain.TerrainData == null)
            {
                return;
            }
            if (!terrain.AutoConnect)
            {
                return;
            }
            if (!isNeighboringFoldoutExpanded)
            {
                return;
            }

            Vector3 terrainSizeXZ = new Vector3(
                terrain.TerrainData.Geometry.Width,
                0,
                terrain.TerrainData.Geometry.Length);

            if (terrain.LeftNeighbor == null)
            {
                Vector3 pos = terrain.transform.position + Vector3.left * terrainSizeXZ.x + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = terrain.transform.parent;
                    t.transform.position = terrain.transform.position + Vector3.left * terrainSizeXZ.x;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
            if (terrain.TopNeighbor == null)
            {
                Vector3 pos = terrain.transform.position + Vector3.forward * terrainSizeXZ.z + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = terrain.transform.parent;
                    t.transform.position = terrain.transform.position + Vector3.forward * terrainSizeXZ.z;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
            if (terrain.RightNeighbor == null)
            {
                Vector3 pos = terrain.transform.position + Vector3.right * terrainSizeXZ.z + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = terrain.transform.parent;
                    t.transform.position = terrain.transform.position + Vector3.right * terrainSizeXZ.x;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
            if (terrain.BottomNeighbor == null)
            {
                Vector3 pos = terrain.transform.position + Vector3.back * terrainSizeXZ.z + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = terrain.transform.parent;
                    t.transform.position = terrain.transform.position + Vector3.back * terrainSizeXZ.z;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }

            GEditorCommon.SceneViewMouseMessage(new GUIContent(
                                                    "Click on a rectangle to pin.\n" +
                                                    "Close the Neighboring foldout to disable terrain pinning mode."));
        }
        public static List <GStylizedTerrain> CreateTerrains(GameObject root)
        {
            GEditorSettings.WizardToolsSettings settings = GEditorSettings.Instance.wizardTools;
            List <GStylizedTerrain>             terrains = new List <GStylizedTerrain>();

#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                GUtilities.EnsureDirectoryExists(settings.dataDirectory);
            }
#endif
            try
            {
                float totalTile = settings.tileCountX * settings.tileCountZ;
                float tileCount = 0;
                for (int z = 0; z < settings.tileCountZ; ++z)
                {
                    for (int x = 0; x < settings.tileCountX; ++x)
                    {
                        tileCount += 1;
#if UNITY_EDITOR
                        GCommonGUI.CancelableProgressBar(
                            "Creating Terrains",
                            string.Format("Creating tile ({0},{1})", x, z),
                            tileCount / totalTile);
#endif
                        GameObject g = new GameObject();
                        g.transform.parent     = root.transform;
                        g.transform.position   = new Vector3(x * settings.tileSize.x, 0, z * settings.tileSize.z) + settings.origin;
                        g.transform.rotation   = Quaternion.identity;
                        g.transform.localScale = Vector3.one;
                        g.name = string.Format("{0}_({1},{2})", settings.terrainNamePrefix, x, z);

                        GTerrainData data = ScriptableObject.CreateInstance <GTerrainData>();

                        if (Application.isPlaying) //Reset() only called in edit mode
                        {
                            data.Reset();
                            data.Geometry.Reset();
                            data.Shading.Reset();
                            data.Rendering.Reset();
                            data.Foliage.Reset();
                            data.Mask.Reset();
                        }
                        data.name            = string.Format("TerrainData_{0}", data.Id);
                        data.Geometry.Width  = settings.tileSize.x;
                        data.Geometry.Height = settings.tileSize.y;
                        data.Geometry.Length = settings.tileSize.z;
                        if (settings.texturingModel == GTexturingModel.VertexColor)
                        {
                            data.Geometry.AlbedoToVertexColorMode = GAlbedoToVertexColorMode.Sharp;
                        }

#if UNITY_EDITOR
                        if (!Application.isPlaying)
                        {
                            string dataAssetPath = Path.Combine(settings.dataDirectory, data.name + ".asset");
                            AssetDatabase.CreateAsset(data, dataAssetPath);
                        }
#endif

                        Material material = GRuntimeSettings.Instance.terrainRendering.GetClonedMaterial(
                            GCommon.CurrentRenderPipeline,
                            settings.lightingModel,
                            settings.texturingModel,
                            settings.splatsModel);
                        if (material != null)
                        {
                            material.name = string.Format("TerrainMaterial_{0}", data.Id);
#if UNITY_EDITOR
                            if (!Application.isPlaying)
                            {
                                string materialAssetPath = Path.Combine(settings.dataDirectory, material.name + ".mat");
                                AssetDatabase.CreateAsset(material, materialAssetPath);
                            }
#endif
                        }
                        data.Shading.CustomMaterial = material;
                        data.Shading.UpdateMaterials();

                        GStylizedTerrain terrain = g.AddComponent <GStylizedTerrain>();
                        terrain.GroupId     = settings.groupId;
                        terrain.TerrainData = data;

#if UNITY_EDITOR
                        Undo.RegisterCreatedObjectUndo(g, "Creating Low Poly Terrain");
#endif

                        GameObject colliderGO = new GameObject("Tree Collider");
                        colliderGO.transform.parent        = g.transform;
                        colliderGO.transform.localPosition = Vector3.zero;
                        colliderGO.transform.localRotation = Quaternion.identity;
                        colliderGO.transform.localScale    = Vector3.one;

                        GTreeCollider collider = colliderGO.AddComponent <GTreeCollider>();
                        collider.Terrain = terrain;
                    }
                }
            }
            catch (GProgressCancelledException)
            {
            }

            GStylizedTerrain.ConnectAdjacentTiles();

#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif

            return(terrains);
        }
Exemple #5
0
        private void OnSceneGUI()
        {
            if (instance.TerrainData == null)
            {
                return;
            }
            if (!instance.AutoConnect)
            {
                return;
            }
            if (!isNeighboringFoldoutExpanded)
            {
                return;
            }

            Vector3 terrainSizeXZ = new Vector3(
                instance.TerrainData.Geometry.Width,
                0,
                instance.TerrainData.Geometry.Length);

            if (instance.LeftNeighbor == null)
            {
                Vector3 pos = instance.transform.position + Vector3.left * terrainSizeXZ.x + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = instance.transform.parent;
                    t.transform.position = instance.transform.position + Vector3.left * terrainSizeXZ.x;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
            if (instance.TopNeighbor == null)
            {
                Vector3 pos = instance.transform.position + Vector3.forward * terrainSizeXZ.z + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = instance.transform.parent;
                    t.transform.position = instance.transform.position + Vector3.forward * terrainSizeXZ.z;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
            if (instance.RightNeighbor == null)
            {
                Vector3 pos = instance.transform.position + Vector3.right * terrainSizeXZ.z + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = instance.transform.parent;
                    t.transform.position = instance.transform.position + Vector3.right * terrainSizeXZ.x;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
            if (instance.BottomNeighbor == null)
            {
                Vector3 pos = instance.transform.position + Vector3.back * terrainSizeXZ.z + terrainSizeXZ * 0.5f;
                if (Handles.Button(pos, Quaternion.Euler(90, 0, 0), terrainSizeXZ.z * 0.5f, terrainSizeXZ.z * 0.5f, Handles.RectangleHandleCap) && Event.current.button == 0)
                {
                    GStylizedTerrain t = CreateNeighborTerrain();
                    t.transform.parent   = instance.transform.parent;
                    t.transform.position = instance.transform.position + Vector3.back * terrainSizeXZ.z;
                    t.name = string.Format("{0}-{1}", t.name, t.transform.position.ToString());
                    Selection.activeGameObject = t.gameObject;
                    GStylizedTerrain.ConnectAdjacentTiles();
                }
            }
        }