// EXECUTABLE: ----------------------------------------------------------------------------

        public override bool Check(GameObject target)
        {
            GameObject targetGO = this.target.GetGameObject(target);

            if (!targetGO)
            {
                Debug.LogError("Condition Attribute: No target defined");
                return(false);
            }

            Stats stats = targetGO.GetComponentInChildren <Stats>();

            if (!stats)
            {
                Debug.LogError("Condition Attribute: Could not get Stats component in target", targetGO);
                return(false);
            }

            switch (this.compare)
            {
            case Comparison.ValueIsGreaterOrEqual:
                return(stats.GetAttrValue(this.attribute.attribute.uniqueName) >= this.value.GetValue(target));

            case Comparison.ValueIsLessOrEqual:
                return(stats.GetAttrValue(this.attribute.attribute.uniqueName) <= this.value.GetValue(target));

            case Comparison.PercentIsGreaterOrEqual:
                return(stats.GetAttrValuePercent(this.attribute.attribute.uniqueName) >= this.percent);

            case Comparison.PercentIsLessOrEqual:
                return(stats.GetAttrValuePercent(this.attribute.attribute.uniqueName) <= this.percent);
            }

            return(false);
        }
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            if (this.attribute != null)
            {
                Stats stats = this.target.GetGameObject(target).GetComponentInChildren <Stats>();
                if (stats == null)
                {
                    Debug.Log("Debug Attribute: No Stats found in target");
                    return(true);
                }

                Debug.LogFormat(
                    "Attribute {0}: {1}/{2}",
                    this.attribute.attribute.uniqueName,
                    stats.GetAttrValue(this.attribute.attribute.uniqueName),
                    stats.GetAttrMaxValue(this.attribute.attribute.uniqueName)
                    );
            }
            else
            {
                Debug.LogError("Attribute is null");
            }

            return(true);
        }
        private void UpdateAttrUI(Stats.EventArgs args)
        {
            Stats stats = this.GetStatsTarget();

            if (!stats)
            {
                return;
            }

            string attrID = this.attribute.attribute.uniqueName;

            if (this.icon)
            {
                this.icon.overrideSprite = stats.GetAttrIcon(attrID);
            }
            if (this.color)
            {
                this.color.color = stats.GetAttrColor(attrID);
            }
            if (this.title)
            {
                this.title.text = stats.GetAttrDescription(attrID);
            }
            if (this.description)
            {
                this.description.text = stats.GetAttrDescription(attrID);
            }
            if (this.shortName)
            {
                this.shortName.text = stats.GetAttrShortName(attrID);
            }

            float curAttr = stats.GetAttrValue(attrID);
            float maxAttr = stats.GetAttrMaxValue(attrID);
            float minAttr = this.attribute.attribute.minValue;

            if (this.value)
            {
                this.value.text = string.Format(
                    this.valueFormat,
                    curAttr,
                    maxAttr,
                    minAttr
                    );
            }

            float percent = Mathf.InverseLerp(minAttr, maxAttr, curAttr);

            this.transitionTargetPercent = percent;
            this.transitionVelocity      = 0f;
            this.transitionTime          = Time.time;

            if ((this.transitionCurrentPercent < percent && !this.smoothTransitionUp) ||
                (this.transitionCurrentPercent > percent && !this.smoothTransitionDown))
            {
                this.transitionCurrentPercent = percent;
            }
        }
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            GameObject targetGO = this.target.GetGameObject(target);

            if (targetGO == null)
            {
                Debug.LogError("Action Attr Sync: No target defined");
                return(true);
            }

            Stats stats = targetGO.GetComponentInChildren <Stats>();

            if (stats == null)
            {
                Debug.LogError("Action Attr Sync: Could not get Stats component in target");
                return(true);
            }

            this.variable.Set(stats.GetAttrValue(this.attribute.attribute.uniqueName), target);
            return(true);
        }
Exemplo n.º 5
0
        private void PaintAttribute(AttrAsset attrAsset)
        {
            if (ATTR_BAR_BACK_BCK == null || ATTR_BAR_BACK_BRD == null)
            {
                ATTR_BAR_BACK_BCK = new Texture2D(1, 1, TextureFormat.ARGB32, false);
                ATTR_BAR_BACK_BCK.SetPixel(0, 0, new Color(0, 0, 0, 0.1f));
                ATTR_BAR_BACK_BCK.Apply();

                ATTR_BAR_BACK_BRD = new Texture2D(1, 1, TextureFormat.ARGB32, false);
                ATTR_BAR_BACK_BRD.SetPixel(0, 0, new Color(0, 0, 0, 0.65f));
                ATTR_BAR_BACK_BRD.Apply();
            }

            if (ATTR_BAR_PROGRESS == null)
            {
                ATTR_BAR_PROGRESS = new Texture2D(1, 1, TextureFormat.ARGB32, false);
                ATTR_BAR_PROGRESS.SetPixel(0, 0, Color.white);
                ATTR_BAR_PROGRESS.Apply();
            }

            Rect rect = GUILayoutUtility.GetRect(
                EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth,
                EditorGUIUtility.singleLineHeight
                );

            Rect rectLabel = new Rect(
                rect.x,
                rect.y,
                EditorGUIUtility.labelWidth,
                rect.height
                );

            Rect rectBg = new Rect(
                rect.x + EditorGUIUtility.labelWidth,
                rect.y,
                rect.width - EditorGUIUtility.labelWidth,
                rect.height
                );

            Rect rectPr = rectBg;

            GUIContent gcLabel  = GUIContent.none;
            string     attrName = attrAsset.attribute.shortName;

            switch (EditorApplication.isPlaying)
            {
            case false:
                rectPr = new Rect(
                    rectBg.x + 1f,
                    rect.y + 1f,
                    (rectBg.width - 2f) * attrAsset.attribute.percent,
                    rect.height - 2f
                    );

                gcLabel = new GUIContent(string.Format(
                                             PR_FMT_ED,
                                             attrName,
                                             attrAsset.attribute.percent * 100f
                                             ));
                break;

            case true:
                float curValue = instance.GetAttrValue(attrAsset.attribute.uniqueName);
                float maxValue = instance.GetAttrMaxValue(attrAsset.attribute.uniqueName);

                rectPr = new Rect(
                    rectBg.x + 1f,
                    rect.y + 1f,
                    (rectBg.width - 2f) * (curValue / maxValue),
                    rect.height - 2f
                    );

                gcLabel = new GUIContent(string.Format(
                                             PR_FMT_RN,
                                             attrName,
                                             curValue,
                                             maxValue
                                             ));
                break;
            }

            EditorGUI.LabelField(rectLabel, gcLabel, STYLE_LABEL);

            Color progrColor = attrAsset.attribute.color;

            GUI.DrawTexture(rectBg, ATTR_BAR_BACK_BCK, ScaleMode.StretchToFill, true, 0, Color.white, 0f, 0f);
            GUI.DrawTexture(rectBg, ATTR_BAR_BACK_BRD, ScaleMode.StretchToFill, true, 0, Color.white, 1f, 0f);
            GUI.DrawTexture(rectPr, ATTR_BAR_PROGRESS, ScaleMode.StretchToFill, true, 0, progrColor, 0f, 0f);
        }
Exemplo n.º 6
0
        private void UpdateAttrUI(Stats.EventArgs args)
        {
            Stats stats = this.GetStatsTarget();

            if (stats == null)
            {
                return;
            }

            string attrID = this.attribute.attribute.uniqueName;

            if (this.icon != null)
            {
                this.icon.overrideSprite = stats.GetAttrIcon(attrID);
            }
            if (this.color != null)
            {
                this.color.color = stats.GetAttrColor(attrID);
            }
            if (this.title != null)
            {
                this.title.text = stats.GetAttrDescription(attrID);
            }
            if (this.description != null)
            {
                this.description.text = stats.GetAttrDescription(attrID);
            }
            if (this.shortName != null)
            {
                this.shortName.text = stats.GetAttrShortName(attrID);
            }

            float curAttr = stats.GetAttrValue(attrID);
            float maxAttr = stats.GetAttrMaxValue(attrID);

            if (this.value != null)
            {
                this.value.text = string.Format(
                    this.valueFormat,
                    curAttr,
                    maxAttr
                    );
            }

            if (this.valueFillImage != null)
            {
                this.valueFillImage.fillAmount = (curAttr / maxAttr);
            }

            if (this.valueScaleX != null)
            {
                this.valueScaleX.localScale = new Vector3(
                    (curAttr / maxAttr),
                    this.valueScaleX.localScale.y,
                    this.valueScaleX.localScale.z
                    );
            }

            if (this.valueScaleY != null)
            {
                this.valueScaleY.localScale = new Vector3(
                    this.valueScaleY.localScale.x,
                    (curAttr / maxAttr),
                    this.valueScaleY.localScale.z
                    );
            }
        }