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;
|
|
|
|
|
|
using Constants = Framework.Constants;
|
2024-03-26 19:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
public class FightWinComponent: MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
|
|
|
|
|
//test
|
|
|
|
|
|
for (int i = 1; i <= 5; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
_testObjs.Add(GameObject.Find("Content/P_S_A0000" + i));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_Load();
|
2024-03-27 14:52:35 +08:00
|
|
|
|
_timelinePlayable.Play();
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
private void _Load()
|
|
|
|
|
|
{
|
|
|
|
|
|
_LoadTimeline();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void _LoadModels()
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void _LoadTimeline()
|
|
|
|
|
|
{
|
|
|
|
|
|
var timeLineObj = new GameObject("GameTimeLine");
|
|
|
|
|
|
var timeline = timeLineObj.AddComponent<PlayableDirector>();
|
|
|
|
|
|
// var playableAsset =
|
|
|
|
|
|
// await AssetManager.Instance.LoadAssetAsync<PlayableAsset>("Assets/_Test/Prefab/VictoryTimeLine.playable");
|
|
|
|
|
|
|
|
|
|
|
|
//test
|
2024-03-27 13:13:58 +08:00
|
|
|
|
#if UNITY_EDITOR
|
2024-03-26 19:28:14 +08:00
|
|
|
|
var playableAsset =
|
2024-03-27 13:13:58 +08:00
|
|
|
|
UnityEditor.AssetDatabase.LoadAssetAtPath<PlayableAsset>("Assets/_Test/Prefab/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)
|
|
|
|
|
|
{
|
|
|
|
|
|
//test
|
|
|
|
|
|
if (index < _testObjs.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
var animObj = _testObjs[index].transform.GetChild(0);
|
|
|
|
|
|
|
|
|
|
|
|
var anim = animObj.GetComponent<Animator>();
|
|
|
|
|
|
if (!anim)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("TimeLine使用的模型未绑定Animator组件!!!");
|
|
|
|
|
|
}
|
|
|
|
|
|
timeline.SetGenericBinding(trackAsset, anim);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var anim = _camera.GetComponent<Animator>();
|
|
|
|
|
|
if (anim)
|
|
|
|
|
|
{
|
|
|
|
|
|
timeline.SetGenericBinding(trackAsset, anim);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
index++;
|
|
|
|
|
|
|
|
|
|
|
|
// if (index < _characterIDs.Count)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var animObj = _objRoot.transform.GetChild(index).GetChild(0).gameObject;
|
|
|
|
|
|
//
|
|
|
|
|
|
// var anim = animObj.GetComponent<Animator>();
|
|
|
|
|
|
// if (!anim)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// DebugUtil.LogError("TimeLine使用的模型未绑定Animator组件!!!");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// timeline.SetGenericBinding(trackAsset, anim);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//index++;
|
2024-03-27 14:52:35 +08:00
|
|
|
|
|
2024-03-26 19:28:14 +08:00
|
|
|
|
}
|
2024-03-27 14:52:35 +08:00
|
|
|
|
#endif
|
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
|
|
|
|
}
|