Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. namespace MaterialUI
  6. {
  7.     [ExecuteInEditMode]
  8.     public class ToastManager : MonoBehaviour
  9.     {
  10.         private static ToastManager _instance;
  11.  
  12.         public static ToastManager instance
  13.         {
  14.             get
  15.             {
  16.                 if (_instance == null)
  17.                 {
  18.                     GameObject go = new GameObject();
  19.                     _instance = go.AddComponent<ToastManager>();
  20.                     go.name = "ToastManager";
  21.                 }
  22.  
  23.                 return _instance;
  24.             }
  25.         }
  26.  
  27.         static GameObject theToast;
  28.         public static string toastText;
  29.         public static float toastDuration;
  30.         public static Color toastPanelColor;
  31.         public static Color toastTextColor;
  32.         public static int toastFontSize;
  33.         public static Canvas parentCanvas;
  34.  
  35.         void Awake()
  36.         {
  37.             _instance = this;
  38.  
  39.             if (!theToast)
  40.                 InitToastSystem(GetComponentInParent<Canvas>());
  41.         }
  42.  
  43.         void OnCreate()
  44.         {
  45.             if (GetComponentInParent<Canvas>())
  46.                 InitToastSystem(GetComponentInParent<Canvas>());
  47.             else
  48.                 Debug.LogWarning("Please put ToastManager under a canvas!");
  49.         }
  50.  
  51.         public static void InitToastSystem(Canvas theCanvas)
  52.         {
  53.             theToast = Resources.Load("Toast", typeof(GameObject)) as GameObject;
  54.             parentCanvas = theCanvas;
  55.         }
  56.  
  57.         public void InstanceShow(string content)
  58.         {
  59.             Show(content);
  60.         }
  61.  
  62.         public static void Show(string content)
  63.         {
  64.             toastText = content;
  65.             toastDuration = 2f;
  66.             toastPanelColor = Color.white;
  67.             toastTextColor = Color.black;
  68.             toastFontSize = 16;
  69.             Instantiate(theToast);
  70.         }
  71.  
  72.         public static void Show(string content, float duration)
  73.         {
  74.             toastText = content;
  75.             toastDuration = duration;
  76.             toastPanelColor = Color.white;
  77.             toastTextColor = Color.black;
  78.             toastFontSize = 16;
  79.             Instantiate(theToast);
  80.         }
  81.  
  82.         public static void Show(string content, float duration, Color panelColor, Color textColor, int fontSize)
  83.         {
  84.             toastText = content;
  85.             toastDuration = duration;
  86.             toastPanelColor = panelColor;
  87.             toastTextColor = textColor;
  88.             toastFontSize = fontSize;
  89.             Instantiate(theToast);
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement