Skip to content

Commit

Permalink
修复ClampList组件无法绑定第一个数据的bug,优化LoopList、LoopGrid组件,修复Transient级别的视图无法关闭…
Browse files Browse the repository at this point in the history
…的bug,修复ConfigEditorWindow无法创建VueConfig的bug
  • Loading branch information
Avalon712 committed Jun 26, 2024
1 parent 4487255 commit 00ab251
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
20 changes: 18 additions & 2 deletions UniVue/Editor/ConfigEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void OnGUI()
private void CreateVueConfigEdit()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("创建的Canvas配置文件的名称");
EditorGUILayout.LabelField("创建的Vue配置文件的名称");
_configFileName = EditorGUILayout.TextField(_configFileName);
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
Expand All @@ -73,7 +73,7 @@ private void CreateVueConfigEdit()

private bool CreateVueConfig()
{
return ConfigBuilderInEditor.CreateViewConfig<VueConfig>(_configFileName, _saveDirectory) != null;
return ConfigBuilderInEditor.CreateVueConfig(_configFileName, _saveDirectory);
}


Expand Down Expand Up @@ -284,6 +284,22 @@ public static void CreateCanvasConfig(string fileName, string directory)
}
}

public static bool CreateVueConfig(string fileName, string directory)
{
string path = $"{directory}{fileName}.asset";
if (!Contains(path, out VueConfig config))
{
config = ScriptableObject.CreateInstance<VueConfig>();
AssetDatabase.CreateAsset(config, path);
return true;
}
else
{
Debug.LogWarning($"路径{directory}下已经存在一个同名{fileName}的资产!");
}
return false;
}

public static V CreateViewConfig<V>(string fileName, string directory) where V : ScriptableObject
{
string path = $"{directory}{fileName}.asset";
Expand Down
24 changes: 13 additions & 11 deletions UniVue/Runtime/View/ViewBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,26 @@ private static void KeepNested(ViewConfig viewConfig)
/// </summary>
private static void FindNestedViewObject(List<ValueTuple<ViewConfig, GameObject, int>> roots, int level)
{
int before = roots.Count;
for (int i = 0; i < roots.Count; i++)
{
if (roots[i].Item3 != level) { continue; }

ViewConfig config = roots[i].Item1;
ViewConfig[] nestedViews = config.nestedViews;
if (nestedViews != null)
if (roots[i].Item3 == level)
{
for (int j = 0; j < nestedViews.Length; j++)
ViewConfig config = roots[i].Item1;
ViewConfig[] nestedViews = config.nestedViews;
if (nestedViews != null)
{
GameObject viewObject = GameObjectFindUtil.BreadthFind(nestedViews[j].name, roots[i].Item2);
roots.Add((nestedViews[j], viewObject, level + 1));

if (nestedViews[j].nestedViews != null)
FindNestedViewObject(roots, level + 1);
for (int j = 0; j < nestedViews.Length; j++)
{
GameObject viewObject = GameObjectFindUtil.BreadthFind(nestedViews[j].name, roots[i].Item2);
roots.Add((nestedViews[j], viewObject, level + 1));
}
}
}
}

if(before < roots.Count)
FindNestedViewObject(roots, level + 1);
}

}
Expand Down
2 changes: 1 addition & 1 deletion UniVue/Runtime/View/Views/BaseView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public virtual void Open()

if (level == ViewLevel.Transient)
{
TweenBehavior.Timer(Close).Delay(transientTime);
TweenBehavior.Timer(() => Vue.Router.Close(name)).Delay(transientTime);
}
}

Expand Down
4 changes: 1 addition & 3 deletions UniVue/Runtime/View/Views/ClampListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public sealed class ClampListView : BaseView
public ClampListView(ClampList comp, GameObject viewObject, string viewName = null, ViewLevel level = ViewLevel.Common) : base(viewObject, viewName, level)
{
_comp = comp;
BindEvent(comp.Content.gameObject);
}


public override void OnLoad()
{

BindEvent(_comp.Content.gameObject);
}

public override void OnUnload()
Expand Down
18 changes: 12 additions & 6 deletions UniVue/Runtime/View/Views/Widgets/ClampList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine.UI;
using UniVue.Model;
using UniVue.Utils;
using UniVue.ViewModel;

namespace UniVue.View.Widgets
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public ClampList(Transform content)

#if UNITY_EDITOR
if (content.GetComponent<LayoutGroup>() == null)
LogUtil.Warning("建议在显示Item的父物体上挂载一个Unity自带的布局组件!ClampList组件不会自动进行布局!");
LogUtil.Warning($"建议在显示Item的父物体{content.name}上挂载一个Unity自带的布局组件! ClampList组件不会自动进行布局!");
#endif

_content = content;
Expand Down Expand Up @@ -168,7 +169,7 @@ public void AddData<T>(T newData) where T : IBindableModel
if (!itemObj.activeSelf)
{
itemObj.SetActive(true);
Rebind(itemObj.name, newData);
Rebind(itemObj, newData);
instance = false;
break;
}
Expand All @@ -178,7 +179,7 @@ public void AddData<T>(T newData) where T : IBindableModel
{
GameObject itemViewObject = CreatItemView();
itemViewObject.SetActive(true);
ViewUtil.Patch3Pass(itemViewObject, newData);
Rebind(itemViewObject, newData);
}
}

Expand Down Expand Up @@ -207,7 +208,7 @@ public void Refresh()
ViewUtil.SetActive(itemObj, i < count);
if (i < count)
{
Rebind(itemObj.name, this[i]);
Rebind(itemObj, this[i]);
}
}
}
Expand Down Expand Up @@ -236,9 +237,14 @@ private GameObject CreatItemView()
return itemViewObject;
}

private void Rebind(string itemName, IBindableModel model)
private void Rebind(GameObject itemViewObject, IBindableModel model)
{
Vue.Updater.Rebind(itemName, model);
UIBundle bundle = UIQuerier.Query(itemViewObject.name, model);
if (bundle == null)
ViewUtil.Patch3Pass(itemViewObject, model);
else
Vue.Updater.Rebind(itemViewObject.name, model);

model.NotifyAll();
}

Expand Down
2 changes: 1 addition & 1 deletion UniVue/Runtime/View/Views/Widgets/LoopGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void Init()
{
RectTransform itemRect = _scrollRect.content.GetChild(i).GetComponent<RectTransform>();
if (_tail < count)
ViewUtil.Patch3Pass(itemRect.gameObject, this[_tail++]);
Rebind(itemRect, this[_tail], _tail++);
else
itemRect.gameObject.SetActive(false);
}
Expand Down
2 changes: 1 addition & 1 deletion UniVue/Runtime/View/Views/Widgets/LoopList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private void Init()
RectTransform itemRectTrans = _scrollRect.content.GetChild(i).GetComponent<RectTransform>();
//数据渲染
if (_tail < count)
ViewUtil.Patch3Pass(itemRectTrans.gameObject, this[_tail++]);
Rebind(itemRectTrans.gameObject, this[_tail++]);
else
itemRectTrans.gameObject.SetActive(false);
}
Expand Down
2 changes: 1 addition & 1 deletion UniVue/Runtime/ViewModel/VMTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void AddBindView(string viewName, IBindableModel model)
{
if (_models.TryGetValue(model, out List<string> viewNames) && !viewNames.Contains(viewName))
viewNames.Add(viewName);
else
else if(viewNames == null)
_models.Add(model, new List<string>(1) { viewName });
}

Expand Down

0 comments on commit 00ab251

Please sign in to comment.