public void PropertyChanged(object sender, string propertyName) { BindingPathPart part = nextPart ?? this; string name = propertyName; if (!string.IsNullOrEmpty(name)) { if (part.isIndexer) { if (name.Contains("[")) { if (name != string.Format("{0}[{1}]", part.indexerName, part.path)) { return; } } else if (name != part.indexerName) { return; } } if (name != part.path) { return; } } m_Binding.OnSourceChanged(this); }
//解绑目标 public void Unapply() { for (var i = 0; i < m_Parts.Count - 1; i++) { BindingPathPart part = m_Parts[i]; part.Unsubscribe(); } }
//返回对象的属性值 public static object GetSourcePropertyValue(object source, BindingPathPart part, bool needSubscribe) { if (instance.m_GetSourceValue == null) { instance.m_GetSourceValue = EnterLua.luaenv.Global.GetInPath <BindPathPartGetValue>("BindingExpression.get_property"); } return(instance.m_GetSourceValue(source, part, needSubscribe)); }
public void Dispose() { Unapply(); target = null; source = null; m_Context = null; m_LastPart = null; m_Parts.Clear(); }
public void Dispose() { for (var i = 0; i < m_Parts.Count - 1; i++) { BindingPathPart part = m_Parts[i]; part.Dispose(); } convert = null; target = null; source = null; m_Context = null; m_LastPart = null; m_Parts.Clear(); }
internal void OnSourceChanged(BindingPathPart lastPart) { bool needSubscribe = mode == BindingMode.OneWay || mode == BindingMode.TwoWay; BindingPathPart part = lastPart.nextPart; object m_Current = part.source; while (part != null) { part.SetSource(m_Current); // m_LastPart = part; if (!part.isSelf && m_Current != null) { if (part.nextPart != null) { part.TryGetValue(needSubscribe && part.nextPart != null, out m_Current); } } // UnityEngine.Debug.LogFormat ("OnSourceChanged current={0},property={1},m_Path={2},parts.Count={3},part={4},part.isSelf={5}", m_Current, propertyName, path, m_Parts.Count, part, part.isSelf); if (!part.isSelf && m_Current == null) { break; } if (part.nextPart != null && needSubscribe) { if (m_Current is INotifyPropertyChanged) { // UnityEngine.Debug.LogFormat ("current = {0}", current); part.Subscribe((INotifyPropertyChanged)m_Current); } } if (part.nextPart != null) { part = part.nextPart; } else { part = null; } } UpdateTarget(); }
//利用lua更新源属性 public static void UpdateSourceValue(object target, string property, object source, BindingPathPart part, string format, object converter) { if (instance.m_UpdateSourceValue == null) { instance.m_UpdateSourceValue = EnterLua.luaenv.Global.GetInPath <UpdateValue>("BindingExpression.update_source"); } instance.m_UpdateSourceValue(target, property, source, part, format, converter); }
void ParsePath() { string p = path.Trim(); var last = new BindingPathPart(this, SelfPath); m_Parts.Add(last); if (p[0] == ExpressionSplit[0]) { if (p.Length == 1) { return; } p = p.Substring(1); } string[] pathParts = p.Split(ExpressionSplit); for (var i = 0; i < pathParts.Length; i++) { string part = pathParts[i].Trim(); if (part == string.Empty) { throw new FormatException("Path contains an empty part:" + this.propertyName); } BindingPathPart indexer = null; //索引解析 int lbIndex = part.IndexOf('['); if (lbIndex != -1) { int rbIndex = part.LastIndexOf(']'); if (rbIndex == -1) { throw new FormatException("Indexer did not contain closing ["); } int argLength = rbIndex - lbIndex - 1; if (argLength == 0) { throw new FormatException("Indexer did not contain arguments"); } string argString = part.Substring(lbIndex + 1, argLength); indexer = new BindingPathPart(this, argString, true); part = part.Substring(0, lbIndex); part = part.Trim(); indexer.indexerName = part; } //方法解析 lbIndex = part.IndexOf('('); if (lbIndex != -1) { int rbIndex = part.LastIndexOf(')'); if (rbIndex == -1) { throw new FormatException("Method did not contain closing ("); } int argLength = rbIndex - lbIndex - 1; string argString = part.Substring(0, lbIndex); var next = new BindingPathPart(this, argString); // if (argLength >= 1) { // next.isSetter = true; // } else { next.isMethod = true; // } last.nextPart = next; m_Parts.Add(next); last = next; } else if (part.Length > 0) { var next = new BindingPathPart(this, part); last.nextPart = next; m_Parts.Add(next); last = next; } if (indexer != null) { last.nextPart = indexer; m_Parts.Add(indexer); last = indexer; } } //解析convert if (!string.IsNullOrEmpty(converter)) { convert = ValueConverterRegister.instance.Get(converter); } }
public void SetLastPart() { m_LastPart = m_Parts[m_Parts.Count - 1]; }
//绑定目标 public void Apply(object context, bool invoke = true) { if (!m_IsApplied) { ParsePath(); m_IsApplied = true; } if (isBound) { Unapply(); } object bindingContext = context; if (source) { bindingContext = source; } m_Context = bindingContext; if (m_Context == null) { return; } object m_Current = bindingContext; #if false ExpressionUtility.ApplyByLua(this, m_Current); #else bool needSubscribe = this.needSubscribe; BindingPathPart part = null; for (var i = 0; i < m_Parts.Count; i++) { part = m_Parts[i]; part.SetSource(m_Current); // if (!part.isSelf && m_Current != null) { if (i < m_Parts.Count - 1) { part.TryGetValue(needSubscribe && part.nextPart != null, out m_Current); //lua NofityObject对象通过此方法在BindingExpression.get_property中订阅 } } if (!part.isSelf && m_Current == null) { break; } if (part.nextPart != null && needSubscribe) { if (m_Current is INotifyPropertyChanged) { part.Subscribe((INotifyPropertyChanged)m_Current); } } } SetLastPart(); if (invoke) { //初始化值 InitValue(); } #endif }
//绑定目标 public void Apply(object context, bool invoke = true) { if (!m_IsApplied) { #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.BeginSample(GetProfilerName() + ".ParsePath"); #endif ParsePath(); #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.EndSample(); #endif m_IsApplied = true; } if (isBound) { #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.BeginSample(GetProfilerName() + ".Unapply"); #endif Unapply(); #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.EndSample(); #endif } object bindingContext = context; if (source) { bindingContext = source; } m_Context = bindingContext; if (m_Context == null) { Unapply(); return; } object m_Current = bindingContext; #if false ExpressionUtility.ApplyByLua(this, m_Current); #else #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.BeginSample(GetProfilerName() + ".Part.TryGetValue"); #endif bool needSubscribe = this.needSubscribe; BindingPathPart part = null; for (var i = 0; i < m_Parts.Count; i++) { part = m_Parts[i]; part.SetSource(m_Current); // if (!part.isSelf && m_Current != null) { if (i < m_Parts.Count - 1) { part.TryGetValue(needSubscribe && part.nextPart != null, out m_Current); //lua NofityObject对象通过此方法在BindingExpression.get_property中订阅 } } if (!part.isSelf && m_Current == null) { break; } if (part.nextPart != null && needSubscribe) { if (m_Current is INotifyPropertyChanged) { part.Subscribe((INotifyPropertyChanged)m_Current); } } } SetLastPart(); #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.EndSample(); #endif if (invoke) { #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.BeginSample(GetProfilerName() + ".InitValue"); #endif //初始化值 InitValue(); #if LUA_PROFILER_DEBUG UnityEngine.Profiling.Profiler.EndSample(); #endif } #endif }