ObjectGroup.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. namespace O3DWB
  4. {
  5. public class ObjectGroup : ScriptableObject, INamedEntity
  6. {
  7. #region Private Variables
  8. [SerializeField]
  9. private string _name;
  10. [SerializeField]
  11. private GameObject _groupObject;
  12. [SerializeField]
  13. private ObjectGroupView _view;
  14. #endregion
  15. #region Public Properties
  16. public string Name
  17. {
  18. get { return _name; }
  19. set
  20. {
  21. if (!string.IsNullOrEmpty(value))
  22. {
  23. _name = value;
  24. if (_groupObject != null) _groupObject.name = value;
  25. }
  26. }
  27. }
  28. public GameObject GroupObject
  29. {
  30. get
  31. {
  32. // Note: This seems like the best place to ensure that the object's name is
  33. // the same as the group name. Names can differ when the user changes
  34. // the name via the GUI and then performs and Undo. Another solution
  35. // would be to capture the Undo event and adjust the name there.
  36. if (_groupObject != null && _groupObject.name != _name) _groupObject.name = _name;
  37. return _groupObject;
  38. }
  39. set
  40. {
  41. if (value != null)
  42. {
  43. _groupObject = value;
  44. _name = _groupObject.name;
  45. }
  46. }
  47. }
  48. public ObjectGroupView View { get { return _view; } }
  49. #endregion
  50. #region Constructors
  51. public ObjectGroup()
  52. {
  53. _view = new ObjectGroupView(this);
  54. }
  55. #endregion
  56. }
  57. }
  58. #endif