87 lines
1.9 KiB
C#
87 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DarkTonic.MasterAudio;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using Valheim;
|
|
|
|
public class Cage : NetworkBehaviour
|
|
{
|
|
public Animator animator;
|
|
|
|
public BoxCollider boxCollider;
|
|
|
|
#if UNITY_EDITOR
|
|
[DisplayOnly]
|
|
#endif
|
|
public int cageId = -1;
|
|
|
|
[NonSerialized]
|
|
public bool isOpen = false;
|
|
|
|
public GameObject boomEffect;
|
|
|
|
//[Header("声音")]
|
|
//[SoundGroup] public string breakSound;
|
|
//[SoundGroup] public string getSound;
|
|
|
|
[Server]
|
|
public void Init(int cageId)
|
|
{
|
|
this.cageId = cageId;
|
|
isOpen = false;
|
|
}
|
|
|
|
[Server]
|
|
public void OpenCage()
|
|
{
|
|
animator.SetBool("IsOpen", true);
|
|
isOpen = true;
|
|
RpcShowEffect();
|
|
PlayBreakSound();
|
|
GameManager.Ins.OpenCage(cageId);
|
|
NetworkServer.Destroy(gameObject);
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void PlayBreakSound()
|
|
{
|
|
MasterAudio.PlaySound3DAtVector3("longbreak", transform.position);
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void RpcShowEffect()
|
|
{
|
|
boomEffect.SetActive(true);
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void PlayGetSound()
|
|
{
|
|
MasterAudio.PlaySound3DAtVector3("long_get", transform.position);
|
|
}
|
|
|
|
[ServerCallback]
|
|
public void OnTriggerEnter(Collider other)
|
|
{
|
|
// 有宠物走出门
|
|
if (other.CompareTag("Pet"))
|
|
{
|
|
Pet pet = other.transform.GetComponent<Pet>();
|
|
if (pet != null && pet.state == PetState.Rescueing)
|
|
{
|
|
Debug.Log("宠物走出门");
|
|
isOpen = false;
|
|
boxCollider.enabled = false;
|
|
pet.Change2State(PetState.NeedAssigned);
|
|
GameManager.Ins.AssignPetIndex();
|
|
GameManager.Ins.PetPlace(pet.id);
|
|
PlayGetSound();
|
|
other.GetComponent<Collider>().isTrigger = false;
|
|
}
|
|
}
|
|
}
|
|
}
|