public void ConvertImageFolder(string path)
        {
            var info     = new DirectoryInfo(path);
            var fileInfo = info.GetFiles();

            foreach (var file in fileInfo)
            {
                string ext = file.Extension.ToUpper();
                if (ext == ".TGA" || ext == ".PNG" || ext == ".JPG" || ext == ".EXR")
                {
                    var    assetDataPath = Datahandling.EnsureAssetDataPath(path);
                    string relativePath  = assetDataPath + "/" + file.Name;
                    Debug.Log(relativePath);
                    Texture2D tex = AssetDatabase.LoadAssetAtPath <Texture2D>(relativePath);
                    Debug.Log(tex.name);
                    ConvertImage(tex);
                }
            }
            AssetDatabase.Refresh();
        }
Example #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            float width = position.width;

            position.width = 22;
            if (GUI.Button(position, EditorGUIUtility.IconContent("Folder Icon")))
            {
                property.stringValue = EditorUtility.OpenFolderPanel("Select Folder", property.stringValue, string.Empty);
                var folderAttribute = attribute as FolderAttribute;
                if (folderAttribute.relative)
                {
                    property.stringValue = Datahandling.EnsureAssetDataPath(property.stringValue);
                }
                property.serializedObject.ApplyModifiedProperties();
                GUIUtility.ExitGUI();
            }
            position.x     = position.x + 22;
            position.width = width - 22;
            position       = EditorGUI.PrefixLabel(position, label);

            GUI.Label(position, property.stringValue);
        }
    private void OnGUI()
    {
        selectedDeviceIndex = EditorGUILayout.Popup(selectedDeviceIndex, Microphone.devices);

        recordingLength    = EditorGUILayout.IntField("Time", recordingLength);
        recordingFrequency = EditorGUILayout.IntField("Frequency", recordingFrequency);
        trimOnSave         = EditorGUILayout.Toggle("Trim On Save", trimOnSave);
        trimLevel          = EditorGUILayout.FloatField("Silence Level", trimLevel);

        if (Microphone.devices.Length > 0)
        {
            if (!Microphone.IsRecording(Microphone.devices[selectedDeviceIndex]))
            {
                if (GUILayout.Button("Record"))
                {
                    recording = Microphone.Start(Microphone.devices[selectedDeviceIndex], false, recordingLength, recordingFrequency);
                    savedClip = null;
                }
            }
            else
            {
                if (GUILayout.Button("Stop Recording"))
                {
                    Microphone.End(Microphone.devices[selectedDeviceIndex]);
                }
            }
        }
        else
        {
            EditorGUILayout.HelpBox("Can't find Microphone Devices.", MessageType.Warning);
            EditorGUI.BeginDisabledGroup(isRecompiling);
            if (GUILayout.Button("Attempt Fix"))
            {
                UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
                void Fix(object o)
                {
                    isRecompiling = false;
                    UnityEditor.Compilation.CompilationPipeline.compilationFinished -= Fix;
                }

                UnityEditor.Compilation.CompilationPipeline.compilationFinished -= Fix;
                UnityEditor.Compilation.CompilationPipeline.compilationFinished += Fix;
                isRecompiling = true;
            }
            EditorGUI.EndDisabledGroup();
        }

        EditorGUI.BeginDisabledGroup(EditorApplication.timeSinceStartup < lockedUntil);

        if ((recording || savedClip))
        {
            if (GUILayout.Button("Play"))
            {
                if (Microphone.devices.Length > 0 && Microphone.IsRecording(Microphone.devices[selectedDeviceIndex]))
                {
                    Microphone.End(Microphone.devices[selectedDeviceIndex]);
                }
                PlayClip(recording ?? savedClip);
                lockedUntil = EditorApplication.timeSinceStartup + (recording ? recording.length : savedClip.length);
            }
        }
        if (recording)
        {
            if (GUILayout.Button("Save Clip"))
            {
                if (Microphone.IsRecording(Microphone.devices[selectedDeviceIndex]))
                {
                    Microphone.End(Microphone.devices[selectedDeviceIndex]);
                }
                string path = EditorUtility.SaveFilePanel("Save Recorded Clip", folderPath, "recording", "wav");
                path = Datahandling.EnsureAssetDataPath(path);
                AudioSave.Save(path, recording, true, trimLevel);
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                recording  = null;
                savedClip  = AssetDatabase.LoadAssetAtPath <AudioClip>(path);
                folderPath = path.Substring(0, path.LastIndexOf("/"));
                Debug.Log(folderPath);
            }
        }
        EditorGUI.EndDisabledGroup();
    }