예제 #1
0
 public override void OnInspectorGUI()
 {
     if (_isUIPrefab)
     {
         GameObject prefab = target as GameObject;
         if (!prefab)
         {
             return;
         }
         GUILayout.Label("UI Style: " + AssetDatabase.GetAssetPath(prefab));
         RectTransform rt = prefab.transform as RectTransform;
         if (rt != null)
         {
             Rect r = rt.rect;
             GUILayout.Label("Size:  " + r.width + ":" + r.height);
         }
         UIType ut = UIPrefabUtility.GetUIType(prefab);
         EditorGUI.BeginChangeCheck();
         ut = (UIType)EditorGUILayout.EnumPopup("Type:", ut);
         if (EditorGUI.EndChangeCheck())
         {
             UIPrefabUtility.SetUIType(prefab, ut);
         }
         bool enabled = UIPrefabUtility.GetUIModifactionProperty <bool>(prefab, UIUtiltiy.UI_ENABLE);
         EditorGUI.BeginChangeCheck();
         enabled = EditorGUILayout.Toggle("Enable:", enabled);
         if (EditorGUI.EndChangeCheck())
         {
             UIPrefabUtility.SetUIModitionProperty(prefab, UIUtiltiy.UI_ENABLE, enabled);
         }
     }
 }
        internal void OnGUI()
        {
            UIType ut = UIPrefabUtility.GetUIType(prefab);

            GUILayout.Space(5);
            GUILayout.TextArea("this is Very important to pick the type of the UI Style for further usage",
                               GUILayout.Height(50));
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Type:", GUILayout.MaxWidth(60));
            EditorGUI.BeginChangeCheck();
            ut = (UIType)EditorGUILayout.EnumPopup("", ut, GUILayout.MaxWidth(160));
            if (EditorGUI.EndChangeCheck())
            {
                errMsg.Clear();
                if (UIPrefabUtility.CheckUIPrefabValidation(prefab, ut, errMsg))
                {
                    string msg = Enum.GetName(typeof(UIType), ut) + " need Component below:\n" +
                                 string.Join(",", errMsg.ToArray());
                    EditorUtility.DisplayDialog("Invalidate Type", msg, "OK");
                    ut = UIType.None;
                    UIPrefabUtility.SetUIModitionProperty(prefab, UIUtiltiy.UI_TYPE, ut);
                }
                else
                {
                    UIPrefabUtility.SetUIModitionProperty(prefab, UIUtiltiy.UI_TYPE, ut);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Apply", GUILayout.MaxWidth(100), GUILayout.Height(20)))
            {
                if (ut == UIType.None)
                {
                    EditorUtility.DisplayDialog("warning", "ui type cannot be none", "ok");
                }
                else
                {
                    UIPrefabUtility.SetUIModitionProperty(prefab, UIUtiltiy.UI_ENABLE, true);
                    AssetDatabase.Refresh();
                    Close();
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
        }