ObjectGroupFactory.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. namespace O3DWB
  5. {
  6. public static class ObjectGroupFactory
  7. {
  8. #region Public Static Functions
  9. public static ObjectGroup Create(string name, List<string> existingGroupNames)
  10. {
  11. if (!string.IsNullOrEmpty(name)) return CreateNewObjectGroupWithUniqueName(name, existingGroupNames);
  12. else
  13. {
  14. Debug.LogWarning("Null or empty object group names are not allowed. Please specify a valid object group name.");
  15. return null;
  16. }
  17. }
  18. public static ObjectGroup Create(GameObject gameObject, List<string> existingGroupNames)
  19. {
  20. if(gameObject == null || string.IsNullOrEmpty(gameObject.name)) return null;
  21. ObjectGroup newObjectGroup = Octave3DWorldBuilder.ActiveInstance.CreateScriptableObject<ObjectGroup>();
  22. newObjectGroup.Name = UniqueEntityNameGenerator.GenerateUniqueName(gameObject.name, existingGroupNames);
  23. newObjectGroup.GroupObject = gameObject;
  24. return newObjectGroup;
  25. }
  26. #endregion
  27. #region Private Static Functions
  28. private static ObjectGroup CreateNewObjectGroupWithUniqueName(string name, List<string> existingGroupNames)
  29. {
  30. GameObject groupParent = new GameObject();
  31. UndoEx.RegisterCreatedGameObject(groupParent);
  32. ObjectGroup newObjectGroup = Octave3DWorldBuilder.ActiveInstance.CreateScriptableObject<ObjectGroup>();
  33. newObjectGroup.GroupObject = groupParent;
  34. newObjectGroup.Name = UniqueEntityNameGenerator.GenerateUniqueName(name, existingGroupNames);
  35. return newObjectGroup;
  36. }
  37. #endregion
  38. }
  39. }
  40. #endif