using Newtonsoft.Json; using PublicTools.XMLDataBase; using SC.XR.Unity; using ShadowStudio.Tool; using System; using System.Collections; using System.Collections.Generic; using System.IO; #if UNITY_EDITOR #endif using UnityEngine; using XRTool.Util; namespace ShadowStudio.Model { /// /// 资源映射表 /// 读取,获取资源映射表 /// 按照id和类型建立资源映射。通过artid获取对应的artinfo /// 通过资源类型获取对应的artinfo /// 创建一个美术资源: /// public class ArtInfoMgr : SC.XR.Unity.Singleton { private string tableName; private TableInterface table; private bool isInit = false; /// /// 所有的资源列表,此列表当前服务器和本地各有一份。后期读取服务器列表数据 /// private List artInfoList; /// /// 资源id对应的资源信息 /// private Dictionary artInfoMap; private Dictionary otherArtInfoMap; /// /// 资源类型对应的资源列表 /// private Dictionary> artInfoTypeMap; /// /// 组件的集合 /// private Dictionary artComponentMap = new Dictionary(); /// /// 资源的引用 /// private Dictionary resArtMap; /// /// 资源对应的工具类 /// private Dictionary artHandlerMap = new Dictionary(); /// /// 对应资源类型的容器,例如视频播放器,图片浏览器,模型浏览器 /// private Dictionary> artContainerMap = new Dictionary>(); /// /// 数据初始化 /// public event Action InitComplete; /// /// 对应资源存储的最大的id /// 本地生成goods的一种辅助方案,此方案即将移除 /// 此方案已移除,请勿使用2020-09-14 /// private Dictionary goodsIdMap = new Dictionary(); /// /// 使用变量缓存服务器下发的物体信息数据 /// private GoodsInfo serverCacheData = new GoodsInfo(); /// /// 此为上传至服务器的物体的数据缓存,理论上上传多个物体列表信息,实际处理中每次只会上传一条物体的同步信息 /// private List goodsDataList = new List(); /// /// 创建容器的事件,某个容器被上传的事件 /// public event Action ContainerCreate; /// /// 删除容器,某个容器被删除的事件 /// public event Action ContainerDel; /// /// 容器被选中或者容器非选中状态的事件 /// public static event Action ContainerSelect; /// /// 编辑菜单的名称 /// private string ModelEditBtnGroup = "ModelEditBtnDlg"; //public ArtEditorContainer ModelEditBtn; /// /// 容器缓存 /// 非即时同步容器缓存 /// private Dictionary containerCache = new Dictionary(); public event Action UserChange; public void AddCacheContainer(string id, ArtContainer container) { if (!ContainerCache.ContainsKey(id)) { ContainerCache.Add(id, container); } } public void SetContainerSelect(ArtContainer container, bool isSelect) { ContainerSelect?.Invoke(container, isSelect); } public bool IsSingleMan() { //if (GameNode.Instance) //{ // return GameNode.Instance.UserMap == null || GameNode.Instance.UserMap.Count < 2; //} return true; } public void RemoveArtInfo(List resModelList) { for (int i = 0; i < resModelList.Count; i++) { string artid = "ArtId_" + resModelList[i].name; table.DeleteData(artid); } } /// /// 将数据添加至xml /// /// /// /// public void AddArtInfo(List resModelList, ArtType artType, InstaceType references, bool isForceUpdate, string url = "") { if (ArtInfoList == null) { ArtInfoList = new List(); } for (int i = 0; i < resModelList.Count; i++) { UnityEngine.Object obj = resModelList[i]; string artid = "ArtId_" + obj.name; if (isForceUpdate || !ArtInfoContains(artid)) { ArtInfo info = new ArtInfo(); info.ArtId = artid; info.ArtName = obj.name; info.ArtType = artType; info.Distance = 1f; ///Icon info.Icon = "ArtIcon/" + artType + "/" + obj.name; info.InstaceType = references; info.Size = 1; if (artType == ArtType.Prefab) { info.Distance = (obj as GameObject).transform.localPosition.z; info.Size = (obj as GameObject).transform.localScale.x; } if (references == InstaceType.References) { info.Url = url; } // else if (references == InstaceType.ResourceLoad) // { //#if UNITY_EDITOR // string path = AssetDatabase.GetAssetPath(obj); // int index = path.LastIndexOf("Resources"); // path = path.Substring((index += "Resources".Length + 1), path.Length - index - 1); // path = path.Replace(Path.GetExtension(path), ""); // info.Url = path; //#endif // } info.Version = Application.version; table.InsertData(info); if (!ArtInfoContains(artid)) { ArtInfoList.Add(info); } } } table.Save(); } public bool ArtInfoContains(string artId) { for (int i = 0; i < ArtInfoList.Count; i++) { if (ArtInfoList[i].ArtId == artId) { return true; } } return false; } public bool IsInit { get => isInit; set => isInit = value; } public List ArtInfoList { get => artInfoList; set => artInfoList = value; } public Dictionary ContainerCache { get => containerCache; set => containerCache = value; } public Dictionary OtherArtInfoMap { get { if (otherArtInfoMap == null) { otherArtInfoMap = new Dictionary(); } return otherArtInfoMap; } } /// /// 房间内物体的映射 /// 房间id与对应的物体资源映射 /// public void LoadModelEditBtn() { //if (!ModelEditBtn) //{ // var tmp = Resources.Load(ModelEditBtnGroup); // if (tmp) // { // ModelEditBtn = GameObject.Instantiate(tmp); // GameNode.Instance.SetParent(ObjNode.WorldCanvas, ModelEditBtn.transform, Vector3.zero, Vector3.zero, Vector3.one * 0.001f, false); // ModelEditBtn.gameObject.SetActive(false); // } //} } public ArtInfoMgr() { var artResList = Resources.LoadAll("ArtConf"); resArtMap = new Dictionary(); if (artResList != null) { for (int i = 0; i < artResList.Length; i++) { resArtMap.Add(artResList[i].name, artResList[i]); } } var containers = Resources.LoadAll("Container"); if (containers != null) { for (int i = 0; i < containers.Length; i++) { var container = containers[i].GetComponent(); if (container != null) { if (!artContainerMap.ContainsKey(container.GetArtType())) { List list = new List(); list.Add(container); artContainerMap.Add(container.GetArtType(), list); } else { List list = artContainerMap[container.GetArtType()]; list.Add(container); } } } } var components = Resources.LoadAll("Container/Component"); if (components != null) { for (int i = 0; i < components.Length; i++) { var component = containers[i].GetComponent(); if (component != null) { if (!artComponentMap.ContainsKey(containers[i].name)) { artComponentMap.Add(containers[i].name, component); } } } } if (BuildConfigMgr.Instance.IsInit) { //ReadArtInfo(Path.Combine(BuildConfig.Instance.LocalPath, BuildConfig.Instance.artInfoPath)); } else { UnityLog.LogError("配置文件丢失!"); } //WSHandler.Room.OnBroadcastGood += SyncGoods; ContainerSelect += OnContainerSelect; } public void ListenUser() { //if (ShowViewMgr.Instance) //{ // ShowViewMgr.Instance.OnUserChange -= OnUserChange; // ShowViewMgr.Instance.OnUserChange += OnUserChange; //} //else //{ // ShowViewMgr.InitComplte += () => // { // if (ShowViewMgr.Instance) // { // ShowViewMgr.Instance.OnUserChange -= OnUserChange; // ShowViewMgr.Instance.OnUserChange += OnUserChange; // } // }; //} } public void ListenPage() { //if (ShowViewMgr.Instance) //{ // ShowViewMgr.Instance.OnRoomPageChange -= OnChangePage; // ShowViewMgr.Instance.OnRoomPageChange += OnChangePage; //} //else //{ // ShowViewMgr.InitComplte += () => // { // if (ShowViewMgr.Instance) // { // ShowViewMgr.Instance.OnRoomPageChange -= OnChangePage; // ShowViewMgr.Instance.OnRoomPageChange += OnChangePage; // } // }; //} } private void OnContainerSelect(ArtContainer container, bool isSelect) { if (container.GetGoodsInfo().art_id == "ArtId_PlayerView") { return; } //if (!ModelEditBtn) //{ // LoadModelEditBtn(); //} //if (ModelEditBtn) //{ // if (ModelEditBtn.gameObject.activeSelf != isSelect) // { // ModelEditBtn.gameObject.SetActive(isSelect); // } // if (isSelect) // { // ModelEditBtn.SetTarget(container, false); // } //} //if (ArtMoreEditor.Instance) //{ // if (isSelect) // { // ArtMoreEditor.Instance.SetTarget(container, false); // } //} } /// /// 读取美术资源 /// /// private void ReadArtInfo(string path) { //languageIndex = SystemSettingMgr.Instance.settings.Language; tableName = typeof(ArtInfo).Name; #if UNITY_EDITOR || !UNITY_ANDROID table = XSql.Instance.OpenTable(path, tableName, ".xml", true); OpenTable(); #else string fullPath = Path.Combine(path, tableName + ".xml"); TimerMgr.Instance.StartCoroutine(XSql.Instance.ReadServerData(fullPath, (List packList) => { InitPackage(packList); })); #endif } public void OpenLocalData() { //ReadArtInfo(Path.Combine(BuildConfig.Instance.LocalPath, BuildConfig.Instance.artInfoPath)); } private void OpenTable() { if (!table.Open()) { table.Create(tableName); UnityLog.Log("create table" + tableName); } var list = table.FindAllData(); for (int i = 0; i < list.Count; i++) { list[i].ArtType = ArtInfo.GetArtType((int)list[i].ArtType); } //table.Save(); //languagePackList = table.FindAllData(); InitPackage(list); } /// /// 初始化包 /// /// public void InitPackage(List lists) { ArtInfoList = lists; if (ArtInfoList == null || ArtInfoList.Count < 1) { UnityLog.LogError("美术资源不存在!"); #if UNITY_EDITOR AddDefaultArt(ArtType.Model); InitPackage(ArtInfoList); #endif return; } else { if (artInfoMap == null) { artInfoMap = new Dictionary(); } if (artInfoTypeMap == null) { artInfoTypeMap = new Dictionary>(); } for (int i = 0; i < ArtInfoList.Count; i++) { if (!artInfoMap.ContainsKey(ArtInfoList[i].ArtId)) { artInfoMap.Add(ArtInfoList[i].ArtId, ArtInfoList[i]); UnityLog.Log(ArtInfoList[i].Url, 3); } if (artInfoTypeMap.ContainsKey(ArtInfoList[i].ArtType)) { List list = artInfoTypeMap[ArtInfoList[i].ArtType]; if (list != null && !list.Contains(ArtInfoList[i])) { list.Add(ArtInfoList[i]); } } else { List list = new List(); list.Add(ArtInfoList[i]); artInfoTypeMap.Add(ArtInfoList[i].ArtType, list); } } } IsInit = true; InitComplete?.Invoke(); } /// /// 添加Unity基本资源到文本 /// public void AddDefaultArt(ArtType artType) { if (ArtInfoList == null) { ArtInfoList = new List(); } if (artType == ArtType.Model) { foreach (PrimitiveType primitive in Enum.GetValues(typeof(PrimitiveType))) { ArtInfo info = new ArtInfo(); info.ArtId = "ArtId_" + (int)primitive; info.ArtName = primitive.ToString(); info.ArtType = ArtType.Model; info.Distance = 1f; ///Icon info.Icon = "PrimitiveType/" + primitive.ToString(); info.InstaceType = InstaceType.UnityBase; info.Size = 1; info.Url = "" + (int)primitive; info.Version = Application.unityVersion; table.InsertData(info); ArtInfoList.Add(info); } } else { ArtInfo info = new ArtInfo(); info.ArtId = "ArtId_GameObject"; info.ArtName = "GameObject"; info.ArtType = ArtType.Prefab; info.Distance = 1f; ///Icon info.Icon = ""; info.InstaceType = InstaceType.UnityBase; info.Size = 1; info.Url = "New"; info.Version = Application.unityVersion; table.InsertData(info); ArtInfoList.Add(info); } table.Save(); } /// /// 根据资源id获取对应的资源 /// /// /// public ArtInfo GetArtInfo(string artId) { if (IsInit && artInfoMap.ContainsKey(artId)) { return artInfoMap[artId]; } return null; } /// /// 根据资源id获取对应的资源 /// /// /// public List GetArtInfoList(ArtType artType) { if (IsInit)// { if (artInfoTypeMap.ContainsKey(artType)) { return artInfoTypeMap[artType]; } List tmp = new List(); foreach (var item in artInfoTypeMap) { ///包含此key if ((item.Key & artType) == item.Key) { tmp.AddRange(item.Value); } } artInfoTypeMap.Add(artType, tmp); return tmp; } return null; } ///// ///// 根据资源id获取对应的资源 ///// ///// ///// //public List GetArtInfoList(ArtType[] artType) //{ // if (IsInit)// // { // List ArtInfoList = new List(); // for (int i = 0; i < artType.Length; i++) // { // if (artInfoTypeMap.ContainsKey(artType[i])) // { // ArtInfoList.AddRange(artInfoTypeMap[artType[i]]); // } // } // return ArtInfoList; // } // return null; //} /// /// 根据资源id获取对应的资源 /// /// /// public List GetArtInfoListSingle(ArtType artType) { if (IsInit)// { return artInfoTypeMap[artType]; } return null; } /// /// 创建一个资源ArtHandler,注意内存回收 /// /// public ArtHandler CreateArtHandler(ArtInfo art, string containerName = "") { if (string.IsNullOrEmpty(containerName)) { containerName = art.ContainerName; } if (artHandlerMap.ContainsKey(art)) { return artHandlerMap[art]; } ArtHandler handler = new ArtHandler(); handler.SetData(art, containerName); artHandlerMap.Add(art, handler); return handler; } /// /// 删除资源帮助类ArtHandler /// /// public void DestrorArtHandler(ArtInfo art) { if (artHandlerMap.ContainsKey(art)) { var handler = artHandlerMap[art]; handler = null; artHandlerMap.Remove(art); } } /// /// 实例化组件 /// /// /// public ArtComponent InstanceComponent(string componentName) { if (artComponentMap != null && artComponentMap.ContainsKey(componentName)) { ArtComponent component = artComponentMap[componentName]; var tmp = GameObject.Instantiate(component.GetInstace()); return tmp.GetComponent(); } return null; } /// /// 实例化出一个容器 /// /// /// public ArtContainer CreateContainer(ArtType artType, string containerName = "") { if (artContainerMap != null && artContainerMap.ContainsKey(artType)) { var containerList = artContainerMap[artType]; if (containerList != null) { ArtContainer container = null; if (containerList.Count == 1) { container = containerList[0]; } else { for (int i = 0; i < containerList.Count; i++) { if (containerList[i].GetInstace().name == containerName) { container = containerList[i]; break; } } } if (container != null) { var tmp = GameObject.Instantiate(container.GetInstace()); return tmp.GetComponent(); } } } return null; } /// /// 获取对应的配置文件 /// /// /// public ArtResConf GetResConf(string resName) { if (resArtMap.ContainsKey(resName)) { return resArtMap[resName]; } UnityLog.LogError(resName + " is not at resArtMap"); return null; } /// /// 物品的自增id设计 /// /// public int GetGoodsId(ArtInfo info) { int id = 1; if (goodsIdMap.ContainsKey(info)) { id = goodsIdMap[info] + 1; goodsIdMap[info] = id; } else { goodsIdMap.Add(info, id); } return id; } /// /// 同步物体: /// 创建物体时,接收到广播消息时的数据同步都调用此方法 /// /// 用户id,物体的创建者 /// 美术资源id /// 物体名称 /// 物体额外信息 /// 物体id /// 物体的姿态信息 public void SyncGoods(int rid, int status, string art_id, string goods_name, string goods_extended, int id, string goods_info) { serverCacheData.rid = rid; serverCacheData.art_id = art_id; serverCacheData.goods_name = goods_name; serverCacheData.goods_extended = goods_extended; serverCacheData.id = id; serverCacheData.goods_info = goods_info; serverCacheData.status = status; SyncGoods(serverCacheData); } public void SyncGoods(List goodDataList) { if (goodDataList != null) { for (int i = 0; i < goodDataList.Count; i++) { SyncGoods(goodDataList[i]); } } } /// /// 同步物体数据 /// 服务器同步或者翻页时同步,服务器同步时开始缓存数据 /// 翻页时同步不添加缓存数据 /// /// /// public void SyncGoods(GoodsInfo goodData, bool isServer = true) { //if (GameNode.Instance.GoodsContainerMap == null) //{ // GameNode.Instance.GoodsContainerMap = new Dictionary(); //} //ArtContainer container = null; //bool isCreate = false; //if (SynUser(goodData)) //{ // container = GameNode.Instance.UserMap[goodData.art_id].Container; //} //else if (goodData.id != 0) //{ // ///先检查此数据是否在此页面 // ///如果数据不在当前页,则只缓存起来 // ///如果在当前页,则缓存后实例化进行同步 // ///如果不是服务器的数据,仅同步设置,不缓存数据 // if (isServer && goodData.scene_id > 0) // { // if (!GameNode.Instance.PageGoods.ContainsKey(goodData.id)) // { // GameNode.Instance.PageGoods.Add(goodData.id, goodData); // } // else // { // GameNode.Instance.PageGoods[goodData.id] = goodData; // } // if (!GameNode.Instance.PageGoodsId.ContainsKey(goodData.scene_id)) // { // var list = new List(); // list.Add(goodData.id); // GameNode.Instance.PageGoodsId.Add(goodData.scene_id, list); // } // else // { // var list = GameNode.Instance.PageGoodsId[goodData.scene_id]; // if (list == null) // { // list = new List(); // } // if (!list.Contains(goodData.id)) // { // list.Add(goodData.id); // } // } // if (goodData.scene_id != CommonMethod.currentScene) // { // return; // } // } // ///对象已存在,进行同步 // if (GameNode.Instance.GoodsContainerMap.ContainsKey(goodData.id)) // { // container = GameNode.Instance.GoodsContainerMap[goodData.id]; // } // else // { // ArtInfo info = GetArtInfo(goodData.art_id); // if (info == null) // { // if (OtherArtInfoMap.ContainsKey(goodData.art_id)) // { // info = OtherArtInfoMap[goodData.art_id]; // } // else // { // NetWorkHeaders.RequestArtInfo(goodData.art_id, (jsonData) => // { // if (!OtherArtInfoMap.ContainsKey(goodData.art_id)) // { // info = JsonConvert.DeserializeObject(jsonData["data"].ToJson()); // if (info != null) // { // info.ArtType = CommonMethod.getArtType(int.Parse(jsonData["data"]["art_type"].ToString())); // info.ImmediateSyn = jsonData["data"]["immediate_syn"].ToString() == "0" ? false : true; // if (string.IsNullOrEmpty(info.Component)) // { // if (info.ArtType == ArtType.Image) // { // info.Component = "PictureComponent"; // } // else if (info.ArtType == ArtType.Movies) // { // info.Component = "VideoComponent"; // } // } // OtherArtInfoMap.Add(goodData.art_id, info); // SyncGoods(goodData, isServer); // UnityLog.Instance.LogError("find artinfo:" + goodData.art_id); // return; // } // else // { // UnityLog.Instance.LogError("Error find artinfo:" + goodData.art_id); // } // } // }); // } // } // if (info != null) // { // ///容器缓存 // if (ContainerCache.ContainsKey(goodData.art_id)) // { // container = ContainerCache[goodData.art_id]; // ContainerCache.Remove(goodData.art_id); // } // else // { // ArtHandler handler = CreateArtHandler(info); // container = handler.CreateArt(); // } // GameNode.Instance.GoodsContainerMap.Add(goodData.id, container); // isCreate = true; // } // else // { // UnityLog.Instance.LogError(goodData.art_id); // } // } //} //try //{ // if (container != null && container.GetInstace()) // { // container.TransferSyn(goodData, goodData.status == (int)TransferState.Doing); // if (isCreate) // { // ContainerCreate?.Invoke(container); // } // } //} //catch //{ // ///某个物体可能被删掉了 // ///此种情况不在处理 //} } //Dictionary form; //Dictionary header; ///// ///// 读取资源信息 ///// ///// //public IEnumerator ReqOtherArtInfo(string artId, Action onReadComplete) //{ // if (header == null) // { // header = new Dictionary(); // header.Add("Content-Type", "application/x-www-form-urlencoded"); // } // if (form == null) // { // form = new Dictionary(); // form.Add("action", ""); // } // yield return 0; //} /// /// 同步用户 /// /// /// private bool SynUser(GoodsInfo goodData) { //if (GameNode.Instance.UserMap == null) //{ // GameNode.Instance.UserMap = new Dictionary(); //} //if (string.IsNullOrEmpty(goodData.art_id)) //{ // return false; //} //return GameNode.Instance.UserMap.ContainsKey(goodData.art_id); return false; } /// /// 删除物体 /// 可能由用户主动删除,主动删除传参true.删除相关的数据缓存 /// 翻页时是被动删除。被动删除不移除相关的数据缓存 /// /// 物体的id /// 是否真实删除,默认真实删除 public void GoodsDelSync(int id, bool isRealDel = true) { //if (GameNode.Instance.GoodsContainerMap == null) //{ // GameNode.Instance.GoodsContainerMap = new Dictionary(); //} //ArtContainer container = null; /////对象已存在,进行同步 //if (GameNode.Instance.GoodsContainerMap.ContainsKey(id)) //{ // container = GameNode.Instance.GoodsContainerMap[id]; // //if (ModelEditBtn) // //{ // // ModelEditBtn.SetTarget(container, true); // //} // if (ArtMoreEditor.Instance) // { // ArtMoreEditor.Instance.SetTarget(container, true); // } // ContainerDel?.Invoke(container); // if (container != null) // { // container.DestroyArt(); // } // GameNode.Instance.GoodsContainerMap.Remove(id); //} /////真实删除 //if (isRealDel) //{ // ///删除物体的id // ///先查找物体id对应的Goods // if (GameNode.Instance.PageGoods.ContainsKey(id)) // { // ///获得Goods // var good = GameNode.Instance.PageGoods[id]; // ///查找页对应的物体的id // if (GameNode.Instance.PageGoodsId.ContainsKey(good.scene_id)) // { // ///获取页对应的id列表,并 // var list = GameNode.Instance.PageGoodsId[good.scene_id]; // if (list != null && list.Contains(id)) // { // list.Remove(id); // } // } // GameNode.Instance.PageGoods.Remove(id); // ContainerDel?.Invoke(null); // } //} } public void SendGoodsTransfer(GoodsInfo info) { //goodsDataList.Add(info); ////WSHandler.Room.BroadcastGood(goodsDataList); //goodsDataList.Clear(); } public void SendTransfer(GoodsInfo info) { //goodsDataList.Add(info); ////WSHandler.Room.TransmitGood(goodsDataList); //goodsDataList.Clear(); } /// /// 当新用户进入时的事件 /// /// //public void OnUserChange(List userList, bool isJoin) //{ // if (GameNode.Instance.UserMap == null) // { // GameNode.Instance.UserMap = new Dictionary(); // } // if (userList != null) // { // for (int i = 0; i < userList.Count; i++) // { // if (GameNode.Instance.UserMap.ContainsKey(userList[i].PeerId)) // { // if (isJoin) // { // continue; // } // else // { // var container = GameNode.Instance.UserMap[userList[i].PeerId]; // container.StopSyn(); // container.DestroyArt(); // UserChange?.Invoke(userList[i].PeerId, false); // GameNode.Instance.UserMap.Remove(userList[i].PeerId); // } // } // else // { // if (isJoin) // { // ArtInfo info = GetArtInfo(PlayerContainer.userArtId); // if (info != null) // { // //string cName = info.ContainerName; // //if (string.IsNullOrEmpty(cName)) // //{ // // cName = PlayerContainer.containerName; // //} // //ArtHandler handler = CreateArtHandler(info, PlayerContainer.containerName); // ArtHandler handler = CreateArtHandler(info); // var container = handler.CreateArt(); // if (container != null) // { // if (container.ArtComponent != null && container.ArtComponent.GetInstace()) // { // if (container.ArtComponent is PlayerContainer) // { // (container.ArtComponent as PlayerContainer).SetPeer(userList[i]); // GameNode.Instance.UserMap.Add(userList[i].PeerId, container.ArtComponent as PlayerContainer); // UserChange?.Invoke(userList[i].PeerId, true); // } // } // } // } // else // { // UnityLog.Instance.LogError(PlayerContainer.userArtId + " cant find art"); // } // } // else // { // continue; // } // } // } // } //} /// /// 删除场景的物体 /// /// /// public void DelGoodsById(int id) { //bool isCanDel = true; //if (GameNode.Instance.PageGoods.ContainsKey(id)) //{ // var goods = GameNode.Instance.PageGoods[id]; // if (goods.scene_id == CommonMethod.currentScene) // { // isCanDel = true; // } //} //if (isCanDel) //{ // WSHandler.Room.DeleteGood(new int[] { id }); //} } public void DelGoodsByIds(List ids) { //List list = new List(); //for (int i = 0; i < ids.Count; i++) //{ // int id = ids[i]; // if (GameNode.Instance.PageGoods.ContainsKey(id)) // { // var goods = GameNode.Instance.PageGoods[id]; // if (goods.scene_id == CommonMethod.currentScene) // { // list.Add(id); // } // } //} //if (list.Count > 0) //{ // WSHandler.Room.DeleteGood(list.ToArray()); //} } /// /// 翻页的数据处理 /// 翻页时注意,删除旧的数据 /// 同步新的数据 /// /// /// public void OnChangePage(int all, int current) { //if (GameNode.Instance) //{ // if (GameNode.Instance.DefaultPageIndex != current) // { // if (GameNode.Instance.DefaultPageIndex >= 0) // { // if (GameNode.Instance.PageGoodsId.ContainsKey(GameNode.Instance.DefaultPageIndex)) // { // var list = GameNode.Instance.PageGoodsId[GameNode.Instance.DefaultPageIndex]; // for (int i = 0; i < list.Count; i++) // { // GoodsDelSync(list[i], false); // } // } // } // if (ModelEditBtn) // { // ModelEditBtn.gameObject.SetActive(false); // } // GameNode.Instance.DefaultPageIndex = current; // if (GameNode.Instance.DefaultPageIndex >= 0) // { // if (GameNode.Instance.PageGoodsId.ContainsKey(GameNode.Instance.DefaultPageIndex)) // { // var list = GameNode.Instance.PageGoodsId[GameNode.Instance.DefaultPageIndex]; // for (int i = 0; i < list.Count; i++) // { // if (GameNode.Instance.PageGoods.ContainsKey(list[i])) // { // SyncGoods(GameNode.Instance.PageGoods[list[i]], false); // } // } // } // } // } //} } } }