void _UpdateMorph(float deltaTime) { _UpdateModelMorph(); float stepValue = 1.0f; if (this.morphSpeed > 0.0f) { stepValue = deltaTime / this.morphSpeed; } if (_modelMorph != null) { MMD4MecanimCommon.Approx(ref _modelMorph.weight, this.morphWeight, stepValue); MMD4MecanimCommon.Approx(ref _weight2, this.overrideWeight ? 1.0f : 0.0f, stepValue); _modelMorph.weight2 = _weight2; } else { MMD4MecanimCommon.Approx(ref _weight2, 1.0f, stepValue); } if (_inactiveModelMorphSet != null) { foreach (var morph in _inactiveModelMorphSet) { MMD4MecanimCommon.Approx(ref morph.weight, 0.0f, stepValue); MMD4MecanimCommon.Approx(ref morph.weight2, 0.0f, stepValue); } _inactiveModelMorphSet.RemoveWhere(s => s.weight == 0.0f && s.weight2 == 0.0f); } }
List <MorphData> _ParseMorphText(string morphText) { if (string.IsNullOrEmpty(morphText)) { return(null); } //Debug.Log( "_ParseMorphText:" + morphText ); // for Debug. System.Text.StringBuilder alphabets = new System.Text.StringBuilder(); List <MorphData> morphDataList = new List <MorphData>(); bool isBeforeAlphabet = false; bool isBeforeMorph = false; int textPos = 0; for (;;) { if (textPos >= morphText.Length) { break; } string japanesePronun = null; char ch = morphText[textPos]; if (ch == '[') { int beginPos = (++textPos); for ( ; textPos < morphText.Length; ++textPos) { if (morphText[textPos] == ']') { int milliSeconds = MMD4MecanimCommon.ToInt(morphText, beginPos, textPos - beginPos); if (isBeforeMorph && morphDataList.Count > 0) { MorphData morphData = morphDataList[morphDataList.Count - 1]; morphData.morphLength = (float)milliSeconds * 0.001f; morphDataList[morphDataList.Count - 1] = morphData; } else { MorphData morphData = new MorphData(); morphData.morphChar = ' '; morphData.morphName = ""; morphData.morphLength = (float)milliSeconds * 0.001f; morphDataList.Add(morphData); } ++textPos; break; } } isBeforeMorph = false; } else if (_IsEscape(ch)) { // ^ ... alveolar // ` ... bilabial // / ... staccato // - ... - // ~ ... - MorphData morphData = new MorphData(); morphData.morphChar = ch; morphData.morphName = ""; switch (ch) { case '^': morphData.morphName = hiraMorphNameList[2]; // u break; case '`': morphData.morphName = ""; // n break; case '/': case '-': case '~': if (morphDataList.Count > 0) { morphData.morphName = morphDataList[morphDataList.Count - 1].morphName; } break; } isBeforeMorph = true; morphDataList.Add(morphData); ++textPos; } else if (MMD4MecanimCommon.IsAlphabet(ch)) { // for English. string tempString = null; bool processedAnything = false; ch = MMD4MecanimCommon.ToHalfLower(ch); if (textPos + 1 < morphText.Length && MMD4MecanimCommon.IsAlphabet(morphText[textPos + 1])) { char ch2 = MMD4MecanimCommon.ToHalfLower(morphText[textPos + 1]); if (textPos + 2 < morphText.Length && MMD4MecanimCommon.IsAlphabet(morphText[textPos + 2])) { char ch3 = MMD4MecanimCommon.ToHalfLower(morphText[textPos + 2]); alphabets.Remove(0, alphabets.Length); alphabets.Append(ch); alphabets.Append(ch2); alphabets.Append(ch3); if (englishPhraseDictionary.TryGetValue(alphabets.ToString(), out tempString)) { _AddMorphData(morphDataList, tempString); processedAnything = true; textPos += 3; } } if (!processedAnything) { alphabets.Remove(0, alphabets.Length); alphabets.Append(ch); alphabets.Append(ch2); if (englishPhraseDictionary.TryGetValue(alphabets.ToString(), out tempString)) { _AddMorphData(morphDataList, tempString); processedAnything = true; textPos += 2; } } } if (!processedAnything) { if (!isBeforeAlphabet && (morphText[textPos] == 'I' || morphText[textPos] == '\uFF29')) { _AddMorphData(morphDataList, "ai"); } else { if (textPos > 0 && MMD4MecanimCommon.ToHalfLower(morphText[textPos - 1]) == 'e' && ch == 'e') // lee, bee, ... { _AddMorphData(morphDataList, "-"); } else { if (englishPronunDictionary.TryGetValue(ch, out tempString)) { _AddMorphData(morphDataList, tempString); } else { _AddMorphData(morphDataList, " "); } } } processedAnything = true; ++textPos; } isBeforeAlphabet = true; isBeforeMorph = true; } else if (japanesePronunDictionary.TryGetValue(ch, out japanesePronun)) { string postPhaseText = null; if (textPos + 1 < morphText.Length && japanesePostPhraseDictionary.TryGetValue(morphText[textPos + 1], out postPhaseText)) { string phaseText = null; if (japanesePhraseDictionary.TryGetValue(morphText.Substring(textPos, 2), out phaseText)) { _AddMorphData(morphDataList, phaseText); } else { _AddMorphData(morphDataList, japanesePronun); _AddMorphData(morphDataList, postPhaseText); } textPos += 2; } else { _AddMorphData(morphDataList, japanesePronun); ++textPos; } isBeforeAlphabet = false; isBeforeMorph = true; } else { if (textPos + 1 < morphText.Length) // Simulate VOICEROID { string tempString = null; if (punctuatDictionary.TryGetValue(ch, out tempString)) { _AddMorphData(morphDataList, " "); // Simulate VOICEROID } else { // Nothing } } isBeforeAlphabet = false; isBeforeMorph = false; ++textPos; } } return(morphDataList); }