Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/SonarViewObject.cs
2026-03-04 09:37:33 +08:00

52 lines
1.1 KiB
C#

using System;
using Obvious.Soap;
using UnityEngine;
public class SonarViewObject : MonoBehaviour
{
public bool Enabled;
public FloatVariable SonarRefreshRate;
public FloatVariable SonarDepthSetting;
public float Depth;
private RectTransform _RectTransform;
public Vector2 MinMaxDepth;
public float DestroyXPos = -0.25f;
private Vector3 _startPosition;
public event Action<SonarViewObject> OnReachOutScreen;
private void Awake()
{
_RectTransform = GetComponent<RectTransform>();
_startPosition = _RectTransform.anchoredPosition;
}
public void ResetObject()
{
Enabled = false;
_RectTransform.anchoredPosition = _startPosition;
this.OnReachOutScreen = null;
}
private void Update()
{
if (Enabled)
{
_RectTransform.anchoredPosition -= new Vector2(1f, 0f) * SonarRefreshRate.Value * Time.deltaTime;
float y = Mathf.Lerp(MinMaxDepth.y, MinMaxDepth.x, Depth / SonarDepthSetting.Value);
_RectTransform.anchoredPosition = new Vector2(_RectTransform.anchoredPosition.x, y);
if (_RectTransform.anchoredPosition.x < DestroyXPos)
{
this.OnReachOutScreen?.Invoke(this);
}
}
}
}