using System.Collections; using System.Collections.Generic; using UnityEngine; using Newtonsoft.Json; public class PropMgr { static PropMgr _ins = null; public static PropMgr ins { get { if (_ins == null) { _ins = new PropMgr(); } return _ins; } } Hashtable propConfigs = new Hashtable(); List propConfigIds = new List(); PropMgr() { for (int i = 1; i <= 5; i++) { PropScaleAim propScaleAim = new PropScaleAim(10, i); CachePropConfig(propScaleAim.id, propScaleAim); } for (int i = 1; i <= 5; i++) { PropScaleShoot propScaleShoot = new PropScaleShoot(20, i); CachePropConfig(propScaleShoot.id, propScaleShoot); } } void CachePropConfig(int id, PropConfig propConfig) { propConfigs.Add(id, propConfig); propConfigIds.Add(id); } public PropConfig GetPropConfig(int id) { return (PropConfig) propConfigs[id]; } public List ListForShop() { List list = new List(); foreach (int id in propConfigIds) { list.Add((PropConfig) propConfigs[id]); } return list; } public List ListForBag() { List list = LoginMgr.myUserInfo.bagList; foreach (var propInfo in list) { propInfo.config = (PropConfig) propConfigs[propInfo.id]; } return list; } public List ListForEquipped() { List list = new List(); foreach (var propInfo in LoginMgr.myUserInfo.bagList) { if (propInfo.inuse) { propInfo.config = (PropConfig) propConfigs[propInfo.id]; list.Add(propInfo); } } return list; } //商店购买接口 public bool isSoldOut(PropConfig propConfig) { if (propConfig.type == 1 || propConfig.type == 2) { List myProps = LoginMgr.myUserInfo.bagList; foreach (var myProp in myProps) { if (myProp.id == propConfig.id && myProp.count > 0) return true; } } return false; } public bool buyProp(PropConfig propConfig) { if (LoginMgr.myUserInfo.diamond >= propConfig.diamond) { LoginMgr.myUserInfo.diamond -= propConfig.diamond; PropInfo propInfo = new PropInfo(); propInfo.id = propConfig.id; propInfo.count = 1; LoginMgr.myUserInfo.bagList.Add(propInfo); LoginMgr.myUserInfo.Save(); return true; } return false; } public bool useProp(PropInfo propInfo) { if (!propInfo.inuse) { if (propInfo.config.type == 1 || propInfo.config.type == 2) { List equippeds = ListForEquipped(); foreach (var equipped in equippeds) { if (equipped.config.type == propInfo.config.type) { equipped.inuse = false; } } } } propInfo.inuse = !propInfo.inuse; LoginMgr.myUserInfo.Save(); return propInfo.inuse; } public void DebugAddAndUseProp(int id) { PropInfo propInfo = new PropInfo(); propInfo.id = id; propInfo.inuse = true; LoginMgr.myUserInfo.bagList.Add(propInfo); } } public class PropInfo { public int id = 0; public int count = 1; [JsonIgnore] public PropConfig config = null; public bool inuse = false; } public class PropConfig { public int id = 0; public int type = 0; public int iconID = 0; public string[] name = {null}; public string[] detail = {null}; public int difficulty = -1; public int diamond = 0; } public class PropScaleAim : PropConfig { public int scaleValue = 0; public PropScaleAim(int baseID, int scaleValue) { this.scaleValue = scaleValue; id = baseID + scaleValue; type = 1; iconID = 1000; name = new string[]{"101000", scaleValue.ToString()}; detail = new string[]{"111000", scaleValue.ToString()}; diamond = scaleValue * 20; } } public class PropScaleShoot : PropConfig { public int scaleValue = 0; public PropScaleShoot(int baseID, int scaleValue) { this.scaleValue = scaleValue; id = baseID + scaleValue; type = 2; iconID = 1001; name = new string[]{"101001", scaleValue.ToString()}; detail = new string[]{"111001", scaleValue.ToString()}; diamond = scaleValue * 20; } }