TC_AnimateNode.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TerrainComposer2 {
  4. [ExecuteInEditMode]
  5. public class TC_AnimateNode : MonoBehaviour {
  6. public Vector3 moveSpeed;
  7. public float rotSpeed;
  8. public float scaleSpeed;
  9. public float opacitySpeed;
  10. TC_ItemBehaviour item;
  11. bool refresh;
  12. void Start()
  13. {
  14. item = GetComponent<TC_ItemBehaviour>();
  15. }
  16. #if UNITY_EDITOR
  17. void OnEnable()
  18. {
  19. UnityEditor.EditorApplication.update += MyUpdate;
  20. }
  21. void OnDisable()
  22. {
  23. UnityEditor.EditorApplication.update -= MyUpdate;
  24. }
  25. #endif
  26. void MyUpdate() {
  27. transform.Rotate(0, rotSpeed, 0);
  28. transform.Translate(moveSpeed * 90);
  29. transform.localScale += new Vector3(scaleSpeed, scaleSpeed, scaleSpeed);
  30. if (rotSpeed != 0 || moveSpeed.x != 0 || moveSpeed.y != 0 || moveSpeed.z != 0 || scaleSpeed != 0) refresh = true;
  31. if (opacitySpeed != 0)
  32. {
  33. if (item != null)
  34. {
  35. item.opacity = Mathf.Abs(Mathf.Sin(Time.realtimeSinceStartup * opacitySpeed));
  36. refresh = true;
  37. }
  38. }
  39. if (refresh)
  40. {
  41. TC.repaintNodeWindow = true;
  42. TC.AutoGenerate();
  43. }
  44. }
  45. }
  46. }