概要
using System.Linq; using UnityEditor; using UnityEditor.Presets; using UnityEngine; using UnityEngine.UI; public static class Example { [MenuItem( "GameObject/MyProject/Image", false, 9 )] private static void CreateImage( MenuCommand menuCommand ) { EditorApplication.ExecuteMenuItem( "GameObject/UI/Image" ); var gameObject = Selection.activeGameObject; var parent = menuCommand.context as GameObject; // 親オブジェクトを設定します GameObjectUtility.SetParentAndAlign( gameObject, parent ); } }
- EditorApplication.ExecuteMenuItem を呼び出すだけだと
親オブジェクトが正しく設定されないので
GameObjectUtility.SetParentAndAlign を実行する必要がある
参考サイト様
優化 Unity uGUI 在 Raycast 效能消耗 – A optimizing tip of uGUI raycast