mirror of
https://github.com/HoonTB/Project-AS.git
synced 2025-12-26 11:51:21 +09:00
feat: Add variable system, scene transition, and improve character layout
- **Introduce Variable System**
- Added singleton class for variable management
- Implemented script commands `[var]` and `[add]` for variable control
- Supported variable substitution (`{variable}`) in dialogue and choices
- **Expand Script Features**
- Added `[scene]` command for scene transition (load scene and link next script)
- **Improve Character Presentation**
- Refactored character object hierarchy for better animation control
- Applied mask-based soft transition effect (Soft Wipe) for expression changes
This commit is contained in:
73
Assets/_MAIN/Scripts/Core/VariableManager.cs
Normal file
73
Assets/_MAIN/Scripts/Core/VariableManager.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VariableManager
|
||||
{
|
||||
private static VariableManager _instance;
|
||||
public static VariableManager Instance => _instance ??= new VariableManager();
|
||||
|
||||
private Dictionary<string, object> _variables = new();
|
||||
|
||||
public void SetVariable(string name, string value)
|
||||
{
|
||||
// Try to parse as int or float, otherwise string
|
||||
if (int.TryParse(value, out int intVal))
|
||||
_variables[name] = intVal;
|
||||
else if (float.TryParse(value, out float floatVal))
|
||||
_variables[name] = floatVal;
|
||||
else
|
||||
_variables[name] = value;
|
||||
|
||||
|
||||
Debug.Log($"VariableManager :: Set {name} = {_variables[name]} ({_variables[name].GetType()})");
|
||||
}
|
||||
|
||||
public object GetVariable(string name)
|
||||
{
|
||||
return _variables.ContainsKey(name) ? _variables[name] : null;
|
||||
}
|
||||
|
||||
public void AddVariable(string name, string valueStr)
|
||||
{
|
||||
if (!_variables.ContainsKey(name))
|
||||
{
|
||||
SetVariable(name, valueStr);
|
||||
return;
|
||||
}
|
||||
|
||||
object current = _variables[name];
|
||||
|
||||
|
||||
if (current is int currentInt && int.TryParse(valueStr, out int addInt))
|
||||
{
|
||||
_variables[name] = currentInt + addInt;
|
||||
}
|
||||
else if (current is float currentFloat && float.TryParse(valueStr, out float addFloat))
|
||||
{
|
||||
_variables[name] = currentFloat + addFloat;
|
||||
}
|
||||
else if (current is string currentStr)
|
||||
{
|
||||
_variables[name] = currentStr + valueStr;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"VariableManager :: Cannot add {valueStr} to {name} (Type: {current.GetType()})");
|
||||
}
|
||||
|
||||
|
||||
Debug.Log($"VariableManager :: Add {name} += {valueStr} -> {_variables[name]}");
|
||||
}
|
||||
|
||||
|
||||
public string ReplaceVariables(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return text;
|
||||
|
||||
foreach (var kvp in _variables)
|
||||
{
|
||||
text = text.Replace($"{{{kvp.Key}}}", kvp.Value.ToString());
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user