public virtual void Initialize(QuickUiControl control)
    {
        _control = control;

        GetReferences();
        _label.text = control.TargetMember.Name;

        gameObject.name = control.TargetMember.Name;
    }
Beispiel #2
0
    public override void Initialize(QuickUiControl control)
    {
        base.Initialize(control);

        _dropdown.value = (int)_control.GetValue();
        _dropdown.onValueChanged.AddListener(val =>
        {
            _control.SetValue(_values[val]);
        });
    }
Beispiel #3
0
    public override void Initialize(QuickUiControl control)
    {
        base.Initialize(control);

        var attributes = control.TargetMember.GetAttributes();

        _toggle.onValueChanged.AddListener(newVal =>
        {
            _control.SetValue(newVal);
        });
    }
    private bool DrawComponentUi(GameObject targetGameObject, string[] componentNames, int[] componentIndices, out string[] memberNames, out int[] memberIndices)
    {
        EditorGUI.BeginChangeCheck();
        var newIndex = EditorGUILayout.IntPopup(GetSelectedIndex(_targetComponentName.stringValue, componentNames), componentNames, componentIndices);

        if (EditorGUI.EndChangeCheck())
        {
            _targetComponentName.stringValue = componentNames[newIndex];
        }
        if (_targetComponentName.stringValue == "")
        {
            _targetMemberName.stringValue = "";
            memberNames   = null;
            memberIndices = null;
            return(false);
        }
        var targetComponent = QuickUiControl.GetTargetComponent(targetGameObject, _targetComponentName.stringValue);

        if (targetComponent == null)
        {
            _targetMemberName.stringValue = "";
            EditorGUILayout.HelpBox("Failed to find component named " + _targetComponentName.stringValue + " on provided object", MessageType.Error);
            memberNames   = null;
            memberIndices = null;
            return(false);
        }

        EditorGUILayout.PropertyField(_targetMemberType, new GUIContent("Member Type"));

        if (!QuickUiControl.GetMemberNameOptions(targetComponent.GetType(), (QuickUiMemberType)_targetMemberType.enumValueIndex, out memberNames, out memberIndices))
        {
            _targetMemberName.stringValue = "";
            EditorGUILayout.HelpBox("Failed to get member name list for provided Object/Component", MessageType.Error);
            return(false);
        }

        if (memberNames.Length != 0)
        {
            return(true);
        }

        _targetMemberName.stringValue = "";
        EditorGUILayout.HelpBox("No members of type " + ((QuickUiMemberType)_targetMemberType.enumValueIndex) + " found on component " + targetComponent.name, MessageType.Warning);
        return(false);
    }
    public override void Initialize(QuickUiControl control)
    {
        base.Initialize(control);

        var value = (Vector3)_control.GetValue();

        for (var i = 0; i < 3; i++)
        {
            _values[i].text = value[i].ToString("0.00");
            var i1 = i;
            _values[i].onValueChanged.AddListener(newVal =>
            {
                var currentValue = (Vector3)_control.GetValue();
                currentValue[i1] = float.Parse(newVal);
                _control.SetValue(currentValue);
            });
        }
    }
    private bool DrawGameObjectUi(out GameObject targetObject, out string[] componentNames, out int[] componentIndices)
    {
        EditorGUILayout.PropertyField(_targetObject, new GUIContent("Target GameObject"));

        if (_targetObject.objectReferenceValue == null)
        {
            _targetComponentName.stringValue = "";
            _targetMemberName.stringValue    = "";
            componentNames   = null;
            componentIndices = null;
            targetObject     = null;
            EditorGUILayout.HelpBox("Assign a GameObject to configure this control", MessageType.Info);
            return(false);
        }

        targetObject = (GameObject)_targetObject.objectReferenceValue;
        if (targetObject == null)
        {
            _targetComponentName.stringValue = "";
            _targetMemberName.stringValue    = "";
            componentNames   = null;
            componentIndices = null;
            EditorGUILayout.HelpBox("The provided object is null or invalid", MessageType.Error);
            return(false);
        }

        if (QuickUiControl.GetComponentEnum(targetObject, out componentNames, out componentIndices))
        {
            return(true);
        }

        _targetComponentName.stringValue = "";
        _targetMemberName.stringValue    = "";
        EditorGUILayout.HelpBox("Failed to get component list for provided Object", MessageType.Error);

        return(false);
    }
Beispiel #7
0
    public override void Initialize(QuickUiControl control)
    {
        base.Initialize(control);

        var hasRange   = false;
        var attributes = control.TargetMember.GetAttributes();

        foreach (var attribute in attributes)
        {
            if (attribute.AttributeType != typeof(RangeAttribute))
            {
                continue;
            }

            if (control.TargetMember.Type == typeof(int))
            {
                _slider.wholeNumbers = true;
            }
            _slider.minValue = (float)attribute.ConstructorArguments[0].Value;
            _slider.maxValue = (float)attribute.ConstructorArguments[1].Value;
            hasRange         = true;
        }

        if (hasRange)
        {
            if (control.TargetMember.Type == typeof(int))
            {
                _slider.value = (int)_control.GetValue();
            }
            else
            {
                _slider.value = (float)_control.GetValue();
            }
            _slider.onValueChanged.AddListener(val =>
            {
                if (control.TargetMember.Type == typeof(int))
                {
                    _control.SetValue((int)val);
                    _slider.value = val;
                }
                else
                {
                    _control.SetValue(val);
                    _slider.value = val;
                }

                _value.text = val.ToString(CultureInfo.InvariantCulture);
            });
        }
        else
        {
            var valueRt = _value.GetComponent <RectTransform>();
            valueRt.anchorMin = new Vector2(0.35f, 0f);
            valueRt.offsetMin = Vector2.zero;
            _slider.gameObject.SetActive(false);
        }

        _value.onValueChanged.AddListener(newVal =>
        {
            if (control.TargetMember.Type == typeof(int))
            {
                var val = int.Parse(newVal);
                _control.SetValue(val);
                _slider.value = val;
            }
            else
            {
                var val = float.Parse(newVal);
                _control.SetValue(val);
                _slider.value = val;
            }
        });

        _value.text = _control.GetValue().ToString();
    }
Beispiel #8
0
 public override void Initialize(QuickUiControl control)
 {
     base.Initialize(control);
     _button.onClick.AddListener(control.Invoke);
 }
Beispiel #9
0
    private void AddControl <T>(ref List <QuickUiSceneControl> controlList, string prefabName, QuickUiControl control, bool alreadyExists = false) where T : QuickUiSceneControl
    {
        var attributes             = control.TargetMember.GetAttributes();
        CustomAttributeData space  = null;
        CustomAttributeData header = null;

        foreach (var attribute in attributes)
        {
            if (attribute.AttributeType == typeof(SpaceAttribute))
            {
                space = attribute;
            }
            if (attribute.AttributeType == typeof(HeaderAttribute))
            {
                header = attribute;
            }
        }

        if (space != null && !alreadyExists)
        {
            AddSpace(ref controlList, "QuickUiSpace", (float)space.ConstructorArguments[0].Value);
        }

        if (header != null && !alreadyExists)
        {
            AddHeader(ref controlList, "QuickUiHeader", (string)header.ConstructorArguments[0].Value);
        }

        if (alreadyExists)
        {
            //note - this will break if multiple members have the same name...
            var sceneControl = transform.Find(control.TargetMemberName).GetComponent <T>();
            sceneControl.Initialize(control);
            controlList.Add(sceneControl);
        }
        else
        {
#if UNITY_EDITOR
            var newObj = PrefabUtility.InstantiatePrefab(Resources.Load(prefabName)) as GameObject;
#else
            var newObj = Instantiate(Resources.Load(prefabName)) as GameObject;
#endif

            if (newObj == null)
            {
                Debug.LogError("Failed to instantiate QuickUi object " + prefabName);
                return;
            }

            ((RectTransform)newObj.transform).SetParentNeutral(ControlParent);
            newObj.name = control.TargetMemberName;

            var sceneControl = newObj.AddComponent <T>();
            sceneControl.Initialize(control);

            controlList.Add(sceneControl);
        }
    }
Beispiel #10
0
 private void AddButtonControl(ref List <QuickUiSceneControl> controlList, QuickUiControl control, bool alreadyExists = false)
 {
     AddControl <QuickUiButton>(ref controlList, "QuickUiButton", control, alreadyExists);
 }
Beispiel #11
0
 private void AddBooleanControl(ref List <QuickUiSceneControl> controlList, QuickUiControl control, bool alreadyExists = false)
 {
     AddControl <QuickUiToggle>(ref controlList, "QuickUiToggle", control, alreadyExists);
 }
Beispiel #12
0
 private void AddEnumControl(ref List <QuickUiSceneControl> controlList, QuickUiControl control, bool alreadyExists = false)
 {
     AddControl <QuickUiDropdown>(ref controlList, "QuickUiDropdown", control, alreadyExists);
 }
Beispiel #13
0
 private void AddVector3Control(ref List <QuickUiSceneControl> controlList, QuickUiControl control, bool alreadyExists = false)
 {
     AddControl <QuickUiVector3>(ref controlList, "QuickUiVector3", control, alreadyExists);
 }
Beispiel #14
0
 private void AddSliderControl(ref List <QuickUiSceneControl> controlList, QuickUiControl control, bool alreadyExists = false)
 {
     AddControl <QuickUiSlider>(ref controlList, "QuickUiSlider", control, alreadyExists);
 }