2024-03-26 19:28:14 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using Gameplay;
|
|
|
|
|
|
using PhxhSDK;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Playables;
|
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
using UnityEngine.Timeline;
|
2024-03-26 19:33:53 +08:00
|
|
|
|
using Framework;
|
2024-03-29 12:05:14 +08:00
|
|
|
|
using Gameplay.Common;
|
|
|
|
|
|
using Gameplay.Level;
|
2024-03-26 19:33:53 +08:00
|
|
|
|
using Constants = Framework.Constants;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
public class FightWinComponent: MonoBehaviour
|
|
|
|
|
|
{
|
2024-03-29 12:05:14 +08:00
|
|
|
|
private Scene _scene;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
private List<uint> _characterIDs;
|
|
|
|
|
|
private uint _vehicleID;
|
|
|
|
|
|
private GameObject _objRoot;
|
|
|
|
|
|
private List<Transform> _posTransList;
|
|
|
|
|
|
|
|
|
|
|
|
private Camera _camera;
|
2024-03-27 14:52:35 +08:00
|
|
|
|
private PlayableDirector _timelinePlayable;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
//test
|
|
|
|
|
|
private List<GameObject> _testObjs = new List<GameObject>();
|
|
|
|
|
|
|
|
|
|
|
|
private readonly int Vehicle_Model_Index = 5;
|
|
|
|
|
|
|
|
|
|
|
|
#region Unity EventFunction
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
2024-03-29 12:05:14 +08:00
|
|
|
|
_SetData();
|
2024-03-26 19:28:14 +08:00
|
|
|
|
_camera = GameObject.Find("CameraRoot").GetComponent<CameraRoot>().Camera;
|
|
|
|
|
|
_objRoot = GameObject.Find("Content/ObjRoot");
|
|
|
|
|
|
var posRootTrans = GameObject.Find("Content/PosRoot").transform;
|
|
|
|
|
|
_posTransList = new List<Transform>();
|
|
|
|
|
|
for (int i = 0; i < posRootTrans.childCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var child = posRootTrans.GetChild(i);
|
|
|
|
|
|
_posTransList.Add(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.FightCmpTimelinePause, _OnPauseEvent);
|
2024-03-26 19:28:14 +08:00
|
|
|
|
_Load();
|
2024-03-29 12:05:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.FightCmpTimelinePause, _OnPauseEvent);
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
private void _SetData()
|
|
|
|
|
|
{
|
|
|
|
|
|
SetData(LevelManager.Instance.ShowCharIDs, LevelManager.Instance.ShowVehicleID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void _Load()
|
|
|
|
|
|
{
|
|
|
|
|
|
await _LoadModels();
|
|
|
|
|
|
await _LoadTimeline();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void _OnPauseEvent()
|
2024-03-26 19:28:14 +08:00
|
|
|
|
{
|
2024-03-29 12:05:14 +08:00
|
|
|
|
if (_timelinePlayable)
|
|
|
|
|
|
{
|
|
|
|
|
|
_timelinePlayable.Pause();
|
|
|
|
|
|
}
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
private async UniTask _LoadModels()
|
2024-03-26 19:28:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (_characterIDs != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < _characterIDs.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _AddCharacterModel(_characterIDs[i], i);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_vehicleID != Constants.INVALID_UINT_ID)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _AddVehicleModel(_vehicleID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask _AddCharacterModel(uint uid, int idx)
|
|
|
|
|
|
{
|
|
|
|
|
|
var modelPath = CommonUtils.GetCharacterShowModelPath(uid);
|
|
|
|
|
|
if (modelPath != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var prefab = await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
|
|
|
|
|
var model = Instantiate(prefab, _objRoot.transform);
|
|
|
|
|
|
var posTrans = _posTransList[idx];
|
|
|
|
|
|
model.transform.SetPositionAndRotation(posTrans.position, posTrans.rotation);
|
|
|
|
|
|
model.transform.localScale = posTrans.localScale;
|
2024-03-29 12:05:14 +08:00
|
|
|
|
model.SetLayerEx(LayerDefine.TeamEdit);
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask _AddVehicleModel(uint uid)
|
|
|
|
|
|
{
|
|
|
|
|
|
var modelPath = CommonUtils.GetVehicleShowModelPath(uid);
|
|
|
|
|
|
if (modelPath != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var prefab = await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
|
|
|
|
|
var model = Instantiate(prefab, _objRoot.transform);
|
|
|
|
|
|
var posTrans = _posTransList[Vehicle_Model_Index];
|
|
|
|
|
|
model.transform.SetPositionAndRotation(posTrans.position, posTrans.rotation);
|
|
|
|
|
|
model.transform.localScale = posTrans.localScale;
|
2024-03-29 12:05:14 +08:00
|
|
|
|
model.SetLayerEx(LayerDefine.TeamEdit);
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
private async UniTask _LoadTimeline()
|
2024-03-26 19:28:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
var timeLineObj = new GameObject("GameTimeLine");
|
2024-03-29 12:05:14 +08:00
|
|
|
|
timeLineObj.transform.SetParent(transform);
|
|
|
|
|
|
timeLineObj.SetLayerEx(LayerDefine.TeamEdit);
|
2024-03-26 19:28:14 +08:00
|
|
|
|
var timeline = timeLineObj.AddComponent<PlayableDirector>();
|
|
|
|
|
|
var playableAsset =
|
2024-03-29 12:05:14 +08:00
|
|
|
|
await AssetManager.Instance.LoadAssetAsync<PlayableAsset>("Assets/Art/Animations/Level/VictoryTimeLine.playable");
|
|
|
|
|
|
|
2024-03-26 19:28:14 +08:00
|
|
|
|
var timeLineAsset = playableAsset as TimelineAsset;
|
|
|
|
|
|
if (!timeLineAsset)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("加载的TimeLine资源为空!!!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
timeline.playableAsset = timeLineAsset;
|
|
|
|
|
|
timeline.timeUpdateMode = DirectorUpdateMode.GameTime;
|
|
|
|
|
|
timeline.playOnAwake = false;
|
|
|
|
|
|
|
2024-03-27 14:52:35 +08:00
|
|
|
|
_timelinePlayable = timeline;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
var trackIEnumerable = timeLineAsset.GetOutputTracks();
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
foreach (var trackAsset in trackIEnumerable)
|
|
|
|
|
|
{
|
2024-03-29 12:05:14 +08:00
|
|
|
|
if (index < _characterIDs.Count)
|
2024-03-26 19:28:14 +08:00
|
|
|
|
{
|
2024-03-29 12:05:14 +08:00
|
|
|
|
var child = _objRoot.transform.GetChild(index);
|
|
|
|
|
|
if (!child)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var animObj = child.GetChild(0).gameObject;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
var anim = animObj.GetComponent<Animator>();
|
|
|
|
|
|
if (!anim)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("TimeLine使用的模型未绑定Animator组件!!!");
|
|
|
|
|
|
}
|
|
|
|
|
|
timeline.SetGenericBinding(trackAsset, anim);
|
|
|
|
|
|
}
|
2024-03-29 12:05:14 +08:00
|
|
|
|
else if(index == 5)
|
2024-03-26 19:28:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
var anim = _camera.GetComponent<Animator>();
|
|
|
|
|
|
if (anim)
|
|
|
|
|
|
{
|
|
|
|
|
|
timeline.SetGenericBinding(trackAsset, anim);
|
|
|
|
|
|
}
|
2024-03-29 12:05:14 +08:00
|
|
|
|
break;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
index++;
|
|
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
_timelinePlayable.Play();
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-27 14:52:35 +08:00
|
|
|
|
#region API
|
2024-03-26 19:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
public void SetData(List<uint> charIDList)
|
|
|
|
|
|
{
|
|
|
|
|
|
_characterIDs = charIDList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetData(uint vehicleID)
|
|
|
|
|
|
{
|
|
|
|
|
|
_vehicleID = vehicleID;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetData(List<uint> charIDList, uint vehicleID)
|
|
|
|
|
|
{
|
|
|
|
|
|
_characterIDs = charIDList;
|
|
|
|
|
|
_vehicleID = vehicleID;
|
|
|
|
|
|
}
|
2024-03-27 14:52:35 +08:00
|
|
|
|
|
|
|
|
|
|
public void StartPlay()
|
|
|
|
|
|
{
|
|
|
|
|
|
_timelinePlayable.Play();
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|