| 1 | /************************************************************************************ |
| 2 | Filename : ONSPPropagationGeometryEditor.cs |
| 3 | Content : Geometry editor class |
| 4 | Attach to geometry to define material properties |
| 5 | Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. |
| 6 | |
| 7 | Licensed under the Oculus SDK Version 3.5 (the "License"); |
| 8 | you may not use the Oculus SDK except in compliance with the License, |
| 9 | which is provided at the time of installation or download, or which |
| 10 | otherwise accompanies this software in either electronic or hard copy form. |
| 11 | |
| 12 | You may obtain a copy of the License at |
| 13 | |
| 14 | https://developer.oculus.com/licenses/sdk-3.5/ |
| 15 | |
| 16 | Unless required by applicable law or agreed to in writing, the Oculus SDK |
| 17 | distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | See the License for the specific language governing permissions and |
| 20 | limitations under the License. |
| 21 | ************************************************************************************/ |
| 22 | //#define ENABLE_DEBUG_EXPORT_OBJ |
| 23 | |
| 24 | using UnityEngine; |
| 25 | using UnityEditor; |
| 26 | |
| 27 | [CustomEditor(typeof(ONSPPropagationGeometry))] |
| 28 | public class ONSPPropagationGeometryEditor : Editor |
| 29 | { |
| 30 | public override void OnInspectorGUI() |
| 31 | { |
| 32 | ONSPPropagationGeometry mesh = (ONSPPropagationGeometry)target; |
| 33 | |
| 34 | EditorGUI.BeginChangeCheck(); |
| 35 | |
| 36 | bool newIncludeChildMeshes = EditorGUILayout.Toggle( new GUIContent("Include Child Meshes","Include all child meshes into single geometry instance"), mesh.includeChildMeshes ); |
| 37 | |
| 38 | Separator(); |
| 39 | |
| 40 | #if UNITY_EDITOR |
| 41 | string newFilePath = mesh.filePath; |
| 42 | bool editedPath = false; |
| 43 | bool writeMesh = false; |
| 44 | EditorGUI.BeginDisabledGroup( Application.isPlaying ); |
| 45 | bool newFileEnabled = EditorGUILayout.Toggle( new GUIContent("File Enabled","If set, the serialized mesh file is used as the mesh data source"), mesh.fileEnabled ); |
| 46 | EditorGUILayout.LabelField( new GUIContent("File Path:","The path to the serialized mesh file, relative to the StreamingAssets directory" ), |
| 47 | new GUIContent(mesh.filePathRelative != null ? mesh.filePathRelative : "")); |
| 48 | |
| 49 | EditorGUILayout.BeginHorizontal(); |
| 50 | EditorGUILayout.PrefixLabel( " " ); |
| 51 | if ( GUILayout.Button("Set Path") ) |
| 52 | { |
| 53 | if (!System.IO.Directory.Exists(Application.streamingAssetsPath)) |
| 54 | { |
| 55 | System.IO.Directory.CreateDirectory(Application.streamingAssetsPath); |
| 56 | } |
| 57 | |
| 58 | string directory = Application.streamingAssetsPath; |
| 59 | string fileName = mesh.gameObject.name + "." + ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION; |
| 60 | |
| 61 | if (newFilePath != "") |
| 62 | { |
| 63 | directory = System.IO.Path.GetDirectoryName(newFilePath); |
| 64 | fileName = System.IO.Path.GetFileName(newFilePath); |
| 65 | } |
| 66 | |
| 67 | newFilePath = EditorUtility.SaveFilePanel( |
| 68 | "Save baked mesh to file", directory, fileName, |
| 69 | ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION); |
| 70 | |
| 71 | // If the user canceled, use the old path. |
| 72 | if ( newFilePath == null || newFilePath.Length == 0 ) |
| 73 | newFilePath = mesh.filePath; |
| 74 | else |
| 75 | editedPath = true; |
| 76 | } |
| 77 | |
| 78 | if ( GUILayout.Button("Bake Mesh to File") ) |
| 79 | writeMesh = true; |
| 80 | |
| 81 | EditorGUILayout.EndHorizontal(); |
| 82 | |
| 83 | #if ENABLE_DEBUG_EXPORT_OBJ |
| 84 | // this allows you to export the geometry to a .obj for viewing |
| 85 | // in an external model viewer for debugging/validation |
| 86 | if ( GUILayout.Button("Write to .obj (debug)") ) |
| 87 | mesh.WriteToObj(); |
| 88 | #endif |
| 89 | |
| 90 | EditorGUI.EndDisabledGroup(); |
| 91 | |
| 92 | #endif |
| 93 | |
| 94 | if ( EditorGUI.EndChangeCheck() ) |
| 95 | { |
| 96 | Undo.RecordObject( mesh, "Edited OVRAudioMesh" ); |
| 97 | |
| 98 | mesh.includeChildMeshes = newIncludeChildMeshes; |
| 99 | mesh.fileEnabled = newFileEnabled; |
| 100 | |
| 101 | newFilePath = newFilePath.Replace(Application.streamingAssetsPath + "/", ""); |
| 102 | |
| 103 | if ( editedPath ) |
| 104 | mesh.filePathRelative = newFilePath; |
| 105 | |
| 106 | if ( editedPath || writeMesh ) |
| 107 | mesh.WriteFile(); |
| 108 | } |
| 109 | |
| 110 | if ( Application.isPlaying && GUILayout.Button("Upload Mesh") ) |
| 111 | mesh.UploadGeometry(); |
| 112 | } |
| 113 | void Separator() |
| 114 | { |
| 115 | GUI.color = new Color(1, 1, 1, 0.25f); |
| 116 | GUILayout.Box("", "HorizontalSlider", GUILayout.Height(16)); |
| 117 | GUI.color = Color.white; |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |