void Awake() { MonoScript ms = MonoScript.FromScriptableObject(this); var m_ScriptFilePath = AssetDatabase.GetAssetPath(ms); var m_ScriptFolder = Path.GetDirectoryName(m_ScriptFilePath); //将skin从resources目录下移动到editor下 if (EditorGUIUtility.isProSkin) { skin = AssetDatabase.LoadAssetAtPath <GUISkin>(m_ScriptFolder + "/UIControlDataSkinPro.guiskin"); } else { skin = AssetDatabase.LoadAssetAtPath <GUISkin>(m_ScriptFolder + "/UIControlDataSkinPersonal.guiskin"); } if (popupAlignLeft == null) { popupAlignLeft = new GUIStyle("Popup"); popupAlignLeft.alignment = TextAnchor.MiddleLeft; } allTypeNames = UIControlData.GetAllTypeNames(); allTypes = UIControlData.GetAllTypes(); }
void Awake() { if (skin == null) { if (EditorGUIUtility.isProSkin) { skin = Resources.Load("UIControlDataSkinPro") as GUISkin; } else { skin = Resources.Load("UIControlDataSkinPersonal") as GUISkin; } } if (popupAlignLeft == null) { popupAlignLeft = new GUIStyle("Popup"); popupAlignLeft.alignment = TextAnchor.MiddleLeft; } allTypeNames = UIControlData.GetAllTypeNames(); allTypes = UIControlData.GetAllTypes(); }
public override void OnInspectorGUI() { if (skin == null || skin.customStyles == null || skin.customStyles.Length == 0) { base.OnInspectorGUI(); return; } UIControlData data = target as UIControlData; if (data.ctrlItemDatas == null) { data.ctrlItemDatas = new List <CtrlItemData>(); } if (data.subUIItemDatas == null) { data.subUIItemDatas = new List <SubUIItemData>(); } _ctrlItemDatas = data.ctrlItemDatas; _subUIItemDatas = data.subUIItemDatas; CheckDrawers(); EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); // 绘制控件绑定 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("控件绑定", skin.customStyles[0]); if (_ctrlItemDrawers.Count == 0) { if (GUILayout.Button("+", EditorStyles.miniButton)) { AddControlAfter(-1); Repaint(); return; } } EditorGUILayout.EndHorizontal(); foreach (var drawer in _ctrlItemDrawers) { GUILayout.Space(10f); if (!drawer.Draw()) { Repaint(); return; } GUILayout.Space(10f); } GUILayout.Space(10f); // 绘制子UI EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("子UI绑定", skin.customStyles[0]); if (_subUIItemDrawers.Count == 0) { if (GUILayout.Button("+", EditorStyles.miniButton)) { AddSubUIAfter(-1); Repaint(); return; } } EditorGUILayout.EndHorizontal(); foreach (var drawer in _subUIItemDrawers) { GUILayout.Space(10f); if (!drawer.Draw()) { Repaint(); return; } GUILayout.Space(10f); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); this.Repaint(); }
/// <summary> /// 解除指定UI及其子节点自动绑定字段的引用 /// </summary> /// <param name="uiGo"></param> public static void UnBindUI(GameObject uiGo) { if (uiGo == null) { return; } #if DEBUG_LOG float time = Time.realtimeSinceStartup; Profiler.BeginSample("UnBindUI"); #endif uiGo.GetComponentsInChildren(true, s_tmpControlDataForUnbind); for (int i = 0, imax = s_tmpControlDataForUnbind.Count; i < imax; i++) { UIControlData controlData = s_tmpControlDataForUnbind[i]; if (controlData.bindUIRefs == null) { continue; } List <WeakReference <IBindableUI> > bindUIRefs = controlData.bindUIRefs; for (int j = 0, jmax = bindUIRefs.Count; j < jmax; j++) { WeakReference <IBindableUI> bindUIRef = bindUIRefs[j]; IBindableUI bindUI; if (!bindUIRef.TryGetTarget(out bindUI)) { continue; } LuaViewRunner luaViewRunner = bindUI as LuaViewRunner; if (luaViewRunner == null) { UIFieldsInfo fieldInfos = GetUIFieldsInfo(bindUI.GetType()); var controls = fieldInfos.controls; for (int k = 0, kmax = controls.Count; k < kmax; k++) { controls[k].SetValue(bindUI, null); } var subUIs = fieldInfos.subUIs; for (int k = 0, kmax = subUIs.Count; k < kmax; k++) { subUIs[k].SetValue(bindUI, null); } } else { LuaTable luaTable = luaViewRunner.luaUI; if (luaTable == null) { continue; } List <CtrlItemData> ctrlItemData = controlData.ctrlItemDatas; for (int k = 0, kmax = ctrlItemData.Count; k < kmax; k++) { CtrlItemData itemData = ctrlItemData[k]; luaTable.Set <string, object>(itemData.name, null); } List <SubUIItemData> subUIItemDatas = controlData.subUIItemDatas; for (int k = 0, kmax = subUIItemDatas.Count; k < kmax; k++) { SubUIItemData subUIItemData = subUIItemDatas[k]; luaTable.Set <string, object>(subUIItemData.name, null); } } } controlData.bindUIRefs = null; } s_tmpControlDataForUnbind.Clear(); #if DEBUG_LOG Profiler.EndSample(); float span = Time.realtimeSinceStartup - time; if (span > 0.002f) { Debug.LogWarningFormat("UnBindUI {0} 耗时{1}ms", uiGo.Name, span * 1000f); } #endif }