114 lines
2.9 KiB
C#
114 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BehaviorDesigner.Runtime;
|
|
using DragonLi.Core;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
|
|
public class ShadowCast : XAgent
|
|
{
|
|
public BehaviorTree behavior;
|
|
public BloodSlider BloodSlider;
|
|
public GameObject explosion_prefab;
|
|
public float explosion_despawn_time = 4f;
|
|
|
|
public void Init(float originHealth, float health)
|
|
{
|
|
base.OnSpawn();
|
|
NavAgent.enabled = true;
|
|
behavior.enabled = true;
|
|
BloodSlider.SetName("幻影者");
|
|
ColliderComponent.enabled = true;
|
|
Data["health"].FloatValue = health;
|
|
OriginHealth = originHealth;
|
|
Health = health;
|
|
}
|
|
|
|
|
|
[Server]
|
|
public override void ApplyDamage(float value, object info, Transform _sender)
|
|
{
|
|
base.ApplyDamage(value, info, _sender);
|
|
if (_sender != null)
|
|
{
|
|
int ownerIndx = _sender.GetComponent<Bullet>().ownerIndex;
|
|
RpcDamage(value, (bool)info, ownerIndx);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[ClientRpc]
|
|
public void RpcDamage(float value, bool info, int ownerIndx)
|
|
{
|
|
if (GameInit.Ins.self.index == ownerIndx)
|
|
{
|
|
BloodSlider.CreateDamagePre(value, info);
|
|
}
|
|
}
|
|
|
|
|
|
[Server]
|
|
public override void OnHeathChanged(float currentHealth)
|
|
{
|
|
base.OnHeathChanged(currentHealth);
|
|
HealthChange(currentHealth);
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void HealthChange(float currentHealth)
|
|
{
|
|
if (BloodSlider != null)
|
|
{
|
|
Debug.Log("当前血量" + currentHealth);
|
|
BloodSlider.SetValue2(currentHealth, OriginHealth);
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (IsAlive && isServer)
|
|
{
|
|
UpdateRotation();
|
|
}
|
|
}
|
|
|
|
private void UpdateRotation()
|
|
{
|
|
if (IsAlive)
|
|
{
|
|
Transform player = MRNetworkManager.Ins.roomSlots[LockPlayer].transform;
|
|
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(player.position - transform.position), 20 * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
[Server]
|
|
public void SpawnExplosion()
|
|
{
|
|
if (explosion_prefab != null)
|
|
{
|
|
GameObject explosion = Instantiate(explosion_prefab);
|
|
explosion.transform.position = transform.position;
|
|
NetworkServer.Spawn(explosion);
|
|
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
|
{
|
|
NetworkServer.Destroy(explosion);
|
|
}, explosion_despawn_time);
|
|
}
|
|
}
|
|
|
|
[Server]
|
|
public override void OnDeath(object info, Transform _sender)
|
|
{
|
|
|
|
ColliderComponent.enabled = false;
|
|
behavior.enabled = false;
|
|
AnimatorComponent.SetBool("Dead", true);
|
|
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
|
{
|
|
NetworkServer.Destroy(transform.gameObject);
|
|
SpawnExplosion();
|
|
}, 3.5f);
|
|
}
|
|
}
|