Files
VFSUnity/Assets/Scripts/Interaction/Point2ClickHandler.cs
T

111 lines
3.0 KiB
C#

using UnityEngine;
public class Point2ClickHandler : MonoBehaviour
{
public GameObject nextObject; // This will be Shose
private bool _clicked;
public bool CanBeClicked() { return !_clicked; }
private MeshRenderer _meshRenderer;
void OnEnable()
{
if (GetComponent<Collider>() == null) gameObject.AddComponent<SphereCollider>().radius = 0.5f;
_meshRenderer = GetComponent<MeshRenderer>();
if (_meshRenderer != null)
{
_meshRenderer.enabled = true;
var mat = _meshRenderer.material;
if (mat != null && mat.HasProperty("_MainColor"))
{
var c = mat.GetColor("_MainColor");
c.a = 0f;
mat.SetColor("_MainColor", c);
if (mat.HasProperty("_OutlineWidth"))
{
mat.SetFloat("_OutlineWidth", OutlineConfig.Width);
}
}
}
_clicked = false;
StopAllCoroutines();
StartCoroutine(BlinkOutline());
}
System.Collections.IEnumerator BlinkOutline()
{
yield return new WaitForSeconds(0.4f);
while (true)
{
if (_meshRenderer != null) _meshRenderer.enabled = !_meshRenderer.enabled;
yield return new WaitForSeconds(0.4f);
}
}
void OnMouseDown()
{
PerformClick();
}
public void PerformClick()
{
if (_clicked) return;
_clicked = true;
Debug.Log("[Point2Click] ★ 被点击 ★");
ActionHistory.Push(ActionHistory.ActionType.Point2, this);
StopAllCoroutines();
if (_meshRenderer != null) _meshRenderer.enabled = false;
var woman = GameObject.Find("woman");
if (woman != null)
{
var anim = woman.GetComponent<Animator>();
if (anim != null)
{
anim.SetBool("IsCheck", true);
}
}
if (nextObject != null)
{
var shoseHandler = nextObject.GetComponent<ShoseClickHandler>();
if (shoseHandler != null) shoseHandler.enabled = true;
else nextObject.SetActive(true);
}
gameObject.SetActive(false);
}
public void ResetState()
{
_clicked = false;
if (_meshRenderer != null) _meshRenderer.enabled = true;
if (nextObject != null)
{
var shoseHandler = nextObject.GetComponent<ShoseClickHandler>();
if (shoseHandler != null) shoseHandler.enabled = false;
else nextObject.SetActive(false);
}
var woman = GameObject.Find("woman");
if (woman != null)
{
var anim = woman.GetComponent<Animator>();
if (anim != null)
{
anim.SetBool("IsCheck", false);
}
}
gameObject.SetActive(true);
StopAllCoroutines();
StartCoroutine(BlinkOutline());
}
}