public void Command(string memberName, object paramater) { var member = _myType.GetRuntimeMember(memberName); if (member == null) { Debug.LogError("Member not found ! " + memberName + " " + _myType); return; } // convert to fit signature var converted = ConverterHelper.ConvertTo(member.GetParamaterType(), paramater); if (member is MethodInfo) { var method = member as MethodInfo; if (method.ReturnType == typeof(IEnumerator)) { if (_insanceBehaviour) { if (!_insanceBehaviour.gameObject.activeSelf) { Debug.LogError("Behavior is inactive ! " + _insanceBehaviour); } // via built in if (converted == null) { _insanceBehaviour.StartCoroutine(method.Name); } else { _insanceBehaviour.StartCoroutine(method.Name, converted); } } else { // via helper var routine = method.Invoke(_instance, converted == null ? null : new[] { converted }); ObservableHandler.Instance.StartCoroutine((IEnumerator)routine); } return; } } member.SetMemberValue(_instance, converted); }
public object GetValue(string memberName, object paramater) { var member = _myType.GetRuntimeMember(memberName); if (member == null) { Debug.LogError("Member not found ! " + memberName + " " + _myType); return(null); } if (member is MethodInfo) { var meth = (member as MethodInfo); if (paramater != null) { var p = meth.GetParameters().FirstOrDefault(); if (p == null) { return(GetValue(memberName)); } var converted = ConverterHelper.ConvertTo(p.GetType(), paramater); return(meth.Invoke(_instance, new[] { converted })); } return(meth.Invoke(_instance, null)); } if (member is PropertyInfo) { #if UNITY_WSA return((member as PropertyInfo).GetValue(_instance)); #else return((member as PropertyInfo).GetValue(_instance, null)); #endif } return((member as FieldInfo).GetValue(_instance)); }