Skip to content

Commit

Permalink
BUG修复以及合并v1.0.1归纳为v1.0.0版本
Browse files Browse the repository at this point in the history
  • Loading branch information
Avalon712 committed Jun 27, 2024
1 parent f66118a commit 63eabd0
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@
1. 优化VMTable,UI更新的复杂度为O(1)常数级;
2. VueConfig继承自ScriptableObject;
3. 优化LoopList、LoopGrid、ClampList组件的Item数据绑定逻辑;
4. 支持为ViewObject(GameObject)生成UIEvent、路由事件、模型数据绑定,无需再构建视图后才能进行绑定,这部分API见**ViewUtil**类;
4. 支持为ViewObject(GameObject)生成UIEvent、路由事件、模型数据绑定,无需再构建视图后才能进行绑定,这部分API见**ViewUtil**类;



**#2024/6/27修复BUG**

1. 当ViewConfig的视图名称与文件名称不一致时导致错误的视图构建;



**#2024/6/27将版本v1.0.1合并为v1.0.0**
13 changes: 13 additions & 0 deletions UniVue/Runtime/Utils/ViewUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public static void BindModel<T>(GameObject viewObject, T model, bool allowUIUpda
/// <param name="exclued">要排除的GameObject</param>
public static void Patch3Pass(GameObject viewObject, IBindableModel model, params GameObject[] exclued)
{
#if UNITY_EDITOR
if (Vue.Updater.Table.ContainsViewName(viewObject.name))
{
LogUtil.Warning($"表中已经存在了一个相同名称{viewObject.name}的ViewObject,这可能将导致错误的结果,你应该确保viewName的唯一性");
}
#endif

List<ValueTuple<Component, UIType>> uis = ComponentFindUtil.FindAllSpecialUIComponents(viewObject, null, exclued);

//1. 构建UIEvent
Expand All @@ -130,6 +137,12 @@ public static void Patch3Pass(GameObject viewObject, IBindableModel model, param
/// <param name="exclued">要排除的GameObject</param>
public static void Patch2Pass(GameObject viewObject, params GameObject[] exclued)
{
#if UNITY_EDITOR
if (Vue.Updater.Table.ContainsViewName(viewObject.name))
{
LogUtil.Warning($"表中已经存在了一个相同名称{viewObject.name}的ViewObject,这可能将导致错误的结果,你应该确保viewName的唯一性");
}
#endif
List<ValueTuple<Component, UIType>> uis = ComponentFindUtil.FindAllSpecialUIComponents(viewObject, null, exclued);

//1. 构建UIEvent
Expand Down
10 changes: 7 additions & 3 deletions UniVue/Runtime/View/ViewBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ private static void KeepNested(ViewConfig viewConfig)
if (viewConfig == null || nestedViews == null || nestedViews.Length == 0)
return;

BaseView view = Vue.Router.GetView(viewConfig.name) as BaseView;
BaseView view = Vue.Router.GetView(viewConfig.viewName) as BaseView;
view.nestedViews = new IView[nestedViews.Length];
for (int i = 0; i < nestedViews.Length; i++)
{
view.nestedViews[i] = Vue.Router.GetView(nestedViews[i].name);
view.nestedViews[i] = Vue.Router.GetView(nestedViews[i].viewName);
KeepNested(nestedViews[i]);
}
}
Expand All @@ -125,7 +125,11 @@ private static void FindNestedViewObject(List<ValueTuple<ViewConfig, GameObject,
{
for (int j = 0; j < nestedViews.Length; j++)
{
GameObject viewObject = GameObjectFindUtil.BreadthFind(nestedViews[j].name, roots[i].Item2);
GameObject viewObject = GameObjectFindUtil.BreadthFind(nestedViews[j].viewName, roots[i].Item2);
#if UNITY_EDITOR
if (viewObject == null)
LogUtil.Warning($"未能在{roots[i].Item1.viewName}的ViewObject下找到名为{nestedViews[j].viewName}的嵌套视图的ViewObject");
#endif
roots.Add((nestedViews[j], viewObject, level + 1));
}
}
Expand Down
7 changes: 2 additions & 5 deletions UniVue/Runtime/View/Views/Widgets/ClampList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void BindList(IObservableList observer)
if (_models != null || _observer != null) { return; }
_observer = observer;
BindListeners();
//创建Item
CreateItemViews();
Refresh();
}

/// <summary>
Expand Down Expand Up @@ -118,8 +118,8 @@ public void BindList<T>(List<T> data) where T : IBindableModel
_models = new List<IBindableModel>(data.Count);
ListUtil.Copy(_models, data);

//创建Item
CreateItemViews();
Refresh();
}

/// <summary>
Expand Down Expand Up @@ -218,14 +218,11 @@ private void CreateItemViews()
GameObject firstItem = _content.GetChild(0).gameObject;

int count = Count;
if (count > 0)
ViewUtil.Patch3Pass(firstItem, this[0]);

for (int i = 1; i < count; i++)
{
GameObject itemViewObject = PrefabCloneUtil.RectTransformClone(firstItem, _content);
itemViewObject.name += i;
ViewUtil.Patch3Pass(itemViewObject, this[i]);
}
}

Expand Down
6 changes: 5 additions & 1 deletion UniVue/Runtime/ViewModel/VMTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public void Unbind(IBindableModel model)
bundles[j].Unbind();
}

public bool ContainsViewName(string viewName)
{
return _views.ContainsKey(viewName);
}

private void RemoveBindView(string viewName, IBindableModel model)
{
Expand All @@ -155,7 +159,7 @@ private void AddBindView(string viewName, IBindableModel model)
_models.Add(model, new List<string>(1) { viewName });
}

public void ClearTable()
internal void ClearTable()
{
_models.Clear();
_views.Clear();
Expand Down
32 changes: 32 additions & 0 deletions UniVue/Runtime/Vue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public static void Initialize(VueConfig config)
_router = new ViewRouter();
_updater = new ViewUpdater();
_initialized = true;

#if UNITY_EDITOR
UnityEditor.EditorApplication.playModeStateChanged += (mode) =>
{
if (mode == UnityEditor.PlayModeStateChange.ExitingPlayMode)
{
Dispose();
}
};
#endif
}
}

Expand Down Expand Up @@ -135,5 +145,27 @@ private static void CheckInitialize()
{
if (!_initialized) { throw new Exception("Vue尚未进行初始化操作!"); }
}


#if UNITY_EDITOR
/// <summary>
/// 仅在Editor模式下执行
/// </summary>
/// <remarks>Help GC</remarks>
private static void Dispose()
{
CheckInitialize();

_router.UnloadAllViews();
_updater.ClearBundles();
_event.SignoutAll();
_event.UnregisterAllUIEvents();
_router = null;
_updater = null;
_event = null;
_initialized = false;
}
#endif

}
}

0 comments on commit 63eabd0

Please sign in to comment.