Пример #1
0
        public static void AddImage(string tType)
        {
            GameObject tGameObject = Selection.activeGameObject;

            if (tGameObject == null)
            {
                return;
            }

            if (WillLosePrefab(tGameObject) == false)
            {
                return;
            }

            Undo.RecordObject(tGameObject, "Add a child UI Image");                     // アンドウバッファに登録

            string tName = "Image";

            if (string.IsNullOrEmpty(tType) == false)
            {
                tName = tType;
            }

            GameObject tChild = new GameObject(tName, typeof(RectTransform));

            Transform tTransform = tChild.transform;

            tTransform.SetParent(tGameObject.transform, false);
            tTransform.localPosition = Vector3.zero;
            tTransform.localRotation = Quaternion.identity;
            tTransform.localScale    = Vector3.one;

            UIImage tImage = tChild.AddComponent <UIImage>();

            tImage.SetDefault(tType);

            Selection.activeGameObject = tChild;

            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
        }