Esempio n. 1
0
 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
         );
     }
 }
    public void UpdateSourceAndDestination()
    {
        oldSource      = source;
        oldDestination = destination;

        if (source != null)
        {
            availableProperties = new List <string>(LinkableFinder.FindLinkableFunctions(source));
        }

        if (destination != null)
        {
            availableLinkableProperties = new List <string>(LinkableFinder.FindAllLinkableProperty(destination));
            activatableFunctions        = new List <string>(LinkableFinder.FindLinkableFunctions(destination, true));
        }
    }
    public override void SetDestination(SpellNode newDestination)
    {
        if (newDestination != oldDestination)
        {
            selectedLinkableProperty  = null;
            linkedActivatableFunction = null;

            if (newDestination != null)
            {
                availableLinkableProperties = new List <string>(LinkableFinder.FindAllLinkableProperty(newDestination));
                activatableFunctions        = new List <string>(LinkableFinder.FindLinkableFunctions(newDestination, true));
                oldDestination = newDestination;
                destination    = newDestination;
            }
        }
    }
    public override void SetSource(SpellNode newSource)
    {
        if (newSource != oldSource)
        {
            selectedProperty          = null;
            boolLinkedFunction        = null;
            linkedActivatableFunction = null;

            if (newSource != null)
            {
                availableProperties = new List <string>(LinkableFinder.FindLinkableFunctions(newSource));
                oldSource           = newSource;
                source = newSource;
            }
        }
    }
Esempio n. 5
0
    public void UpdateSelectSensitiveDropdowns()
    {
        // Update Linkable Properties Sink
        string[] linkProperties = LinkableFinder.FindAllLinkableProperty(selectedMagicCircle);
        linkablePropertiesSink.options.Clear();
        for (int i = 0; i < linkProperties.Length; i++)
        {
            print("new prop: " + linkProperties[i]);
            linkablePropertiesSink.options.Add(new Dropdown.OptionData(linkProperties[i]));
        }
        linkablePropertiesSink.RefreshShownValue();

        if (selectedMagicCircle != null)
        {
            // Update Main types Dropdown
            mainTypeDropdown.value = (int)selectedMagicCircle.GetMcType();

            // Update sub types Dropdown
            subTypeDropdown.value = selectedMagicCircle.GetSubType();
        }
    }
    void Update()
    {
        if (source != oldSource)
        {
            selectedProperty          = null;
            boolLinkedFunction        = null;
            linkedActivatableFunction = null;

            if (source != null)
            {
                availableProperties = new List <string>(LinkableFinder.FindLinkableFunctions(source));
                oldSource           = source;
            }
        }

        if (destination != oldDestination)
        {
            selectedLinkableProperty  = null;
            linkedActivatableFunction = null;

            if (destination != null)
            {
                availableLinkableProperties = new List <string>(LinkableFinder.FindAllLinkableProperty(destination));
                activatableFunctions        = new List <string>(LinkableFinder.FindLinkableFunctions(destination, true));
                oldDestination = destination;
            }
        }


        if (link)
        {
            link = false;
            if (source != null && destination != null)
            {
                if (previousLinkedProperty != null && previousLinkedProperty != selectedLinkableProperty)
                {
                    ResetProperty(previousLinkedProperty);
                }
                if (selectedProperty != null)
                {
                    // Link properties
                    if (selectedLinkableProperty != null)
                    {
                        Type[] conversionTypes = GetConversion();
                        if (conversionTypes[0] != null)
                        {
                            PickConversionTypes(conversionTypes[0], conversionTypes[1]);
                        }
                        else
                        {
                            Debug.LogWarning("Failed to match one value with the destination or source");
                        }
                    }
                    // Link bool to activator function
                    if (selectedActivatableFunction != null)
                    {
                        LinkActivatorFunction();
                    }
                }
            }
        }

        DrawLink();
    }
    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());
            }
        }
    }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // if left click is pressed...
            Vector3    mousePoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Collider2D obj        = Physics2D.OverlapPoint((Vector2)mousePoint);
            if (obj != null)
            {
                MagicCircle mc = obj.GetComponent <MagicCircle>();
                if (mc != null)
                {
                    drag = true;
                }
                if (mc != null && selectedMagicCircle != mc)
                {
                    selectedMagicCircle = mc;
                    if (selectedMagicCircle.GetMcType() == MagicCircleType.None)
                    {
                        rootMagicCircle = selectedMagicCircle;
                    }
                    UpdateSelectSensitiveDropdowns();
                }
            }
        }
        if (Input.GetMouseButtonDown(2))
        {
            if (selectedMagicCircle != null)
            {
                Vector3    mousePoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Collider2D obj        = Physics2D.OverlapPoint((Vector2)mousePoint);
                if (obj != null)
                {
                    MagicCircle mc = obj.GetComponent <MagicCircle>();
                    if (mc != null && selectedMagicCircle != mc)
                    {
                        linkableSourceMagicCircle = mc;
                        print(linkablePropertiesSink.captionText.text);
                        string[] linkableMethods = LinkableFinder.FindPropertiesToLinkTo(linkablePropertiesSink.captionText.text, selectedMagicCircle, linkableSourceMagicCircle);

                        linkablePropertiesSource.options.Clear();
                        for (int i = 0; i < linkableMethods.Length; i++)
                        {
                            linkablePropertiesSource.options.Add(new Dropdown.OptionData(linkableMethods[i]));
                        }
                        linkablePropertiesSource.RefreshShownValue();
                    }
                }
            }
        }
        if (Input.GetMouseButtonUp(1))
        {
            selectedMagicCircle = null;
            linkablePropertiesSink.options.Clear();
            linkablePropertiesSource.options.Clear();
        }
        if (Input.GetMouseButtonUp(0))
        {
            drag = false;
        }
        if (drag)
        {
            Vector3 mousePoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            selectedMagicCircle.transform.position = new Vector3(mousePoint.x, mousePoint.y, selectedMagicCircle.transform.position.z);
        }
    }