You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class AlertController : MonoBehaviour
  6. {
  7. public Text text;
  8. public Slider slider;
  9. public float hideTime = 5f;
  10. private Vector3 originalPos;
  11. private float lastSpotted;
  12. void Start ()
  13. {
  14. NotificationServer.register("spotted boat", spottedBoat);
  15. NotificationServer.register("lost boat", lostBoat);
  16. originalPos = text.rectTransform.anchoredPosition3D;
  17. }
  18. public void spottedBoat()
  19. {
  20. LeanTween.cancel(text.gameObject, false);
  21. LeanTween.cancel(slider.gameObject, false);
  22. lastSpotted = Time.timeSinceLevelLoad;
  23. NotificationServer.notify("show AlertText");
  24. text.text = "hide!";
  25. setTimer(0f);
  26. }
  27. public void lostBoat()
  28. {
  29. LeanTween.cancel(text.gameObject, false);
  30. LeanTween.cancel(slider.gameObject, false);
  31. NotificationServer.notify("show AlertText");
  32. NotificationServer.notify("show AlertTimer");
  33. text.text = "stay hidden";
  34. LeanTween.value(slider.gameObject, 0f, 1f, hideTime).setOnUpdate((float val)=>{
  35. setTimer(val);
  36. }).setOnComplete(()=>{
  37. NotificationServer.notify("hide AlertTimer");
  38. NotificationServer.notify("statechange Searchlight returning");
  39. text.text = "hidden...";
  40. LeanTween.delayedCall(text.gameObject, 2f, ()=>{
  41. NotificationServer.notify("hide AlertText");
  42. });
  43. });
  44. }
  45. public void setTimer(float val)
  46. {
  47. slider.value = val;
  48. }
  49. }