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.

84 lines
3.5 KiB

7 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. using DentedPixel;
  4. public class OldGUIExamplesCS : MonoBehaviour {
  5. public Texture2D grumpy;
  6. public Texture2D beauty;
  7. private float w;
  8. private float h;
  9. private LTRect buttonRect1;
  10. private LTRect buttonRect2;
  11. private LTRect buttonRect3;
  12. private LTRect buttonRect4;
  13. private LTRect grumpyRect;
  14. private LTRect beautyTileRect;
  15. // Use this for initialization
  16. void Start () {
  17. w = Screen.width;
  18. h = Screen.height;
  19. buttonRect1 = new LTRect(0.10f*w, 0.8f*h, 0.2f*w, 0.14f*h );
  20. buttonRect2 = new LTRect(1.2f*w, 0.8f*h, 0.2f*w, 0.14f*h );
  21. buttonRect3 = new LTRect(0.35f*w, 0.0f*h, 0.3f*w, 0.2f*h, 0f );
  22. buttonRect4 = new LTRect(0.0f*w, 0.4f*h, 0.3f*w, 0.2f*h, 1.0f, 15.0f );
  23. grumpyRect = new LTRect(0.5f*w - grumpy.width*0.5f, 0.5f*h - grumpy.height*0.5f, grumpy.width, grumpy.height );
  24. beautyTileRect = new LTRect(0.0f,0.0f,1.0f,1.0f );
  25. LeanTween.move( buttonRect2, new Vector2(0.55f*w, buttonRect2.rect.y), 0.7f ).setEase(LeanTweenType.easeOutQuad);
  26. }
  27. public void catMoved(){
  28. Debug.Log("cat moved...");
  29. }
  30. // Update is called once per frame
  31. void OnGUI () {
  32. GUI.DrawTexture( grumpyRect.rect, grumpy);
  33. Rect staticRect = new Rect(0.0f*w, 0.0f*h, 0.2f*w, 0.14f*h);
  34. if(GUI.Button( staticRect, "Move Cat")){
  35. if(LeanTween.isTweening(grumpyRect)==false){ // Check to see if the cat is already tweening, so it doesn't freak out
  36. Vector2 orig = new Vector2( grumpyRect.rect.x, grumpyRect.rect.y );
  37. LeanTween.move( grumpyRect, new Vector2( 1.0f*Screen.width - grumpy.width, 0.0f*Screen.height ), 1.0f).setEase(LeanTweenType.easeOutBounce).setOnComplete(catMoved);
  38. LeanTween.move( grumpyRect, orig, 1.0f ).setDelay(1.0f).setEase( LeanTweenType.easeOutBounce);
  39. }
  40. }
  41. if(GUI.Button(buttonRect1.rect, "Scale Centered")){
  42. LeanTween.scale( buttonRect1, new Vector2(buttonRect1.rect.width, buttonRect1.rect.height) * 1.2f, 0.25f ).setEase( LeanTweenType.easeOutQuad );
  43. LeanTween.move( buttonRect1, new Vector2(buttonRect1.rect.x-buttonRect1.rect.width*0.1f, buttonRect1.rect.y-buttonRect1.rect.height*0.1f), 0.25f ).setEase(LeanTweenType.easeOutQuad);
  44. }
  45. if(GUI.Button(buttonRect2.rect, "Scale")){
  46. LeanTween.scale( buttonRect2, new Vector2(buttonRect2.rect.width, buttonRect2.rect.height) * 1.2f, 0.25f ).setEase(LeanTweenType.easeOutBounce);
  47. }
  48. staticRect = new Rect(0.76f*w, 0.53f*h, 0.2f*w, 0.14f*h);
  49. if(GUI.Button( staticRect, "Flip Tile")){
  50. LeanTween.move( beautyTileRect, new Vector2( 0f, beautyTileRect.rect.y + 1.0f ), 1.0f ).setEase(LeanTweenType.easeOutBounce);
  51. }
  52. GUI.DrawTextureWithTexCoords( new Rect(0.8f*w, 0.5f*h - beauty.height*0.5f, beauty.width*0.5f, beauty.height*0.5f), beauty, beautyTileRect.rect);
  53. if(GUI.Button(buttonRect3.rect, "Alpha")){
  54. LeanTween.alpha( buttonRect3, 0.0f, 1.0f).setEase(LeanTweenType.easeOutQuad);
  55. LeanTween.alpha( buttonRect3, 1.0f, 1.0f).setDelay(1.0f).setEase( LeanTweenType.easeInQuad);
  56. LeanTween.alpha( grumpyRect, 0.0f, 1.0f).setEase(LeanTweenType.easeOutQuad);
  57. LeanTween.alpha( grumpyRect, 1.0f, 1.0f).setDelay(1.0f).setEase(LeanTweenType.easeInQuad);
  58. }
  59. GUI.color = new Color(1.0f,1.0f,1.0f,1.0f); // Reset to normal alpha, otherwise other gui elements will be effected
  60. if(GUI.Button(buttonRect4.rect, "Rotate")){
  61. LeanTween.rotate( buttonRect4, 150.0f, 1.0f ).setEase(LeanTweenType.easeOutElastic);
  62. LeanTween.rotate( buttonRect4, 0.0f, 1.0f ).setDelay(1.0f).setEase(LeanTweenType.easeOutElastic);
  63. }
  64. GUI.matrix = Matrix4x4.identity;
  65. }
  66. }