コード例 #1
0
ファイル: AudioManager.cs プロジェクト: TasiYokan/Protool
        /// <summary>
        /// Write a json to record all audio tracks we have.
        /// </summary>
        private void GenerateAllAudioList()
        {
            List <string> names             = new List <string>();
            string        audioRootPath     = Application.dataPath + "/Audio/Resources/" + GetAudioRootPath();
            DirectoryInfo rootDirectoryPath = new DirectoryInfo(audioRootPath);

            FileInfo[] fileInfo = rootDirectoryPath.GetFiles("*.*", SearchOption.AllDirectories);
            //Debug.Log("full path " + rootDirectoryPath + _prefixName + "_*.*");

            foreach (FileInfo file in fileInfo)
            {
                // file extension check
                if (file.Extension == ".mp3" || file.Extension == ".wav")
                {
                    string   nameWithFolder = file.Name.Split('.')[0];
                    string[] fullName       = file.FullName.Split('\\');
                    if (fullName[fullName.Length - 2] + '/' != GetAudioRootPath())
                    {
                        nameWithFolder = fullName[fullName.Length - 2] + '\\' + nameWithFolder;
                    }

                    names.Add(nameWithFolder);
                }
            }

            Debug.Log("Update audio track list. Count: " + names.Count);
            if (Directory.Exists(GetStreamingAssetsRootPath()) == false)
            {
                Directory.CreateDirectory(GetStreamingAssetsRootPath());
            }
            JsonSerializationHelper.WriteJsonList <string>(GetStreamingAssetsRootPath() + "/AudioTrackList.json", names);
        }
コード例 #2
0
        private void DrawButtons()
        {
            EditorGUI.BeginChangeCheck();
            m_manipulateMode = (ManipulationMode)EditorGUILayout.EnumPopup(
                "Mode to manipulate node", m_manipulateMode);
            if (EditorGUI.EndChangeCheck())
            {
                PlayerPrefs.SetInt("Editor_ManipulateMode", (int)m_manipulateMode);
                SceneView.RepaintAll();
            }

            EditorGUI.BeginChangeCheck();
            m_drawPathInEditor = GUILayout.Toggle(m_drawPathInEditor, "Draw path in Editor", GUILayout.Width(Screen.width));
            if (EditorGUI.EndChangeCheck())
            {
                PlayerPrefs.SetInt("Editor_DrawPath", m_drawPathInEditor ? 1 : 0);
            }

            EditorGUI.BeginChangeCheck();
            m_autoSmooth = GUILayout.Toggle(m_autoSmooth, "Smooth another handle in the BezierPoint", GUILayout.Width(Screen.width));
            if (EditorGUI.EndChangeCheck())
            {
                PlayerPrefs.SetInt("Editor_AutoSmooth", m_autoSmooth ? 1 : 0);
            }

            isAutoConnectProperty.boolValue = GUILayout.Toggle(isAutoConnectProperty.boolValue, "Connect first and last nodes?", GUILayout.Width(Screen.width));

            drawDebugPathProperty.boolValue = GUILayout.Toggle(drawDebugPathProperty.boolValue,
                                                               "Use LineRenderer to draw path in game?", GUILayout.Width(Screen.width));

            if (GUILayout.Button(addPointContent))
            {
                Undo.RecordObject(Target, "Added a waypoint");

                BezierPoint point = new BezierPoint(
                    Vector3.zero,
                    Quaternion.identity,
                    true);;
                Target.AddPoint(point);

                if (Target.Points.Count > 1)
                {
                    Vector3 dir = -SceneView.lastActiveSceneView.camera.transform.right;
                    if (Target.Points.Count > 2)
                    {
                        Vector3 prevDir = (Target.Points[Target.Points.Count - 2].Position - Target.Points[Target.Points.Count - 3].Position);
                        dir *= prevDir.magnitude;
                        if (Vector3.Dot(prevDir, dir) < 0)
                        {
                            dir *= -1;
                        }
                    }
                    Target.SetAnchorPosition(Target.Points.Count - 1,
                                             Target.Points[Target.Points.Count - 2].Position + dir);
                    Target.SetAnchorRotation(Target.Points.Count - 1,
                                             Quaternion.LookRotation(dir));
                }

                SceneView.RepaintAll();
            }

            if (GUILayout.Button(clearAllPointsContent))
            {
                //TODO: Use Target.RemoveAll() later
                Target.Points.Clear();

                SceneView.RepaintAll();
            }

            if (GUILayout.Button(savePathData))
            {
                string savePath = EditorUtility.SaveFilePanel(
                    "Save path into file",
                    Application.dataPath,
                    Target.name,
                    "json");

                if (savePath.Length != 0)
                {
                    JsonSerializationHelper.WriteJsonList <BezierPoint>(savePath, Target.Points);
                }
            }

            if (GUILayout.Button(loadPathData))
            {
                // Simple version
                //string loadPath = EditorUtility.OpenFilePanel(
                //    "Load path from file",
                //    Application.dataPath,
                //    "json,*");

                // More customized
                string loadPath = EditorUtility.OpenFilePanelWithFilters(
                    "Load path from file",
                    Application.dataPath,
                    new string[] { "Json files", "json", "All files", "*" });
                if (loadPath.Length != 0)
                {
                    Target.SetPoints(JsonSerializationHelper.ReadJsonList <BezierPoint>(loadPath));
                }
                Target.UpdateAnchorTransforms();

                SceneView.RepaintAll();
            }

            GUILayout.Space(10);
        }