Ejemplo n.º 1
0
        public static void OnSceneViewGUI(SceneView sv)
        {
            Event e = Event.current;

            if (e == null)
            {
                return;
            }
            int controlId = EditorGUIUtility.GetControlID(FocusType.Passive, sv.position);

            if (e.type == EventType.DragUpdated)
            {
                Object[] draggedObjects = DragAndDrop.objectReferences;
                if (draggedObjects.Length == 1 &&
                    draggedObjects[0] is GTerrainData)
                {
                    DragAndDrop.AcceptDrag();
                    DragAndDrop.visualMode      = DragAndDropVisualMode.Generic;
                    DragAndDrop.activeControlID = controlId;
                    e.Use();
                }
            }
            else if (e.type == EventType.DragPerform)
            {
                Object[] draggedObjects = DragAndDrop.objectReferences;
                if (draggedObjects.Length == 1 &&
                    draggedObjects[0] is GTerrainData)
                {
                    GTerrainData data = draggedObjects[0] as GTerrainData;
                    GCommon.CreateTerrain(data);
                    e.Use();
                }
            }
        }
Ejemplo n.º 2
0
 public void CopyTo(GTerrainData des)
 {
     Geometry.CopyTo(des.Geometry);
     Shading.CopyTo(des.Shading);
     Rendering.CopyTo(des.Rendering);
     Foliage.CopyTo(des.Foliage);
 }
Ejemplo n.º 3
0
        public static GTerrainGeneratedData GetTerrainGeneratedDataAsset(GTerrainData terrainData, string namePrefix = "Generated")
        {
            GTerrainGeneratedData generatedData = null;

#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                string path      = AssetDatabase.GetAssetPath(terrainData);
                string directory = Path.GetDirectoryName(path);
                string filePath  = Path.Combine(directory, string.Format("{0}_{1}.asset", namePrefix, terrainData.Id));
                generatedData = AssetDatabase.LoadAssetAtPath <GTerrainGeneratedData>(filePath);
                if (generatedData == null)
                {
                    generatedData = ScriptableObject.CreateInstance <GTerrainGeneratedData>();
                    AssetDatabase.CreateAsset(generatedData, filePath);
                }
            }
            else
            {
                generatedData = ScriptableObject.CreateInstance <GTerrainGeneratedData>();
            }
#else
            generatedData = ScriptableObject.CreateInstance <GTerrainGeneratedData>();
#endif
            return(generatedData);
        }
Ejemplo n.º 4
0
 private void DrawGUI()
 {
     InjectGUI(0);
     instance.TerrainData = EditorGUILayout.ObjectField("Terrain Data", instance.TerrainData, typeof(GTerrainData), false) as GTerrainData;
     data        = instance.TerrainData;
     GUI.enabled = false;
     EditorGUILayout.ObjectField("Generated Geometry", data.GeometryData, typeof(GTerrainGeneratedData), false);
     EditorGUILayout.ObjectField("Generated Foliage", data.FoliageData, typeof(GTerrainGeneratedData), false);
     GUI.enabled = true;
     InjectGUI(1);
     DrawGeometryGUI();
     InjectGUI(2);
     DrawShadingGUI();
     InjectGUI(3);
     DrawRenderingGUI();
     InjectGUI(4);
     DrawFoliageGUI();
     InjectGUI(5);
     DrawDataGUI();
     InjectGUI(6);
     if (data != null)
     {
         GEditorCommon.SetTerrainDataDirty(data);
     }
     DrawNeighboringGUI();
     InjectGUI(7);
 }
 private void OnTerrainDataDirty(GTerrainData data, GTerrainData.DirtyFlags flag)
 {
     if (Terrain != null &&
         Terrain.TerrainData == data)
     {
         if (flag == GTerrainData.DirtyFlags.All ||
             flag == GTerrainData.DirtyFlags.Foliage)
         {
             CopyTreeInstances();
         }
     }
 }
        public static void ShowWindowSetShaderMode(GTerrainData terrainData)
        {
            if (terrainData == null)
            {
                return;
            }
            GTerrainWizardWindow window = ScriptableObject.CreateInstance <GTerrainWizardWindow>();

            window.titleContent = new GUIContent("Wizard");
            window.minSize      = new Vector2(400, 100);
            window.terrainData  = terrainData;
            window.mode         = MODE_SET_SHADER;
            window.ShowUtility();
        }
Ejemplo n.º 7
0
        public static GStylizedTerrain CreateTerrain(GTerrainData data)
        {
            GameObject g = new GameObject("Styllized Terrain");

            g.transform.localPosition = Vector3.zero;
            g.transform.localRotation = Quaternion.identity;
            g.transform.localScale    = Vector3.one;

            GStylizedTerrain terrain = g.AddComponent <GStylizedTerrain>();

            terrain.GroupId     = 0;
            terrain.TerrainData = data;
            terrain.Refresh();
            CreateTreeCollider(terrain);

            return(terrain);
        }
Ejemplo n.º 8
0
        private void DrawGUI()
        {
            InjectGUI(0);
            terrain.TerrainData = EditorGUILayout.ObjectField("Terrain Data", terrain.TerrainData, typeof(GTerrainData), false) as GTerrainData;
            data = terrain.TerrainData;

            if (data.Geometry.StorageMode == GGeometry.GStorageMode.SaveToAsset)
            {
                GUI.enabled = false;
                EditorGUILayout.ObjectField("Generated Geometry", data.GeometryData, typeof(GTerrainGeneratedData), false);
                GUI.enabled = true;
            }
            else
            {
                data.GeometryData = null;
            }
            InjectGUI(1);
            DrawGeometryGUI();
            InjectGUI(2);
            DrawShadingGUI();
            InjectGUI(3);
            DrawRenderingGUI();
            InjectGUI(4);
            DrawFoliageGUI();
            InjectGUI(5);
            DrawMaskGUI();
            InjectGUI(6);
            DrawDataGUI();
            InjectGUI(7);
            if (data != null)
            {
                GEditorCommon.SetTerrainDataDirty(data);
            }
            DrawNeighboringGUI();
            InjectGUI(8);
            DrawStatisticsGUI();
            InjectGUI(9);
        }
Ejemplo n.º 9
0
        private static void OnHierarchyGUI(int instanceID, Rect r)
        {
            Event e = Event.current;

            if (e == null)
            {
                return;
            }
            int controlId = EditorGUIUtility.GetControlID(FocusType.Passive);

            if (e.type == EventType.DragUpdated)
            {
                Object[] draggedObjects = DragAndDrop.objectReferences;
                if (draggedObjects.Length == 1 &&
                    draggedObjects[0] is GTerrainData)
                {
                    DragAndDrop.AcceptDrag();
                    DragAndDrop.visualMode      = DragAndDropVisualMode.Generic;
                    DragAndDrop.activeControlID = controlId;
                    e.Use();
                }
            }
            else if (e.type == EventType.DragPerform)
            {
                Object[] draggedObjects = DragAndDrop.objectReferences;
                if (draggedObjects.Length == 1 &&
                    draggedObjects[0] is GTerrainData)
                {
                    GTerrainData data = draggedObjects[0] as GTerrainData;
                    GCommon.CreateTerrain(data);
                    data.Geometry.ClearDirtyRegions();
                    data.Foliage.ClearTreeDirtyRegions();
                    data.Foliage.ClearGrassDirtyRegions();
                    e.Use();
                }
            }
        }
Ejemplo n.º 10
0
 private void OnEnable()
 {
     instance = (GTerrainData)target;
 }
Ejemplo n.º 11
0
 public static GTerrainDataInspectorDrawer Create(GTerrainData data, GStylizedTerrain terrain = null)
 {
     return(new GTerrainDataInspectorDrawer(data, terrain));
 }
Ejemplo n.º 12
0
 public GTerrainDataInspectorDrawer(GTerrainData data, GStylizedTerrain terrain = null)
 {
     this.data    = data;
     this.terrain = terrain;
 }
Ejemplo n.º 13
0
        public static GStylizedTerrain CreateStylizedTerrain(GTerrainData srcData = null)
        {
            GameObject g = new GameObject("Low Poly Terrain");

            g.transform.localPosition = Vector3.zero;
            g.transform.localRotation = Quaternion.identity;
            g.transform.localScale    = Vector3.one;

            GTerrainData terrainData = GTerrainData.CreateInstance <GTerrainData>();

            terrainData.Reset();
            string assetName = "TerrainData_" + terrainData.Id;

            //AssetDatabase.CreateAsset(terrainData, string.Format("Assets/{0}.asset", assetName));
            GUtilities.EnsureDirectoryExists(GGriffinSettings.Instance.DefaultTerrainDataDirectory);
            AssetDatabase.CreateAsset(terrainData, Path.Combine(GGriffinSettings.Instance.DefaultTerrainDataDirectory, assetName + ".asset"));
            if (srcData != null)
            {
                srcData.CopyTo(terrainData);
            }

            Material mat = GGriffinSettings.Instance.WizardSettings.GetClonedMaterial();

            if (mat == null && GGriffinSettings.Instance.TerrainDataDefault.Shading.CustomMaterial != null)
            {
                mat = Object.Instantiate(GGriffinSettings.Instance.TerrainDataDefault.Shading.CustomMaterial);
            }
            if (mat != null)
            {
                string matName = "TerrainMaterial_" + terrainData.Id;
                mat.name = matName;
                //AssetDatabase.CreateAsset(mat, string.Format("Assets/{0}.mat", matName));
                GUtilities.EnsureDirectoryExists(GGriffinSettings.Instance.DefaultTerrainDataDirectory);
                AssetDatabase.CreateAsset(mat, Path.Combine(GGriffinSettings.Instance.DefaultTerrainDataDirectory, matName + ".mat"));
                terrainData.Shading.CustomMaterial = mat;
            }

            GStylizedTerrain terrain = g.AddComponent <GStylizedTerrain>();

            terrain.GroupId     = 0;
            terrain.TerrainData = terrainData;

            Undo.RegisterCreatedObjectUndo(g, "Creating Low Poly Terrain");

            GameObject colliderGO = new GameObject("Tree Collider");

            GameObjectUtility.SetParentAndAlign(colliderGO, terrain.gameObject);
            colliderGO.transform.localPosition = Vector3.zero;
            colliderGO.transform.localRotation = Quaternion.identity;
            colliderGO.transform.localScale    = Vector3.one;

            GTreeCollider collider = colliderGO.AddComponent <GTreeCollider>();

            collider.Terrain = terrain;

            GTerrainTools tools = Object.FindObjectOfType <GTerrainTools>();

            if (tools == null)
            {
                CreateTerrainTools(null);
            }

            Selection.activeGameObject = g;
            return(terrain);
        }
Ejemplo n.º 14
0
 public GGeometryGenerationContext(GStylizedTerrain terrain, GTerrainData data)
 {
     subDivMapData       = data.Geometry.Internal_SubDivisionMap.GetPixels();
     subDivMapResolution = GCommon.SUB_DIV_MAP_RESOLUTION;
 }