Guest User

Untitled

a guest
Feb 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public class BaseMonoBehaviour : MonoBehaviour
  2. {
  3. void OnDestroy()
  4. {
  5. foreach (FieldInfo field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
  6. {
  7. Type fieldType = field.FieldType;
  8.  
  9. if (typeof(IList).IsAssignableFrom(fieldType))
  10. {
  11. IList list = field.GetValue(this) as IList;
  12. if (list != null)
  13. {
  14. list.Clear();
  15. }
  16. }
  17.  
  18. if (typeof(IDictionary).IsAssignableFrom(fieldType))
  19. {
  20. IDictionary dictionary = field.GetValue(this) as IDictionary;
  21. if (dictionary != null)
  22. {
  23. dictionary.Clear();
  24. }
  25. }
  26.  
  27. if (!fieldType.IsPrimitive)
  28. {
  29. field.SetValue(this, null);
  30. }
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment