Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/vp_Interactable.cs
2026-02-21 16:45:37 +08:00

111 lines
1.9 KiB
C#

using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Collider))]
public abstract class vp_Interactable : MonoBehaviour
{
public enum vp_InteractType
{
Normal = 0,
Trigger = 1,
CollisionTrigger = 2
}
public vp_InteractType InteractType;
public List<string> RecipientTags = new List<string>();
public float InteractDistance;
public Texture m_InteractCrosshair;
public string InteractText = string.Empty;
public float DelayShowingText = 2f;
protected Transform m_Transform;
protected vp_FPController m_Controller;
protected vp_FPCamera m_Camera;
protected vp_WeaponHandler m_WeaponHandler;
protected vp_PlayerEventHandler m_Player;
public bool isSeeingMe;
protected virtual void Start()
{
m_Transform = base.transform;
if (RecipientTags.Count == 0)
{
RecipientTags.Add("Player");
}
if (InteractType == vp_InteractType.Trigger && GetComponent<Collider>() != null)
{
GetComponent<Collider>().isTrigger = true;
}
}
protected virtual void OnEnable()
{
if (m_Player != null)
{
m_Player.Register(this);
}
}
protected virtual void OnDisable()
{
if (m_Player != null)
{
m_Player.Unregister(this);
}
}
public virtual bool TryInteract(vp_PlayerEventHandler player)
{
return false;
}
public virtual void UpdateSeeing(bool isSeeing)
{
if (isSeeingMe != isSeeing)
{
isSeeingMe = isSeeing;
}
}
protected virtual void OnTriggerEnter(Collider col)
{
if (InteractType != vp_InteractType.Trigger)
{
return;
}
using (List<string>.Enumerator enumerator = RecipientTags.GetEnumerator())
{
string current = string.Empty;
do
{
if (enumerator.MoveNext())
{
current = enumerator.Current;
continue;
}
return;
}
while (!(col.gameObject.tag == current));
}
m_Player = col.gameObject.GetComponent<vp_PlayerEventHandler>();
if (!(m_Player == null))
{
TryInteract(m_Player);
}
}
public virtual void FinishInteraction()
{
}
}