Esempio n. 1
0
 public RuntimeAttrData(int index, float value, AttrAsset attrAsset)
 {
     this.index     = index;
     this.value     = value;
     this.attrAsset = attrAsset;
     this.statAsset = attrAsset.attribute.stat;
     this.onChange  = new UnityEvent();
 }
        public static AttrAsset AddAttributeAsset()
        {
            AttrAsset attrAsset = ScriptableObject.CreateInstance <AttrAsset>();

            attrAsset.name = GameCreatorUtilities.RandomHash(8);

            string path = Path.Combine(ASSETS_PATH, ATTRSASSET_FILE);

            AssetDatabase.AddObjectToAsset(attrAsset, path);

            return(attrAsset);
        }
Esempio n. 3
0
        // ATTRIBUTES PAINTER: --------------------------------------------------------------------

        private void PaintAttributes()
        {
            if (this.attrsAsset.attributes.Length == 0)
            {
                return;
            }
            EditorGUILayout.Space();

            for (int i = 0; i < this.attrsAsset.attributes.Length; ++i)
            {
                AttrAsset attrAsset = this.attrsAsset.attributes[i];
                this.PaintAttribute(attrAsset);

                GUILayout.Space(5f);
            }
        }
Esempio n. 4
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);
        }