Object.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.ComponentModel;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. #if !SERVER
  5. using UnityEngine;
  6. #endif
  7. namespace ETModel
  8. {
  9. public abstract class Object: ISupportInitialize, IDisposable
  10. {
  11. #if UNITY_EDITOR
  12. public static GameObject Global
  13. {
  14. get
  15. {
  16. return GameObject.Find("/Global");
  17. }
  18. }
  19. [BsonIgnore]
  20. public GameObject ViewGO { get; }
  21. #endif
  22. public Object()
  23. {
  24. #if UNITY_EDITOR
  25. if (!this.GetType().IsDefined(typeof (HideInHierarchy), true))
  26. {
  27. this.ViewGO = new GameObject();
  28. this.ViewGO.name = this.GetType().Name;
  29. this.ViewGO.layer = LayerMask.NameToLayer("Hidden");
  30. this.ViewGO.transform.SetParent(Global.transform, false);
  31. this.ViewGO.AddComponent<ComponentView>().Component = this;
  32. }
  33. #endif
  34. }
  35. public virtual void BeginInit()
  36. {
  37. }
  38. public virtual void EndInit()
  39. {
  40. }
  41. public virtual void Dispose()
  42. {
  43. #if UNITY_EDITOR
  44. if (this.ViewGO != null)
  45. {
  46. UnityEngine.Object.Destroy(this.ViewGO);
  47. }
  48. #endif
  49. }
  50. }
  51. }