コード例 #1
0
        public void ApplyEffect(ValueCollection.Value value)
        {
            switch (value.Type)
            {
            case ValueType._NONE: break;

            case ValueType.Damage:
                this[ValueType.Health] -= Mathf.Clamp(value.Derived - this[ValueType.DamageReduction], 0, this[ValueType.Health]);
                break;

            case ValueType.Health:
                this[ValueType.Health] += Mathf.Clamp(value.Derived, 0, this[ValueType.HealthMax] - this[ValueType.Health]);
                break;

            case ValueType.ContactDamage:
                ApplyEffect(ValueType.Damage, value.Derived);
                break;

            case ValueType.ContactDamageBonus:
                this[ValueType.ContactDamage, ValueSubtype.Base]     += value.Base;
                this[ValueType.ContactDamage, ValueSubtype.Modifier] += value.Modifier;
                break;

            case ValueType.HealthMax:
                var pct = this[ValueType.Health] / this[ValueType.HealthMax];
                this[ValueType.HealthMax, ValueSubtype.Base]     = value.Base;
                this[ValueType.HealthMax, ValueSubtype.Modifier] = value.Modifier;
                this[ValueType.Health] = pct * this[ValueType.HealthMax];

                break;

            case ValueType.WalkSpeed:
                this[ValueType.WalkSpeed] = value.Derived;
                break;

            case ValueType.WalkAnimationSpeed:
                this[ValueType.WalkAnimationSpeed] = value.Derived;
                break;

            case ValueType.WalkSoundPitch:
                this[ValueType.WalkSoundPitch] = value.Derived;
                GetComponentInChildren <CharacterFootfall>().Sound.pitch = value.Derived;
                break;

            default:
                Debug.LogWarning(gameObject.name + " - EntityAttributes::ApplyEffect(): Unknown value type: " + value.Type.ToString());
                break;
            }
        }
コード例 #2
0
    /// <summary>
    /// Code sourced from: https://docs.unity3d.com/Manual/editor-PropertyDrawers.html
    /// </summary>
    /// <param name="position"></param>
    /// <param name="property"></param>
    /// <param name="label"></param>
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //base.OnGUI(position, property, label);

        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);

        label.text = ((ValueType)property.FindPropertyRelative("Type").intValue).ToString();


        // Draw foldout label
        //property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);

        Rect typeRect = new Rect(position.x, position.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);

        EditorGUI.PropertyField(typeRect, property.FindPropertyRelative("Type"), GUIContent.none);

        position.x     += EditorGUIUtility.labelWidth;
        position.width -= EditorGUIUtility.labelWidth;

        // Don't make child fields be indented
        int indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        // Calculate rects
        var thirds = position;

        thirds.width /= 3.0f;
        thirds.height = EditorGUIUtility.singleLineHeight;// property.FindPropertyRelative("Base");


        Rect baseRect     = new Rect(thirds.x, thirds.y, thirds.width, thirds.height);
        Rect modifierRect = new Rect(thirds.x + thirds.width, thirds.y, thirds.width, thirds.height);
        Rect derivedRect  = new Rect(thirds.x + 2 * thirds.width, thirds.y, thirds.width, thirds.height);

        var value = new ValueCollection.Value {
            Base = property.FindPropertyRelative("Base").floatValue, Modifier = property.FindPropertyRelative("Modifier").floatValue
        };

        var oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 18;

        // Draw fields - passs GUIContent.none to each so they are drawn without labels
        EditorGUI.PropertyField(baseRect, property.FindPropertyRelative("Base"), new GUIContent(" B", "Base"));
        EditorGUI.PropertyField(modifierRect, property.FindPropertyRelative("Modifier"), new GUIContent(" M", "Modifier"));
        EditorGUI.LabelField(derivedRect, new GUIContent(" D", "Derived: Base * (1.0 + Modifier)\nREAD ONLY"), new GUIContent(value.Derived.ToString()), new GUIStyle(EditorStyles.numberField));

        EditorGUIUtility.labelWidth = oldLabelWidth;

        //if (property.isExpanded) {
        //    var typeRect = position;

        //    typeRect.y += EditorGUIUtility.singleLineHeight;
        //    typeRect.height = EditorGUIUtility.singleLineHeight;

        //    EditorGUI.PropertyField(typeRect, property.FindPropertyRelative("Type"), GUIContent.none);
        //}

        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }