public void Tick() { for (int i = 0; i < this.m_SynchronizedVariables.Count; i++) { VariableSynchronizer.SynchronizedVariable synchronizedVariable = this.m_SynchronizedVariables[i]; switch (synchronizedVariable.synchronizationType) { case VariableSynchronizer.SynchronizationType.BehaviorDesigner: if (synchronizedVariable.setVariable) { synchronizedVariable.sharedVariable.SetValue(synchronizedVariable.targetSharedVariable.GetValue()); } else { synchronizedVariable.targetSharedVariable.SetValue(synchronizedVariable.sharedVariable.GetValue()); } break; case VariableSynchronizer.SynchronizationType.Property: if (synchronizedVariable.setVariable) { synchronizedVariable.sharedVariable.SetValue(synchronizedVariable.getDelegate()); } else { synchronizedVariable.setDelegate(synchronizedVariable.sharedVariable.GetValue()); } break; case VariableSynchronizer.SynchronizationType.Animator: if (synchronizedVariable.setVariable) { switch (synchronizedVariable.animatorParameterType) { case VariableSynchronizer.AnimatorParameterType.Bool: synchronizedVariable.sharedVariable.SetValue(synchronizedVariable.animator.GetBool(synchronizedVariable.targetID)); break; case VariableSynchronizer.AnimatorParameterType.Float: synchronizedVariable.sharedVariable.SetValue(synchronizedVariable.animator.GetFloat(synchronizedVariable.targetID)); break; case VariableSynchronizer.AnimatorParameterType.Integer: synchronizedVariable.sharedVariable.SetValue(synchronizedVariable.animator.GetInteger(synchronizedVariable.targetID)); break; } } else { switch (synchronizedVariable.animatorParameterType) { case VariableSynchronizer.AnimatorParameterType.Bool: synchronizedVariable.animator.SetBool(synchronizedVariable.targetID, (bool)synchronizedVariable.sharedVariable.GetValue()); break; case VariableSynchronizer.AnimatorParameterType.Float: synchronizedVariable.animator.SetFloat(synchronizedVariable.targetID, (float)synchronizedVariable.sharedVariable.GetValue()); break; case VariableSynchronizer.AnimatorParameterType.Integer: synchronizedVariable.animator.SetInteger(synchronizedVariable.targetID, (int)synchronizedVariable.sharedVariable.GetValue()); break; } } break; case VariableSynchronizer.SynchronizationType.PlayMaker: case VariableSynchronizer.SynchronizationType.uFrame: synchronizedVariable.thirdPartyTick(synchronizedVariable); break; } } }
public void Awake() { for (int i = this.m_SynchronizedVariables.Count - 1; i > -1; i--) { VariableSynchronizer.SynchronizedVariable synchronizedVariable = this.m_SynchronizedVariables[i]; if (synchronizedVariable.global) { synchronizedVariable.sharedVariable = GlobalVariables.Instance.GetVariable(synchronizedVariable.variableName); } else { synchronizedVariable.sharedVariable = synchronizedVariable.behavior.GetVariable(synchronizedVariable.variableName); } string text = string.Empty; if (synchronizedVariable.sharedVariable == null) { text = "the SharedVariable can't be found"; } else { switch (synchronizedVariable.synchronizationType) { case VariableSynchronizer.SynchronizationType.BehaviorDesigner: { Behavior behavior = synchronizedVariable.targetComponent as Behavior; if (behavior == null) { text = "the target component is not of type Behavior Tree"; } else { if (synchronizedVariable.targetGlobal) { synchronizedVariable.targetSharedVariable = GlobalVariables.Instance.GetVariable(synchronizedVariable.targetName); } else { synchronizedVariable.targetSharedVariable = behavior.GetVariable(synchronizedVariable.targetName); } if (synchronizedVariable.targetSharedVariable == null) { text = "the target SharedVariable cannot be found"; } } break; } case VariableSynchronizer.SynchronizationType.Property: { PropertyInfo property = synchronizedVariable.targetComponent.GetType().GetProperty(synchronizedVariable.targetName); if (property == null) { text = "the property " + synchronizedVariable.targetName + " doesn't exist"; } else if (synchronizedVariable.setVariable) { MethodInfo getMethod = property.GetGetMethod(); if (getMethod == null) { text = "the property has no get method"; } else { synchronizedVariable.getDelegate = VariableSynchronizer.CreateGetDelegate(synchronizedVariable.targetComponent, getMethod); } } else { MethodInfo setMethod = property.GetSetMethod(); if (setMethod == null) { text = "the property has no set method"; } else { synchronizedVariable.setDelegate = VariableSynchronizer.CreateSetDelegate(synchronizedVariable.targetComponent, setMethod); } } break; } case VariableSynchronizer.SynchronizationType.Animator: synchronizedVariable.animator = (synchronizedVariable.targetComponent as Animator); if (synchronizedVariable.animator == null) { text = "the component is not of type Animator"; } else { synchronizedVariable.targetID = Animator.StringToHash(synchronizedVariable.targetName); Type propertyType = synchronizedVariable.sharedVariable.GetType().GetProperty("Value").PropertyType; if (propertyType.Equals(typeof(bool))) { synchronizedVariable.animatorParameterType = VariableSynchronizer.AnimatorParameterType.Bool; } else if (propertyType.Equals(typeof(float))) { synchronizedVariable.animatorParameterType = VariableSynchronizer.AnimatorParameterType.Float; } else if (propertyType.Equals(typeof(int))) { synchronizedVariable.animatorParameterType = VariableSynchronizer.AnimatorParameterType.Integer; } else { text = "there is no animator parameter type that can synchronize with " + propertyType; } } break; case VariableSynchronizer.SynchronizationType.PlayMaker: { Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly("BehaviorDesigner.Runtime.VariableSynchronizer_PlayMaker"); if (typeWithinAssembly != null) { MethodInfo method = typeWithinAssembly.GetMethod("Start"); if (method != null) { int num = (int)method.Invoke(null, new object[] { synchronizedVariable }); if (num == 1) { text = "the PlayMaker NamedVariable cannot be found"; } else if (num == 2) { text = "the Behavior Designer SharedVariable is not the same type as the PlayMaker NamedVariable"; } else { MethodInfo method2 = typeWithinAssembly.GetMethod("Tick"); if (method2 != null) { synchronizedVariable.thirdPartyTick = (Action <VariableSynchronizer.SynchronizedVariable>)Delegate.CreateDelegate(typeof(Action <VariableSynchronizer.SynchronizedVariable>), method2); } } } } else { text = "has the PlayMaker classes been imported?"; } break; } case VariableSynchronizer.SynchronizationType.uFrame: { Type typeWithinAssembly2 = TaskUtility.GetTypeWithinAssembly("BehaviorDesigner.Runtime.VariableSynchronizer_uFrame"); if (typeWithinAssembly2 != null) { MethodInfo method3 = typeWithinAssembly2.GetMethod("Start"); if (method3 != null) { int num2 = (int)method3.Invoke(null, new object[] { synchronizedVariable }); if (num2 == 1) { text = "the uFrame property cannot be found"; } else if (num2 == 2) { text = "the Behavior Designer SharedVariable is not the same type as the uFrame property"; } else { MethodInfo method4 = typeWithinAssembly2.GetMethod("Tick"); if (method4 != null) { synchronizedVariable.thirdPartyTick = (Action <VariableSynchronizer.SynchronizedVariable>)Delegate.CreateDelegate(typeof(Action <VariableSynchronizer.SynchronizedVariable>), method4); } } } } else { text = "has the uFrame classes been imported?"; } break; } } } if (!string.IsNullOrEmpty(text)) { UnityEngine.Debug.LogError(string.Format("Unable to synchronize {0}: {1}", synchronizedVariable.sharedVariable.name, text)); this.synchronizedVariables.RemoveAt(i); } } if (this.synchronizedVariables.Count == 0) { base.enabled = false; return; } this.UpdateIntervalChanged(); }