No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ItemCreationUtility.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Purchasing
  4. {
  5. /// <summary>
  6. /// This code is taken from the com.unity.2d.sprite@1.0.0 package
  7. /// </summary>
  8. static class ItemCreationUtility
  9. {
  10. internal static GameObject CreateGameObject(string name)
  11. {
  12. var parent = Selection.activeGameObject;
  13. var newGameObject = ObjectFactory.CreateGameObject(name);
  14. CreateGameObject(name, newGameObject, parent);
  15. return newGameObject;
  16. }
  17. internal static GameObject CreateGameObject(string name, params Type[] components)
  18. {
  19. var parent = Selection.activeGameObject;
  20. var newGameObject = ObjectFactory.CreateGameObject(name, components);
  21. CreateGameObject(name, newGameObject, parent);
  22. return newGameObject;
  23. }
  24. static void CreateGameObject(string name, GameObject newGameObject, GameObject parent)
  25. {
  26. newGameObject.name = name;
  27. Selection.activeObject = newGameObject;
  28. GOCreationCommands.Place(newGameObject, parent);
  29. if (EditorSettings.defaultBehaviorMode == EditorBehaviorMode.Mode2D)
  30. {
  31. var position = newGameObject.transform.position;
  32. position.z = 0;
  33. newGameObject.transform.position = position;
  34. }
  35. Undo.RegisterCreatedObjectUndo(newGameObject, string.Format("Create {0}", name));
  36. }
  37. }
  38. }