Esempio n. 1
0
    public static bool AssetExists(int index)
    {
        string assetFileName, fullFileName;

        EasyVoiceClipCreator.GenerateFullFileName(index, out assetFileName, out fullFileName);
        Object foundAsset = (Object)AssetDatabase.LoadAssetAtPath(assetFileName, typeof(Object));

        return(foundAsset != null);
    }
Esempio n. 2
0
    public static void LinkClipsAfterImport()
    {
        for (int i = lastImportStartingLineCount; i < EasyVoiceSettings.instance.data.LineCount(); i++)
        {
            string assetFileName, fullFileName;
            EasyVoiceClipCreator.GenerateFullFileName(i, out assetFileName, out fullFileName);
            AudioClip foundClip = (AudioClip)AssetDatabase.LoadAssetAtPath(assetFileName, typeof(AudioClip));
            if (foundClip != null)
            {
                EasyVoiceSettings.instance.data.SetClip(i, foundClip); // don't mark changed though
            }
        }

        EasyVoiceIssueChecker.CheckAllLineIssues();
    }
Esempio n. 3
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);
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 4
0
    public static ImportResult ImportData(string fileName, EasyVoiceSettings settings, bool append)
    {
        try
        {
            if (!File.Exists(fileName))
            {
                Debug.LogWarning("EasyVoice.ImportData tried to open the file returned by Unity's dialog, but such file doesn't appear to exist: \"" + fileName + "\"!");
                return(ImportResult.fail);
            }

            FileStream   fileStream   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader streamReader = new StreamReader(fileStream, settings.exportCSVFileEncodingUTF8 ? Encoding.Unicode : Encoding.ASCII);

            string        header      = streamReader.ReadLine();
            List <string> headerSplit = SplitLine(header);
            if (headerSplit == null || headerSplit.Count != 6 || headerSplit[0] != "ID" || headerSplit[1] != "Group" || headerSplit[2] != "Status" || headerSplit[3] != "Speaker" || headerSplit[4] != "Text" || headerSplit[5] != "File name")
            {
                Debug.LogWarning("EasyVoice.ImportData opened the CSV the file, but the header syntax did not match the expected format!");
                return(ImportResult.fail);
            }

            List <int>       tempIds          = new List <int>();
            List <string>    tempGroups       = new List <string>();
            List <byte>      tempStatuses     = new List <byte>();
            List <string>    tempSpeakerNames = new List <string>();
            List <string>    tempSpeechTexts  = new List <string>();
            List <string>    tempFileNames    = new List <string>();
            List <LineIssue> tempIssues       = new List <LineIssue>();

            while (!streamReader.EndOfStream)
            {
                string        line      = streamReader.ReadLine();
                List <string> splitLine = SplitLine(line);
                //Debug.Log(splitLine);
                if (splitLine != null && splitLine.Count == 6)
                {
                    int id;
                    if (!int.TryParse(splitLine[0], out id))
                    {
                        Debug.LogWarning("EasyVoice.ImportData opened the CSV the file, but an encountered id field syntax did not match the expected format!");
                        return(ImportResult.fail);
                    }
                    tempIds.Add(id);
                    tempGroups.Add(splitLine[3]);
                    byte status;
                    if (!byte.TryParse(splitLine[2], out status))
                    {
                        Debug.LogWarning("EasyVoice.ImportData opened the CSV the file, but an encountered status field syntax did not match the expected format!");
                        return(ImportResult.fail);
                    }
                    tempStatuses.Add(status);
                    tempSpeakerNames.Add(splitLine[3]);
                    tempSpeechTexts.Add(splitLine[4]);
                    tempFileNames.Add(splitLine[5]);
                    tempIssues.Add(0);
                }
                else
                {
                    Debug.LogWarning("EasyVoice.ImportData opened the CSV the file, but an encountered line syntax did not match the expected format!");
                    return(ImportResult.fail);
                }
            }

            streamReader.Close();
            fileStream.Close();

            if (!append)
            {
                settings.data.DeleteAllLines();
            }

            lastImportStartingLineCount = settings.data.LineCount();

            bool defaultFolderValid = settings.IsDefaultFolderValid(); // so we don't check this too many times
            bool clipFound          = false;

            for (int i = 0; i < tempSpeakerNames.Count; i++)
            {
                settings.data.AddNewLine(tempIds[i], tempGroups[i], tempStatuses[i], tempSpeakerNames[i], tempSpeechTexts[i], tempFileNames[i], tempIssues[i]);

                // If we need to find a clip (haven't found one yet) and also settings are valid to do this check
                if (!clipFound && defaultFolderValid)
                {
                    string assetFileName, fullFileName;
                    EasyVoiceClipCreator.GenerateFullFileName(i, out assetFileName, out fullFileName);
                    AudioClip foundClip = (AudioClip)AssetDatabase.LoadAssetAtPath(assetFileName, typeof(AudioClip));
                    if (foundClip != null)
                    {
                        clipFound = true;
                    }
                }
            }

            EasyVoiceIssueChecker.CheckAllLineIssues(); // this will get called again after linking clips, but we don't know if user will decide to do this yet

            return(clipFound ? ImportResult.matchingClipsFound : ImportResult.okay);
        }
        catch (Exception e)
        {
            Debug.LogError("EasyVoice.ImportData encountered an error: " + e);
            return(ImportResult.fail);
        }
    }