94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace STRIPS
|
|
{
|
|
[CreateAssetMenu(fileName = "VarMapping", menuName = "STRIPS/Create New Variable Mapping", order = 2)]
|
|
public class StripsVariableMapping : ScriptableObject
|
|
{
|
|
[SerializeField]
|
|
private VariableMapping[] variableMappings;
|
|
|
|
public Dictionary<string, VariableMapping> Mappings
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, VariableMapping> mapping = new Dictionary<string, VariableMapping>();
|
|
foreach (VariableMapping map in variableMappings)
|
|
{
|
|
mapping.Add(map.varName, map);
|
|
}
|
|
return mapping;
|
|
}
|
|
}
|
|
public VariableMapping Find(string name)
|
|
{
|
|
return Mappings[name];
|
|
}
|
|
|
|
public PackageMapping CreateCopy()
|
|
{
|
|
VariableMapping[] copiedMappings = new VariableMapping[variableMappings.Length];
|
|
int i = 0;
|
|
foreach(VariableMapping mapping in variableMappings)
|
|
{
|
|
VariableMapping newMapping = new VariableMapping();
|
|
newMapping.variable = mapping.variable;
|
|
newMapping.value = mapping.value;
|
|
newMapping.varName = mapping.varName;
|
|
copiedMappings[i] = newMapping;
|
|
i++;
|
|
}
|
|
return new PackageMapping(copiedMappings);
|
|
}
|
|
|
|
public class PackageMapping
|
|
{
|
|
public PackageMapping(VariableMapping[] variableMappings)
|
|
{
|
|
this.variableMappings= variableMappings;
|
|
}
|
|
public void SetMapping(string name, string value)
|
|
{
|
|
for(int i =0;i <variableMappings.Length; i++)
|
|
{
|
|
if (variableMappings[i].varName == name)
|
|
{
|
|
variableMappings[i].value = value;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
private VariableMapping[] variableMappings;
|
|
|
|
public Dictionary<string, VariableMapping> Mappings
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, VariableMapping> mapping = new Dictionary<string, VariableMapping>();
|
|
foreach (VariableMapping map in variableMappings)
|
|
{
|
|
mapping.Add(map.varName, map);
|
|
}
|
|
return mapping;
|
|
}
|
|
}
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class VariableMapping
|
|
{
|
|
public string varName;
|
|
public VarType variable;
|
|
public string value;
|
|
}
|
|
public enum VarType { Integer, Float, String, Boolean };
|
|
}
|
|
|
|
|
|
}
|
|
|