MenuItemYIUIAllPopupView.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace YIUIFramework.Editor
  4. {
  5. public static class MenuItemYIUIAllPopupView
  6. {
  7. [MenuItem("GameObject/YIUI/Create UIAllPopupView", false, 5)]
  8. static void CreateYIUIAllViewByGameObject()
  9. {
  10. var activeObject = Selection.activeObject as GameObject;
  11. if (activeObject == null)
  12. {
  13. UnityTipsHelper.ShowError($"请选择一个目标");
  14. return;
  15. }
  16. var uiBindCDETable = activeObject.GetComponent<UIBindCDETable>();
  17. if (uiBindCDETable == null)
  18. {
  19. UnityTipsHelper.ShowError($"请选择一个UIBindCDETable组件的GameObject");
  20. return;
  21. }
  22. if (uiBindCDETable.UICodeType != EUICodeType.Panel)
  23. {
  24. UnityTipsHelper.ShowError($"请选择一个面板类型的UIBindCDETable组件的GameObject");
  25. return;
  26. }
  27. if (uiBindCDETable.PanelSplitData.AllPopupViewParent != null)
  28. {
  29. UnityTipsHelper.ShowError($"该面板已经创建过AllPopupView");
  30. return;
  31. }
  32. Selection.activeObject = CreateYIUIAllPopupView(uiBindCDETable);
  33. }
  34. public static GameObject CreateYIUIAllPopupView(UIBindCDETable panelCdeTable )
  35. {
  36. var allViewObject = new GameObject();
  37. allViewObject.name = YIUIConstHelper.Const.UIAllPopupViewParentName;
  38. var viewRect = allViewObject.GetOrAddComponent<RectTransform>();
  39. allViewObject.GetOrAddComponent<CanvasRenderer>();
  40. viewRect.SetParent(panelCdeTable.transform, false);
  41. viewRect.ResetToFullScreen();
  42. allViewObject.SetLayerRecursively(LayerMask.NameToLayer("UI"));
  43. panelCdeTable.PanelSplitData.AllPopupViewParent = viewRect;
  44. panelCdeTable.PanelSplitData.AllPopupView.Clear();
  45. EditorUtility.SetDirty(panelCdeTable);
  46. return allViewObject;
  47. }
  48. }
  49. }