├── .gitignore ├── README.md ├── UguiOptimizeEditor.cs └── UguiOptimizeEditor.cs.meta /.gitignore: -------------------------------------------------------------------------------- 1 | *.meta 2 | !*.*.meta -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to use? 2 | Clone this project at your Editor folder. 3 | 4 | ## Feature 5 | * Default disable raycastTarget for Image, Text. 6 | * Default disable rich Text. -------------------------------------------------------------------------------- /UguiOptimizeEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEngine.UI; 4 | using UnityEngine.EventSystems; 5 | 6 | public class UguiOptimizeEditor : MonoBehaviour 7 | { 8 | [MenuItem("GameObject/UI/Image")] 9 | public static void CreatImage() 10 | { 11 | GameObject imageObj = new GameObject("Image", typeof(Image)); 12 | imageObj.GetComponent().raycastTarget = false; 13 | setParent(imageObj); 14 | } 15 | 16 | [MenuItem("GameObject/UI/Text")] 17 | public static void CreatText() 18 | { 19 | GameObject textObj = new GameObject("Text", typeof(Text)); 20 | Text text = textObj.GetComponent(); 21 | text.raycastTarget = false; 22 | text.supportRichText = false; 23 | text.text = "New Text"; 24 | text.color = Color.black; 25 | setParent(textObj); 26 | } 27 | 28 | private static void setParent(GameObject obj) 29 | { 30 | Transform objTransform = obj.transform; 31 | 32 | if (Selection.activeTransform == null || Selection.activeTransform.GetComponent() == null) 33 | { 34 | Canvas canvas = (Canvas)FindObjectOfType(typeof(Canvas)); 35 | GameObject canvasObj = null; 36 | if (canvas == null) 37 | { 38 | canvasObj = new GameObject("Canvas", typeof(Canvas)); 39 | canvasObj.GetComponent().renderMode = RenderMode.ScreenSpaceOverlay; 40 | canvasObj.AddComponent(); 41 | canvasObj.AddComponent(); 42 | checkRootEventSystem(); 43 | } 44 | else 45 | { 46 | canvasObj = canvas.gameObject; 47 | } 48 | 49 | objTransform.SetParent(canvasObj.transform); 50 | } 51 | else 52 | { 53 | objTransform.SetParent(Selection.activeTransform); 54 | } 55 | objTransform.localPosition = Vector2.zero; 56 | objTransform.localScale = Vector2.one; 57 | } 58 | 59 | private static void checkRootEventSystem() 60 | { 61 | GameObject[] rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); 62 | 63 | foreach (GameObject obj in rootObjs) 64 | { 65 | if (obj.GetComponent() != null) 66 | return; 67 | } 68 | GameObject eventSystemObj = new GameObject("EventSystem", typeof(EventSystem)); 69 | eventSystemObj.AddComponent(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /UguiOptimizeEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ef46bc8f4046f641bf28980a2b17e52 3 | timeCreated: 1461496822 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | --------------------------------------------------------------------------------