257 lines
5.3 KiB
C#
257 lines
5.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Moonlit.Utils;
|
|
using UnityEngine;
|
|
|
|
namespace Moonlit.IceFishing
|
|
{
|
|
public class Auger : MonoBehaviour
|
|
{
|
|
public string engineSound = string.Empty;
|
|
|
|
public string drillSound = "IceDrill_01";
|
|
|
|
[HideInInspector]
|
|
public AudioObject engineAudioObject;
|
|
|
|
[HideInInspector]
|
|
public AudioObject drillAudioObject;
|
|
|
|
private Vector3 particlesPosition = Vector3.zero;
|
|
|
|
[SerializeField]
|
|
private float _Radius = 0.3f;
|
|
|
|
[SerializeField]
|
|
private Vector3 _OffsetPosition;
|
|
|
|
public List<MeshRenderer> modelParts = new List<MeshRenderer>();
|
|
|
|
[SerializeField]
|
|
[Header("Lower")]
|
|
private float _LowerHeight;
|
|
|
|
[SerializeField]
|
|
private float _LowerTime;
|
|
|
|
[SerializeField]
|
|
[Header("Drill")]
|
|
private float _DepthPerSecond;
|
|
|
|
[SerializeField]
|
|
private float _RevolutionsPerSecond;
|
|
|
|
[Header("Rise")]
|
|
[SerializeField]
|
|
private float _RaiseHeight;
|
|
|
|
[SerializeField]
|
|
private float _RaiseTime;
|
|
|
|
[SerializeField]
|
|
[Header("Particles")]
|
|
private ParticleSystem _Particles;
|
|
|
|
private float _CurrentDepth;
|
|
|
|
public float previousRotation;
|
|
|
|
public float depthSpeed = 0.2f;
|
|
|
|
public float Radius
|
|
{
|
|
get
|
|
{
|
|
return _Radius;
|
|
}
|
|
}
|
|
|
|
public float Depth
|
|
{
|
|
get
|
|
{
|
|
return _CurrentDepth;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
drillAudioObject = AudioController.Play(drillSound, base.transform);
|
|
drillAudioObject.Pause();
|
|
if (engineSound != string.Empty)
|
|
{
|
|
engineAudioObject = AudioController.Play(engineSound, base.transform);
|
|
engineAudioObject.Pause();
|
|
}
|
|
FadeDriller(false);
|
|
}
|
|
|
|
public void FadeDriller(bool fade)
|
|
{
|
|
for (int i = 0; i < modelParts.Count; i++)
|
|
{
|
|
if (fade)
|
|
{
|
|
modelParts[i].GetComponent<ChangeMaterial>().SetMaterial(1);
|
|
}
|
|
else
|
|
{
|
|
modelParts[i].GetComponent<ChangeMaterial>().SetMaterial(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetParticles(ParticleSystem particles)
|
|
{
|
|
if ((bool)_Particles)
|
|
{
|
|
_Particles.Stop();
|
|
}
|
|
_Particles = particles;
|
|
if (particles != null)
|
|
{
|
|
ParticleSystem.ShapeModule shape = _Particles.shape;
|
|
shape.radius = _Radius;
|
|
}
|
|
}
|
|
|
|
public void Position(Vector3 position)
|
|
{
|
|
position = Singleton<HolesController>.Instance.FindIcePosition(position);
|
|
base.transform.position = _OffsetPosition + position;
|
|
particlesPosition = base.transform.position;
|
|
}
|
|
|
|
public IEnumerator Lower()
|
|
{
|
|
base.gameObject.SetActive(true);
|
|
_CurrentDepth = 0f;
|
|
float time = 0f;
|
|
Vector3 startPosition = base.transform.position + Vector3.up * _LowerHeight;
|
|
Vector3 endPosition = (particlesPosition = base.transform.position);
|
|
while (time < _LowerTime)
|
|
{
|
|
base.transform.position = Vector3.Lerp(startPosition, endPosition, time / _LowerTime);
|
|
time += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public IEnumerator Drill(float thickness)
|
|
{
|
|
float drilled = 0f;
|
|
while (drilled < thickness)
|
|
{
|
|
_CurrentDepth = drilled;
|
|
float rotationDifference = MakeRotation();
|
|
if (Input.GetKey(KeyCode.Space))
|
|
{
|
|
rotationDifference *= 10f;
|
|
}
|
|
if (UtilitiesInput.GetButton("DRILLING"))
|
|
{
|
|
rotationDifference = 600f * Time.deltaTime;
|
|
}
|
|
if (!GameController.Instance.IsPauseMenu() && rotationDifference > 0f)
|
|
{
|
|
drilled += rotationDifference * depthSpeed;
|
|
base.transform.position += Vector3.down * rotationDifference * depthSpeed;
|
|
base.transform.Rotate(Vector3.up, 0f - rotationDifference);
|
|
if (drillAudioObject.IsPaused())
|
|
{
|
|
drillAudioObject.Unpause();
|
|
if ((bool)engineAudioObject)
|
|
{
|
|
engineAudioObject.Unpause();
|
|
}
|
|
}
|
|
if ((bool)_Particles)
|
|
{
|
|
_Particles.Play();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
drillAudioObject.Pause();
|
|
if ((bool)engineAudioObject)
|
|
{
|
|
engineAudioObject.Pause();
|
|
}
|
|
if ((bool)_Particles)
|
|
{
|
|
_Particles.Stop();
|
|
}
|
|
}
|
|
if ((bool)_Particles)
|
|
{
|
|
_Particles.transform.position = particlesPosition;
|
|
}
|
|
yield return null;
|
|
}
|
|
_CurrentDepth = thickness;
|
|
drillAudioObject.Pause();
|
|
if ((bool)engineAudioObject)
|
|
{
|
|
engineAudioObject.Pause();
|
|
}
|
|
if ((bool)_Particles)
|
|
{
|
|
_Particles.Stop();
|
|
}
|
|
yield return null;
|
|
}
|
|
|
|
public IEnumerator Raise()
|
|
{
|
|
float time = 0f;
|
|
Vector3 startPosition = base.transform.position;
|
|
Vector3 endPosition = base.transform.position + Vector3.up * _RaiseHeight;
|
|
while (time < _RaiseTime)
|
|
{
|
|
base.transform.position = Vector3.Lerp(startPosition, endPosition, time / _RaiseTime);
|
|
time += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
|
|
public float MakeRotation()
|
|
{
|
|
Vector3 mousePosition = Input.mousePosition;
|
|
Vector2 vector = new Vector2((float)Screen.width * 0.5f, (float)Screen.height * 0.5f);
|
|
mousePosition.x -= vector.x;
|
|
mousePosition.y -= vector.y;
|
|
float num = Mathf.Atan2(mousePosition.y, mousePosition.x) * 57.29578f;
|
|
num += 180f;
|
|
if (previousRotation == -666f)
|
|
{
|
|
previousRotation = num;
|
|
return 0f;
|
|
}
|
|
float num2 = num - previousRotation;
|
|
if (num2 > 180f)
|
|
{
|
|
num2 -= 360f;
|
|
}
|
|
if (num2 < -180f)
|
|
{
|
|
num2 += 360f;
|
|
}
|
|
if (num2 > 90f || num2 < -90f)
|
|
{
|
|
num2 = 0f;
|
|
}
|
|
if (num2 < 0f)
|
|
{
|
|
num2 = 0f;
|
|
}
|
|
previousRotation = num;
|
|
return num2;
|
|
}
|
|
}
|
|
}
|