Skip to content

Commit aa7c921

Browse files
author
邹杭特
committed
更新project教学Demo
1 parent f799f35 commit aa7c921

39 files changed

+815
-302
lines changed

Assets/BridgeUI/Common/SelectabesPanel/SelectAblesPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public virtual string[] Ports
2525
{
2626
get
2727
{
28-
return selectables.Select(x => x.name).ToArray();
28+
return selectables.Where(x => x != null).Select(x => x.name).ToArray();
2929
}
3030
}
3131

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ public static void UpdateScripts(GameObject go, List<ComponentItem> components,
161161
}
162162
else
163163
{
164-
var scriptPath = AssetDatabase.GetAssetPath(go).Replace(".prefab", "_ViewModel.cs");
164+
var vscript = MonoScript.FromMonoBehaviour(viewScript as PanelBase);
165+
string scriptPath = null;
166+
if (vscript.name == go.name)
167+
{
168+
scriptPath = AssetDatabase.GetAssetPath(vscript).Replace(".cs", "_ViewModel.cs");
169+
}
170+
else
171+
{
172+
scriptPath = AssetDatabase.GetAssetPath(go).Replace(".prefab", "_ViewModel.cs");
173+
}
165174
CreateNewViewModelScript(go.name + "_ViewModel", scriptPath, components);
166175
}
167176
}
@@ -205,24 +214,42 @@ public static void CreateViewScript(GameObject go, List<ComponentItem> component
205214
var tree = uiCoder.tree;
206215
var className = uiCoder.className;
207216
var classNode = tree.Descendants.OfType<TypeDeclaration>().Where(x => x.Name == className).First();
217+
var type = typeof(BridgeUI.PanelBase).Assembly.GetType(className);
208218

209219
CreateMemberFields(classNode, needAdd);
210220
BindingInfoMethods(classNode, needAdd, rule);
211221
SortClassMembers(classNode);
212222

213223
var prefabPath = AssetDatabase.GetAssetPath(go);
214-
var folder = prefabPath.Remove(prefabPath.LastIndexOf("/"));
215-
var scriptPath = string.Format("{0}/{1}.cs", folder, uiCoder.className);
224+
var script = go.GetComponent(type);
225+
var scriptPath = "";
226+
if (script != null)
227+
{
228+
var vScript = MonoScript.FromMonoBehaviour(script as MonoBehaviour);
229+
if(vScript.name == go.name)
230+
{
231+
scriptPath = AssetDatabase.GetAssetPath(vScript);
232+
}
233+
else
234+
{
235+
scriptPath = AssetDatabase.GetAssetPath(go).Replace(".prefab", ".cs");
236+
}
237+
}
238+
else
239+
{
240+
var folder = prefabPath.Remove(prefabPath.LastIndexOf("/"));
241+
scriptPath = string.Format("{0}/{1}.cs", folder, uiCoder.className);
242+
}
243+
216244
var scriptValue = uiCoder.Compile();
217245
System.IO.File.WriteAllText(scriptPath, scriptValue, System.Text.Encoding.UTF8);
218246
AssetDatabase.Refresh();
219247

220248
EditorApplication.delayCall += () =>
221249
{
222-
var type = typeof(BridgeUI.PanelBase).Assembly.GetType(className);
223250
if (type != null)
224251
{
225-
var script = go.GetComponent(type);
252+
script = go.GetComponent(type);
226253
if (script == null)
227254
{
228255
go.AddComponent(type);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private void TrySaveAllPrefabs(SerializedProperty arrayProp)
528528
var instanceIDPorp = item.FindPropertyRelative("instanceID");
529529
var obj = EditorUtility.InstanceIDToObject(instanceIDPorp.intValue);
530530
if (obj == null) continue;
531-
var prefab = PrefabUtility.GetPrefabObject(obj);
531+
var prefab = PrefabUtility.GetPrefabParent(obj);
532532
if (prefab != null)
533533
{
534534
var root = PrefabUtility.FindPrefabRoot((GameObject)prefab);

Assets/Demos/5.ProjectDemo/Anims.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using BridgeUI;
2+
using BridgeUI.uTween;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
using UnityEngine.Events;
6+
using UnityEngine.UI;
7+
public class ColorAnim : AnimPlayer
8+
{
9+
[SerializeField]
10+
private float dely = 1;
11+
[SerializeField]
12+
private float duration = 2;
13+
[SerializeField]
14+
private Color startColor = Color.red;
15+
[SerializeField]
16+
private Color endColor = Color.white;
17+
18+
protected override List<uTweener> CreateTweeners()
19+
{
20+
var tweens = new List<uTweener>();
21+
var colorTween = uTweenColor.Begin(panel.transform as RectTransform, startColor, Color.white, duration, dely);
22+
colorTween.includeChildren = true;
23+
tweens.Add(colorTween);
24+
return tweens;
25+
}
26+
}

Assets/Demos/5.ProjectDemo/Anims/ColorAnim.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_PrefabParentObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 0}
8+
m_GameObject: {fileID: 0}
9+
m_Enabled: 1
10+
m_EditorHideFlags: 0
11+
m_Script: {fileID: 11500000, guid: 15c88235c1dc63744884eae9c7fc4791, type: 3}
12+
m_Name: colorAnim
13+
m_EditorClassIdentifier:
14+
reverse: 0
15+
dely: 1
16+
duration: 2
17+
startColor: {r: 0, g: 1, b: 0.43330193, a: 1}
18+
endColor: {r: 1, g: 1, b: 1, a: 1}

Assets/Demos/5.ProjectDemo/UI/project_common.asset.meta renamed to Assets/Demos/5.ProjectDemo/Anims/colorAnim.asset.meta

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Demos/5.ProjectDemo/Scripts/ProgressTrigger.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@
66
using UnityEngine.EventSystems;
77

88
public class ProgressTrigger : MonoBehaviour {
9-
public bool playOnAwake;
109
public float time = 2;
10+
public Text progress;
1111
public Slider slider;
1212
public UnityEvent onComplete;
1313

14-
private void Awake()
15-
{
16-
if(playOnAwake)
17-
{
18-
Play();
19-
}
20-
}
21-
22-
public void Play()
14+
private void OnEnable()
2315
{
2416
StartCoroutine(DelayPlaying());
2517
}
@@ -30,6 +22,10 @@ IEnumerator DelayPlaying()
3022
{
3123
yield return null;
3224
slider.value = (slider.maxValue - slider.minValue) * i / time + slider.minValue;
25+
if(progress!=null)
26+
{
27+
progress.text = string.Format("{0}%", (int)(slider.value * 100));
28+
}
3329
}
3430
onComplete.Invoke();
3531
}

Assets/Demos/5.ProjectDemo/Scripts/ViewModel/vm_listPanel.cs renamed to Assets/Demos/5.ProjectDemo/Scripts/ViewModel/ListPanel_ViewModel0.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@
77
using BridgeUI.Binding;
88
using System;
99

10-
public class vm_listPanel : ViewModelObject
10+
public class ListPanel_ViewModel0 : ListPanel_ViewModel
1111
{
1212
#region 属性列表
13-
14-
public System.String[] options {
13+
protected System.String[] options {
1514
get {
16-
return GetValue<System.String[]> ("options");
15+
return GetValue<System.String[]> (keyword_options);
1716
}
1817
set {
19-
SetValue<System.String[]> ("options", value);
18+
SetValue<System.String[]> (keyword_options, value);
2019
}
2120
}
2221

23-
24-
public BridgeUI.Binding.PanelAction<System.Int32> on_selectid {
22+
protected BridgeUI.Binding.PanelAction<System.Int32> on_selectid {
2523
get {
26-
return GetValue<BridgeUI.Binding.PanelAction<System.Int32>> ("on_selectid");
24+
return GetValue<BridgeUI.Binding.PanelAction<System.Int32>> (keyword_on_selectid);
2725
}
2826
set {
29-
SetValue<BridgeUI.Binding.PanelAction<System.Int32>> ("on_selectid", value);
27+
SetValue<BridgeUI.Binding.PanelAction<System.Int32>> (keyword_on_selectid, value);
3028
}
3129
}
3230

@@ -44,8 +42,12 @@ public override void OnBinding (IBindingContext context)
4442
private void OnSelectID (IBindingContext panel, int arg0)
4543
{
4644
UIFacade.Instence.Open ("PopupPanel", new string[] {
47-
arg0.ToString (),
45+
"小提示-" + arg0.ToString (),
4846
options [arg0]
4947
});
5048
}
49+
50+
protected const string keyword_options = "options";
51+
52+
protected const string keyword_on_selectid = "on_selectid";
5153
}

0 commit comments

Comments
 (0)