CreateLocatorHere.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //CreateLocatorHere.cs
  2. //
  3. //Original Script is here (JavaScript):
  4. //http://answers.unity3d.com/questions/7755/how-do-i-create-a-new-object-in-the-editor-as-a-ch.html
  5. //
  6. //CS Version made by N.Kobayashi 2014/06/14
  7. //
  8. using UnityEngine;
  9. using System.Collections;
  10. using UnityEditor;
  11. namespace UnityChan
  12. {
  13. public class CreateLocatorHere
  14. {
  15. // Add menu to the main menu
  16. [MenuItem("GameObject/Create Locator Here")]
  17. static void CreateGameObjectAsChild ()
  18. {
  19. GameObject go = new GameObject ("Locator_");
  20. go.transform.parent = Selection.activeTransform;
  21. go.transform.localPosition = Vector3.zero;
  22. }
  23. // The item will be disabled if no transform is selected.
  24. [MenuItem("GameObject/Create Locator Here",true)]
  25. static bool ValidateCreateGameObjectAsChild ()
  26. {
  27. return Selection.activeTransform != null;
  28. }
  29. // Add context menu to Transform's context menu
  30. [MenuItem("CONTEXT/Transform/Create Locator Here")]
  31. static void CreateGameObjectAsChild (MenuCommand command)
  32. {
  33. Transform tr = (Transform)command.context;
  34. GameObject go = new GameObject ("Locator_");
  35. go.transform.parent = tr;
  36. go.transform.localPosition = Vector3.zero;
  37. }
  38. }
  39. }