Roofen-Game
  • Welcome to Roofen Game
  • Frameworks
    • Common Stat
      • Demo
      • 🚀 Quick Start Guide
      • Runtime
      • Action
      • Formula
      • Examples
      • Debugger
      • FAQ
      • Version Update
      • FutureDirection
    • RToDo
  • Survivors Roguelike Kit
    • Quick Start
    • Core Concepts Overview
      • Scene Concepts
      • Stat Concepts
      • Skill Concepts
    • Adding a New Playable Character
    • Adding a New Enemy
    • Adding a New Stage Configuration
    • Adding a New Map Configuration
    • Adding a New Level
    • Adding a New Attack Skill
    • Adding a New Buff
    • Configuring the Exp System
    • Damage Numbers Display Guide
    • Upcoming Features Preview
    • Release Notes
  • RSOFramework
Powered by GitBook
On this page
  • Opening the Demo Scene
  • 🔧 Troubleshooting
  • Stat Setting
  • Formula
  1. Frameworks
  2. Common Stat

🚀 Quick Start Guide

Opening the Demo Scene

Follow these steps to explore the Common Stat Pro demonstration:

Step 1: Navigate to the Demo Scene

Open the example scene located at:

Assets/Roofen/ScriptableCoreKitPro/CommonStatPro/Example/Scene/StatTest.unity

Pro Tip: You can quickly navigate to this path by using Unity's search bar (Ctrl+K / Cmd+K) and typing "StatTest"


Step 2: TextMeshPro Setup (If Required)

If the scene displays incorrectly or shows missing text elements, you'll need to import TextMeshPro:

{% tabs %} {% tab title="Automatic Import" %}

  1. Unity will typically prompt you automatically when opening the scene

  2. Click "Import TMP Essentials" in the popup dialog

  3. Wait for the import process to complete {% endtab %}

Manual Import

  1. Go to Window → TextMeshPro → Import TMP Essential Resources

  2. Click "Import" in the dialog that appears

  3. Wait for Unity to finish importing the resources

Important: After importing TextMeshPro, you must reopen the StatTest scene. Do not save the scene during this process to avoid any configuration conflicts.


🔧 Troubleshooting

Ready to integrate? Once you've explored the demo, check out our Integration Guide to start using Common Stat Pro in your own project!

Stat Setting

Create -> RGame -> Value -> ValueConfig. You can edit your desired stat here.

Create -> RGame -> Value -> Runtime Values. This is your entity's Stat Data Manager. You can drag and drop the ValueConfig you want into it.

Drag and drop the created Runtime Value SO into the Value SO to use it. You can use the ValueName, get Value, and MaxValue you want to look up by dragging and dropping them into the Value SO.

public CommonStatRuntimeSO ValueSO;
ValueSO.GetValue(ValueName), ValueSO.GetMaxValue(ValueName)

The following is the UI code for displaying the properties in the example, and the effect at runtime.

namespace RGame.Example
{
    public class ShowStatUI : MonoBehaviour
    {
        public CommonStatValueSO ValueSO;

        public string ValueName;

        public bool IsMaxValue = true;
        
        private TextMeshProUGUI mText;

        private void Awake()
        {
            mText = GetComponent<TextMeshProUGUI>();
        }

        private void OnEnable()
        {
            ValueSO.AddAction(ValueName,UpdateUI);
        }

        private void OnDisable()
        {
            ValueSO.RemoveAction(ValueName,UpdateUI);
        }

        private void Start()
        {
            UpdateUI(ValueSO.GetValue(ValueName), ValueSO.GetMaxValue(ValueName));
        }

        private void UpdateUI(int _value,int _maxValue)
        {
            if (IsMaxValue)
            {
                mText.text = $"{ValueName}: {_value}/{_maxValue}";
            }
            else
            {
                mText.text = $"{ValueName}: {_value}";
            }
        }
    }
}

Formula

Create -> RGame-> Formula .You can enter the formula here again, or you can test the formula below to see if it's correct, and if it's not, you'll get the appropriate error message. The format is @{parameter} ${variable} variable is the ValueName in your stat.

You can use it via the Evaluate method, In order to support multiple parameters, you need to pass in the parameter names and values used in a dictionary.

namespace RGame
{
    /// <summary>
    /// ScriptableObject for defining a formula and calculating its result.
    /// </summary>
    [CreateAssetMenu(fileName = "NewFormulaCal", menuName = "RGame/FormulaCal")]
    public class FormulaCalSO : ScriptableObject
    {
        [TextArea]
        public string Formula;

        /// <summary>
        /// Calculate the final value based on the formula and provided runtime values.
        /// </summary>
        public int Evaluate(CommonStatRuntimeSO _runtimeValues, Dictionary<string, double> parameters = null)
        {
            var valueDic = new Dictionary<string, (int,int)>();

            foreach (var item in _runtimeValues.RuntimeValues)
            {
                valueDic.Add(item.Key,(item.Value.GetCurrentValue(),item.Value.GetMaxValue()));
            }

            return FormulaParser.Evaluate(Formula,valueDic,parameters);
        }
    }
}

PreviousDemoNextRuntime

Last updated 9 days ago