Skip to content

Commit e13f5ec

Browse files
author
邹杭特
committed
fixed project demo,fixed drag and drop
1 parent aa7c921 commit e13f5ec

File tree

14 files changed

+128
-78
lines changed

14 files changed

+128
-78
lines changed

Assets/BridgeUI/Core/Binding/Editor/BindingWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private void DrawPreComponents()
304304
if (item is GameObject)
305305
{
306306
var obj = item as GameObject;
307-
var parent = PrefabUtility.GetPrefabObject(obj);
307+
var parent = PrefabUtility.GetPrefabParent(obj);
308308
if (parent){
309309
obj = parent as GameObject;
310310
}

Assets/BridgeUI/Core/Editor/PanelGroupDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private void TrySaveAllPrefabs(UIInfoBase[] proprety)
281281
var item = proprety[i];
282282
var obj = EditorUtility.InstanceIDToObject(item.instanceID);
283283
if (obj == null) continue;
284-
var prefab = PrefabUtility.GetPrefabObject(obj);
284+
var prefab = PrefabUtility.GetPrefabParent(obj);
285285
if (prefab != null)
286286
{
287287
var root = PrefabUtility.FindPrefabRoot((GameObject)prefab);

Assets/BridgeUI/Core/GenCode/Editor/ComponentItemDrawer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void DrawScriptTarget(Rect targetRect, ComponentItem item)
150150
var newTarget = EditorGUI.ObjectField(targetRect, item.scriptTarget, item.componentType, true);
151151
if (newTarget != item.scriptTarget)
152152
{
153-
var prefabTarget = PrefabUtility.GetPrefabObject(newTarget);
153+
var prefabTarget = PrefabUtility.GetPrefabParent(newTarget);
154154
Debug.Log(prefabTarget);
155155
if (prefabTarget != null)
156156
{
@@ -175,7 +175,7 @@ private void DrawTarget(Rect targetRect, ComponentItem item)
175175
var newTarget = EditorGUI.ObjectField(targetRect, item.target, item.componentType, true);
176176
if (newTarget != item.target)
177177
{
178-
var prefabTarget = PrefabUtility.GetPrefabObject(newTarget);
178+
var prefabTarget = PrefabUtility.GetPrefabParent(newTarget);
179179
if (prefabTarget != null)
180180
{
181181
newTarget = prefabTarget;
@@ -185,7 +185,7 @@ private void DrawTarget(Rect targetRect, ComponentItem item)
185185

186186
if (EditorGUI.EndChangeCheck() && item.target)
187187
{
188-
var parent = PrefabUtility.GetPrefabObject(item.target);
188+
var parent = PrefabUtility.GetPrefabParent(item.target);
189189
if (parent)
190190
{
191191
item.target = parent as GameObject;

Assets/BridgeUI/Core/GenCode/Editor/ComponetCode/ComponentCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ protected virtual void BindingMemberInvocations(string name, BindingShow binding
9696
var invocations = PropBindingsNode.Body.Descendants.OfType<InvocationExpression>();
9797
var arg0_name = "m_" + name + "." + bindingInfo.bindingTarget;
9898
var arg0 = arg0_name;
99-
UnityEngine.Debug.Log(bindingInfo.bindingTargetType.type);
100-
UnityEngine.Debug.Log(bindingInfo.isMethod);
99+
//UnityEngine.Debug.Log(bindingInfo.bindingTargetType.type);
100+
//UnityEngine.Debug.Log(bindingInfo.isMethod);
101101

102102
if (!bindingInfo.isMethod)
103103
{

Assets/BridgeUI/Core/GenCode/Editor/GenCodeUtil.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,15 @@ public static void UpdateScripts(GameObject go, List<ComponentItem> components,
147147
{
148148
if (viewScript is PanelBase)
149149
{
150+
var viewScriptPath = AssetDatabase.GetAssetPath(viewScript);
151+
//!!!ViewModelScript需要放置到ViewScript下
152+
var vmScriptTempPath = viewScriptPath.Replace(".cs", "_ViewModel.cs");
153+
var viewModelScript = AssetDatabase.LoadAssetAtPath<MonoScript>(vmScriptTempPath);
154+
150155
var viewModel = (viewScript as PanelBase).ViewModel;
151-
if (viewModel is Binding.ViewModelObject && viewModel.GetType() != typeof(Binding.ViewModelObject))
152-
{
153-
GenCodeUtil.UpdateViewModelScript(viewModel as Binding.ViewModelObject, components);
154-
}
155-
else if((viewModel is Binding.ViewModelContainer))
156+
if (viewModelScript != null)
156157
{
157-
var instence = (viewModel as Binding.ViewModelContainer).instence;
158-
if(instence != null){
159-
GenCodeUtil.UpdateViewModelScript(instence, components);
160-
}
158+
GenCodeUtil.UpdateViewModelScript(viewModelScript, components);
161159
}
162160
else
163161
{
@@ -185,6 +183,7 @@ public static void UpdateScripts(GameObject go, List<ComponentItem> components,
185183
public static void CompleteKeyField(string bindingSource, TypeDeclaration classNode)
186184
{
187185
var fieldName = GetSourceKeyWord(bindingSource);
186+
188187
var field = classNode.Descendants.OfType<FieldDeclaration>().Where(x => x.Variables.Where(y => y.Name == fieldName).Count() > 0).FirstOrDefault();
189188

190189
if (field == null)
@@ -334,9 +333,8 @@ public static void CreateNewViewModelScript(string className, string scriptPath,
334333
/// </summary>
335334
/// <param name="viewModel"></param>
336335
/// <param name="components"></param>
337-
public static void UpdateViewModelScript(Binding.ViewModelObject viewModel, List<ComponentItem> components)
336+
public static void UpdateViewModelScript(MonoScript monoScript, List<ComponentItem> components)
338337
{
339-
var monoScript = MonoScript.FromScriptableObject(viewModel);
340338
var classType = monoScript.GetClass();
341339
var baseType = classType.BaseType;
342340
var className = classType.Name;
@@ -360,8 +358,7 @@ private static string GenerateViewModelScript(string className, string oldScript
360358
{
361359
startRegion = new PreProcessorDirective(PreProcessorDirectiveType.Region, "属性列表");
362360
AstNode firstMember = classNode.GetChildByRole(Roles.TypeMemberRole);
363-
if (firstMember == null)
364-
{
361+
if (firstMember == null){
365362
firstMember = classNode.LastChild;
366363
}
367364
classNode.InsertChildBefore<PreProcessorDirective>(firstMember, startRegion, Roles.PreProcessorDirective);
@@ -377,12 +374,16 @@ private static string GenerateViewModelScript(string className, string oldScript
377374
#region 处理属性列表
378375
foreach (var component in components)
379376
{
377+
var flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.FlattenHierarchy;
378+
380379
foreach (var viewItem in component.viewItems)
381380
{
382381
//忽略已经存在于父级的属性
383-
if (baseType.GetProperty(viewItem.bindingSource, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.FlattenHierarchy) != null)
382+
if (baseType.GetProperty(viewItem.bindingSource, flag) != null)
384383
continue;
385384

385+
//Debug.Log(baseType);
386+
386387
CompleteKeyField(viewItem.bindingSource, classNode);
387388

388389
if (viewItem.bindingTargetType.type != null)
@@ -399,7 +400,7 @@ private static string GenerateViewModelScript(string className, string oldScript
399400
foreach (var eventItem in component.eventItems)
400401
{
401402
//忽略已经存在于父级的属性
402-
if (baseType.GetProperty(eventItem.bindingSource, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.FlattenHierarchy) != null)
403+
if (baseType.GetProperty(eventItem.bindingSource, flag) != null)
403404
continue;
404405

405406
CompleteKeyField(eventItem.bindingSource, classNode);

Assets/BridgeUI/Core/Graph/Editor/BridgeUIGraphCtrl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ internal override void OnDragUpdated()
467467
}
468468
protected static string GetInstenceObjectPath(GameObject instenceObj)
469469
{
470-
var pfbTrans = PrefabUtility.GetPrefabObject(instenceObj);
470+
var pfbTrans = PrefabUtility.GetPrefabParent(instenceObj);
471471
if (pfbTrans != null)
472472
{
473473
var prefab = PrefabUtility.FindPrefabRoot(pfbTrans as GameObject);
@@ -508,7 +508,7 @@ internal override List<KeyValuePair<string, Node>> OnDragAccept(UnityEngine.Obje
508508
else if (obj is GameObject)
509509
{
510510
panelNode = ScriptableObject.CreateInstance<PanelNode>();
511-
var prefab = PrefabUtility.GetPrefabObject(obj);
511+
var prefab = PrefabUtility.GetPrefabParent(obj);
512512
if (prefab == null)
513513
{
514514
prefab = obj;

Assets/BridgeUI/Core/Graph/Editor/Drawers/PanelNodeDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private void DrawPreComponents()
268268
if (item is GameObject)
269269
{
270270
var obj = item as GameObject;
271-
var parent = PrefabUtility.GetPrefabObject(obj);
271+
var parent = PrefabUtility.GetPrefabParent(obj);
272272
if (parent)
273273
{
274274
obj = parent as GameObject;

Assets/BridgeUI/Core/Static/Editor/BridgeEditorUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static void SavePrefab(SerializedProperty instanceIDProp, bool destroy =
235235
private static void InternalApplyPrefab(GameObject gitem)
236236
{
237237
var instanceRoot = PrefabUtility.FindValidUploadPrefabInstanceRoot(gitem);
238-
var prefab = PrefabUtility.GetPrefabObject(instanceRoot);
238+
var prefab = PrefabUtility.GetPrefabParent(instanceRoot);
239239
if (prefab != null)
240240
{
241241
if (prefab.name == gitem.name)
@@ -481,7 +481,7 @@ private static bool Ignore(UnityEngine.Object instence)
481481
var changed = false;
482482

483483
var instanceRoot = PrefabUtility.FindValidUploadPrefabInstanceRoot(instence as GameObject) as GameObject;
484-
var prefab = PrefabUtility.GetPrefabObject(instanceRoot) as GameObject;
484+
var prefab = PrefabUtility.GetPrefabParent(instanceRoot) as GameObject;
485485

486486
if (prefab == null) return true;
487487

Assets/Demos/5.ProjectDemo/Scripts/ViewModel/ListPanel_ViewModel0.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@
99

1010
public class ListPanel_ViewModel0 : ListPanel_ViewModel
1111
{
12-
#region 属性列表
13-
protected System.String[] options {
14-
get {
15-
return GetValue<System.String[]> (keyword_options);
16-
}
17-
set {
18-
SetValue<System.String[]> (keyword_options, value);
19-
}
20-
}
21-
22-
protected BridgeUI.Binding.PanelAction<System.Int32> on_selectid {
23-
get {
24-
return GetValue<BridgeUI.Binding.PanelAction<System.Int32>> (keyword_on_selectid);
25-
}
26-
set {
27-
SetValue<BridgeUI.Binding.PanelAction<System.Int32>> (keyword_on_selectid, value);
28-
}
29-
}
30-
31-
#endregion 属性列表
3212
[SerializeField]
3313
private string[] optionStrs;
3414

@@ -41,13 +21,9 @@ public override void OnBinding (IBindingContext context)
4121

4222
private void OnSelectID (IBindingContext panel, int arg0)
4323
{
44-
UIFacade.Instence.Open ("PopupPanel", new string[] {
24+
UIFacade.Instence.Open (panel as IUIPanel,"PopupPanel", new string[] {
4525
"小提示-" + arg0.ToString (),
4626
options [arg0]
4727
});
4828
}
49-
50-
protected const string keyword_options = "options";
51-
52-
protected const string keyword_on_selectid = "on_selectid";
5329
}

Assets/Demos/5.ProjectDemo/Scripts/ViewScripts/ListPanel/ListPanel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ public class ListPanel : BridgeUI.SinglePanel
2222
[SerializeField]
2323
private BridgeUI.Control.ButtonListSelector m_List;
2424

25+
[SerializeField]
26+
private UnityEngine.UI.Text m_Text;
27+
28+
protected const string keyword_title = "title";
29+
2530
protected override void PropBindings ()
2631
{
2732
Binder.RegistEvent (m_List.onSelectID, keyword_on_selectid);
2833
Binder.RegistValueChange<System.String[]> (x => m_List.options = x, keyword_options);
34+
Binder.RegistValueChange<System.String> (x=>m_Text.text=x, keyword_title);
2935
}
3036
}

0 commit comments

Comments
 (0)