自动方式用枚举表示:
public enum AutoMode{ Full,Semi,Burst }有些枪只有半自动,有些有半自动、全自动,有些有半自动、三连发。
用一个自动方式枚举的列表
List<AutoMode>autoModes在枪械的配置SO里写一个方法为autoModes列表去重。就是转换成集合再转换回来。
[ContextMenu("为枪的AutoMode列表去重")] void GunAutoModeRemoveRepeat() { for (int i = 0; i < gunDataBins.Count; i++) { HashSet<AutoMode>set=new HashSet<AutoMode>(gunDataBins[i].autoModes); gunDataBins[i].autoModes = new List<AutoMode>(set); } }枪械切换自动方式的方法:
public void ToggleAutoMode(){ int index = gunConfig.autoModes.IndexOf(autoMode); index++; index = index % gunConfig.autoModes.Count; autoMode = gunConfig.autoModes[index]; }