Example #1
0
        private void AddSubUIAfter(int idx)
        {
            SubUIItemData itemData = new SubUIItemData();

            _subUIItemDatas.Insert(idx + 1, itemData);

            SubUIItemDrawer drawer = new SubUIItemDrawer(this, itemData);

            _subUIItemDrawers.Insert(idx + 1, drawer);
        }
 private int GetSubUIIndex(string name)
 {
     for (int i = 0, imax = subUIItemDatas.Count; i < imax; i++)
     {
         SubUIItemData item = subUIItemDatas[i];
         if (item.name == name)
         {
             return(i);
         }
     }
     return(-1);
 }
        /// <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
        }
Example #4
0
 public SubUIItemDrawer(UIControlDataEditor container, SubUIItemData itemData)
 {
     _container = container;
     _itemData  = itemData;
 }