77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.SceneManagement;
|
|
using GeoSus.Client;
|
|
|
|
public class WindController : MonoBehaviour, ITask
|
|
{
|
|
[Header("Settings větru")]
|
|
public float maxWindTorque = 8f;
|
|
public float windChangeSpeed = 0.6f;
|
|
public float gustInterval = 4f;
|
|
public float gustMultiplier = 2.0f;
|
|
|
|
public float CurrentWindTorque { get; private set; }
|
|
|
|
private float targetTorque;
|
|
private float gustTimer;
|
|
|
|
|
|
private Action<ITask> _onCompleted;
|
|
private Action<ITask> _onExit;
|
|
|
|
public string TaskID { get; set; }
|
|
public TaskType TaskType { get; set; }
|
|
public string TaskName { get; set; }
|
|
public Position TaskLocation { get; set; }
|
|
public bool IsCompleted { get; private set; }
|
|
|
|
void Start()
|
|
{
|
|
PickNewTargetTorque();
|
|
gustTimer = gustInterval;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
CurrentWindTorque = Mathf.Lerp(CurrentWindTorque, targetTorque, Time.deltaTime * windChangeSpeed);
|
|
|
|
gustTimer -= Time.deltaTime;
|
|
if (gustTimer <= 0f)
|
|
{
|
|
float gust = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque) * gustMultiplier;
|
|
targetTorque = Mathf.Clamp(gust, -maxWindTorque * gustMultiplier, maxWindTorque * gustMultiplier);
|
|
|
|
gustTimer = gustInterval;
|
|
Invoke(nameof(PickNewTargetTorque), 0.8f);
|
|
}
|
|
}
|
|
|
|
private void PickNewTargetTorque()
|
|
{
|
|
targetTorque = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque);
|
|
}
|
|
|
|
|
|
|
|
public void Initialize(Action<ITask> onCompleted)
|
|
{
|
|
_onCompleted = onCompleted;
|
|
IsCompleted = false;
|
|
}
|
|
|
|
public void Complete()
|
|
{
|
|
if (IsCompleted) return;
|
|
|
|
IsCompleted = true;
|
|
_onCompleted?.Invoke(this);
|
|
}
|
|
|
|
public void ExitTask(Action<ITask> onExit)
|
|
{
|
|
_onExit = onExit;
|
|
_onExit?.Invoke(this);
|
|
}
|
|
} |