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(); }
//绑定目标 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 }