Inheritance: UnityEngine.ScriptableObject
Esempio n. 1
0
    public static void ExportData(string fileName)
    {
        try
        {
            FileStream   fileStream   = new FileStream(fileName, FileMode.Create, FileAccess.Write);
            StreamWriter streamWriter = new StreamWriter(fileStream, EasyVoiceSettings.instance.exportCSVFileEncodingUTF8 ? Encoding.UTF8 : Encoding.ASCII);

            //streamWriter.WriteLine(csvHeader);

            EasyVoiceDataAsset data = EasyVoiceSettings.instance.data; // readability

            streamWriter.Write(
                "|"
                );

            for (int i = 0; i < EasyVoiceSettings.instance.data.LineCount(); i++)
            {
                string speechText = data.GetSpeechText(i);                 // cache, using thrice
                streamWriter.Write(
                    speechText + "<"
                    );
            }

            streamWriter.Write(
                "|"
                );

            for (int i = 0; i < EasyVoiceSettings.instance.data.LineCount(); i++)
            {
                streamWriter.Write(
                    data.GetFileName(i) + ">"
                    );
            }


//            for (int i = 0; i < EasyVoiceSettings.instance.data.LineCount(); i++)
//            {
//                string speechText = data.GetSpeechText(i); // cache, using thrice
//                streamWriter.WriteLine(
//                    "" + data.GetId(i) + "," +
//                    "\"" + data.GetGroup(i).Replace("\"", "\"\"") + "\"," +
//                    "" + data.GetStatus(i) + "," +
//                    "\"" + data.GetSpeakerName(i).Replace("\"", "\"\"") + "\"," +
//                    (NeedCSVEscaping(speechText) ? "\"" + speechText.Replace("\"", "\"\"") + "\"" : speechText.Replace("\"", "\"\"")) + "," +
//                    "\"" + data.GetFileName(i).Replace("\"", "\"\"") + "\""
//                );
//            }

            streamWriter.Close();
            fileStream.Close();
        }
        catch (Exception e)
        {
            Debug.LogError("EasyVoice.ExportData encountered an error: " + e);
        }
    }
Esempio n. 2
0
    //public string MakeFileName(string speakerName, List<string> fileNames)
    //{
    //    for (int i = 1; i < 10000; i++) -- using ids now
    //    {
    //        string tempName = MakeFileName(speakerName, );
    //        if (!fileNames.Contains(tempName))
    //        {
    //            return tempName;
    //        }
    //    }
    //    Debug.LogWarning("EasyVoice couldn't find a unique default file name after 10k attempts.");
    //    return MakeFileName(speakerName, 0); // 10k lines... sure
    //}

    public string MakeFileNameFromTemplate(string speakerName, int index)
    {
        if (speakerName == defaultSpeakerNameString)
        {
            if (defaultVoice == defaultSpeakerNameString)
            {
                return(BuildFileNameFromTemplate("Default", index));
            }
            else
            {
                return(BuildFileNameFromTemplate(defaultVoice, index));
            }
        }
        else
        {
            return(EasyVoiceDataAsset.SanitizeFileName(BuildFileNameFromTemplate(speakerName, index)));
        }
    }
Esempio n. 3
0
 public bool SetBaseDefaultFileName(string newValue)
 {
     newValue = EasyVoiceDataAsset.SanitizeFileName(newValue);
     newValue = newValue.Replace("\r\n", " ").Replace('\r', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim();
     newValue = TrimStringFromRepeatedCharacters(newValue);
     if (newValue.IndexOf('#') == -1)
     {
         newValue += " #";
     }
     if (baseDefaultFileName != newValue)
     {
         baseDefaultFileName = newValue;
         data.MakeSureAllDefaultFileNamesAreUnique();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 4
0
 public void AssignDataAsset(EasyVoiceDataAsset newDataAsset)
 {
     if (newDataAsset.dataVersion < easyVoiceVersion)
     {
         data = newDataAsset;
         UpgradeAsset();
         Debug.Log("Your backwards-compatible EasyVoice data asset was successfully assigned from '" + "Assets/" + dataAssetName + "' and upgraded, you may now edit it.");
         //EditorUtility.SetDirty(this);
     }
     else if (newDataAsset.dataVersion > easyVoiceVersion)
     {
         Debug.LogError("Selected EasyVoice data asset version (" + newDataAsset.dataVersion + ") is higher than our version (" + easyVoiceVersion + "), please update the plugin before importing!");
         // We could let them import it... If there are no compile errors then stuff might be still compatible
         // The problem is, if there are issues, they won't be obvious or immediate as much as corrupt everything, which we really want to avoid
     }
     else
     {
         data = newDataAsset;
         //Debug.Log("Selected EasyVoice data asset was successfully assigned from '" + "Assets/" + EasyVoiceSettings.dataAssetName + "', you may now edit your lines.");
         //EditorUtility.SetDirty(this);
     }
 }
    //public static EasyVoiceSettings.AudioImportSettings.SampleRate SampleRate(AudioSampleRateSetting sampleRate)
    //{
    //    switch (sampleRate)
    //    {
    //        case AudioSampleRateSetting.PreserveSampleRate:
    //            return EasyVoiceSettings.AudioImportSettings.SampleRate.PreserveSampleRate;
    //        case AudioSampleRateSetting.OptimizeSampleRate:
    //            return EasyVoiceSettings.AudioImportSettings.SampleRate.OptimizeSampleRate;
    //        case AudioSampleRateSetting.OverrideSampleRate:
    //            return EasyVoiceSettings.AudioImportSettings.SampleRate.OverrideSampleRate;
    //        default:
    //            return EasyVoiceSettings.AudioImportSettings.SampleRate.PreserveSampleRate; // Unity has a new value?
    //    }
    //}

    public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        // This will make sure that if any changed assets match our lines, then these lines will have their clip/file name re-checked for issues (or no more issues)

        if (EasyVoiceSettings.instance != null && EasyVoiceSettings.instance.data != null) // we are not yet initialized?
        {
            EasyVoiceDataAsset data = EasyVoiceSettings.instance.data;
            for (int lineIndex = 0; lineIndex < data.LineCount(); lineIndex++)
            {
                //string assetFileName, fullFileName;
                //EasyVoiceClipCreator.GenerateFullFileName(lineIndex, out assetFileName, out fullFileName);
                //if ((deletedAssets != null && deletedAssets.Contains(assetFileName)) ||
                //    (movedAssets != null && movedAssets.Contains(assetFileName)) ||
                //    (importedAssets != null && importedAssets.Contains(assetFileName)) ||
                //    (movedFromAssetPaths != null && movedFromAssetPaths.Contains(assetFileName)))
                //{ -- WE CAN'T RELY ON THIS, IT DOESN'T TELL US WHAT THE FILE NAME *WAS* (and keeping this cached is an overkill imo)
                EasyVoiceIssueChecker.VerifyFileNameOrClip(lineIndex);
                //    break;
                //}
            }
        }
    }
Esempio n. 6
0
 public void UnlinkDataAsset()
 {
     data = null;
 }
Esempio n. 7
0
 public void AssignDataAsset(EasyVoiceDataAsset newDataAsset)
 {
     if (newDataAsset.dataVersion < easyVoiceVersion)
     {
         data = newDataAsset;
         UpgradeAsset();
         Debug.Log("Your backwards-compatible EasyVoice data asset was successfully assigned from '" + "Assets/" + dataAssetName + "' and upgraded, you may now edit it.");
         //EditorUtility.SetDirty(this);
     }
     else if (newDataAsset.dataVersion > easyVoiceVersion)
     {
         Debug.LogError("Selected EasyVoice data asset version (" + newDataAsset.dataVersion + ") is higher than our version (" + easyVoiceVersion + "), please update the plugin before importing!");
         // We could let them import it... If there are no compile errors then stuff might be still compatible
         // The problem is, if there are issues, they won't be obvious or immediate as much as corrupt everything, which we really want to avoid
     }
     else
     {
         data = newDataAsset;
         //Debug.Log("Selected EasyVoice data asset was successfully assigned from '" + "Assets/" + EasyVoiceSettings.dataAssetName + "', you may now edit your lines.");
         //EditorUtility.SetDirty(this);
     }
 }
Esempio n. 8
0
 public void UnlinkDataAsset()
 {
     data = null;
 }
Esempio n. 9
0
    private static void VerifyFileNameOrClip(int index, bool allowFurtherCalls)
    {
        verifyCount++;

        EasyVoiceDataAsset data = EasyVoiceSettings.instance.data; // readability

        data.SetIssue(index, LineIssue.badFileName, !ValidFileName(data.GetFileName(index)));

        // CLear all issues that we can possibly set in the loops below
        data.SetIssue(index, LineIssue.duplicateBaseFileName, false);
        data.SetIssue(index, LineIssue.duplicateAssetFileName, false);
        data.SetIssue(index, LineIssue.clashingExistingAsset, false);
        data.SetIssue(index, LineIssue.duplicateClipReference, false);

        //Debug.Log("Clearing line " + index + " file name or clip issues");

        AudioClip ourClip = data.GetClip(index);

        string ourAssetFileName, ourFullFileName;

        EasyVoiceClipCreator.GenerateFullFileName(index, out ourAssetFileName, out ourFullFileName);

        if (ourClip == null)
        {
            string ourFileName = data.GetFileNameOrDefault(index);

            for (int otherIndex = 0; otherIndex < data.LineCount(); otherIndex++)
            {
                if (otherIndex == index)
                {
                    continue;
                }

                if (data.GetClip(otherIndex) == null)
                {
                    // Check for duplicate file names -- another line has the same file name as us
                    if (ourFileName == data.GetFileNameOrDefault(otherIndex))
                    {
                        data.SetIssue(index, LineIssue.duplicateBaseFileName, true);
                        if (allowFurtherCalls)
                        {
                            // Recheck the other file as well now, because we probably just clashed it
                            VerifyFileNameOrClip(otherIndex, false);
                        }
                    }
                    else
                    {
                        // Recheck existing lines with duplicate issue, in case we were the one causing it
                        if (allowFurtherCalls)
                        {
                            if (data.HasIssue(otherIndex, LineIssue.duplicateBaseFileName))
                            {
                                VerifyFileNameOrClip(otherIndex, false);
                            }
                        }
                    }
                }
                else
                {
                    string otherAssetFileName, otherFullFileName;
                    EasyVoiceClipCreator.GenerateFullFileName(otherIndex, out otherAssetFileName, out otherFullFileName); // TODO: cache?

                    // Check for clashing clip names -- another line has a clip name+path the same as our potential file path
                    if (ourAssetFileName == otherAssetFileName)
                    {
                        data.SetIssue(index, LineIssue.duplicateAssetFileName, true);
                        if (allowFurtherCalls)
                        {
                            // Recheck the other file as well now, because we probably just clashed it
                            VerifyFileNameOrClip(otherIndex, false);
                        }
                    }
                    else
                    {
                        // Recheck existing lines with clashing file name issue, in case we were the one causing it
                        if (allowFurtherCalls)
                        {
                            if (data.HasIssue(otherIndex, LineIssue.duplicateAssetFileName))
                            {
                                VerifyFileNameOrClip(otherIndex, false);
                            }
                        }
                    }
                }
            }

            if (!data.HasIssue(index, LineIssue.duplicateAssetFileName)) // below issue is implied if already clashing another line with that asset, performance
            {
                // Check for clashing existing assets -- an asset already exists at the path that "our" asset will potentially be created at
                Object foundAsset = (Object)AssetDatabase.LoadAssetAtPath(ourAssetFileName, typeof(Object));
                if (foundAsset != null)
                {
                    data.SetIssue(index, LineIssue.clashingExistingAsset, true);
                }
            }
        }
        else
        {
            for (int otherIndex = 0; otherIndex < data.LineCount(); otherIndex++)
            {
                if (otherIndex == index)
                {
                    continue;
                }

                if (data.GetClip(otherIndex) != null)
                {
                    // Check for duplicate clip references -- another line has the same clip as we do
                    if (ourClip == data.GetClip(otherIndex))
                    {
                        data.SetIssue(index, LineIssue.duplicateClipReference, true);
                        if (allowFurtherCalls)
                        {
                            // Recheck the other file as well now, because we probably just clashed it
                            VerifyFileNameOrClip(otherIndex, false);
                        }
                    }
                    else
                    {
                        // Recheck existing lines with duplicate clip issue, in case we were the one causing it
                        if (allowFurtherCalls)
                        {
                            if (data.HasIssue(otherIndex, LineIssue.duplicateClipReference))
                            {
                                VerifyFileNameOrClip(otherIndex, false);
                            }
                        }
                    }
                }
                else
                {
                    // Check for clashing clip names -- another line has a the same potential file path as our clip name+path

                    string otherAssetFileName, otherFullFileName;
                    EasyVoiceClipCreator.GenerateFullFileName(otherIndex, out otherAssetFileName, out otherFullFileName); // TODO: cache?

                    if (ourAssetFileName == otherAssetFileName)
                    {
                        data.SetIssue(index, LineIssue.duplicateAssetFileName, true);
                        if (allowFurtherCalls)
                        {
                            // Recheck the other file as well now, because we probably just clashed it
                            VerifyFileNameOrClip(otherIndex, false);
                        }
                    }
                    else
                    {
                        // Recheck existing lines with clashing file name issue, in case we were the one causing it
                        if (allowFurtherCalls)
                        {
                            if (data.HasIssue(otherIndex, LineIssue.duplicateAssetFileName))
                            {
                                VerifyFileNameOrClip(otherIndex, false);
                            }
                        }
                    }
                }
            }
        }
    }
 private void AssignDataAssetToSettings(EasyVoiceDataAsset givenData)
 {
     settings.AssignDataAsset(givenData);
     EasyVoiceIssueChecker.CheckAllLineIssues();
 }