diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index 4883ed7..9f852cf 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -85,20 +85,20 @@ public class UmaViewerBuilder : MonoBehaviour yield break; } - public IEnumerator LoadLiveUma(List characters) + public void LoadLiveUma(List characters) { UnloadAllBundle(); for (int i = 0; i < characters.Count; i++) { - CurrentUMAContainer = new GameObject($"Chara_{characters[i].CharaEntry.Id}_{characters[i].CostumeId}").AddComponent(); - CurrentUMAContainer.IsLive = true; - CurrentUMAContainer.CharaData = UmaDatabaseController.ReadCharaData(characters[i].CharaEntry); - CurrentUMAContainer.transform.parent = Gallop.Live.Director.instance.charaObjs[i]; - LoadNormalUma(characters[i].CharaEntry, characters[i].CostumeId); + if (characters[i].CharaEntry.Name != "") + { + CurrentUMAContainer = new GameObject($"Chara_{characters[i].CharaEntry.Id}_{characters[i].CostumeId}").AddComponent(); + CurrentUMAContainer.IsLive = true; + CurrentUMAContainer.CharaData = UmaDatabaseController.ReadCharaData(characters[i].CharaEntry); + CurrentUMAContainer.transform.parent = Gallop.Live.Director.instance.charaObjs[i]; + LoadNormalUma(characters[i].CharaEntry, characters[i].CostumeId); + } } - - - yield break; } private void LoadNormalUma(CharaEntry chara, string costumeId) @@ -666,11 +666,12 @@ public class UmaViewerBuilder : MonoBehaviour { if (a.CharaEntry == null || a.CostumeId == "") { - a.CharaEntry = Main.Characters[Random.Range(0, Main.Characters.Count)]; - a.CostumeId = "00"; + //a.CharaEntry = Main.Characters[Random.Range(0, Main.Characters.Count)]; + //a.CostumeId = "00"; } });//fill empty + UI.SetEyeTrackingEnable(false); GameObject MainLive = new GameObject("Live"); GameObject Director = new GameObject("Director"); @@ -681,7 +682,11 @@ public class UmaViewerBuilder : MonoBehaviour Destroy(Director); - StartCoroutine(LoadLiveUma(characters)); + LoadLiveUma(characters); + + Gallop.Live.Director.instance.InitializeTimeline(); + + Gallop.Live.Director.instance.Play(); } //Use CriWare Library @@ -962,8 +967,14 @@ public class UmaViewerBuilder : MonoBehaviour { case AnimationClip aClip: { + if (UI.LiveTime) + { + break; + } + if (CurrentUMAContainer && CurrentUMAContainer.UmaAnimator && CurrentUMAContainer.UmaAnimator.runtimeAnimatorController) { + Debug.Log("LiveTime" + UI.LiveTime.ToString()); LoadAnimation(aClip); } diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index eed49bb..63f0bca 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -133,6 +133,8 @@ public class UmaViewerUI : MonoBehaviour public bool EnableEyeTracking = true; public bool EnableFaceOverride = true; + public bool LiveTime = false; + public FaceDrivenKeyTarget currentFaceDrivenKeyTarget; private IEnumerator UpdateResVerCoroutine; @@ -585,6 +587,7 @@ public class UmaViewerUI : MonoBehaviour var selectlist = LiveSelectList.content.GetComponentsInChildren(); if (selectlist != null) { + LiveTime = true; Builder.LoadLive(currentLive, new List(selectlist)); LiveSelectPannel.SetActive(false); } @@ -957,6 +960,7 @@ public class UmaViewerUI : MonoBehaviour /// Toggles one object ON and all others from UI.TogglablePanels list OFF public void ToggleUIPanel(GameObject go) { + if (go.activeSelf || !TogglablePanels.Contains(go)) { go.SetActive(!go.activeSelf); diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs index b75a17f..3e0f987 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs @@ -19,6 +19,10 @@ namespace Gallop.Live.Cutt public const float BaseCharaHeightMax = 190; public const float BaseCharaHeightDiff = 60; + private LiveTimelineMotionSequence[] _motionSequenceArray; + + public LiveTimelineKeyCharaMotionSeqDataList[] _keyArray; + public void CopyValues(T from, T to) { var json = JsonUtility.ToJson(from); @@ -44,6 +48,55 @@ namespace Gallop.Live.Cutt // CopyValues(worksheet, LoadSheet); //} } + + public void InitCharaMotionSequence() + { + //Create Animation + foreach (var obj in Director.instance.charaObjs) + { + var container = obj.GetComponentInChildren(); + if (container) + { + var animation = container.gameObject.AddComponent(); + Director.instance.charaAnims.Add(animation); + } + } + + //Get KeyArray + var listCount = data.worksheetList[0].charaMotSeqList.Count; + + _keyArray = new LiveTimelineKeyCharaMotionSeqDataList[listCount]; + + for (int i = 0; i < listCount; i++) + { + _keyArray[i] = data.worksheetList[0].charaMotSeqList[i].keys; + } + + //Set Motion + int CharaPositionMax = characterStandPosLocators.Length; + + _motionSequenceArray = new LiveTimelineMotionSequence[CharaPositionMax]; + + for (int i = 0; i < CharaPositionMax; i++) + { + _motionSequenceArray[i] = new LiveTimelineMotionSequence(); + _motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, i, this); + } + + } + + public void AlterUpdate(float liveTime) + { + AlterUpdate_CharaMotionSequence(liveTime); + } + + public void AlterUpdate_CharaMotionSequence(float liveTime) + { + foreach (var motion in _motionSequenceArray) + { + motion.AlterUpdate(liveTime); + } + } } diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineMotionSequence.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineMotionSequence.cs new file mode 100644 index 0000000..154fe3e --- /dev/null +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineMotionSequence.cs @@ -0,0 +1,118 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Gallop.Live.Cutt +{ + public class LiveTimelineMotionSequence + { + private ILiveTimelineMSQTarget _target; // 0x10 + private Animation[] _animationArray; // 0x18 + private int _targetIndex; // 0x20 + private LiveTimelineKeyCharaMotionSeqDataList[] _keyArray; // 0x28 + private LiveTimelineKeyCharaMotionSeqDataList _currentKey; // 0x30 + private int _indexOfPlayingKey; // 0x38 + private LiveTimelineControl _timelineControl; // 0x40 + private float _heightRate; // 0x48 + private LiveTimelineDefine.SheetIndex _currentSheetIndex; // 0x4C + //private LivePlayableAnimator[] _playableAnimatorArray; // 0x50 + private int _prevSysTextId; // 0x58 + private const float OVERRIDE_ANIMATOR_FACIAL_WAIT = 1; + private int _prevFrame; // 0x5C + private float _prevFrameAnimationTime; // 0x60 + + //Testing + private Transform _tempTarget; + private Animation _tempAnim; + + private bool _needChange; + private LiveTimelineKeyCharaMotionData _prevKey; + + public void Initialize(Transform target, int targetIndex, int seqDataIndex, LiveTimelineControl timelineControl) + { + _tempTarget = target; + _targetIndex = targetIndex; + + _keyArray = timelineControl._keyArray; + + if (seqDataIndex < _keyArray.Length) + { + _currentKey = _keyArray[seqDataIndex]; + } + + if (targetIndex < Director.instance.charaAnims.Count) + { + _tempAnim = Director.instance.charaAnims[targetIndex]; + } + + if(_currentKey != null && _tempAnim != null) + { + foreach (var key in _currentKey.thisList) + { + _tempAnim.AddClip(key.clip, key.clip.name); + } + } + } + + public void AlterUpdate(float currentTime) + { + if (_currentKey != null && _tempAnim != null) + { + /* + var seqs = _currentKey.thisList; + + for (int i = seqs.Count - 1; i >= 0; i--) + { + Debug.Log(currentTime); + if (currentTime >= (double)seqs[i].frame / 60) + { + Debug.Log("ʱ¼ä:" + ((double)seqs[i].frame / 60).ToString()); + + AnimationClip anim = seqs[i].clip; + double start = (double)seqs[i].motionHeadFrame / 60; + double interval = currentTime - (double)seqs[i].frame / 60; + + Debug.Log("time:" + interval.ToString()); + + //anim.SampleAnimation(container.gameObject, (float)(start + interval)); + _tempAnim[anim.name].time = (float)(start + interval); + _tempAnim.Play(anim.name); + + break; + } + } + */ + + var timelineKey = GetKey(currentTime); + + //if ( _prevKey != timelineKey ) Play animation all the time not affect performance maybe? + if ( true ) + { + AnimationClip anim = timelineKey.clip; + double start = (double)timelineKey.motionHeadFrame / 60; + double interval = currentTime - (double)timelineKey.frame / 60; + + _tempAnim[anim.name].time = (float)(start + interval); + _tempAnim.Play(anim.name); + + _prevKey = timelineKey; + } + } + } + + public LiveTimelineKeyCharaMotionData GetKey(float time) + { + var seqs = _currentKey.thisList; + + for (int i = seqs.Count - 1; i >= 0; i--) + { + if (time >= (double)seqs[i].frame / 60) + { + return seqs[i]; + } + } + + return seqs[0]; + } + } +} diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineMotionSequence.cs.meta b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineMotionSequence.cs.meta new file mode 100644 index 0000000..5269670 --- /dev/null +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineMotionSequence.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45bb442f0483bbb45807fe98ea8069f2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/umamusume/Gallop/Live/Director.cs b/Assets/Scripts/umamusume/Gallop/Live/Director.cs index 8d8d07b..94acefc 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Director.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Director.cs @@ -7,6 +7,8 @@ using UnityEngine; using Gallop.Live.Cutt; using static Director; using UnityEditor.SceneManagement; +using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters; +using System.Data; namespace Gallop.Live { @@ -161,9 +163,9 @@ namespace Gallop.Live private RandomRatioTable _blinkLightRandomRatioTable; private float _sceneFrameRate; [SerializeField] - private float _liveCurrentTime; + public float _liveCurrentTime; //Edited to public private bool _isRequestFadeOut; - private bool _isLiveSetup; + public bool _isLiveSetup; //Edit to pulic [SerializeField] private bool _isEnableBloom; private bool _isBloom; @@ -313,6 +315,10 @@ namespace Gallop.Live public List charaObjs; + public List charaAnims; + + public List seqData; + private void Awake() { if (live != null) @@ -324,6 +330,7 @@ namespace Gallop.Live Builder.LoadAssetPath(string.Format(STAGE_PATH, live.BackGroundId), this.gameObject.transform); //Make CharacterObject + var characterStandPos = this._liveTimelineControl.transform.Find("CharacterStandPos"); int counter = 0; foreach (Transform trans in characterStandPos.GetComponentsInChildren()) { @@ -336,6 +343,86 @@ namespace Gallop.Live charaObjs.Add(newObj.transform); counter++; }; + + + //Set Animation + + + + + } + } + + public void InitializeTimeline() + { + //Move? + _liveTimelineControl.InitCharaMotionSequence(); + } + + public void Play() + { + /* + int counter = 0; + + var motionSeq = this._liveTimelineControl.data.worksheetList[0].charaMotSeqList; + foreach (var seq in motionSeq) + { + var anim = seq.keys.thisList[4].clip; + var container = charaObjs[counter].GetComponentInChildren(); + Debug.Log(container); + if (container != null) + { + var animation = container.gameObject.AddComponent(); + animation.AddClip(anim, anim.name); + animation.Play(anim.name); + + counter++; + } + } + */ + seqData = this._liveTimelineControl.data.worksheetList[0].charaMotSeqList; + _isLiveSetup = true; + _liveCurrentTime = 0; + } + + private void OnTimelineUpdate(float _liveCurrentTime) + { + /* + var seqs = seqData[0].keys.thisList; + var container = charaObjs[0].GetComponentInChildren(); + + for(int i = seqs.Count - 1; i >=0; i--) + { + Debug.Log(_liveCurrentTime); + if (_liveCurrentTime >= (double)seqs[i].frame/60) + { + Debug.Log("ʱ¼ä:" + ((double)seqs[i].frame / 60).ToString()); + + AnimationClip anim = seqs[i].clip; + double start = (double)seqs[i].motionHeadFrame/60; + double interval = _liveCurrentTime - (double)seqs[i].frame/ 60; + + Debug.Log("time:" + interval.ToString()); + + anim.SampleAnimation(container.gameObject, (float)(start + interval)); + + break; + } + } + */ + _liveTimelineControl.AlterUpdate(_liveCurrentTime); + } + + void Update() + { + if (_isLiveSetup) + { + _liveCurrentTime += Time.deltaTime; + OnTimelineUpdate(_liveCurrentTime); + } + else + { + _liveCurrentTime = 0; } } }