2025-04-18 20:27:57 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2025-04-23 14:48:45 +08:00
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using Cysharp.Threading.Tasks;
|
2025-04-18 20:27:57 +08:00
|
|
|
using Dreamteck.Splines.Primitives;
|
2025-04-23 14:48:45 +08:00
|
|
|
using Project.B.Entities;
|
2025-04-18 20:27:57 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using Object = System.Object;
|
|
|
|
using Random = UnityEngine.Random;
|
|
|
|
|
|
|
|
namespace Net.Like.Xue.Tokyo
|
|
|
|
{
|
|
|
|
public class ReplaceModel : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private Animator animator;
|
|
|
|
[SerializeField] private Transform[] models;
|
|
|
|
|
2025-04-23 14:48:45 +08:00
|
|
|
private async void Start()
|
2025-04-18 20:27:57 +08:00
|
|
|
{
|
2025-04-23 14:48:45 +08:00
|
|
|
if(animator.TryGetComponent<IEntity>(out var entity) is false)return;
|
|
|
|
|
|
|
|
BITApp.ServiceProvider.QueryComponents(out INpcFactory npcFactory);
|
|
|
|
|
|
|
|
npcFactory.OnEntityCreate += OnEntityCreated;
|
|
|
|
|
|
|
|
await destroyCancellationToken.WaitUntilCanceled();
|
|
|
|
|
|
|
|
npcFactory.OnEntityCreate -= OnEntityCreated;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async UniTask OnEntityCreated(string arg1, IEntity arg2)
|
|
|
|
{
|
|
|
|
if(arg2.Id!=animator.GetComponent<IEntity>().Id)return;
|
|
|
|
|
2025-04-18 20:27:57 +08:00
|
|
|
for (var i = 0; i < transform.childCount; i++)
|
|
|
|
{
|
2025-04-23 14:48:45 +08:00
|
|
|
DestroyImmediate(transform.GetChild(0).gameObject);
|
2025-04-18 20:27:57 +08:00
|
|
|
}
|
|
|
|
|
2025-04-23 14:48:45 +08:00
|
|
|
var index = Random.Range(0, models.Length);
|
2025-04-18 20:27:57 +08:00
|
|
|
var newModel =models[index];
|
2025-04-23 14:48:45 +08:00
|
|
|
newModel = Instantiate(newModel, transform);
|
|
|
|
|
|
|
|
newModel.localPosition = newModel.localEulerAngles = default;
|
|
|
|
|
|
|
|
if (newModel.TryGetComponent<Animator>(out var x))
|
|
|
|
{
|
|
|
|
animator.avatar = x.avatar;
|
|
|
|
DestroyImmediate(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
await UniTask.NextFrame();
|
2025-04-18 20:27:57 +08:00
|
|
|
|
2025-04-23 14:48:45 +08:00
|
|
|
animator.Rebind();
|
2025-04-18 20:27:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|