public List <Sprite> MakeSortedSprites(AvatarPattern pattern) { List <Sprite> sprites = new List <Sprite>(); foreach (var category in categories) { if (category.Tag != optionTag) { //アクセサリなどのオプションではないので //パターンデータに一致するスプライトを追加していく foreach (var data in pattern.DataList) { //カテゴリタグがあうものを取得 if (category.Tag != data.tag) { continue; } //パタ―ン名が一致する一つだけを取得 sprites.Add(category.GetSprite(data.patternName)); } } else { //アクセサリなどのオプションの場合は、パターン名に一致するものはすべて取得 foreach (var optionPattern in pattern.OptionPatternNameList) { sprites.AddRange(category.Sprites.FindAll(x => AvatarData.ToPatternName(x) == optionPattern)); } } } return(sprites); }
//イメージデータから作成 void MakeImageFromAvartorData(AvatarData data) { if (AvatarData == null) { return; } List <Sprite> parts = data.MakeSortedSprites(avatarPattern); foreach (var part in parts) { if (part == null) { continue; } RectTransform child = RootChildren.AddChildGameObjectComponent <RectTransform>(part.name); child.gameObject.hideFlags = HideFlags.DontSave; Image image = child.gameObject.AddComponent <Image>(); image.material = this.Material; image.sprite = part; image.SetNativeSize(); UguiFlip flip = image.gameObject.AddComponent <UguiFlip>(); flip.FlipX = flipX; flip.FlipY = FlipY; } }
//********描画時のリソース変更********// internal override void ChangeResourceOnDraw(AdvGraphicInfo graphic, float fadeTime) { Avatar.Material = graphic.RenderTextureSetting.GetRenderMaterialIfEnable(Avatar.Material); //既に描画されている場合は、クロスフェード用のイメージを作成 // bool crossFade = TryCreateCrossFadeImage(fadeTime); //新しくリソースを設定 AvatarData avatarData = graphic.File.UnityObject as AvatarData; Avatar.AvatarData = avatarData; Avatar.CachedRectTransform.sizeDelta = avatarData.Size; Avatar.AvatarPattern.SetPattern(graphic.RowData); //目パチを設定 SetEyeBlinkSync(graphic.EyeBlinkData); //口パクを設定 SetLipSynch(graphic.LipSynchData); //アニメーションを設定 SetAnimation(graphic.AnimationData); if (LastResource == null) { ParentObject.FadeIn(fadeTime, () => { }); } }
bool CheckPatternError(AvatarPattern pattern, AvatarPattern.PartternData patternData) { if (string.IsNullOrEmpty(patternData.patternName)) { return(false); } foreach (var category in categories) { if (category.Tag != optionTag) { if (category.Tag != patternData.tag) { continue; } if (category.GetSprite(patternData.patternName) != null) { return(false); } } else { foreach (var optionPattern in pattern.OptionPatternNameList) { if (category.Sprites.Exists(x => AvatarData.ToPatternName(x) == optionPattern)) { return(false); } } } } return(true); }
protected override IEnumerator CoUpdateLipSync() { while (IsPlaying) { string pattern = AvatarData.ToPatternName(Avator.AvatarPattern.GetPatternName(LipTag)); if (string.IsNullOrEmpty(pattern)) { break; } foreach (var data in AnimationData.DataList) { Avator.ChangePattern(LipTag, data.ComvertName(pattern)); yield return(TimeUtil.WaitForSeconds(UnscaledTime, data.Duration)); while (IsPausing) { yield return(null); } } Avator.ChangePattern(LipTag, pattern); if (!IsPlaying) { break; } yield return(TimeUtil.WaitForSeconds(UnscaledTime, Interval)); while (IsPausing) { yield return(null); } } coLypSync = null; yield break; }
//すべてのパターン名を取得 public HashSet <string> GetAllPatternNames() { HashSet <string> set = new HashSet <string>(); this.Sprites.ForEach(x => set.Add(AvatarData.ToPatternName(x))); return(set); }
protected override void OnStopLipSync() { base.OnStopLipSync(); string pattern = AvatarData.ToPatternName(Avator.AvatarPattern.GetPatternName(LipTag)); if (string.IsNullOrEmpty(pattern)) { return; } Avator.ChangePattern(LipTag, pattern); }
public void OnPreviewGUI(AvatarData data, AvatarPattern pattern, Rect r, GUIStyle background) { List <Sprite> parts = data.MakeSortedSprites(pattern); foreach (var part in parts) { if (part == null) { continue; } GUI.DrawTexture(r, AssetDatabase.LoadAssetAtPath <Texture2D>(AssetDatabase.GetAssetPath(part)), ScaleMode.ScaleToFit, true); } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { AvatarData data = CallFunction <AvatarData>(property, Attribute.Function); if (data == null) { return(LineHeight()); } SerializedProperty dataListProperty = property.FindPropertyRelative("avatarPatternDataList"); return(LineHeight() * (dataListProperty.arraySize + data.GetAllOptionPatterns().Count)); }
internal override void ChangeResourceOnDraw(AdvGraphicInfo graphic, float fadeTime) { this.Avatar.Material = graphic.RenderTextureSetting.GetRenderMaterialIfEnable(this.Avatar.Material); AvatarData unityObject = graphic.File.UnityObject as AvatarData; this.Avatar.AvatarData = unityObject; this.Avatar.CachedRectTransform.set_sizeDelta(unityObject.Size); this.Avatar.AvatarPattern.SetPattern(graphic.RowData); this.SetEyeBlinkSync(graphic.EyeBlinkData); this.SetLipSynch(graphic.LipSynchData); this.SetAnimation(graphic.AnimationData); if (base.LastResource == null) { if (< > f__am$cache0 == null) {
internal void RebuildOnApply(AvatarData data) { List <PartternData> dataList = this.DataList; this.avatarPatternDataList = new List <PartternData>(); Rebuild(data); foreach (var pattern1 in DataList) { var pattern0 = dataList.Find(x => x.tag == pattern1.tag); if (pattern0 != null) { pattern1.patternName = pattern0.patternName; } } Debug.LogFormat("this.DataList = {0}", this.DataList.Count); dataList.Clear(); }
//パターン名からスプライトを取得 public Sprite GetSprite(string pattern) { //パタ―ン名が一致する一つだけを取得 Sprite sprite = Sprites.Find(x => AvatarData.ToPatternName(x) == pattern); if (sprite == null) { //パターン名で一致しない場合は、直接スプライト名を検索 sprite = Sprites.Find(x => x != null && x.name == pattern); } if (sprite == null) { //それでも一致しない場合は、パターン名のほうが正規化されてない可能性があるので sprite = Sprites.Find(x => x != null && x.name == AvatarData.ToPatternName(pattern)); } return(sprite); }
internal bool Rebuild(AvatarData data) { if (data == null) { return(false); } bool hasChanged = false; foreach (var category in data.categories) { PartternData partternData = DataList.Find(x => x.tag == category.Tag); if (partternData == null) { partternData = new PartternData(); partternData.tag = category.Tag; DataList.Add(partternData); hasChanged = true; } } return(hasChanged); }
protected override IEnumerator CoEyeBlink(Action onComplete) { string pattern = AvatarData.ToPatternName(Avator.AvatarPattern.GetPatternName(EyeTag)); if (string.IsNullOrEmpty(pattern)) { if (onComplete != null) { onComplete(); } yield break; } foreach (var data in AnimationData.DataList) { Avator.ChangePattern(EyeTag, data.ComvertName(pattern)); yield return(new WaitForSeconds(data.Duration)); } Avator.ChangePattern(EyeTag, pattern); if (onComplete != null) { onComplete(); } yield break; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { AvatarData data = CallFunction <AvatarData>(property, Attribute.Function); if (data == null) { return; } //パターンデータ(タグとパターン名) EditorGUI.BeginProperty(position, label, property); var dataListProperty = property.FindPropertyRelative("avatarPatternDataList"); float h = LineHeight(); for (int i = 0; i < dataListProperty.arraySize; ++i) { var childProperty = dataListProperty.GetArrayElementAtIndex(i); var tagProperty = childProperty.FindPropertyRelative("tag"); var patternNameProperty = childProperty.FindPropertyRelative("patternName"); if (tagProperty.stringValue == data.OptionTag) { continue; } List <string> patternNameList = new List <string> { "None" }; patternNameList.AddRange(data.GetPatternNameListInTag(tagProperty.stringValue)); int currentPatternIndex = patternNameList.FindIndex(x => x == patternNameProperty.stringValue); currentPatternIndex = Mathf.Max(0, currentPatternIndex); position.height = h; int index = EditorGUI.Popup(position, tagProperty.stringValue, currentPatternIndex, patternNameList.ToArray()); patternNameProperty.stringValue = patternNameList[index]; position.y += h; } //オプションデータ(アクセサリなどの表示) var optionPatternNameListProperty = property.FindPropertyRelative("optionPatternNameList"); List <string> list = DrawerUtil.GetStringList(optionPatternNameListProperty); List <string> newList = new List <string>(); bool hasChanged = false; foreach (var optionPattern in data.GetAllOptionPatterns()) { bool check = list.FindIndex(x => x == optionPattern) >= 0; bool check1 = EditorGUI.Toggle(position, optionPattern, check); if (check != check1) { hasChanged = true; check = check1; } if (check) { newList.Add(optionPattern); } position.y += h; } if (hasChanged) { DrawerUtil.SetStringArray(optionPatternNameListProperty, newList); } EditorGUI.EndProperty(); }
//********描画時にクロスフェードが失敗するであろうかのチェック********// internal override bool CheckFailedCrossFade(AdvGraphicInfo graphic) { AvatarData avatarData = graphic.File.UnityObject as AvatarData; return(Avatar.AvatarData != avatarData); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { AvatarData obj = this.target as AvatarData; obj.OnPreviewGUI(r, background, obj.previewPattern); }