using UnityEngine; using System.Collections; using UnityEditor; using UnityEngine.UI; namespace UnityEditor.UI { /// /// This class adds a Menu Item "GameObject/UI/Procedural Image" /// Bahviour of this command is the same as with regular Images /// public class ProceduralImageEditorUtility { [MenuItem("GameObject/UI/Procedural Image")] public static void AddProceduralImage(){ GameObject o = new GameObject (); o.AddComponent (); o.name = "Procedural Image"; if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponentInParent () != null) { o.transform.SetParent (Selection.activeGameObject.transform, false); Selection.activeGameObject = o; } /*else if (Selection.activeGameObject != null) { //selected GameObject is not child of canvas: }*/ else { if(GameObject.FindObjectOfType()==null) { EditorApplication.ExecuteMenuItem("GameObject/UI/Canvas"); } Canvas c = GameObject.FindObjectOfType(); o.transform.SetParent (c.transform, false); Selection.activeGameObject = o; } } /// /// Replaces an Image Component with a Procedural Image Component. /// [MenuItem("CONTEXT/Image/Replace with Procedural Image")] public static void ReplaceWithProceduralImage(MenuCommand command){ Image image = (Image)command.context; GameObject obj = image.gameObject; GameObject.DestroyImmediate (image); obj.AddComponent (); } } }