/// <summary>
 /// Changes the specified attribute of this Bar by the specified amount.
 /// </summary>
 /// <param name="attribute">The attribute of the Bar to change.</param>
 /// <param name="changeAmount">The amount to change by (additive).</param>
 public void UpdateBar(BarAttribute attribute, float changeAmount)
 {
     if (attribute == BarAttribute.Height)
     {
         bar.sizeDelta = new Vector2(barWidthSize, barHeightSize + changeAmount);
         barHeightSize = bar.sizeDelta.y;
     }
     if (attribute == BarAttribute.Width)
     {
         bar.sizeDelta = new Vector2(barWidthSize + changeAmount, barHeightSize);
         barWidthSize  = bar.sizeDelta.x;
     }
 }
        /// <summary>
        /// Changes the specified attribute of this Bar by the specified amount.
        /// </summary>
        /// <param name="attribute">The attribute of the Bar to change.</param>
        /// <param name="changeAmount">The amount to change by (additive).</param>
        /// <param name="newAmount">The new amount to be displayed.</param>
        public void UpdateBar(BarAttribute attribute, float changeAmount, float newAmount)
        {
            if (attribute == BarAttribute.Height)
            {
                //bar.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, barHeightSize + changeAmount);
                bar.sizeDelta = new Vector2(barWidthSize, barHeightSize + changeAmount);
                barHeightSize = bar.sizeDelta.y;

                displayText.text = (label + newAmount);
            }
            if (attribute == BarAttribute.Width)
            {
                bar.sizeDelta = new Vector2(barWidthSize + changeAmount, barHeightSize);
                barWidthSize  = bar.sizeDelta.x;

                displayText.text = (label + newAmount);
            }
        }
    public static string Name(this Foo Value)
    {
        string    rv        = string.Empty;
        FieldInfo fieldInfo = Value.GetType().GetField(Value.ToString());

        if (fieldInfo != null)
        {
            object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(BarAttribute), true);
            if (customAttributes.Length > 0 && customAttributes[0] != null)
            {
                BarAttribute barAttribute = customAttributes[0] as BarAttribute;
                if (barAttribute != null)
                {
                    rv = barAttribute.Name;
                }
            }
        }
        return(rv);
    }
Exemple #4
0
    //实现IIterator的三个接口
    Object IIterator.Next()
    {
        if (mListEnumerator.MoveNext())
        {
            XmlNode node = (XmlNode)mListEnumerator.Current;
            try{
                mCurrentBar = new BarAttribute(
                    (EnumBarType)Enum.Parse(typeof(EnumBarType), node.Attributes["beat_type"].Value),
                    Convert.ToInt32(node.Attributes["bar_num"].Value)
                    );
            }
            catch {
                return(null);
            }

            mIndex++;
            return(mCurrentBar);
        }
        else
        {
            return(null);
        }
    }
Exemple #5
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        #region Variable Declaration

        var barAttribute = attribute as BarAttribute;

        float lineHight = EditorGUIUtility.singleLineHeight;
        float padding   = EditorGUIUtility.standardVerticalSpacing;

        var barPosition = new Rect(position.position.x, position.position.y, position.size.x, lineHight);

        float  fillPercentage        = 0;
        string barLabel              = string.Empty;
        bool   maxValueIsInvalid     = false;
        bool   currentFieldIsInvalid = false;
        bool   error = false;

        #endregion Variable Declaration

        #region Cache Reflection

        if (!_alreadyAttemptedToRetrieve)
        {
            _alreadyAttemptedToRetrieve = true;

            _classType      = property.serializedObject.targetObject.GetType();
            _retrievedField = property.serializedObject.FindProperty(barAttribute.maxValueName);

            if (barAttribute.maxValueName != null)
            {
                _retrievedProperty = _classType.GetProperty(barAttribute.maxValueName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                _retrievedMethod   = _classType.GetMethod(barAttribute.maxValueName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            }
        }

        #endregion Cache Reflection

        MaxValueUsed maxValueType = MaxValueUsed.StaticValue;

        if (barAttribute.UsingStaticMaxValue)
        {
            maxValueType = MaxValueUsed.StaticValue;
        }
        else if (_retrievedMethod != null)
        {
            maxValueType = MaxValueUsed.Method;
        }
        else if (_retrievedProperty != null)
        {
            maxValueType = MaxValueUsed.Property;
        }
        else if (_retrievedField != null)
        {
            maxValueType = MaxValueUsed.Field;
        }
        else // Provided Max Value Is Invalid
        {
            maxValueIsInvalid = true;
            barLabel          = "Invalid Field/Property/Method. Please Check.";
        }

        // If field with parameter is invalid.
        currentFieldIsInvalid = property.propertyType != SerializedPropertyType.Integer &&
                                property.propertyType != SerializedPropertyType.Float;

        if (currentFieldIsInvalid)
        {
            string message = string.Format("The <b><i>BarAttribute</i></b> Cannot Be Used On \"<i><b>{0}s</b></i>\". Only Ints and Floats.", property.propertyType.ToString());
            barLabel = barLabel == String.Empty ? message : string.Format("{0}\nAlso, {1}", barLabel, message);
        }

        error = currentFieldIsInvalid || maxValueIsInvalid;


        // No errors, get normal bar label.
        if (!error)
        {
            float current = property.propertyType == SerializedPropertyType.Integer
                ? property.intValue
                : property.floatValue;

            float max = GetMax(maxValueType, property, barAttribute.staticMaxValue);

            // Get Fill %
            fillPercentage = current / max;

            // Draw Label Text
            barLabel = string.Format("{0} ({3:0.0}%) | {1:0.0}/{2:0.0}",
                                     string.Format("{0}{1}", property.name[0].ToString().ToUpperInvariant(), property.name.Substring(1)),
                                     current,
                                     max,
                                     fillPercentage * 100);
        }

        EditorGUI.PropertyField(new Rect(position.position.x, position.position.y + lineHight + padding, position.size.x, lineHight), property);

        #region Draw Result

        if (error)
        {
            GUI.Label(barPosition, string.Format("<color=red>{0}</color>", barLabel), new GUIStyle {
                richText = true
            });
        }
        else
        {
            var color  = BarAttribute.GetConcreteColor(barAttribute.color);
            var color2 = Color.white;
            DrawBar(barPosition, Mathf.Clamp01(fillPercentage), barLabel, color, color2);
        }

        #endregion Draw Result

        // Force to always redraw, else when inspector gets out of focus, any highlight will also be turned off.
        EditorUtility.SetDirty(property.serializedObject.targetObject);
    }