Exemplo n.º 1
0
    public void Enable(AudioClip _loadedClip)
    {
        if (!Serializer.IsExtratingClip && Serializer.ClipExtratedComplete)
        {
            audioSource.clip  = _loadedClip;
            audioSourceLoaded = true;
            m_Slider.maxValue = audioSource.clip.length;
            m_Slider.value    = 0;
            if (IsSpectrumCached())
            {
                try {
                    using (FileStream file = File.OpenRead(spectrumCachePath + Serializer.CleanInput(Serializer.ChartData.AudioName + spc_ext))) {
                        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        preProcessedSpectralFluxAnalyzer = (SpectralFluxAnalyzer)bf.Deserialize(file);
                    }

                    EndSpectralAnalyzer();
                    Debug.Log("Spectrum loaded from cached");
                } catch (Exception ex) {
                    Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert,
                                                  "Error while dezerializing Spectrum " + ex.ToString()
                                                  );
                    Debug.Log(ex.ToString());
                }
            }
            else
            {
                Debug.Log("Spectrum data not cached!");
            }
        }
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        m_DialogObject.SetActive(false);
        lateOutWait = new WaitForSeconds(0.5f);
        waitForRead = new WaitForSeconds(5f);

        s_instance = this;
    }
Exemplo n.º 3
0
    public void AddNodeToActiveRail(float _x, float _y, float _z)
    {
        if (Track.s_instance.isOnLongNoteMode)
        {
            Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "Can't add to rail in Long Mode.'");
            return;
        }
        activeRail = FindNearestRailBack();
        if (!activeRail.exists)
        {
            return;
        }
        List <Segment> segments = Track.s_instance.SegmentsList.FindAll(x => x.measure == Track.CurrentSelectedMeasure && x.note.Type == selectedNoteType);

        if (segments != null && segments.Count > 0)
        {
            Debug.Log("Existing node found!");
            return;
        }
        GameObject noteGO = GameObject.Instantiate(Track.s_instance.GetNoteMarkerByType(selectedNoteType, true));

        noteGO.transform.localPosition = new Vector3(_x, _y, _z);
        noteGO.transform.rotation      = Quaternion.identity;
        noteGO.transform.localScale   *= Track.s_instance.m_NoteSegmentMarkerRedution;
        noteGO.transform.parent        = activeRail.noteGO.transform.Find("LineArea");
        noteGO.name = activeRail.note.Id + "_Segment";
        activeRail.GetConnectedNodes();
        Track.HistoryChangeRailNode(selectedNoteType, true, Track.CurrentSelectedMeasure, new float[] { _x, _y, _z });
        Dictionary <float, List <Note> > workingTrack = Track.s_instance.GetCurrentTrackDifficulty();

        if (!workingTrack.ContainsKey(activeRail.time))
        {
            Debug.Log("Error while finding rail start.");
        }
        float[,] poses = GetLineSegementArrayPoses(activeRail.connectedNodes);

        if (workingTrack[activeRail.time][0].Type == selectedNoteType && workingTrack[activeRail.time][0].Segments != null)
        {
            workingTrack[activeRail.time][0].Segments = poses;
        }
        else
        {
            workingTrack[activeRail.time][1].Segments = poses;
        }
        var waveCustom = activeRail.noteGO.transform.Find("LineArea").GetComponentInChildren <Game_LineWaveCustom>();

        if (waveCustom)
        {
            waveCustom.targetOptional = poses;
            waveCustom.RenderLine(true, true);

            if (Track.s_instance.FullStatsContainer.activeInHierarchy)
            {
                Track.s_instance.GetCurrentStats();
            }
        }
        Track.s_instance.UpdateSegmentsList();
    }
Exemplo n.º 4
0
    IEnumerator LoadTrackArtwork(string url, bool isEdit = false)
    {
        /* WWW m_get = new WWW(url);
         *
         * yield return m_get; */

        using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
        {
            yield return(uwr.SendWebRequest());

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.LogError("Problem opening image, please check extension" + uwr.error);
            }
            else
            {
                // Get downloaded asset bundle
                // var texture = DownloadHandlerTexture.GetContent(uwr);
                try {
                    Serializer.AudioCoverToCompress = new System.Uri(url).LocalPath;
                    // Texture2D selectedTexture = m_get.texture;
                    Texture2D selectedTexture = DownloadHandlerTexture.GetContent(uwr);
                    if (selectedTexture != null)
                    {
                        if (selectedTexture.width > 512 || selectedTexture.height > 512)
                        {
                            Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_CoverImageWrongSize);
                        }
                        else
                        {
                            loadedArtwork = Convert.ToBase64String(selectedTexture.EncodeToPNG());
                            if (loadedArtwork != null)
                            {
                                artWorkField = System.IO.Path.GetFileName(new System.Uri(url).LocalPath);
                                if (isEdit)
                                {
                                    SetSpriteToImage(editArtworkField, loadedArtwork);
                                }
                                else
                                {
                                    SetSpriteToImage(newArtworkField, loadedArtwork);
                                }
                                artworkEdited = isEdit;
                            }
                        }
                    }
                    else
                    {
                        Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_NoImageSelected);
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError("Problem opening image, please check extension" + ex.Message);
                }
            }
        }
    }
Exemplo n.º 5
0
        private IEnumerator BatchProccesser(string dirPath)
        {
            // Get all the SynthFiles of the direrctory
            string[] synthFiles = Directory.GetFiles(@dirPath, "*.synth");

            WriteToLogFile("Starting batch converter at " + dirPath);

            int  cont     = 0;
            bool complete = false;

            while (!complete)
            {
                foreach (string synthFile in synthFiles)
                {
                    cont += 1;
                    Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert,
                                                  string.Format("Converting {0} of {1}", cont, synthFiles.Length)
                                                  );

                    try {
                        MemoryStream memStream = new MemoryStream();
                        // Section for load of files previos to version 1.8
                        using (ZipFile zip = ZipFile.Read(synthFile))
                        {
                            ZipEntry e = zip[meta_field_name];
                            e.Extract(memStream);
                        }
                        memStream.Seek(0, SeekOrigin.Begin);

                        BinaryFormatter bf   = new BinaryFormatter();
                        Chart           data = (Chart)bf.Deserialize(memStream);

                        using (ZipFile zip = ZipFile.Read(synthFile))
                        {
                            zip.UpdateEntry(meta_field_name, JsonConvert.SerializeObject(data, Formatting.Indented));
                            zip.Save();
                        }
                    } catch (Exception e) {
                        Debug.Log("File not in compatible BinaryFormtter or already converted");
                        WriteToLogFile("Bach error " + e.ToString());
                    }
                    yield return(batchWait);
                }
                complete = true;
            }

            Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, "Batch converter complete!");
            WriteToLogFile("batch converter complete");
            BachComplete = true;
        }
Exemplo n.º 6
0
        /// <sumary>
        /// Method for the bach conver of SynthFiles of Binaryformater to JSON
        /// </sumary>
        public static void BachProcess(string dirPath)
        {
            if (s_instance == null)
            {
                Debug.LogError("Serializer class not initialized");
                return;
            }

            if (!Directory.Exists(dirPath))
            {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadError);
                return;
            }

            BachComplete = false;
            s_instance.StartCoroutine(s_instance.BatchProccesser(dirPath));
        }
Exemplo n.º 7
0
        public static bool SerializeToJSON()
        {
            if (s_instance == null)
            {
                Debug.LogError("Serializer class not initialized");
                return(false);
            }

            if (IsBusy)
            {
                return(false);
            }

            IsBusy = true;

            try {
                if (!Directory.Exists(CHART_SAVE_PATH))
                {
                    Directory.CreateDirectory(CHART_SAVE_PATH);
                }

                s_instance.PathToSave = string.Format("{0}{1}.{2}",
                                                      CHART_SAVE_PATH,
                                                      CleanInput(ChartData.Name),
                                                      "json"
                                                      );

                string destination = s_instance.PathToSave;
                File.WriteAllText(s_instance.PathToSave, JsonConvert.SerializeObject(ChartData, Formatting.Indented));
            } catch (Exception e) {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert,
                                              "There was error exporting the song data, please check if the target folder is not write protected\n" +
                                              "or the file is not being use by other program\n" +
                                              e.ToString(),
                                              true
                                              );

                WriteToLogFile(e.ToString());
                IsBusy = false;
                return(false);
            }

            IsBusy = false;
            return(true);
        }
Exemplo n.º 8
0
        /// <sumary>
        /// Deserialize the Chart Data from JSON file
        /// </sumary>
        public static bool LoadFronFile(string filePath, bool isJSON, bool isBeatSong = false)
        {
            if (s_instance == null)
            {
                Debug.LogError("Serializer class not initialized");
                return(false);
            }

            if (IsBusy)
            {
                return(false);
            }

            IsBusy = true;

            if (!File.Exists(filePath))
            {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadError);
                IsBusy = false;
                return(false);
            }

            try {
                Chart tmp = isBeatSong ? BeatSynthConverter.Convert(filePath) : JsonConvert.DeserializeObject <Chart>(File.ReadAllText(filePath));
                ChartData           = tmp;
                ChartData.AudioName = null;
                ChartData.FilePath  = string.Empty;
            } catch (Exception e) {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadError);
                Debug.Log(e);
                IsBusy = false;
                return(false);
            }

            if (ChartData.IsAdminOnly && !s_instance.IsAdminMode)
            {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadNotAdmin);
                ChartData = null;
                IsBusy    = false;
                return(false);
            }

            IsBusy = false;
            return(true);
        }
Exemplo n.º 9
0
 public static void WriteToLogFile(string msg)
 {
     try {
         string LogFile = Application.dataPath + "/../ErrorLog.txt";
         if (File.Exists(LogFile))
         {
             File.AppendAllText(LogFile, string.Format("{0}: {1}\n", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), msg));
         }
         else
         {
             File.WriteAllText(LogFile, string.Format("{0}: {1}\n", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), msg));
         }
         File.AppendAllText(LogFile, Environment.NewLine);
     } catch (Exception e) {
         Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert,
                                       "There was error saving the log file\n" +
                                       e.ToString()
                                       );
     }
 }
Exemplo n.º 10
0
        /// <sumary>
        /// Deserialize the Chart Data from disk
        /// </sumary>
        public static bool LoadFronFile(string filePath)
        {
            if (s_instance == null)
            {
                Debug.LogError("Serializer class not initialized");
                return(false);
            }

            if (IsBusy)
            {
                return(false);
            }

            IsBusy = true;

            if (!File.Exists(filePath))
            {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadError);
                IsBusy = false;
                return(false);
            }

            try {
                MemoryStream memStream = new MemoryStream();

                try {
                    using (ZipFile zip = ZipFile.Read(filePath))
                    {
                        ZipEntry e = zip[meta_field_name];
                        e.Extract(memStream);
                    }
                    memStream.Seek(0, SeekOrigin.Begin);
                    StreamReader reader   = new StreamReader(memStream);
                    string       jsonDATA = reader.ReadToEnd();
                    ChartData = JsonConvert.DeserializeObject <Chart>(jsonDATA);
                } catch (Exception) {
                    Debug.Log("File made in version previous to 1.8, trying BinaryFormatter");
                    // Section for load of files previos to version 1.8
                    using (ZipFile zip = ZipFile.Read(filePath))
                    {
                        ZipEntry e = zip[meta_field_name];
                        e.Extract(memStream);
                    }
                    memStream.Seek(0, SeekOrigin.Begin);

                    BinaryFormatter bf = new BinaryFormatter();
                    ChartData = (Chart)bf.Deserialize(memStream);
                }
            } catch (Exception) {
                // Section for very old Synth Files
                try {
                    FileStream      file = File.OpenRead(filePath);
                    BinaryFormatter bf   = new BinaryFormatter();
                    ChartData = (Chart)bf.Deserialize(file);
                    file.Close();
                } catch (Exception e) {
                    Debug.LogError("Deserialization Error");
                    Debug.LogError(e);
                    Serializer.WriteToLogFile("Deserialization Error");
                    Serializer.WriteToLogFile(e.ToString());

                    Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadNotAdmin);
                    ChartData = null;
                    IsBusy    = false;
                    return(false);
                }
            }

            if (ChartData.IsAdminOnly && !s_instance.IsAdminMode)
            {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadNotAdmin);
                ChartData = null;
                IsBusy    = false;
                return(false);
            }

            IsBusy = false;
            return(true);
        }
Exemplo n.º 11
0
        /// <sumary>
        /// Serialize Chart Data to disk
        /// </sumary>
        public static bool SerializeToFile(string pathToSave = null)
        {
            if (s_instance == null)
            {
                Debug.LogError("Serializer class not initialized");
                return(false);
            }

            if (IsBusy)
            {
                return(false);
            }

            IsBusy = true;

            try {
                s_instance.PathToSave = pathToSave;
                if (pathToSave == null || pathToSave.Equals(string.Empty))
                {
                    // If the [CHART_SAVE_PATH] directory does not exist we created it
                    // TODO Selecte Save folder
                    if (!Directory.Exists(CHART_SAVE_PATH))
                    {
                        Directory.CreateDirectory(CHART_SAVE_PATH);
                    }

                    s_instance.PathToSave = string.Format("{0}{1}.{2}",
                                                          CHART_SAVE_PATH,
                                                          CleanInput(ChartData.Name),
                                                          CHART_FILE_EXT
                                                          );

                    ChartData.FilePath = s_instance.PathToSave;
                }


                string destination = s_instance.PathToSave;
                // Debug.Log("Destination "+destination);
                bool isUpdate = false;
                if (File.Exists(destination))
                {
                    if (ChartData.AudioData == null)
                    {
                        isUpdate = true;
                    }
                    else
                    {
                        Debug.Log("deleting " + destination);
                        File.Delete(destination);
                    }
                }

                if (CurrentAudioFileToCompress != null && !CurrentAudioFileToCompress.Equals(string.Empty))
                {
                    var audioEXT = CurrentAudioFileToCompress != null && !CurrentAudioFileToCompress.Equals(string.Empty) ? Path.GetExtension(@CurrentAudioFileToCompress) : Path.GetExtension(ChartData.AudioName);
                    ChartData.AudioData = null;
                    ChartData.AudioName = string.Format(
                        "{0}{1}",
                        CleanInput(ChartData.Name),
                        audioEXT
                        );
                }


                // Deprecated, now using JSON

                /* MemoryStream memStream = new MemoryStream();
                 * BinaryFormatter bf = new BinaryFormatter();
                 * bf.Serialize(memStream, ChartData);
                 * memStream.Seek(0, SeekOrigin.Begin); */

                // using (memStream)
                {
                    if (isUpdate)
                    {
                        using (ZipFile zip = ZipFile.Read(destination))
                        {
                            // zip.UpdateEntry(meta_field_name, memStream);
                            zip.UpdateEntry(meta_field_name, JsonConvert.SerializeObject(ChartData, Formatting.Indented));
                            if (CurrentAudioFileToCompress != null && !CurrentAudioFileToCompress.Equals(string.Empty))
                            {
                                ZipEntry toDelete = null;
                                //foreach (ZipEntry e in zip.Where(x => !x.FileName.EndsWith(".bin")))
                                foreach (ZipEntry e in zip.Where(x => x.FileName.EndsWith(".ogg") || x.FileName.EndsWith(".wav")))
                                {
                                    toDelete = e;
                                }
                                if (toDelete != null)
                                {
                                    zip.RemoveEntry(toDelete);
                                }
                                // zip.AddFile(@CurrentAudioFileToCompress, "");
                                zip.AddEntry(
                                    ChartData.AudioName,
                                    File.ReadAllBytes(@CurrentAudioFileToCompress)
                                    );
                            }

                            if (AudioCoverToCompress != null && !AudioCoverToCompress.Equals(string.Empty))
                            {
                                ZipEntry toDelete = null;
                                //foreach (ZipEntry e in zip.Where(x => !x.FileName.EndsWith(".bin")))
                                foreach (ZipEntry e in zip.Where(x => x.FileName.EndsWith(".jpg") || x.FileName.EndsWith(".png")))
                                {
                                    toDelete = e;
                                }
                                if (toDelete != null)
                                {
                                    zip.RemoveEntry(toDelete);
                                }
                                zip.AddFile(@AudioCoverToCompress, "");
                            }

                            ZipEntry jsonToDelete = null;
                            foreach (ZipEntry e in zip.Where(x => x.FileName.EndsWith(".json")))
                            {
                                jsonToDelete = e;
                            }

                            if (jsonToDelete != null)
                            {
                                zip.RemoveEntry(jsonToDelete);
                            }

                            zip.AddEntry(data_field_name, Track.TrackInfo.SaveToJSON(), ASCIIEncoding.Unicode);
                            zip.Save();
                        }
                    }
                    else
                    {
                        using (ZipFile zip = new ZipFile(Encoding.UTF8))
                        {
                            // zip.AddEntry(meta_field_name, memStream);
                            zip.AddEntry(meta_field_name, JsonConvert.SerializeObject(ChartData, Formatting.Indented));
                            // zip.AddFile(@CurrentAudioFileToCompress, "");
                            zip.AddEntry(
                                ChartData.AudioName,
                                File.ReadAllBytes(@CurrentAudioFileToCompress)
                                );

                            if (AudioCoverToCompress != null && !AudioCoverToCompress.Equals(string.Empty))
                            {
                                zip.AddFile(@AudioCoverToCompress, "");
                            }
                            zip.AddEntry(data_field_name, Track.TrackInfo.SaveToJSON(), ASCIIEncoding.Unicode);
                            zip.Save(destination);
                        }
                    }
                }

                CurrentAudioFileToCompress = null;
            } catch (Exception e) {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert,
                                              "There was error saving the song file, please check if the target folder is not write protected\n" +
                                              "or the file is not being use by other program\n" +
                                              e.ToString(),
                                              true
                                              );

                WriteToLogFile(e.ToString());
                IsBusy = false;
                return(false);
            }

            IsBusy = false;
            return(true);
        }
Exemplo n.º 12
0
    void LateUpdate()
    {
        if (!gameObject.activeSelf || !gameObject.activeInHierarchy)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.LeftAlt) || Input.GetKeyDown(KeyCode.RightAlt) ||
            Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftControl))
        {
            isCTRLDown = true;
        }

        if (Input.GetKeyUp(KeyCode.LeftAlt) || Input.GetKeyUp(KeyCode.RightAlt) ||
            Input.GetKeyUp(KeyCode.RightControl) || Input.GetKeyUp(KeyCode.LeftControl))
        {
            isCTRLDown = false;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
        {
            isSHIFTDown = true;
        }

        if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
        {
            isSHIFTDown = false;
        }

        if ((Input.GetKeyDown(KeyCode.Alpha8) || Input.GetKeyDown(KeyCode.Keypad8)) && isCTRLDown)
        {
            ResetCamera();
            Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "Camera position was reset");
        }

        // Get the right mouse button
        if (Input.GetMouseButtonDown(1))
        {
            // Get mouse origin
            mouseOrigin = Input.mousePosition;
            isRotating  = true;
        }

        // Get the middle mouse button

        /* if(Input.GetMouseButtonDown(0) && isCTRLDown)
         * {
         *      // Get mouse origin
         *      mouseOrigin = Input.mousePosition;
         * isPanning = true;
         * } */

        float horizontalPanning = Input.GetAxis("Horizontal Free Camera");
        float verticalPanning   = Input.GetAxis("Vertical Free Camera");

        if ((horizontalPanning != 0 || verticalPanning != 0) && !Track.PromtWindowOpen && !isCTRLDown && !isSHIFTDown)
        {
            isPanning = true;
        }
        else
        {
            isPanning = false;
        }

        /* if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward
         * {
         *      DoZoom( -zoomSpeed );
         * }
         * else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards
         * {
         *      DoZoom( zoomSpeed );
         * } */

        // Disable movements on button release
        if (!Input.GetMouseButton(1))
        {
            isRotating = false;
        }
        //if (!Input.GetMouseButton(0)) { isPanning = false; }

        // Rotate camera along X and Y axis
        if (isRotating)
        {
            Vector3 pos = attachedCamera.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);

            transform.RotateAround(transform.position, transform.right, -pos.y * turnSpeed);
            transform.RotateAround(transform.position, Vector3.up, pos.x * turnSpeed);
        }

        // Move the camera on it's XY plane
        if (isPanning)
        {
            //Vector3 pos = attachedCamera.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);

            /* Vector3 pos = transform.localPosition;
            *  pos.x += horizontalPanning * 0.001f;
            *  pos.y += verticalPanning * 0.001f;
            *
            *  Vector3 move = new Vector3(pos.x * panSpeed, pos.y * panSpeed, 0);
            *  transform.Translate(move, Space.Self); */

            float translateY = verticalPanning * panSpeed;
            float translateX = horizontalPanning * panSpeed;
            transform.Translate(translateX, translateY, 0, Space.Self);
        }
    }
Exemplo n.º 13
0
        /// <sumary>
        /// Deserialize the Chart Data from disk
        /// </sumary>
        public static bool LoadFronFile(string filePath)
        {
            if (s_instance == null)
            {
                Debug.LogError("Serializer class not initialized");
                return(false);
            }

            if (IsBusy)
            {
                return(false);
            }

            IsBusy = true;

            if (!File.Exists(filePath))
            {
                Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadError);
                IsBusy = false;
                return(false);
            }

            try {
                MemoryStream memStream = new MemoryStream();

                try {
                    using (ZipFile zip = ZipFile.Read(filePath))
                    {
                        ZipEntry e = zip[meta_field_name];
                        e.Extract(memStream);
                    }
                    memStream.Seek(0, SeekOrigin.Begin);
                    StreamReader reader   = new StreamReader(memStream);
                    string       jsonDATA = reader.ReadToEnd();
                    // Update Crouch floats to new Crouch class, if necessary
                    if (!jsonDATA.Contains("UpdatedWithMovementPositions"))
                    {
                        Debug.Log("Updating wall formats...");
                        JObject      oldJSON                  = JObject.Parse(jsonDATA);
                        JArray       newCrouchEasy            = new JArray();
                        JArray       newCrouchNormal          = new JArray();
                        JArray       newCrouchHard            = new JArray();
                        JArray       newCrouchExpert          = new JArray();
                        JArray       newCrouchMaster          = new JArray();
                        JArray       newCrouchCustom          = new JArray();
                        JObject      allNewCrouchDifficulties = new JObject();
                        List <float> currentCrouchs;
                        foreach (JToken sourceCrouch in oldJSON["Crouchs"]["Easy"].Values())
                        {
                            JObject newTime = new JObject();
                            newTime.Add("time", sourceCrouch);
                            newCrouchEasy.Add(newTime);
                        }
                        foreach (JToken sourceCrouch in oldJSON["Crouchs"]["Normal"].Values())
                        {
                            JObject newTime = new JObject();
                            newTime.Add("time", sourceCrouch);
                            newCrouchNormal.Add(newTime);
                        }
                        foreach (JToken sourceCrouch in oldJSON["Crouchs"]["Hard"].Values())
                        {
                            JObject newTime = new JObject();
                            newTime.Add("time", sourceCrouch);
                            newCrouchHard.Add(newTime);
                        }
                        foreach (JToken sourceCrouch in oldJSON["Crouchs"]["Expert"].Values())
                        {
                            JObject newTime = new JObject();
                            newTime.Add("time", sourceCrouch);
                            newCrouchExpert.Add(newTime);
                        }
                        foreach (JToken sourceCrouch in oldJSON["Crouchs"]["Master"].Values())
                        {
                            JObject newTime = new JObject();
                            newTime.Add("time", sourceCrouch);
                            newCrouchMaster.Add(newTime);
                        }
                        foreach (JToken sourceCrouch in oldJSON["Crouchs"]["Custom"].Values())
                        {
                            JObject newTime = new JObject();
                            newTime.Add("time", sourceCrouch);
                            newCrouchCustom.Add(newTime);
                        }
                        allNewCrouchDifficulties.Add("Easy", newCrouchEasy.Value <JArray>());
                        allNewCrouchDifficulties.Add("Normal", newCrouchNormal.Value <JArray>());
                        allNewCrouchDifficulties.Add("Hard", newCrouchHard.Value <JArray>());
                        allNewCrouchDifficulties.Add("Expert", newCrouchExpert.Value <JArray>());
                        allNewCrouchDifficulties.Add("Master", newCrouchMaster.Value <JArray>());
                        allNewCrouchDifficulties.Add("Custom", newCrouchCustom.Value <JArray>());
                        Debug.Log("allNewCrouchDifficulties: " + allNewCrouchDifficulties);
                        oldJSON["Crouchs"] = allNewCrouchDifficulties;
                        jsonDATA           = JsonConvert.SerializeObject(oldJSON, Formatting.Indented);
                        Debug.Log("Wall format update complete");
                    }
                    ChartData = JsonConvert.DeserializeObject <Chart>(jsonDATA, new JsonSerializerSettings {
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    });
                } catch (Exception) {
                    Debug.Log("File made in version previous to 1.8, trying BinaryFormatter");
                    // Section for load of files previos to version 1.8
                    using (ZipFile zip = ZipFile.Read(filePath))
                    {
                        ZipEntry e = zip[meta_field_name];
                        e.Extract(memStream);
                    }
                    memStream.Seek(0, SeekOrigin.Begin);

                    BinaryFormatter bf = new BinaryFormatter();
                    ChartData = (Chart)bf.Deserialize(memStream);
                }
            } catch (Exception) {
                // Section for very old Synth Files
                try {
                    FileStream      file = File.OpenRead(filePath);
                    BinaryFormatter bf   = new BinaryFormatter();
                    ChartData = (Chart)bf.Deserialize(file);
                    file.Close();
                } catch (Exception e) {
                    Debug.LogError("Deserialization Error");
                    Debug.LogError(e);
                    Serializer.WriteToLogFile("Deserialization Error");
                    Serializer.WriteToLogFile(e.ToString());

                    Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadNotAdmin);
                    ChartData = null;
                    IsBusy    = false;
                    return(false);
                }
            }

            /* if(ChartData.IsAdminOnly && !s_instance.IsAdminMode) {
             *  Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_FileLoadNotAdmin);
             *      ChartData = null;
             *  IsBusy = false;
             *  return false;
             * } */

            IsBusy = false;
            return(true);
        }
Exemplo n.º 14
0
    public EditorNote FindNearestRailBack()
    {
        selectedNoteType = Track.s_instance.selectedNoteType;

        EditorNote railStart = new EditorNote();

        Dictionary <float, List <Note> > workingTrack = Track.s_instance.GetCurrentTrackDifficulty();

        List <float> keys_tofilter = workingTrack.Keys.ToList();


        List <float> keysOrdered_ToFilter = keys_tofilter.OrderBy(f => f).ToList();


        int totalFilteredTime = keysOrdered_ToFilter.Count - 1;

        for (int filterList = totalFilteredTime; filterList >= 0; filterList--)
        {
            // If the time key exist, check how many notes are added
            //float targetTime = Track.GetTimeByMeasure(keysOrdered_ToFilter[filterList]);
            float targetBeat = keysOrdered_ToFilter[filterList];

            if (targetBeat > Track.CurrentSelectedMeasure)
            {
                continue;
            }

            List <Note> notes      = workingTrack[targetBeat];
            int         totalNotes = notes.Count;

            foreach (Note n in notes)
            {
                //If it's a rail start and it's the same note type as the user has selected.
                if (n.Segments != null && n.Type == selectedNoteType)
                {
                    //Debug.Log("Rail found! Note ID " + n.Id);

                    railStart.note   = n;
                    railStart.type   = EditorNoteType.RailStart;
                    railStart.noteGO = GameObject.Find(n.Id);
                    railStart.time   = targetBeat;
                    railStart.exists = true;

                    railStart.GetConnectedNodes();

                    if ((currentOriginPos.position.z - railStart.connectedNodes.Last().position.z) > distanceBackThreshold)
                    {
                        Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "Nearest rail is too far back to edit.");
                        return(new EditorNote());
                    }


                    return(railStart);
                }
            }
        }


        Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "No rails found to edit.");

        return(new EditorNote());
    }
Exemplo n.º 15
0
    IEnumerator LoadAudioTrack(string url, bool isEdit = false)
    {
        /* WWW m_get = new WWW(url);
         *
         * yield return m_get; */


        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.OGGVORBIS))
        {
            // ((DownloadHandlerAudioClip)www.downloadHandler).audioClip.
            yield return(www.SendWebRequest());

            try {
                if (www.isNetworkError)
                {
                    Debug.LogError("Problem opening audio, please check extension" + www.error);
                }
                else
                {
                    Serializer.CurrentAudioFileToCompress = new System.Uri(url).LocalPath;
                    // loadedClip = m_get.GetAudioClip();
                    loadedClip = DownloadHandlerAudioClip.GetContent(www);
                    if (loadedClip != null)
                    {
                        //_audioSource.clip = clip;

                        //_audioSource.Play();
                        audioData = new float[loadedClip.samples * loadedClip.channels];
                        if (loadedClip.GetData(audioData, 0))
                        {
                            if (isEdit)
                            {
                                editTrackField.text = System.IO.Path.GetFileName(new System.Uri(url).LocalPath);
                            }
                            else
                            {
                                trackField.text = System.IO.Path.GetFileName(new System.Uri(url).LocalPath);
                            }
                            newAudioSelected = true;
                            audioEdited      = isEdit;
                        }
                        else
                        {
                            Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_AudioLoadError);
                        }

                        HidePreloader();
                    }
                    else
                    {
                        Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Alert, StringVault.Alert_NoAudioSelected);
                        HidePreloader();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("Problem opening audio, please check extension" + ex.Message);
                HidePreloader();
            }
        }
    }