1
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Dreamteck.Splines.Primitives;
|
||||
using Project.B.Entities;
|
||||
using UnityEngine;
|
||||
using Object = System.Object;
|
||||
using Random = UnityEngine.Random;
|
||||
@@ -13,22 +17,43 @@ namespace Net.Like.Xue.Tokyo
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private Transform[] models;
|
||||
|
||||
private void Start()
|
||||
private async void Start()
|
||||
{
|
||||
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;
|
||||
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
DestroyImmediate(transform.GetChild(0));
|
||||
DestroyImmediate(transform.GetChild(0).gameObject);
|
||||
}
|
||||
|
||||
var index = Random.Range(0, transform.childCount);
|
||||
var index = Random.Range(0, models.Length);
|
||||
var newModel =models[index];
|
||||
newModel = Instantiate(newModel, transform);
|
||||
if (newModel.TryGetComponent<Animator>(out var x))
|
||||
{
|
||||
DestroyImmediate(x);
|
||||
}
|
||||
newModel = Instantiate(newModel, transform);
|
||||
|
||||
newModel.localPosition = newModel.localEulerAngles = default;
|
||||
|
||||
animator.Rebind();
|
||||
if (newModel.TryGetComponent<Animator>(out var x))
|
||||
{
|
||||
animator.avatar = x.avatar;
|
||||
DestroyImmediate(x);
|
||||
}
|
||||
|
||||
await UniTask.NextFrame();
|
||||
|
||||
animator.Rebind();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user