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