Advertisement
uglenXD

GlobalF.cs

Apr 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class GlobalF : MonoBehaviour
  7. {
  8.     public static bool TransitionImages(ref Image activeImage, ref List<Image> allImages, float speed, bool smooth)
  9.     {
  10.         bool anyValueChanged = false;
  11.  
  12.         speed *= Time.deltaTime;
  13.         for (int i = allImages.Count - 1; i >= 0; i--)
  14.         {
  15.             Image image = allImages [i];
  16.             if (image == activeImage)
  17.             {
  18.                 if (image.color.a < 1f)
  19.                 {
  20.                     image.color = SetAlpha (image.color, smooth ? Mathf.Lerp (image.color.a, 1f, speed) : Mathf.MoveTowards (image.color.a, 1f, speed));
  21.                     anyValueChanged = true;
  22.                 }
  23.             }
  24.             else
  25.             {
  26.                 if (image.color.a > 0)
  27.                 {
  28.                     image.color = SetAlpha (image.color, smooth ? Mathf.Lerp (image.color.a, 0f, speed) : Mathf.MoveTowards (image.color.a, 0f, speed));
  29.                     anyValueChanged = true;
  30.                 }
  31.                 else
  32.                 {
  33.                     allImages.RemoveAt (i);
  34.                     DestroyImmediate (image.gameObject);
  35.                     continue;
  36.                 }
  37.             }
  38.         }
  39.  
  40.         return anyValueChanged;
  41.     }
  42.  
  43.     public static bool TransitionRawImages(ref RawImage activeImage, ref List<RawImage> allImages, float speed, bool smooth)
  44.     {
  45.         bool anyValueChanged = false;
  46.  
  47.         speed *= Time.deltaTime;
  48.         for (int i = allImages.Count - 1; i >= 0; i--)
  49.         {
  50.             RawImage image = allImages[i];
  51.             if (image == activeImage)
  52.             {
  53.                 if (image.color.a < 1f)
  54.                 {
  55.                     image.color = SetAlpha(image.color, smooth ? Mathf.Lerp(image.color.a, 1f, speed) : Mathf.MoveTowards(image.color.a, 1f, speed));
  56.                     anyValueChanged = true;
  57.                 }
  58.             }
  59.             else
  60.             {
  61.                 if (image.color.a > 0)
  62.                 {
  63.                     image.color = SetAlpha(image.color, smooth ? Mathf.Lerp(image.color.a, 0f, speed) : Mathf.MoveTowards(image.color.a, 0f, speed));
  64.                     anyValueChanged = true;
  65.                 }
  66.                 else
  67.                 {
  68.                     MovieTexture mov = image.texture as MovieTexture;
  69.                     if (mov != null)
  70.                         mov.Stop();
  71.  
  72.                     allImages.RemoveAt(i);
  73.                     DestroyImmediate(image.gameObject);
  74.                     continue;
  75.                 }
  76.             }
  77.         }
  78.  
  79.         return anyValueChanged;
  80.     }
  81.  
  82.     public static Color SetAlpha(Color color, float alpha)
  83.     {
  84.         return new Color (color.r, color.g, color.b, alpha);
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement