91 lines
1.8 KiB
C#
91 lines
1.8 KiB
C#
using System.Collections;
|
|
using Moonlit.Utils;
|
|
using UnityEngine;
|
|
|
|
namespace Moonlit.IceFishing
|
|
{
|
|
public class Hole : MonoBehaviour
|
|
{
|
|
public float sitDistance = 0.8f;
|
|
|
|
public Transform holeCenter;
|
|
|
|
public Collider aroundHoleCollider;
|
|
|
|
public float finalTubeScale = -1f;
|
|
|
|
public Vector3 centerDown = Vector3.zero;
|
|
|
|
[SerializeField]
|
|
private HoleView _View;
|
|
|
|
[SerializeField]
|
|
private HoleData _Data;
|
|
|
|
public HoleData Data
|
|
{
|
|
get
|
|
{
|
|
return _Data;
|
|
}
|
|
}
|
|
|
|
public HoleView View
|
|
{
|
|
get
|
|
{
|
|
return _View;
|
|
}
|
|
}
|
|
|
|
public void Set(HoleData data)
|
|
{
|
|
_Data = data;
|
|
base.transform.position = Data.Position;
|
|
base.transform.localScale = new Vector3(Data.Radius * 2f, 1f, Data.Radius * 2f);
|
|
base.transform.rotation = Quaternion.Euler(0f, Data.Rotation, 0f);
|
|
_View.SetState(_Data);
|
|
}
|
|
|
|
public void SetProgress(float depth, float thickness)
|
|
{
|
|
_Data.Depth = depth;
|
|
View.SetDepth(_Data.Depth);
|
|
}
|
|
|
|
public void StartDrilling()
|
|
{
|
|
_View.IcePlane.SetActive(true);
|
|
_View.WaterPlane.SetActive(false);
|
|
_View.DrilledSnow.SetActive(true);
|
|
}
|
|
|
|
public void FinishDrilling()
|
|
{
|
|
StartCoroutine(RaiseWaterCoroutine(_Data.Depth, Singleton<HolesController>.Instance.WaterRaiseTime));
|
|
if (finalTubeScale >= 0f)
|
|
{
|
|
_View.Tube.transform.localScale = new Vector3(1f, finalTubeScale, 1f);
|
|
}
|
|
}
|
|
|
|
private IEnumerator RaiseWaterCoroutine(float depth, float waterRaiseTime)
|
|
{
|
|
_View.SetWaterLevel(depth);
|
|
Object.Destroy(_View.Particles);
|
|
_View.IcePlane.SetActive(false);
|
|
_View.WaterPlane.SetActive(true);
|
|
float time = 0f;
|
|
while (time < waterRaiseTime)
|
|
{
|
|
_View.SetWaterLevel(Mathf.Lerp(depth, 0f, time / waterRaiseTime));
|
|
time += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
_View.SetWaterLevel(0f);
|
|
_Data.State = HoleData.HoleState.Finished;
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|