public override void OnInspectorGUI()
    {
        ONSPPropagationGeometry mesh = (ONSPPropagationGeometry)target;

        EditorGUI.BeginChangeCheck();

        bool newIncludeChildMeshes = EditorGUILayout.Toggle(new GUIContent("Include Child Meshes", "Include all child meshes into single geometry instance"), mesh.includeChildMeshes);

        Separator();

        #if UNITY_EDITOR
        string newFilePath = mesh.filePath;
        bool   editedPath  = false;
        bool   writeMesh   = false;
        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        bool newFileEnabled = EditorGUILayout.Toggle(new GUIContent("File Enabled", "If set, the serialized mesh file is used as the mesh data source"), mesh.fileEnabled);
        EditorGUILayout.LabelField(new GUIContent("File Path:", "The path to the serialized mesh file, relative to the StreamingAssets directory"),
                                   new GUIContent(mesh.filePathRelative != null ? mesh.filePathRelative : ""));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(" ");
        if (GUILayout.Button("Set Path"))
        {
            if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
            {
                System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
            }

            string directory = Application.streamingAssetsPath;
            string fileName  = mesh.gameObject.name + "." + ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION;

            if (newFilePath != "")
            {
                directory = System.IO.Path.GetDirectoryName(newFilePath);
                fileName  = System.IO.Path.GetFileName(newFilePath);
            }

            newFilePath = EditorUtility.SaveFilePanel(
                "Save baked mesh to file", directory, fileName,
                ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION);

            // If the user canceled, use the old path.
            if (newFilePath == null || newFilePath.Length == 0)
            {
                newFilePath = mesh.filePath;
            }
            else
            {
                editedPath = true;
            }
        }

        if (GUILayout.Button("Bake Mesh to File"))
        {
            writeMesh = true;
        }

        EditorGUILayout.EndHorizontal();

#if ENABLE_DEBUG_EXPORT_OBJ
        // this allows you to export the geometry to a .obj for viewing
        // in an external model viewer for debugging/validation
        if (GUILayout.Button("Write to .obj (debug)"))
        {
            mesh.WriteToObj();
        }
#endif

        EditorGUI.EndDisabledGroup();
        #endif

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(mesh, "Edited OVRAudioMesh");

            mesh.includeChildMeshes = newIncludeChildMeshes;
            mesh.fileEnabled        = newFileEnabled;

            newFilePath = newFilePath.Replace(Application.streamingAssetsPath + "/", "");

            if (editedPath)
            {
                mesh.filePathRelative = newFilePath;
            }

            if (editedPath || writeMesh)
            {
                mesh.WriteFile();
            }
        }

        if (Application.isPlaying && GUILayout.Button("Upload Mesh"))
        {
            mesh.UploadGeometry();
        }
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        ONSPPropagationGeometry mesh = (ONSPPropagationGeometry)target;

        EditorGUI.BeginChangeCheck();

        bool newIncludeChildMeshes = EditorGUILayout.Toggle(new GUIContent("Include Child Meshes", "Include all child meshes into single geometry instance"), mesh.includeChildMeshes);

        Separator();

        #if UNITY_EDITOR
        string newFilePath = mesh.filePath;
        bool   editedPath  = false;
        bool   writeMesh   = false;
        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        bool newFileEnabled = EditorGUILayout.Toggle(new GUIContent("File Enabled", "If set, the serialized mesh file is used as the mesh data source"), mesh.fileEnabled);
        EditorGUILayout.LabelField(new GUIContent("File Path:", "The path to the serialized mesh file, relative to the StreamingAssets directory"),
                                   new GUIContent(mesh.filePathRelative != null ? mesh.filePathRelative : ""));

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(" ");
        if (GUILayout.Button("Set Path"))
        {
            if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
            {
                System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
            }
            newFilePath = EditorUtility.SaveFilePanel(
                "Save baked mesh to file", Application.streamingAssetsPath, mesh.gameObject.name + ".ovramesh", "ovramesh");

            // If the user canceled, use the old path.
            if (newFilePath == null || newFilePath.Length == 0)
            {
                newFilePath = mesh.filePath;
            }
            else
            {
                editedPath = true;
            }
        }
        if (GUILayout.Button("Bake Mesh to File"))
        {
            writeMesh = true;
        }

        EditorGUILayout.EndHorizontal();
        EditorGUI.EndDisabledGroup();
        #endif

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(mesh, "Edited OVRAudioMesh");

            mesh.includeChildMeshes = newIncludeChildMeshes;
            mesh.fileEnabled        = newFileEnabled;

            newFilePath = newFilePath.Replace(Application.streamingAssetsPath + "/", "");

            if (editedPath)
            {
                mesh.filePathRelative = newFilePath;
            }

            if (editedPath || writeMesh)
            {
                mesh.WriteFile();
            }
        }

        if (Application.isPlaying && GUILayout.Button("Upload Mesh"))
        {
            mesh.UploadGeometry();
        }
    }