| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using Mirror;
- using System.Collections;
- using System.Collections.Generic;
- using UnityCommon;
- using UnityEngine;
- using UnityEngine.AI;
- namespace DTYJ
- {
- public class Chengke : NetworkBehaviour
- {
- NavMeshAgent navMeshAgent;
- Animator animator;
- int nUpdate;
- int animatorSpeed;
- public override void OnStartServer()
- {
- base.OnStartServer();
- animatorSpeed = Animator.StringToHash("Speed");
- navMeshAgent = GetComponent<NavMeshAgent>();
- animator = GetComponent<Animator>();
- nUpdate = Utility.Update(1, () =>
- {
- if (!navMeshAgent.enabled)
- animator.SetFloat(animatorSpeed, 0);
- else
- animator.SetFloat(animatorSpeed, navMeshAgent.remainingDistance < 0.25f ? 0 : navMeshAgent.speed);
- });
- }
- [ServerCallback]
- private void OnDestroy()
- {
- Utility.StopCoroutineExe(nUpdate);
- }
- [ServerCallback]
- private void OnTriggerEnter(Collider other)
- {
- if (other.name == "³öÕ¾´¥·¢"|| other.name == "³öÕ¾´¥·¢_1")
- {
- OnlineCtrl.Instance.chengKeCtrl.RemoveCK(gameObject);
- }
- else if (other.name == "TrainTrigger")
- {
- RpcSetInTrain(other.transform.parent.name);
- OnlineCtrl.Instance.chengKeCtrl.SetCKInTrain(other.transform.parent.name, gameObject);
- }
- }
- [ServerCallback]
- private void OnTriggerExit(Collider other)
- {
- if (other.name == "TrainTrigger")
- {
- RpcSetOutTrain();
- OnlineCtrl.Instance.chengKeCtrl.SetCkOutTrain(other.transform.parent.name, gameObject);
- }
- }
- [ClientRpc]
- public void RpcSetInTrain(string trainNo)
- {
- if (TrainCtrl.TrainCtrlDic.ContainsKey(trainNo))
- {
- transform.SetParent(TrainCtrl.TrainCtrlDic[trainNo].transform);
- }
- }
- [ClientRpc]
- public void RpcSetOutTrain()
- {
- transform.SetParent(null);
- }
- }
- }
|