private void DrawArrows(SpriteBatch b, int top, int leftLeft, int rightLeft)
 {
     if (currentValue > 0)
     {
         leftButton.Draw(b, leftLeft, top);
     }
     if (currentValue < GetMaxValue())
     {
         rightButton.Draw(b, rightLeft, top);
     }
 }
Ejemplo n.º 2
0
    public static void DrawDebugFields(ref Rect area, SerializedProperty property)
    {
        var debug           = property.isExpanded;
        var debugButtonArea = area.RequestLeft(ICON_SIZE);

        area = area.CutLeft(ICON_SIZE);

        if (debug)
        {
            var fieldWidth = Mathf.Min(100, area.width / 9);
            var labelWidth = 25;
            var totalWidth = (fieldWidth + labelWidth) * 2;

            var spacing = 10;

            var testArea = area.RequestLeft(totalWidth + spacing);
            area = area.CutLeft(totalWidth + spacing);
            GUI.Box(testArea.ExpandLeft(ICON_SIZE), string.Empty);
            testArea = testArea.HorizontalShrink(spacing);

            EditorGUI.LabelField(testArea.RequestLeft(labelWidth), " x = ");
            testArea  = testArea.CutLeft(labelWidth);
            testValue = EditorGUI.FloatField(testArea.RequestLeft(fieldWidth), testValue);
            testArea  = testArea.CutLeft(fieldWidth);

            EditorGUI.LabelField(testArea.RequestLeft(labelWidth), " y = ");
            testArea = testArea.CutLeft(labelWidth);

            string result = "Fail";
            try
            {
                result = ((float)property.TriggerMethod("Evaluate", testValue)).ToStringOrNull();
            }
            catch (System.Exception ex)
            {
                result = ex.Message;
            }

            // EditorGUI.BeginDisabledGroup( true );
            EditorGUI.TextField(testArea.RequestLeft(fieldWidth), result);
            // EditorGUI.EndDisabledGroup();
        }
        else
        {
            GUI.Box(debugButtonArea, string.Empty);
        }

        if (IconButton.Draw(debugButtonArea, debug ? "DebugOn" : "DebugOff"))
        {
            property.isExpanded = !debug;
        }
    }
Ejemplo n.º 3
0
 public static bool Draw(Rect area, GameObject go)
 {
     if (go != null)
     {
         var t = AssetPreview.GetAssetPreview(go);
         if (IconButton.Draw(area, t ?? IconCache.Get("search").Texture))
         {
             EditorGUIUtility.PingObject(go);
         }
         return(t != null);
     }
     return(false);
 }
Ejemplo n.º 4
0
    public static void Draw(Rect area, SerializedProperty property, string addFolder)
    {
        bool valid = (property.objectReferenceValue != null) && (property.objectReferenceValue is T);

        var id = -1;

        if (valid)
        {
            id = PrefabCache <T> .Cache.IndexOf(property.objectReferenceValue as T);
        }
        id++;

        var iconSize = Mathf.Min(area.height, area.width / 4);

        var iconArea = area.CutRight(area.width - iconSize).RequestHeight(iconSize);

        if (id == 0 && addFolder != null)
        {
            if (IconButton.Draw(iconArea, "add", '+', "Create new " + typeof(T).ToString() + " prefab", Color.green))
            {
                property.objectReferenceValue = K10EditorGUIUtils.CreateSequentialGO <T>(addFolder + "/New" + typeof(T).ToString());
                PrefabCache <T> .Refresh();
            }
        }
        else
        {
            PreviewButton.Draw(iconArea, property.objectReferenceValue as T);
        }

        area = area.CutLeft(iconSize).RequestHeight(EditorGUIUtility.singleLineHeight);

        var nid = EditorGUI.Popup(area.CutRight(iconSize), id, PrefabCache <T> .NamesWithNone);

        if (nid != id)
        {
            nid--;
            if (nid < 0)
            {
                property.objectReferenceValue = null;
            }
            else
            {
                property.objectReferenceValue = PrefabCache <T> .Cache[nid];
            }
        }

        if (IconButton.Draw(area.CutLeft(area.width - iconSize).RequestHeight(iconSize), "refreshButton", 'R', "Refresh prefabs loaded", Color.blue))
        {
            PrefabCache <T> .Refresh();
        }
    }
Ejemplo n.º 5
0
    public static void DrawParameters(Rect area, SerializedProperty property)
    {
        var parameters = property.FindPropertyRelative("_parameters");

        var buttonsArea = area.RequestRight(ICON_SIZE * 2);

        if (IconButton.Draw(buttonsArea.VerticalSlice(0, 2), "minus"))
        {
            parameters.arraySize--;
        }
        if (IconButton.Draw(buttonsArea.VerticalSlice(1, 2), "add"))
        {
            parameters.arraySize++;
        }
        area = area.CutRight(buttonsArea.width);


        if (parameters.arraySize == 0)
        {
            EditorGUI.LabelField(area, " No parameters, equation will be always 0(zero)! ( Add more parameters --> )");
        }
        else
        {
            var parSize = 7;
            EditorGUI.LabelField(area.RequestLeft(parSize), "(");
            EditorGUI.LabelField(area.RequestRight(parSize), ")");
            area = area.HorizontalShrink(2 * parSize);

            for (int i = 0; i < parameters.arraySize; i++)
            {
                var lastElement = (i >= parameters.arraySize - 1);
                var p           = parameters.GetArrayElementAtIndex(i);
                var a           = area.VerticalSlice(i, parameters.arraySize);

                float xPartW = 28;
                if (lastElement)
                {
                    xPartW = 16;
                }
                xPartW = Mathf.Min(xPartW, a.width / 2);

                EditorGUI.PropertyField(a.CutRight(xPartW), p, GUIContent.none);
                var str = string.Empty;
                EditorGUI.LabelField(a.RequestRight(xPartW), $" x{GetPowerString( i )}" + ((lastElement) ? "" : " + "));
            }
        }
    }
Ejemplo n.º 6
0
    public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
    {
        var groupProp        = property.FindPropertyRelative("_group");
        var volumeProp       = property.FindPropertyRelative("_volume");
        var minPitchProp     = property.FindPropertyRelative("_minPitch");
        var maxPitchProp     = property.FindPropertyRelative("_maxPitch");
        var panProp          = property.FindPropertyRelative("_pan");
        var spatialBlendProp = property.FindPropertyRelative("_spatialBlend");
        var dopplerLevelProp = property.FindPropertyRelative("_dopplerLevel");
        var spreadProp       = property.FindPropertyRelative("_spread");
        var rolloffProp      = property.FindPropertyRelative("_rolloff");
        var minDistanceProp  = property.FindPropertyRelative("_minDistance");
        var maxDistanceProp  = property.FindPropertyRelative("_maxDistance");

        EditorGuiIndentManager.New(0);

        var fold = Fold(property);

        var open = !fold.Get;

        GUI.Box(area, default(Texture2D));

        var lh  = EditorGUIUtility.singleLineHeight;
        var lhs = lh + SPACING;

        var line = area.CutBottom(area.height - lh);

        var labelSize = label.text.Length * 6;

        fold.Set = !EditorGUI.Foldout(line.CutRight(area.width - labelSize), open, open ? "" : label.text);

        if (!open)
        {
            var icon = IconCache.Get("Gear").Texture;

            if (icon != null && GUI.Button(line.RequestHeight(icon.height).CutLeft(line.width - icon.width).MoveLeft(2).MoveDown(1), icon, K10GuiStyles.basicStyle))
            {
                fold.Set = false;
            }

            EditorGuiIndentManager.Revert();
            return;
        }

        area = area.CutTop(2 * SPACING);
        area = area.CutLeft(SPACING * 4);
        area = area.CutRight(SPACING * 4);

        //line = line.CutLeft( labelSize );
        line = area.CutBottom(area.height - lh);
        //line = SeparationLine.Vertical( line );
        //GUI.Box( line, default( Texture2D ) );
        //EditorGUI.PropertyField( area.CutBottom( area.height - lh ), groupProp ); area = area.CutTop( lhs );
        GuiLabelWidthManager.New(42);
        EditorGUI.PropertyField(line, groupProp); area = area.CutTop(lhs);
        GuiLabelWidthManager.Revert();
        GuiLabelWidthManager.New(50);
        EditorGUI.PropertyField(area.CutBottom(area.height - lh), volumeProp); area = area.CutTop(lhs);
        GuiLabelWidthManager.Revert();
//		GuiLabelWidthManager.New( 33 );
        var minPitch = minPitchProp.floatValue;
        var maxPitch = maxPitchProp.floatValue;

        GUI.Label(area.CutBottom(area.height - lh).CutRight(area.width - 33), "Pitch");
        minPitch = EditorGUI.FloatField(area.CutBottom(area.height - lh).CutLeft(33).CutRight(area.width - 83), minPitch);
        minPitch = Mathf.Clamp(minPitch, .011f, 3f);
        EditorGUI.MinMaxSlider(area.CutBottom(area.height - lh).CutLeft(88).CutRight(55), ref minPitch, ref maxPitch, 0.01f, 3f);
        maxPitch = EditorGUI.FloatField(area.CutBottom(area.height - lh).CutLeft(area.width - 50), maxPitch);
        maxPitch = Mathf.Clamp(maxPitch, .011f, 3f);
        area     = area.CutTop(lhs);
        minPitchProp.floatValue = minPitch;
        maxPitchProp.floatValue = maxPitch;
//		GuiLabelWidthManager.Revert();
        GuiLabelWidthManager.New(27);
        EditorGUI.PropertyField(area.CutBottom(area.height - lh), panProp); area = area.CutTop(lhs);
        GuiLabelWidthManager.Revert();

        GuiLabelWidthManager.New(85);
        EditorGUI.PropertyField(area.CutBottom(area.height - lh), spatialBlendProp); area = area.CutTop(lhs);
        EditorGUI.PropertyField(area.CutBottom(area.height - lh), dopplerLevelProp); area = area.CutTop(lhs);
        GuiLabelWidthManager.Revert();
        GuiLabelWidthManager.New(47);
        EditorGUI.PropertyField(area.CutBottom(area.height - lh), spreadProp); area  = area.CutTop(lhs);
        EditorGUI.PropertyField(area.CutBottom(area.height - lh), rolloffProp); area = area.CutTop(lhs);
        GuiLabelWidthManager.Revert();

        line = area.CutBottom(area.height - lh);
        GuiLabelWidthManager.New(28);
        var distSize = 55;

        GUI.Label(line.CutRight(line.width - distSize), "Distance");

        line = line.CutLeft(distSize);

        var iconSize = 16;

        if (IconButton.Draw(line.CutLeft(line.width - iconSize).RequestHeight(iconSize), "RefreshButton", 'R', "Reset configuration to default value", Color.white))
        {
            volumeProp.floatValue       = 1;
            minPitchProp.floatValue     = 1;
            maxPitchProp.floatValue     = 1;
            panProp.floatValue          = 0;
            spatialBlendProp.floatValue = 0;
            dopplerLevelProp.floatValue = 1;
            spreadProp.floatValue       = 1;
            rolloffProp.enumValueIndex  = (int)AudioRolloffMode.Custom;
            minDistanceProp.floatValue  = 1;
            maxDistanceProp.floatValue  = 25;
        }

        line = line.CutRight(iconSize);
        maxDistanceProp.floatValue = EditorGUI.FloatField(line.CutLeft(line.width / 2), "Max", maxDistanceProp.floatValue);
        minDistanceProp.floatValue = EditorGUI.FloatField(line.CutRight(line.width / 2), "Min", minDistanceProp.floatValue);
        EditorGuiIndentManager.Revert();
        GuiLabelWidthManager.Revert();
        area = area.CutTop(lhs);
        EditorGuiIndentManager.Revert();
    }
Ejemplo n.º 7
0
    void OnEnable()
    {
        _author = Persistent <string> .At(AuthorPath);

        _urlField     = serializedObject.FindProperty("_url");
        _exportFields = serializedObject.FindProperty("_exportFields");
        _exportList   = new KReorderableList(serializedObject, _exportFields, "Configurations", IconCache.Get("gear").Texture);

        float lineHeight = EditorGUIUtility.singleLineHeight;
        float vSpacing   = EditorGUIUtility.standardVerticalSpacing;
        var   exporter   = target as JsonExporterData;

        _exportList.List.elementHeightCallback = ( int index ) =>
        {
            var element   = _exportFields.GetArrayElementAtIndex(index);
            var firstLine = lineHeight + vSpacing;
            var reference = element.FindPropertyRelative("_reference");
            if (!element.isExpanded)
            {
                return(firstLine);
            }
            if (reference.objectReferenceValue == null)
            {
                return(firstLine);
            }
            var data            = (JsonFieldDefinition)reference.objectReferenceValue;
            SerializedObject so = new SerializedObject(data);
            var p    = so.FindProperty("_definition");
            var edit = ExportFieldUtility.CalculateHeight(p, lineHeight);

            var inspect        = so.FindProperty("_inspect");
            var inspectionSize = 0f;

            if (!inspect.boolValue)
            {
                inspectionSize = lineHeight;
            }
            else
            {
                var minHeight     = lineHeight;
                var serialization = p.FindPropertyRelative("_serialization");
                var serType       = (EFieldSerializationType)serialization.enumValueIndex;
                if (serType == EFieldSerializationType.ToArray)
                {
                    minHeight = 3 * lineHeight;
                }
                var inspectedElement = so.FindProperty("_inspectedElement");
                var lines            = 1;

                try
                {
                    var oRef           = data.Definition.RootObject;
                    var type           = oRef.GetType();
                    var inspectionText = JsonFieldDefinitionEditor.GetInspectionText(data.Definition, type, oRef, serType, inspectedElement);
                    lines = inspectionText.Count((c) => c == '\n') + 1;
                }
                catch { }

                inspectionSize = Mathf.Max((lineHeight - 2.5f) * lines, minHeight);
            }

            return(firstLine + edit + inspectionSize);
        };

        _exportList.List.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            var firstLineRect = rect.RequestTop(lineHeight);
            var element       = _exportFields.GetArrayElementAtIndex(index);
            var selected      = element.FindPropertyRelative("_selected");
            var batchSize     = element.FindPropertyRelative("_batch");
            var reference     = element.FindPropertyRelative("_reference");

            var data = (JsonFieldDefinition)reference.objectReferenceValue;
            var w    = firstLineRect.width / 3;
            element.isExpanded = EditorGUI.Foldout(firstLineRect.RequestLeft(w).RequestRight(w - 12), element.isExpanded, data?.Definition?.FieldName ?? "*********", true);
            firstLineRect      = firstLineRect.CutLeft(w);

            selected.boolValue = EditorGUI.ToggleLeft(firstLineRect.RequestLeft(16), "", selected.boolValue);
            var r      = firstLineRect.CutLeft(16);
            var soRect = r;
            if (reference.objectReferenceValue is JsonFieldDefinition jsd && jsd.Definition.ShowBatchSize)
            {
                var batchRect = r.RequestLeft(60);
                soRect = soRect.CutLeft(62);
                EditorGUI.LabelField(batchRect, batchSize.intValue == 0 ? "(∞)batch" : "batch", K10GuiStyles.unitStyle);
                batchSize.intValue = Mathf.Max(EditorGUI.IntField(batchRect, batchSize.intValue), 0);
            }
            ScriptableObjectField.Draw <JsonFieldDefinition>(soRect, reference, "Assets/[_Configurations_]/ExportFields/");

            if (element.isExpanded && reference.objectReferenceValue != null)
            {
                SerializedObject so = new SerializedObject(data);
                var p    = so.FindProperty("_definition");
                var edit = ExportFieldUtility.CalculateHeight(p, lineHeight);
                rect = rect.CutTop(lineHeight + vSpacing);
                data.Definition.DrawElement(p, rect.RequestTop(edit), lineHeight, null);
                var inspectionRect       = rect.CutTop(edit);
                var inspectionTextRect   = inspectionRect.CutLeft(32);
                var inspectionFieldsRect = inspectionRect.RequestLeft(32);

                var inspect       = so.FindProperty("_inspect");
                var inspectChange = IconButton.Draw(inspectionFieldsRect.RequestTop(lineHeight), inspect.boolValue ? "spy" : "visibleOff");

                var inspectionText = "";

                if (inspect.boolValue && data.Definition != null)
                {
                    var count         = 0;
                    var serialization = p.FindPropertyRelative("_serialization");
                    var serType       = (EFieldSerializationType)serialization.enumValueIndex;

                    var oRef = data.Definition.RootObject;
                    if (serType == EFieldSerializationType.ToArray)
                    {
                        var enu = oRef as System.Collections.IEnumerable;
                        if (enu != null)
                        {
                            foreach (var o in enu)
                            {
                                count++;
                            }
                        }
                    }

                    var inspectedElement = so.FindProperty("_inspectedElement");
                    if (count > 0)
                    {
                        var fieldsModRect = inspectionFieldsRect.CutTop(lineHeight);
                        inspectedElement.intValue = EditorGUI.IntField(fieldsModRect.RequestTop(lineHeight), inspectedElement.intValue);
                        bool canGoUp = inspectedElement.intValue < (count - 1);

                        var btsRect = fieldsModRect.CutTop(lineHeight).RequestTop(lineHeight);
                        EditorGUI.BeginDisabledGroup(!canGoUp);
                        var up = IconButton.Draw(btsRect.VerticalSlice(1, 2), "upTriangle", '▲', "", Color.white);
                        EditorGUI.EndDisabledGroup();
                        bool canGoDown = inspectedElement.intValue > 0;
                        EditorGUI.BeginDisabledGroup(!canGoDown);
                        var down = IconButton.Draw(btsRect.VerticalSlice(0, 2), "downTriangle", '▼', "", Color.white);
                        EditorGUI.EndDisabledGroup();
                        if (up)
                        {
                            inspectedElement.intValue++;
                        }
                        if (down)
                        {
                            inspectedElement.intValue--;
                        }
                        inspectedElement.intValue = Mathf.Max(inspectedElement.intValue, 0);
                    }

                    var type = oRef.GetType();
                    inspectionText = JsonFieldDefinitionEditor.GetInspectionText(data.Definition, type, oRef, serType, inspectedElement);
                }

                if (inspectChange)
                {
                    inspect.boolValue = !inspect.boolValue;
                }

                EditorGUI.TextArea(inspectionTextRect, inspectionText);

                if (GUI.changed)
                {
                    so.ApplyModifiedProperties();
                }
            }
        };
    }