UITweener.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UITweener : MonoBehaviour {
  5. public RectTransform mainWindow = null;
  6. public LeanTweenType leanTweenType = LeanTweenType.notUsed;
  7. public float time = .1f;
  8. public float Delaytime = .1f;
  9. private bool isOpen = false;
  10. void Start () {
  11. }
  12. void Open()
  13. {
  14. mainWindow.transform.position = new Vector3(1, 0, 0);
  15. LeanTween.move(mainWindow, Vector3.zero, time).setEase(leanTweenType);
  16. //mainWindow.localScale = Vector3.zero;
  17. //LeanTween.scale(mainWindow, new Vector3(0.001f, 0.001f, 0.001f), time).setEase(leanTweenType).setDelay(Delaytime);
  18. CanvasGroup cg = mainWindow.GetComponent<CanvasGroup>();
  19. cg.alpha = 0;
  20. LeanTween.alphaCanvas(cg, 1f, time).setDelay(Delaytime);
  21. }
  22. void Close()
  23. {
  24. LeanTween.scale(mainWindow, Vector3.zero, 2.6f).setDelay(0.5f).setEase(LeanTweenType.easeInBack);
  25. CanvasGroup cg = mainWindow.GetComponent<CanvasGroup>();
  26. LeanTween.alphaCanvas(cg, 0f, 1f).setDelay(2.5f);
  27. }
  28. // Update is called once per frame
  29. void Update () {
  30. if (Input.GetKeyUp(KeyCode.Space))
  31. {
  32. Open();
  33. }
  34. }
  35. }