Exemple #1
0
    private void InitializePropertyNames(object convertedSource)
    {
        AvailablePropertyNames = convertedSource.GetType().GetProperties()
                                 .Where(t => VariableUtilities.ClassifyType(t.PropertyType) != VariableType.Unspecified)
                                 .Where(t => t.GetGetMethod() != null)
                                 .Select(p => p.Name).ToArray();
        selectedPropertyIndex = 0;
        string name  = PropNameP?.stringValue;
        int    index = System.Array.FindIndex(AvailablePropertyNames, s => s.Equals(name));

        if (index != -1)
        {
            selectedPropertyIndex = index;
        }
    }
Exemple #2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.ObjectField(SourceP);
        UnityEngine.Component selectedSource = SourceP.objectReferenceValue as UnityEngine.Component;
        if (selectedSource == null)
        {
            return;
        }
        if (GUILayout.Button(selectedSource.ToString()))
        {
            System.Action <object> callback = o => {
                serializedObject.Update();
                InitializePropertyNames(SourceP.objectReferenceValue);
            };
            GenericMenu dropdownMenu = EditorHelper.CreateAvailableComponentsDropdown(SourceP, typeof(UnityEngine.Component), callback);
            dropdownMenu.ShowAsContext();
        }
        bool sourceChanged = EditorGUI.EndChangeCheck();


        BindingUpdateMode oldUpdateMode = (BindingUpdateMode)BindingUpdateModeP.enumValueIndex;
        BindingUpdateMode newUpdateMode = oldUpdateMode;

        if (drawEditUpdateMode)
        {
            newUpdateMode = (BindingUpdateMode)EditorGUILayout.EnumPopup(oldUpdateMode);
        }
        if (oldUpdateMode != newUpdateMode && drawEditUpdateMode)
        {
            BindingUpdateModeP.enumValueIndex = (int)newUpdateMode;
        }

        Object unconvertedSource = SourceP.objectReferenceValue;
        INotifyPropertyChanged convertedSource = unconvertedSource as INotifyPropertyChanged;

        if (convertedSource == null && unconvertedSource != null && newUpdateMode == BindingUpdateMode.PropertyChangedEvent)
        {
            EditorGUILayout.HelpBox("The target you have selected does not implement the INotifyPropertyChanged interface. Without this reacting to changes at the source will not be possible.", MessageType.Error);
        }
        else if (unconvertedSource != null)
        {
            if (sourceChanged || AvailablePropertyNames == null)
            {
                unconvertedSource = SourceP.objectReferenceValue;
                InitializePropertyNames(unconvertedSource);
            }
            SerializedProperty PropertyNameP = this.serializedObject.FindProperty("propertyName");
            EditorGUI.BeginChangeCheck();
            selectedPropertyIndex = EditorGUILayout.Popup("Property", selectedPropertyIndex, AvailablePropertyNames);
            if (EditorGUI.EndChangeCheck() || sourceChanged)
            {
                PropNameP.stringValue = AvailablePropertyNames.ElementAtOrDefault(selectedPropertyIndex);
                if (PropNameP.stringValue == null)
                {
                    selectedPropertyIndex = 0;
                    PropNameP.stringValue = AvailablePropertyNames.ElementAtOrDefault(selectedPropertyIndex);
                }
                System.Reflection.PropertyInfo propertyInfo = unconvertedSource.GetType().GetProperty(PropNameP.stringValue);
                System.Type  rawType = propertyInfo.PropertyType;
                VariableType type    = VariableUtilities.ClassifyType(rawType);

                PropTypeP.enumValueIndex = (int)type;
            }
        }

        GUI.enabled = false;
        EditorGUILayout.PropertyField(this.serializedObject.FindProperty("sourceType"));
        GUI.enabled = true;
        serializedObject.ApplyModifiedProperties();
    }
Exemple #3
0
    public override void setFromObject(object value)
    {
        float temp = VariableUtilities.getValueFloat(value);

        this.Value = temp;
    }
Exemple #4
0
 public override void setFromObject(object value)
 {
     float v = VariableUtilities.getValueFloat(value);
 }
    public override void setFromObject(object value)
    {
        int temp = VariableUtilities.getValueInteger(value);

        this.Value = temp;
    }