Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.50 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Helper;
  4. public class ZoneScript : BaseGate {
  5.  
  6.    
  7.  
  8.     Color makeTransparent = new Color(0f, 0f, 0f, -0.5f);
  9.  
  10.    
  11.  
  12.     public bool StayActivated = false;
  13.     public float StayActiveTime = 1f;
  14.     float timer = 0f;
  15.  
  16.  
  17.  
  18.     public AnimationCurve Animaton;
  19.  
  20.     public LineRenderer LineR;
  21.     Vector3[] Vertices;
  22.  
  23.    
  24.  
  25.     public Transform Electron;
  26.     float Radius = 2F;
  27.     float minRadius = 2f;
  28.     float maxRadius = 3f;
  29.     Vector2 ElectronPos;
  30.     float ElectronSpeed = 1f;
  31.     float minSpeed = 1f;
  32.     float maxSpeed = 8f;
  33.     float someVelocityThing = 1f;
  34.  
  35.     bool Rising = true;
  36.  
  37.     const float twoPi = Mathf.PI * 2f;
  38.  
  39.     void SwapMyColor()
  40.     {
  41.         myRend.color = Active ? Color.red + makeTransparent : Color.blue + makeTransparent;
  42.     }
  43.  
  44.     SpriteRenderer myRend;
  45.  
  46.  
  47.  
  48.     void Awake()
  49.     {
  50.        
  51.         CheckForReAssignment = false;
  52.         myRend = GetComponent<SpriteRenderer>();
  53.         //ActivationEvent += SwapMyColor;
  54.         //DeActivationEvent += SwapMyColor;
  55.  
  56.         myRend.color = Color.red + makeTransparent;
  57.  
  58.  
  59.         Vertices = new Vector3[128];
  60.         LineR.material = new Material(Shader.Find("Sprites/Default"));
  61.        
  62.        
  63.     }
  64.  
  65.    
  66.  
  67.     void Update()
  68.     {
  69.         someVelocityThing += Time.deltaTime * ElectronSpeed;
  70.         ElectronPos = (Vector2) transform.position + new Vector2(Mathf.Cos(someVelocityThing), Mathf.Sin(someVelocityThing)) * Radius;
  71.         Electron.position = ElectronPos;
  72.        
  73.         if(!StayActivated && Active)
  74.         {
  75.             if(timer < 0.5f)
  76.                 timer += Time.deltaTime;
  77.             else
  78.             {
  79.                 timer = 0.5f;
  80.             }
  81.  
  82.             float val = LerpFunctions.Remap(timer, 0f, 0.5f, 0f, 1f);
  83.             float crvEval = Animaton.Evaluate(val);
  84.             ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
  85.             Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
  86.  
  87.             float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
  88.  
  89.             for (int i = 0; i < 128; ++i)
  90.             {
  91.                 float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
  92.                 Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
  93.             }
  94.  
  95.             LineR.SetPositions(Vertices);
  96.  
  97.         }
  98.         else if(!StayActivated && !Active)
  99.         {
  100.             if(timer > 0f)
  101.             {
  102.                 timer -= Time.deltaTime;
  103.             }
  104.             else
  105.             {
  106.                 timer = 0f;
  107.             }
  108.  
  109.             float val = LerpFunctions.Remap(timer, 0f, 0.5f, 0f, 1f);
  110.             float crvEval = Animaton.Evaluate(val);
  111.             ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
  112.             Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
  113.             float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
  114.  
  115.             for(int i = 0; i < 128; ++i)
  116.             {
  117.                 float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
  118.                 Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
  119.             }
  120.  
  121.             LineR.SetPositions(Vertices);
  122.         }
  123.  
  124.         if(StayActivated && Active && Rising)
  125.         {
  126.             timer += Time.deltaTime;
  127.  
  128.             float val = LerpFunctions.Remap(timer, 0f, StayActiveTime, 0f, 1f);
  129.             float crvEval = Animaton.Evaluate(val);
  130.             ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
  131.             Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
  132.             float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
  133.  
  134.             for (int i = 0; i < 128; ++i)
  135.             {
  136.                 float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
  137.                 Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
  138.             }
  139.  
  140.             LineR.SetPositions(Vertices);
  141.  
  142.             if (timer >= StayActiveTime)
  143.             {
  144.                 Rising = false;
  145.             }
  146.         }
  147.         else if(Active && StayActivated  && !Rising)
  148.         {
  149.             timer -= Time.deltaTime;
  150.  
  151.             float val = LerpFunctions.Remap(timer, 0f, StayActiveTime, 0f, 1f);
  152.             float crvEval = Animaton.Evaluate(val);
  153.             ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
  154.             Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
  155.             float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
  156.  
  157.             for (int i = 0; i < 128; ++i)
  158.             {
  159.                 float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
  160.                 Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
  161.             }
  162.  
  163.             LineR.SetPositions(Vertices);
  164.  
  165.             if (timer <= 0f)
  166.             {
  167.                 timer = 0f;
  168.                 Active = false;
  169.                 Rising = true;
  170.             }
  171.         }
  172.         else if(Rising && StayActivated && !Active && timer == 0f)
  173.         {
  174.             for (int i = 0; i < 128; ++i)
  175.             {
  176.                 float currentTime = someVelocityThing - i * 1f / 128f * 0.2f * twoPi;
  177.                 Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
  178.             }
  179.  
  180.             LineR.SetPositions(Vertices);
  181.         }
  182.        
  183.     }
  184.  
  185.     void OnTriggerEnter2D(Collider2D other)
  186.     {
  187.         if (Sleeping) return;
  188.         if (other.gameObject.layer == Hero.INACTIVE) return;
  189.         if (Active) return;
  190.  
  191.         if (IInteractWith == 0)
  192.         {
  193.             Active = true;
  194.         }
  195.         else
  196.         {
  197.             if ((int)IInteractWith == other.gameObject.layer)
  198.             {
  199.  
  200.                 Active = true;
  201.             }
  202.            
  203.         }
  204.  
  205.        
  206.     }
  207.  
  208.     void OnTriggerExit2D(Collider2D other)
  209.     {
  210.         if (Sleeping) return;
  211.         if (other.gameObject.layer == Hero.INACTIVE) return;
  212.  
  213.         if (StayActivated) return;
  214.         if (IInteractWith == 0)
  215.         {
  216.             Active = false;
  217.         }
  218.         else
  219.         {
  220.             if ((int)IInteractWith == other.gameObject.layer)
  221.             {
  222.  
  223.                 Active = false;
  224.             }
  225.            
  226.            
  227.         }
  228.     }
  229.  
  230.    
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement