From 72a75c121acdafe4c38ee29ee56c1503f30e272c Mon Sep 17 00:00:00 2001 From: krylj Date: Sat, 28 Mar 2026 10:03:46 +0100 Subject: [PATCH] itask --- Assets/Scripts/satelity/WindController.cs | 58 ++++++++++++++++------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/satelity/WindController.cs b/Assets/Scripts/satelity/WindController.cs index 37ceeac..abb9640 100644 --- a/Assets/Scripts/satelity/WindController.cs +++ b/Assets/Scripts/satelity/WindController.cs @@ -1,18 +1,15 @@ +using System; using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.SceneManagement; +using UnityEngine.UI; -public class WindController : MonoBehaviour +public class WindController : MonoBehaviour, ITask { - [Header("settings větru")] - [Tooltip("Maximální síla větru (kladná i záporná)")] + [Header("Settings větru")] public float maxWindTorque = 8f; - - [Tooltip("Jak rychle se větr mění směrem/sílou")] public float windChangeSpeed = 0.6f; - - [Tooltip("Jak často se objeví silnější vichřice (v sekundách)")] public float gustInterval = 4f; - - [Tooltip("Multiplier pro sílu vichřice")] public float gustMultiplier = 2.0f; public float CurrentWindTorque { get; private set; } @@ -20,6 +17,16 @@ public class WindController : MonoBehaviour private float targetTorque; private float gustTimer; + + private Action _onCompleted; + private Action _onExit; + + public string TaskID { get; set; } + public TaskType TaskType { get; set; } + public string TaskName { get; set; } + public (double, double) TaskLocation { get; set; } + public bool IsCompleted { get; private set; } + void Start() { PickNewTargetTorque(); @@ -28,24 +35,43 @@ public class WindController : MonoBehaviour void Update() { - // Smoothly move wind toward target torque CurrentWindTorque = Mathf.Lerp(CurrentWindTorque, targetTorque, Time.deltaTime * windChangeSpeed); - // Occasional gusts gustTimer -= Time.deltaTime; if (gustTimer <= 0f) { - // Apply a short gust by shifting target torque more aggressively - float gust = Random.Range(-maxWindTorque, maxWindTorque) * gustMultiplier; + float gust = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque) * gustMultiplier; targetTorque = Mathf.Clamp(gust, -maxWindTorque * gustMultiplier, maxWindTorque * gustMultiplier); gustTimer = gustInterval; - Invoke(nameof(PickNewTargetTorque), 0.8f); // gust lasts ~0.8s + Invoke(nameof(PickNewTargetTorque), 0.8f); } } private void PickNewTargetTorque() { - targetTorque = Random.Range(-maxWindTorque, maxWindTorque); + targetTorque = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque); } -} + + + + public void Initialize(Action onCompleted) + { + _onCompleted = onCompleted; + IsCompleted = false; + } + + public void Complete() + { + if (IsCompleted) return; + + IsCompleted = true; + _onCompleted?.Invoke(this); + } + + public void ExitTask(Action onExit) + { + _onExit = onExit; + _onExit?.Invoke(this); + } +} \ No newline at end of file