HellFireKoder

SimplePlanes ShowStatusMessageInDesigner

Oct 29th, 2016 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1.     private static Transform UIRoot; // could probably skip caching this...
  2.     private static MonoBehaviour StatusMessage; // The status message script
  3.     private static MethodInfo ShowMessage;
  4.     private static void ShowStatusMessageInDesigner(string Message, float Time = 5.0f)
  5.     {   // you know, it'd be nice if Service Provider's ShowStatusMessage worked in the designer ;) <------ message to Nathan... I don't think he saw it
  6.         if (!UIRoot || !StatusMessage)
  7.         {   // basically, if we don't have both the UI root and status message object, get them both...
  8.             UIRoot = ServiceProvider.Instance.UserInterface.UIRootObject.transform;// this may also be acheived with GameObject.Find("UI Root");
  9.             GameObject StatusMessageGameObject = UIRoot.FindChild("StatusMessage").gameObject;
  10.             MonoBehaviour[] Scripts = StatusMessageGameObject.GetComponents<MonoBehaviour>();
  11.             for (int i = 0; i < Scripts.Length; i++)
  12.             {
  13.                 if (Scripts[i].GetType().Name == "StatusMessageScript")
  14.                 {
  15.                     StatusMessage = Scripts[i];
  16.                     ShowMessage = StatusMessage.GetType().GetMethod("ShowMessage");
  17.                     break;
  18.                 }
  19.             }
  20.         }
  21.         ShowMessage.Invoke(StatusMessage, new object[] { Message, Time });
  22.     }
Add Comment
Please, Sign In to add comment