GeneralSimpleUI.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using UnityEngine;
  2. using System.Collections;
  3. using DentedPixel;
  4. public class GeneralSimpleUI : MonoBehaviour {
  5. #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5
  6. public RectTransform button;
  7. void Start () {
  8. Debug.Log("For better examples see the 4.6_Examples folder!");
  9. if(button==null){
  10. Debug.LogError("Button not assigned! Create a new button via Hierarchy->Create->UI->Button. Then assign it to the button variable");
  11. return;
  12. }
  13. // Tweening various values in a block callback style
  14. LeanTween.value(button.gameObject, button.anchoredPosition, new Vector2(200f,100f), 1f ).setOnUpdate(
  15. (Vector2 val)=>{
  16. button.anchoredPosition = val;
  17. }
  18. );
  19. LeanTween.value(gameObject, 1f, 0.5f, 1f ).setOnUpdate(
  20. (float volume)=>{
  21. Debug.Log("volume:"+volume);
  22. }
  23. );
  24. LeanTween.value(gameObject, gameObject.transform.position, gameObject.transform.position + new Vector3(0,1f,0), 1f ).setOnUpdate(
  25. (Vector3 val)=>{
  26. gameObject.transform.position = val;
  27. }
  28. );
  29. LeanTween.value(gameObject, Color.red, Color.green, 1f ).setOnUpdate(
  30. (Color val)=>{
  31. UnityEngine.UI.Image image = (UnityEngine.UI.Image)button.gameObject.GetComponent( typeof(UnityEngine.UI.Image) );
  32. image.color = val;
  33. }
  34. );
  35. // Tweening Using Unity's new Canvas GUI System
  36. LeanTween.move(button, new Vector3(200f,-100f,0f), 1f).setDelay(1f);
  37. LeanTween.rotateAround(button, Vector3.forward, 90f, 1f).setDelay(2f);
  38. LeanTween.scale(button, button.localScale*2f, 1f).setDelay(3f);
  39. LeanTween.rotateAround(button, Vector3.forward, -90f, 1f).setDelay(4f).setEase(LeanTweenType.easeInOutElastic);
  40. }
  41. #else
  42. void Start(){
  43. Debug.LogError("Unity 4.6+ is required to use the new UI");
  44. }
  45. #endif
  46. }