Extension.cs 848 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System;
  5. using System.Linq;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using Random = UnityEngine.Random;
  9. public static class Extension
  10. {
  11. #region Regist
  12. public static T AddScript<T>(this Component comp) where T : Component
  13. {
  14. return AddScript<T>(comp.gameObject);
  15. }
  16. public static T AddScript<T>(this GameObject go) where T : Component
  17. {
  18. Component comp = go.AddComponent(typeof(T));
  19. if (comp is Regist)
  20. {
  21. Regist regist = (Regist) comp;
  22. regist.enabled = false;
  23. regist.InitAtOnce();
  24. Initializer.RegistList.Add(regist);
  25. return (T) comp;
  26. }
  27. else
  28. {
  29. throw new Exception();
  30. }
  31. }
  32. #endregion
  33. }