Advertisement
medvedya

EXAMPLE_createSpriteDeformer

Dec 20th, 2014
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Medvedya.SpriteDeformerTools;
  4.  
  5. public class EXAMPLE_createSpriteDeformer : MonoBehaviour
  6. {
  7.  
  8.     public Sprite sprite;
  9.     public Material material;
  10.     SpriteDeformerStatic mySprite;
  11.     private SpritePoint centerPoint;
  12.     void Start () {
  13.         mySprite = gameObject.AddComponent<SpriteDeformerStatic>();
  14.         mySprite.sprite = sprite;
  15.         mySprite.referenceMaterial = material;
  16.         mySprite.SetRectanglePoints();
  17.  
  18.         centerPoint = new SpritePoint(0.5f, 0.5f);
  19.         mySprite.AddPoint(centerPoint);
  20.        
  21.         Bounds b = mySprite.bounds;
  22.         foreach (var item in mySprite.points)
  23.         {
  24.             b.Encapsulate((Vector3)mySprite.SpritePositionToLocal(item.spritePosition));
  25.         }
  26.         mySprite.bounds = b;
  27.         mySprite.UpdateMeshImmediate();
  28.     }
  29.    
  30.     void Update()
  31.     {
  32.         centerPoint.offset2d =
  33.             new Vector2(Mathf.Cos(Time.time) * 0.3f,
  34.                 Mathf.Sin(Time.time) * 0.3f);
  35.  
  36.         mySprite.dirty_offset = true;
  37.        
  38.         float t = Mathf.PingPong(Time.time,1);
  39.         centerPoint.color = Color.Lerp(Color.blue, Color.red,t);
  40.         mySprite.dirty_color = true;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement