MenuItemScript.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace MagicaCloth
  8. {
  9. /// <summary>
  10. /// メニューアイテム
  11. /// </summary>
  12. public class MenuItemScript
  13. {
  14. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Virtual Deformer", priority = 0)]
  15. static void AddMergeDeformer()
  16. {
  17. var obj = AddObject("Magica Virtual Deformer", true);
  18. obj.AddComponent<MagicaVirtualDeformer>();
  19. Selection.activeGameObject = obj;
  20. }
  21. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Bone Cloth", priority = 0)]
  22. static void AddBoneCloth()
  23. {
  24. var obj = AddObject("Magica Bone Cloth", true);
  25. obj.AddComponent<MagicaBoneCloth>();
  26. Selection.activeGameObject = obj;
  27. }
  28. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Bone Spring", priority = 0)]
  29. static void AddBoneSpring()
  30. {
  31. var obj = AddObject("Magica Bone Spring", true);
  32. obj.AddComponent<MagicaBoneSpring>();
  33. Selection.activeGameObject = obj;
  34. }
  35. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Mesh Cloth", priority = 0)]
  36. static void AddMeshCloth()
  37. {
  38. var obj = AddObject("Magica Mesh Cloth", true);
  39. obj.AddComponent<MagicaMeshCloth>();
  40. Selection.activeGameObject = obj;
  41. }
  42. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Mesh Spring", priority = 0)]
  43. static void AddMeshSpring()
  44. {
  45. var obj = AddObject("Magica Mesh Spring", true);
  46. obj.AddComponent<MagicaMeshSpring>();
  47. Selection.activeGameObject = obj;
  48. }
  49. /*[MenuItem("GameObject/Create Other/Magica Cloth/Merge Mesh Deformer", priority = 100)]
  50. static void AddMergeMeshDeformer()
  51. {
  52. var obj = AddObject("Merge Mesh Deformer", false);
  53. obj.AddComponent<MergeMeshDeformer>();
  54. Selection.activeGameObject = obj;
  55. }*/
  56. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Sphere Collider", priority = 200)]
  57. static void AddSphereCollider()
  58. {
  59. var obj = AddObject("Magica Sphere Collider", true, true);
  60. obj.AddComponent<MagicaSphereCollider>();
  61. Selection.activeGameObject = obj;
  62. }
  63. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Capsule Collider", priority = 200)]
  64. static void AddCapsuleCollider()
  65. {
  66. var obj = AddObject("Magica Capsule Collider", true, true);
  67. obj.AddComponent<MagicaCapsuleCollider>();
  68. Selection.activeGameObject = obj;
  69. }
  70. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Plane Collider", priority = 200)]
  71. static void AddPlaneCollider()
  72. {
  73. var obj = AddObject("Magica Plane Collider", true, true);
  74. obj.AddComponent<MagicaPlaneCollider>();
  75. Selection.activeGameObject = obj;
  76. }
  77. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Directional Wind", priority = 200)]
  78. static void AddDirectionalWind()
  79. {
  80. var obj = AddObject("Magica Directional Wind", true);
  81. obj.AddComponent<MagicaDirectionalWind>();
  82. Selection.activeGameObject = obj;
  83. }
  84. [MenuItem("GameObject/Create Other/Magica Cloth/Magica Area Wind", priority = 200)]
  85. static void AddAreaWind()
  86. {
  87. var obj = AddObject("Magica Area Wind", true);
  88. obj.AddComponent<MagicaAreaWind>();
  89. Selection.activeGameObject = obj;
  90. }
  91. //=========================================================================================
  92. /// <summary>
  93. /// ヒエラルキーにオブジェクトを1つ追加する
  94. /// </summary>
  95. /// <param name="objName"></param>
  96. /// <returns></returns>
  97. static GameObject AddObject(string objName, bool addParentName, bool autoScale = false)
  98. {
  99. var parent = Selection.activeGameObject;
  100. GameObject obj = new GameObject(addParentName && parent ? objName + " (" + parent.name + ")" : objName);
  101. if (parent)
  102. {
  103. obj.transform.parent = parent.transform;
  104. }
  105. obj.transform.localPosition = Vector3.zero;
  106. obj.transform.localRotation = Quaternion.identity;
  107. if (autoScale && parent)
  108. {
  109. var scl = parent.transform.lossyScale;
  110. obj.transform.localScale = new Vector3(1.0f / scl.x, 1.0f / scl.y, 1.0f / scl.z);
  111. }
  112. else
  113. obj.transform.localScale = Vector3.one;
  114. return obj;
  115. }
  116. //=========================================================================================
  117. [MenuItem("Assets/Magica Cloth/Clean up sub-assets", priority = 201)]
  118. static void CleanUpSubAssets()
  119. {
  120. try
  121. {
  122. Debug.Log("Clean up MagicaCloth sub-asssets.");
  123. if (Selection.activeGameObject == null)
  124. throw new Exception("No Object");
  125. var obj = Selection.activeGameObject;
  126. //Debug.Log(obj.name);
  127. // プレハブ判定
  128. if (PrefabUtility.IsPartOfAnyPrefab(obj) == false || PrefabUtility.IsPartOfPrefabAsset(obj) == false)
  129. throw new Exception("No Prefab");
  130. // クリーンアップ
  131. ShareDataPrefabExtension.CleanUpSubAssets(obj);
  132. Debug.Log("Complete.");
  133. }
  134. catch
  135. {
  136. Debug.LogWarning("Run it against the Prefab in the Project window.");
  137. }
  138. }
  139. }
  140. }