예제 #1
0
    void DrawMeter(SerializedProperty meterProp)
    {
        SerializedProperty startBarProp    = meterProp.FindPropertyRelative("StartBar");
        SerializedProperty tempoProp       = meterProp.FindPropertyRelative("Tempo");
        SerializedProperty unitPerBarProp  = meterProp.FindPropertyRelative("UnitPerBar");
        SerializedProperty unitPerBeatProp = meterProp.FindPropertyRelative("UnitPerBeat");
        SerializedProperty numeratorProp   = meterProp.FindPropertyRelative("Numerator");
        SerializedProperty denominatorProp = meterProp.FindPropertyRelative("Denominator");

        int    startBar    = startBarProp.intValue;
        double tempo       = tempoProp.doubleValue;
        int    unitPerBar  = unitPerBarProp.intValue;
        int    unitPerBeat = unitPerBeatProp.intValue;
        int    numerator   = numeratorProp.intValue;
        int    denominator = denominatorProp.intValue;

        meterProp.isExpanded = EditorGUILayout.Foldout(meterProp.isExpanded, string.Format("Meter {0}~ ({1}/{2}, {3:F2})", startBar, numerator, denominator, tempo));
        if (meterProp.isExpanded)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(startBarProp);
            EditorGUILayout.PropertyField(tempoProp);

            if (showUnitPerBarBeat_)
            {
                EditorGUILayout.PropertyField(unitPerBeatProp);
                EditorGUILayout.PropertyField(unitPerBarProp);

                if (unitPerBar != unitPerBarProp.intValue || unitPerBeat != unitPerBeatProp.intValue)
                {
                    MusicMeter.CalcMeterByUnits(unitPerBeatProp.intValue, unitPerBarProp.intValue, out numerator, out denominator);
                    numeratorProp.intValue   = numerator;
                    denominatorProp.intValue = denominator;
                }
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Meter", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                    EditorGUIUtility.labelWidth = 1;
                    EditorGUILayout.PropertyField(numeratorProp, GUILayout.Width(55));
                    denominatorProp.intValue    = EditorGUILayout.IntPopup("/", denominatorProp.intValue, MeterDenominatorCandidatesString, MeterDenominatorCandidates);
                    EditorGUIUtility.labelWidth = 0;

                    if (numerator != numeratorProp.intValue || denominator != denominatorProp.intValue)
                    {
                        MusicMeter.CalcMeterByFraction(numeratorProp.intValue, denominatorProp.intValue, out unitPerBeat, out unitPerBar);
                        unitPerBeatProp.intValue = unitPerBeat;
                        unitPerBarProp.intValue  = unitPerBar;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel--;
        }
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Init(property);

        var fieldRect = position;

        fieldRect.height = GetPropertyHeight(property, label);

        using (new EditorGUI.PropertyScope(fieldRect, label, property))
        {
            //int startBar = _property.StartBar.intValue;
            double tempo       = _property.Tempo.doubleValue;
            int    unitPerBar  = _property.UnitPerBar.intValue;
            int    unitPerBeat = _property.UnitPerBeat.intValue;
            int    numerator   = _property.Numerator.intValue;
            int    denominator = _property.Denominator.intValue;

            fieldRect.height = EditorGUIUtility.singleLineHeight;

            property.isExpanded = EditorGUI.Foldout(fieldRect, property.isExpanded, string.Format("{0} ({1}/{2}, {3:F2})", label.text, numerator, denominator, tempo));
            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;

                //fieldRect.y += EditorGUIUtility.singleLineHeight;
                //EditorGUI.PropertyField(fieldRect, _property.StartBar);
                fieldRect.y += EditorGUIUtility.singleLineHeight;
                EditorGUI.PropertyField(fieldRect, _property.Tempo);

                fieldRect.y        += EditorGUIUtility.singleLineHeight;
                showUnitPerBarBeat_ = EditorGUI.Toggle(fieldRect, "Show Meter In UnitPerBar/Beat", showUnitPerBarBeat_);

                if (showUnitPerBarBeat_)
                {
                    fieldRect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.PropertyField(fieldRect, _property.UnitPerBeat);
                    fieldRect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.PropertyField(fieldRect, _property.UnitPerBar);

                    if (unitPerBar != _property.UnitPerBar.intValue || unitPerBeat != _property.UnitPerBeat.intValue)
                    {
                        MusicMeter.CalcMeterByUnits(_property.UnitPerBeat.intValue, _property.UnitPerBar.intValue, out numerator, out denominator);
                        _property.Numerator.intValue   = numerator;
                        _property.Denominator.intValue = denominator;
                    }
                }
                else
                {
                    fieldRect.y    += EditorGUIUtility.singleLineHeight;
                    fieldRect       = EditorGUI.PrefixLabel(fieldRect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Meter"));
                    fieldRect.x    -= 16;
                    fieldRect.width = 55;
                    EditorGUI.PropertyField(fieldRect, _property.Numerator, GUIContent.none);
                    fieldRect.x    += 60;
                    fieldRect.width = 60;
                    _property.Denominator.intValue = EditorGUI.IntPopup(fieldRect, _property.Denominator.intValue, MeterDenominatorCandidatesString, MeterDenominatorCandidates);

                    if (numerator != _property.Numerator.intValue || denominator != _property.Denominator.intValue)
                    {
                        MusicMeter.CalcMeterByFraction(_property.Numerator.intValue, _property.Denominator.intValue, out unitPerBeat, out unitPerBar);
                        _property.UnitPerBeat.intValue = unitPerBeat;
                        _property.UnitPerBar.intValue  = unitPerBar;
                    }
                }

                EditorGUI.indentLevel--;
            }
        }
    }