Exemple #1
0
        /// <summary>
        /// Create the BasicAttributes and add the Health attribute
        /// </summary>
        /// <param name="rMotionController"></param>
        /// <param name="rHealth">Health value to set; if the Health attribute already exist, then its value
        /// is not overwritten</param>
        /// <param name="rMana"></param>
        /// <param name="rStamina"></param>
        /// <returns></returns>
        public static BasicAttributes CreateBasicAttributes(MotionController rMotionController, float rHealth, float rMana = 0, float rStamina = 0)
        {
            BasicAttributes lAttributes = rMotionController.GetOrAddComponent <BasicAttributes>();

            if (!lAttributes.AttributeExists("Health"))
            {
                lAttributes.SetAttributeValue <float>("Health", rHealth);
                BasicAttributeFloat lHealth = lAttributes.GetAttribute("Health") as BasicAttributeFloat;
                if (lHealth != null)
                {
                    lHealth.MinValue = 0;
                    lHealth.MaxValue = rHealth;
                }
            }

            if (rMana > 0 && !lAttributes.AttributeExists("Mana"))
            {
                lAttributes.SetAttributeValue <float>("Mana", rMana);
                BasicAttributeFloat lMana = lAttributes.GetAttribute("Mana") as BasicAttributeFloat;
                if (lMana != null)
                {
                    lMana.MinValue = 0;
                    lMana.MaxValue = rMana;
                }
            }

            if (rStamina > 0 && !lAttributes.AttributeExists("Stamina"))
            {
                lAttributes.SetAttributeValue <float>("Stamina", rStamina);
                BasicAttributeFloat lStamina = lAttributes.GetAttribute("Stamina") as BasicAttributeFloat;
                if (lStamina != null)
                {
                    lStamina.MinValue = 0;
                    lStamina.MaxValue = rMana;
                }
            }

            lAttributes.OnBeforeSerialize();

            return(lAttributes);
        }
Exemple #2
0
    /// <summary>
    /// Allows us to add to a list
    /// </summary>
    /// <param name="rList"></param>
    private void OnItemListItemAdd(ReorderableList rList)
    {
        if (mAttributeValue.Length == 0)
        {
            return;
        }
        if (mTarget.AttributeExists(mAttributeValue))
        {
            return;
        }

        mTarget.AddAttribute(mAttributeValue);

        mItemList.index = mTarget.Items.Count - 1;
        OnItemListItemSelect(rList);

        mIsDirty = true;
    }