Files
2026-02-21 16:45:37 +08:00

80 lines
2.1 KiB
C#

using Moonlit.Utils;
using UnityEngine;
namespace Moonlit.IceFishing
{
public class HoleView : MonoBehaviour
{
public GameObject IcePlane;
public GameObject WaterPlane;
public GameObject Tube;
public GameObject TubeModel;
public GameObject NormalMask;
public GameObject UnderwaterMask;
public GameObject FakeUnderwaterMask;
public ParticleSystem Particles;
[HideInInspector]
public GameObject DrilledSnow;
[HideInInspector]
public float IcePlaneDepth;
[HideInInspector]
public float WaterPlaneDepth;
private void Awake()
{
IcePlaneDepth = IcePlane.transform.localPosition.y;
WaterPlaneDepth = WaterPlane.transform.localPosition.y;
DrilledSnow = Object.Instantiate(Singleton<HolesController>.Instance.GetRandomSnowPrefab());
DrilledSnow.transform.SetParent(base.transform, false);
if ((bool)Singleton<HolesController>.Instance.iceMaterial)
{
DrilledSnow.GetComponent<MeshRenderer>().material = Singleton<HolesController>.Instance.iceMaterial;
}
}
public void SetState(HoleData data)
{
switch (data.State)
{
case HoleData.HoleState.Drilling:
IcePlane.SetActive(true);
WaterPlane.SetActive(false);
DrilledSnow.SetActive(false);
SetDepth(data.Depth);
break;
case HoleData.HoleState.Finished:
IcePlane.SetActive(false);
WaterPlane.SetActive(true);
DrilledSnow.SetActive(true);
SetDepth(data.Depth);
SetWaterLevel(0f);
break;
}
}
public void SetDepth(float depth)
{
DrilledSnow.transform.localScale = new Vector3(1f, 1f, depth * 0.8f);
Tube.transform.localScale = new Vector3(1f, depth, 1f);
IcePlane.transform.localPosition = new Vector3(0f, IcePlaneDepth - depth, 0f);
UnderwaterMask.transform.localPosition = new Vector3(UnderwaterMask.transform.localPosition.x, 0f - depth, UnderwaterMask.transform.localPosition.z);
FakeUnderwaterMask.transform.localPosition = UnderwaterMask.transform.localPosition - Vector3.up * 0.01f;
}
public void SetWaterLevel(float depth)
{
WaterPlane.transform.localPosition = new Vector3(0f, WaterPlaneDepth - depth, 0f);
}
}
}