Exemplo n.º 1
0
    public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
    {
        EditorGUI.LabelField(area.RequestLeft(EditorGUIUtility.labelWidth), label);
        var restArea = area.CutLeft(EditorGUIUtility.labelWidth);

        DrawRangedFloatVariable(property, restArea.VerticalSlice(3, 13, 10));
        EditorGUI.BeginDisabledGroup(true);
        var percentageArea     = restArea.VerticalSlice(0, 13, 3);
        var obj                = property.GetInstance(out var objType);
        var percentageProp     = objType.GetProperty(PercentageRangedFloatState.PERCENTAGE_PROPERTY_NAME);
        var percentagePropInst = percentageProp.GetValue(obj) as IValueStateObserver <float>;
        var percentageValue    = percentagePropInst.Value;

        EditorGUI.FloatField(percentageArea.CutLeft(24), percentageValue * 100);
        EditorGUI.EndDisabledGroup();
        EditorGUI.LabelField(percentageArea.Shrink(2), "%", K10GuiStyles.unitStyle);
        var keyCode = property.GetKey() + ".Percentage";

        SerializedPropertyExtensions.DebugWatcherField <float>(keyCode, percentageProp.GetValue(obj), percentageProp.PropertyType, percentageArea.RequestLeft(20));
    }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label.tooltip = EditorHelper.GetTooltipAttribute(fieldInfo)?.tooltip ?? string.Empty;
            bool foundGeneric = false;
            bool valid        = false;

            try
            {
                Vector2 input  = SerializedPropertyExtensions.GetValue <FloatRange>(property).ToVector2();
                Vector2 output = BuildSlider(position, label, input, out valid);
                if (valid)
                {
                    SerializedPropertyExtensions.SetValue <FloatRange>(property, new FloatRange(output));
                }
                foundGeneric = true;
            }
            catch (System.Exception)
            {
                Error(position, label);
            }

            if (!foundGeneric)
            {
                switch (property.propertyType)
                {
                case SerializedPropertyType.Vector2:
                    Vector2 input  = property.vector2Value;
                    Vector2 output = BuildSlider(position, label, input, out valid);
                    if (valid)
                    {
                        property.vector2Value = output;
                    }
                    break;

                default:
                    Error(position, label);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label.tooltip = VRTK_EditorUtilities.GetTooltipAttribute(fieldInfo).tooltip;
            bool foundGeneric = false;
            bool valid        = false;

            try
            {
                Vector2 input  = SerializedPropertyExtensions.GetValue <Limits2D>(property).AsVector2();
                Vector2 output = BuildSlider(position, label, input, out valid);
                if (valid)
                {
                    SerializedPropertyExtensions.SetValue <Limits2D>(property, new Limits2D(output));
                }
                foundGeneric = true;
            }
            catch (System.Exception)
            {
                Error(position, label);
            }

            if (!foundGeneric)
            {
                switch (property.propertyType)
                {
                case SerializedPropertyType.Vector2:
                    Vector2 input  = property.vector2Value;
                    Vector2 output = BuildSlider(position, label, input, out valid);
                    if (valid)
                    {
                        property.vector2Value = output;
                    }
                    break;

                default:
                    Error(position, label);
                    break;
                }
            }
        }
Exemplo n.º 4
0
        private void OnGUI()
        {
            //search bar
            var style = new GUIStyle(EditorStyles.toolbarSearchField);

            input = EditorGUILayout.TextField("Search", input, style);
            if (input != null && input != "")
            {
                input = Regex.Replace(input, @"\s+", ""); //remove spaces in input
            }
            //get matches
            matches = FindMatches(subclasses, input);
            //display matches
            for (int i = 0; i < matches.Length; i++)
            {
                if (GUILayout.Button(matches[i].Name))
                {
                    var obj = ScriptableObject.CreateInstance(matches[i]);
                    obj.name = matches[i].Name;
                    SerializedPropertyExtensions.SetNestedObject(data.path, data.serObject, obj);
                }
            }
        }
Exemplo n.º 5
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        float width = position.width - x;

        EditorGUI.LabelField(new Rect(x, position.y * (Height * 0), width, Height), label);
        string labelText = label.text;

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        string AddressableType = "";

        if (property.name == "AddressableAudioSource")
        {
            AddressableType = "SoundAndMusic";
        }
        else
        {
            AddressableType = "SoundAndMusic";
        }

        bool Refresh = GUILayout.Button("Refresh catalogue");

        if (Refresh)
        {
            AddressablePicker.Refresh();
        }
        //EditorGUI.indentLevel++;
        EditorGUI.BeginChangeCheck();
        var Path           = property.FindPropertyRelative("AssetAddress");
        var AssetReference = property.FindPropertyRelative("AssetReference");

        EditorGUI.PropertyField(new Rect(x, position.y + (Height * 1), width, Height),
                                property.FindPropertyRelative("SetLoadSetting"), new GUIContent("Dispose Mode"));

        //EditorGUI.BeginDisabledGroup(true);
        EditorGUI.PropertyField(new Rect(x, position.y + (Height * 2), width, Height), Path,
                                new GUIContent("Addressable Path"));
        //EditorGUI.EndDisabledGroup();

        //UnityEngine.Object oldAssetReference = AssetReference.objectReferenceValue;
        EditorGUI.indentLevel++;
        var newsearchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));

        if (newsearchString != searchString)
        {
            //searchChange = true;
            searchString = newsearchString;
        }


        if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
        {
            // Remove focus if cleared
            searchString = "";
            GUI.FocusControl(null);
        }

        var inint = 0;

        if (searchString != "")
        {
            temarry = (AddressablePicker.options[AddressableType].Where(x =>
                                                                        x.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) >= 0)).ToArray();
            inint = temarry.ToList().IndexOf(Path.stringValue);
        }
        else
        {
            inint = AddressablePicker.options[AddressableType].ToList().IndexOf(Path.stringValue);
        }

        if (inint == -1)
        {
            inint = 0;
        }

        if (searchString != "")
        {
            _choiceIndex = EditorGUILayout.Popup(inint, temarry);
        }
        else
        {
            _choiceIndex = EditorGUILayout.Popup(inint, AddressablePicker.options[AddressableType]);
        }



        EditorGUI.indentLevel--;
        if (searchString != "")
        {
            if (temarry.Length <= _choiceIndex)
            {
                if (temarry.Length > 0)
                {
                    Path.stringValue = temarry[0];
                }
                else
                {
                    Path.stringValue = "None";
                }
            }
            else
            {
                Path.stringValue = temarry[_choiceIndex];
            }
        }
        else
        {
            Path.stringValue = AddressablePicker.options[AddressableType][_choiceIndex];
        }

        EditorGUI.PropertyField(new Rect(x, position.y + (Height * 3), width, Height), AssetReference,
                                new GUIContent("AssetReference"));

        // Drag & Drop of AssetReference doesn't seem to trigger EndChangeCheck.  So, we verify it manually.
        if (EditorGUI.EndChangeCheck())
        {
            var m_AssetRefObject =
                SerializedPropertyExtensions.GetActualObjectForSerializedProperty <AssetReference>(AssetReference,
                                                                                                   fieldInfo, ref labelText);
            var Addressable = AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(m_AssetRefObject.AssetGUID);
            if (Addressable != null)
            {
                Path.stringValue = AddressableAssetSettingsDefaultObject.Settings
                                   .FindAssetEntry(m_AssetRefObject.AssetGUID).address;
            }
        }



        //EditorGUI.indentLevel--;
        property.serializedObject.ApplyModifiedProperties();
        EditorGUI.EndProperty();
    }