54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
public partial class VariablesContainer : GameElement
|
|
{
|
|
#region [变量存储字典] Values Dictionary
|
|
public Dictionary<string, int> originalVariables;
|
|
public Dictionary<string, int> currentVariables;
|
|
#endregion
|
|
|
|
#region [生命周期] Lifecycle & Factory
|
|
public static VariablesContainer GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
|
|
GameElement parentElement, Dictionary<string, int> variables)
|
|
{
|
|
VariablesContainer variablesContainer =
|
|
Instantiate(GameManager.Instance.basePrefabs.emptyObject).AddComponent<VariablesContainer>();
|
|
|
|
GameManager.Instance.variablesContainer = variablesContainer;
|
|
variablesContainer.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
|
|
variablesContainer.originalVariables = new Dictionary<string, int>(variables);
|
|
variablesContainer.currentVariables = new Dictionary<string, int>(variables);
|
|
|
|
return variablesContainer;
|
|
}
|
|
#endregion
|
|
|
|
#region [变量交互接口] Variable Interactions
|
|
public void SetVariable(string variableName, int value)
|
|
{
|
|
currentVariables[variableName] = value;
|
|
}
|
|
|
|
public int GetVariable(string variableName)
|
|
{
|
|
return currentVariables[variableName];
|
|
}
|
|
|
|
public void RevertVariable(string variableName)
|
|
{
|
|
currentVariables[variableName] = originalVariables[variableName];
|
|
}
|
|
|
|
public void RevertAllVariables()
|
|
{
|
|
currentVariables = new Dictionary<string, int>(originalVariables);
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
} |