Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

70 行
2.5 KiB

using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Logic
{
public class SaveDataSwitchOnIntLogic : LogicBase
{
public GameSaveManager.Location SaveLocation = GameSaveManager.Location.System;
public string Key = "SomeKey";
[NonNullCheck]
public Callable[] DefaultCaseToCall;
[ReorderableList, NonNullCheck]
public Callable[] CasesToCall;
public override void Execute(GameObject instigator = null)
{
var gsm = Manager.Get<GameSaveManager>();
if (gsm.HasInt(Key, SaveLocation))
{
int value = gsm.GetInt(Key, SaveLocation);
if(value > 0 && value < CasesToCall.Length)
{
if (CasesToCall[value] != null)
Callable.Call(CasesToCall[value], instigator);
else
{
Debug.LogWarning($"[SaveDataSwitchOnIntLogic] {gameObject.name} : Callable at index #{Key} was null, using default case.");
CallDefault(instigator);
}
}
else
{
Debug.LogWarning($"[SaveDataSwitchOnIntLogic] {gameObject.name} : Callable at index #{Key} was out of range, using default case.");
CallDefault(instigator);
}
}
else
{
Debug.LogWarning($"[SaveDataSwitchOnIntLogic] {gameObject.name} : Could not Find {Key} in {SaveLocation} Save, using default case.");
CallDefault(instigator);
}
}
void CallDefault(GameObject instigator)
{
if(DefaultCaseToCall != null)
{
Callable.Call(DefaultCaseToCall, instigator);
}
else
{
Debug.LogWarning($"[SaveDataSwitchOnIntLogic] {gameObject.name} : Did not set a default callable, aborting.");
}
}
public override string GetDefaultName()
{
return $"Switch on Integer {SaveLocation} Save Data '{Key}'";
}
void WarnNotExist(string name, GameSaveManager.ValueType type, GameSaveManager.Location location)
{
Debug.LogWarning(string.Format("Save Data Logic: Trying to get {0} value to non existent {1} data in {2} save.", type, name, location));
}
}
}