示例#1
0
        public static bool Draw(Rect r, SerializedProperty prop, System.Type type, string path = null, bool ignoreIdentation = true)
        {
            var createdNewSO = false;
            var obj          = prop.objectReferenceValue;

            if (obj == null)
            {
                var iconSize = 16;
                var create   = GUI.Button(new Rect(r.x, r.y + (r.height - iconSize) / 2, iconSize, iconSize), IconCache.Get("match").Texture, new GUIStyle());
                if (create)
                {
                    var target = prop.serializedObject.targetObject;
                    if (prop.serializedObject.targetObject is MonoBehaviour)
                    {
                        target = MonoScript.FromMonoBehaviour((MonoBehaviour)prop.serializedObject.targetObject);
                    }
                    var selectedAssetPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(target));

                    var go = ScriptableObjectUtils.CreateSequential(selectedAssetPath + "\\" + prop.ToFileName(), type);
                    prop.objectReferenceValue = go;
                    prop.serializedObject.ApplyModifiedProperties();
                    createdNewSO = true;
                }
                r = r.CutLeft(iconSize + 2);
            }

            if (ignoreIdentation)
            {
                EditorGuiIndentManager.New(0);
            }
            var newObj = EditorGUI.ObjectField(r, obj, type, false);

            if (ignoreIdentation)
            {
                EditorGuiIndentManager.Revert();
            }
            if (newObj != obj)
            {
                prop.objectReferenceValue = newObj;
                prop.serializedObject.ApplyModifiedProperties();
            }

            return(createdNewSO);
        }
示例#2
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();
    }
示例#3
0
 public static void Revert()
 {
     GuiLabelWidthManager.Revert();
     EditorGuiIndentManager.Revert();
 }
示例#4
0
    public override void OnGUI(Rect area, SerializedProperty prop, GUIContent label)
    {
        if (prop.type != nameof(Bits))
        {
            EditorGUI.HelpBox(area, $"This field {prop.displayName} need to be from type {nameof( Bits )}, {prop.type} is not a valid type", MessageType.Error);
            return;
        }

        var typeAttr = attribute as HashedElementFilterBitsAttribute;
        var inst     = ScriptableObject.CreateInstance(typeAttr.propType) as HashedScriptableObject;

        if (inst == null)
        {
            EditorGUI.HelpBox(area, $"The editor for {prop.displayName} need to be derived from type {nameof( HashedScriptableObject )}, {typeAttr.propType} is not a valid type", MessageType.Error);
            return;
        }

        // return;

        var bits    = prop.FindPropertyRelative("_array");
        var adapter = new PropIntListAdapter(bits);

        var col   = inst.GetCollection();
        var steps = ((col.Count - 1) / BATCH_SIZE) + 1;

        var       labelArea    = area.RequestLeft(EditorGUIUtility.labelWidth);
        const int BUTTON_WIDTH = 40;
        var       masksArea    = area.CutLeft(EditorGUIUtility.labelWidth).CutRight(BUTTON_WIDTH);
        var       buttonArea   = area.RequestRight(BUTTON_WIDTH);

        var allSet   = BitsManipulator.IsAll(adapter, true);
        var allunset = BitsManipulator.IsAll(adapter, false);

        if (GUI.Button(buttonArea, allSet ? "ALL" : (allunset ? "NONE" : BitsManipulator.CountSet(adapter).ToString())))
        {
            BitsManipulator.SetAll(adapter, !allSet);
        }

        label.text = label.text + "(" + BitsManipulator.ToString(adapter) + ") { " + string.Join(", ", adapter.ToList().ConvertAll((v) => v.ToString())) + " }";
        GUI.Label(labelArea, label.text);

        EditorGuiIndentManager.New(0);
        var names = new List <string[]>();

        for (int i = 0; i < steps; i++)
        {
            var init  = i * BATCH_SIZE;
            var count = Mathf.Min(col.Count - init, BATCH_SIZE);
            var n     = new string[count];
            names.Add(n);
            for (int j = 0; j < count; j++)
            {
                var eId = init + j;
                var e   = col.GetElementBase(eId);
                n[j] = e.ToStringOrNull();
            }
            var val    = BitsManipulator.QuerySector32(adapter, i);
            var newVal = EditorGUI.MaskField(masksArea.VerticalSlice(i, steps), GUIContent.none, val, n);

            if (newVal != val)
            {
                var changes = newVal ^ val;
                for (int j = 0; j < 32; j++)
                {
                    var itMask = (1 << j);
                    if ((changes & itMask) == 0)
                    {
                        continue;
                    }
                    var newBit = (newVal & itMask) != 0;
                    BitsManipulator.Set(adapter, init + j, newBit);
                }
            }
        }
        EditorGuiIndentManager.Revert();
    }