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(); } } }
public void CopyTo(GTerrainData des) { Geometry.CopyTo(des.Geometry); Shading.CopyTo(des.Shading); Rendering.CopyTo(des.Rendering); Foliage.CopyTo(des.Foliage); }
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); }
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(); }
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); }
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); }
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(); } } }
private void OnEnable() { instance = (GTerrainData)target; }
public static GTerrainDataInspectorDrawer Create(GTerrainData data, GStylizedTerrain terrain = null) { return(new GTerrainDataInspectorDrawer(data, terrain)); }
public GTerrainDataInspectorDrawer(GTerrainData data, GStylizedTerrain terrain = null) { this.data = data; this.terrain = terrain; }
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); }
public GGeometryGenerationContext(GStylizedTerrain terrain, GTerrainData data) { subDivMapData = data.Geometry.Internal_SubDivisionMap.GetPixels(); subDivMapResolution = GCommon.SUB_DIV_MAP_RESOLUTION; }