void ModifyAttribute() { GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go == null) { return; } mBasicAttributes = go.GetComponent <BasicAttributes>(); if (mBasicAttributes != null) { if (!perSecond) { float lValue = mBasicAttributes.GetAttributeValue <float>(attribute.Value); mBasicAttributes.SetAttributeValue(attribute.Value, lValue + floatValue.Value); } else { float lValue = mBasicAttributes.GetAttributeValue <float>(attribute.Value); mBasicAttributes.SetAttributeValue(attribute.Value, lValue + floatValue.Value * Time.deltaTime); } } }
/// <summary> /// Called when the script object is loaded /// </summary> void OnEnable() { // Grab the serialized objects mTarget = (BasicAttributes)target; mTargetSO = new SerializedObject(target); // Initialize the cache if (!Application.isPlaying) { mTarget.Awake(); } // Temporary int lCount = 0; for (int i = mTarget.Items.Count - 1; i >= 0; i--) { if (mTarget.Items[i] == null) { lCount++; mTarget.Items.RemoveAt(i); } } if (lCount > 0 && mTarget.Items.Count == 0) { mTarget.SetAttributeValue <float>("Health", 100f); } // Create the list of items to display InstantiateAttributeItemList(); }
/// <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); }
void SetAttribute() { GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go == null) { return; } mBasicAttributes = go.GetComponent <BasicAttributes>(); if (mBasicAttributes != null) { float lValue = mBasicAttributes.GetAttributeValue <float>(attribute.Value); mBasicAttributes.SetAttributeValue(attribute.Value, floatValue.Value); } }