public void OnLinkProperties() { if (linkablePropertiesSink.captionText.text.Length > 0 && linkablePropertiesSource.captionText.text.Length > 0 && linkableSourceMagicCircle != null && selectedMagicCircle != null) { LinkableFinder.LinkField ( linkablePropertiesSink.captionText.text, selectedMagicCircle, linkablePropertiesSource.captionText.text, linkableSourceMagicCircle ); } }
void PickConversionTypes(Type originType, Type targetType) { if (originType == targetType) { LinkableFinder.LinkField(selectedLinkableProperty, destination, selectedProperty, source); } if (originType == typeof(GameObject)) { GameObjectConversions(targetType); } else if (originType == typeof(Vector3)) { Vector3Conversions(targetType); } else { try { var convertTest = Convert.ChangeType(Activator.CreateInstance(originType), targetType); MethodInfo mi = source.GetType().GetMethod(selectedProperty); FieldInfo fi = destination.GetType().GetField(selectedLinkableProperty); Debug.Log("Linking " + mi.Name + " from " + source.GetType().ToString() + " to " + fi.Name + " from " + destination.GetType().ToString()); MethodInfo setLinkedValueMethod = fi.FieldType.GetMethod("SetLinkedValue"); object makemeSource = source; MethodInfo makemeMI = mi; if (invert && originType == typeof(bool)) { BoolFunctionInverter bfi = new BoolFunctionInverter(mi, source); makemeMI = bfi.GetType().GetMethod("InvertFunction"); makemeSource = bfi; // Func<bool> invertedMethod = (() => !(bool) mi.Invoke( source, null )); // makemeMI = RuntimeReflectionExtensions.GetMethodInfo(invertedMethod); // makemeSource = this; print(mi.ToString()); print(makemeMI); } var d1 = typeof(DataLinkConverter <>); Type[] typeArgs = { targetType }; var makeme = d1.MakeGenericType(typeArgs); object o = Activator.CreateInstance(makeme, makemeMI, makemeSource); var convertedLinkedMethod = Convert.ChangeType(Delegate.CreateDelegate(setLinkedValueMethod.GetParameters()[0].ParameterType, o, o.GetType().GetMethod("ConvertToType"), true), setLinkedValueMethod.GetParameters()[0].ParameterType); object[] myParams = new object[1]; myParams[0] = convertedLinkedMethod; MonoBehaviour.print(convertedLinkedMethod.ToString()); // if( fi.GetType() == typeof( bool ) && invert ) // { // setLinkedValueMethod.Invoke( !fi.GetValue( destination ), myParams ); // } // else // { setLinkedValueMethod.Invoke(fi.GetValue(destination), myParams); // } Debug.Log(" The conversion succeeded "); } catch (Exception e) { Debug.LogWarning(" The conversion failed with exception " + e.ToString()); } } }