12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145 |
- 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
- using UnityEditor;
- #endif
- using UnityEngine;
- using XRTool.Util;
- namespace ShadowStudio.Model
- {
-
-
-
-
-
-
-
- public class ArtInfoMgr : SC.XR.Unity.Singleton<ArtInfoMgr>
- {
- private string tableName;
- private TableInterface table;
- private bool isInit = false;
-
-
-
- private List<ArtInfo> artInfoList;
-
-
-
- private Dictionary<string, ArtInfo> artInfoMap;
- private Dictionary<string, ArtInfo> otherArtInfoMap;
-
-
-
- private Dictionary<ArtType, List<ArtInfo>> artInfoTypeMap;
-
-
-
- private Dictionary<string, ArtComponent> artComponentMap = new Dictionary<string, ArtComponent>();
-
-
-
- private Dictionary<string, ArtResConf> resArtMap;
-
-
-
- private Dictionary<ArtInfo, ArtHandler> artHandlerMap = new Dictionary<ArtInfo, ArtHandler>();
-
-
-
- private Dictionary<ArtType, List<ArtContainer>> artContainerMap = new Dictionary<ArtType, List<ArtContainer>>();
-
-
-
- public event Action InitComplete;
-
-
-
-
-
- private Dictionary<ArtInfo, int> goodsIdMap = new Dictionary<ArtInfo, int>();
-
-
-
- private GoodsInfo serverCacheData = new GoodsInfo();
-
-
-
- private List<GoodsInfo> goodsDataList = new List<GoodsInfo>();
-
-
-
- public event Action<ArtContainer> ContainerCreate;
-
-
-
- public event Action<ArtContainer> ContainerDel;
-
-
-
- public static event Action<ArtContainer, bool> ContainerSelect;
-
-
-
- private string ModelEditBtnGroup = "ModelEditBtnDlg";
-
-
-
-
-
- private Dictionary<string, ArtContainer> containerCache = new Dictionary<string, ArtContainer>();
- public event Action<string, bool> 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()
- {
-
-
-
-
- return true;
- }
- public void RemoveArtInfo(List<UnityEngine.Object> resModelList)
- {
- for (int i = 0; i < resModelList.Count; i++)
- {
- string artid = "ArtId_" + resModelList[i].name;
- table.DeleteData<ArtInfo>(artid);
- }
- }
-
-
-
-
-
-
- public void AddArtInfo(List<UnityEngine.Object> resModelList, ArtType artType, InstaceType references, bool isForceUpdate, string url = "")
- {
- if (ArtInfoList == null)
- {
- ArtInfoList = new List<ArtInfo>();
- }
- 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;
-
- 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<ArtInfo> ArtInfoList { get => artInfoList; set => artInfoList = value; }
- public Dictionary<string, ArtContainer> ContainerCache { get => containerCache; set => containerCache = value; }
- public Dictionary<string, ArtInfo> OtherArtInfoMap
- {
- get
- {
- if (otherArtInfoMap == null)
- {
- otherArtInfoMap = new Dictionary<string, ArtInfo>();
- }
- return otherArtInfoMap;
- }
- }
-
-
-
-
- public void LoadModelEditBtn()
- {
-
-
-
-
-
-
-
-
-
-
- }
- public ArtInfoMgr()
- {
- var artResList = Resources.LoadAll<ArtResConf>("ArtConf");
- resArtMap = new Dictionary<string, ArtResConf>();
- if (artResList != null)
- {
- for (int i = 0; i < artResList.Length; i++)
- {
- resArtMap.Add(artResList[i].name, artResList[i]);
- }
- }
- var containers = Resources.LoadAll<GameObject>("Container");
- if (containers != null)
- {
- for (int i = 0; i < containers.Length; i++)
- {
- var container = containers[i].GetComponent<ArtContainer>();
- if (container != null)
- {
- if (!artContainerMap.ContainsKey(container.GetArtType()))
- {
- List<ArtContainer> list = new List<ArtContainer>();
- list.Add(container);
- artContainerMap.Add(container.GetArtType(), list);
- }
- else
- {
- List<ArtContainer> list = artContainerMap[container.GetArtType()];
- list.Add(container);
- }
- }
- }
- }
- var components = Resources.LoadAll<GameObject>("Container/Component");
- if (components != null)
- {
- for (int i = 0; i < components.Length; i++)
- {
- var component = containers[i].GetComponent<ArtComponent>();
- if (component != null)
- {
- if (!artComponentMap.ContainsKey(containers[i].name))
- {
- artComponentMap.Add(containers[i].name, component);
- }
- }
- }
- }
- if (BuildConfigMgr.Instance.IsInit)
- {
-
- }
- else
- {
- UnityLog.LogError("配置文件丢失!");
- }
-
- ContainerSelect += OnContainerSelect;
- }
- public void ListenUser()
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- public void ListenPage()
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- private void OnContainerSelect(ArtContainer container, bool isSelect)
- {
- if (container.GetGoodsInfo().art_id == "ArtId_PlayerView")
- {
- return;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
- private void ReadArtInfo(string path)
- {
-
- 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<ArtInfo> packList) =>
- {
- InitPackage(packList);
- }));
- #endif
- }
- public void OpenLocalData()
- {
-
- }
- private void OpenTable()
- {
- if (!table.Open())
- {
- table.Create(tableName);
- UnityLog.Log("create table" + tableName);
- }
- var list = table.FindAllData<ArtInfo>();
- for (int i = 0; i < list.Count; i++)
- {
- list[i].ArtType = ArtInfo.GetArtType((int)list[i].ArtType);
- }
-
-
- InitPackage(list);
- }
-
-
-
-
- public void InitPackage(List<ArtInfo> 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<string, ArtInfo>();
- }
- if (artInfoTypeMap == null)
- {
- artInfoTypeMap = new Dictionary<ArtType, List<ArtInfo>>();
- }
- 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<ArtInfo> list = artInfoTypeMap[ArtInfoList[i].ArtType];
- if (list != null && !list.Contains(ArtInfoList[i]))
- {
- list.Add(ArtInfoList[i]);
- }
- }
- else
- {
- List<ArtInfo> list = new List<ArtInfo>();
- list.Add(ArtInfoList[i]);
- artInfoTypeMap.Add(ArtInfoList[i].ArtType, list);
- }
- }
- }
- IsInit = true;
- InitComplete?.Invoke();
- }
-
-
-
- public void AddDefaultArt(ArtType artType)
- {
- if (ArtInfoList == null)
- {
- ArtInfoList = new List<ArtInfo>();
- }
- 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;
-
- 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;
-
- info.Icon = "";
- info.InstaceType = InstaceType.UnityBase;
- info.Size = 1;
- info.Url = "New";
- info.Version = Application.unityVersion;
- table.InsertData(info);
- ArtInfoList.Add(info);
- }
- table.Save();
- }
-
-
-
-
-
- public ArtInfo GetArtInfo(string artId)
- {
- if (IsInit && artInfoMap.ContainsKey(artId))
- {
- return artInfoMap[artId];
- }
- return null;
- }
-
-
-
-
-
- public List<ArtInfo> GetArtInfoList(ArtType artType)
- {
- if (IsInit)
- {
- if (artInfoTypeMap.ContainsKey(artType))
- {
- return artInfoTypeMap[artType];
- }
- List<ArtInfo> tmp = new List<ArtInfo>();
- foreach (var item in artInfoTypeMap)
- {
-
- if ((item.Key & artType) == item.Key)
- {
- tmp.AddRange(item.Value);
- }
- }
- artInfoTypeMap.Add(artType, tmp);
- return tmp;
- }
- return null;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public List<ArtInfo> GetArtInfoListSingle(ArtType artType)
- {
- if (IsInit)
- {
- return artInfoTypeMap[artType];
- }
- return null;
- }
-
-
-
-
- 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;
- }
-
-
-
-
- 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<ArtComponent>();
- }
- 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<ArtContainer>();
- }
- }
- }
- return null;
- }
-
-
-
-
-
- public ArtResConf GetResConf(string resName)
- {
- if (resArtMap.ContainsKey(resName))
- {
- return resArtMap[resName];
- }
- UnityLog.LogError(resName + " is not at resArtMap");
- return null;
- }
-
-
-
-
- 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;
- }
-
-
-
-
-
-
-
-
-
-
- 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<GoodsInfo> goodDataList)
- {
- if (goodDataList != null)
- {
- for (int i = 0; i < goodDataList.Count; i++)
- {
- SyncGoods(goodDataList[i]);
- }
- }
- }
-
-
-
-
-
-
-
- public void SyncGoods(GoodsInfo goodData, bool isServer = true)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private bool SynUser(GoodsInfo goodData)
- {
-
-
-
-
-
-
-
-
-
- return false;
- }
-
-
-
-
-
-
-
- public void GoodsDelSync(int id, bool isRealDel = true)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- public void SendGoodsTransfer(GoodsInfo info)
- {
-
-
-
- }
- public void SendTransfer(GoodsInfo info)
- {
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void DelGoodsById(int id)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- public void DelGoodsByIds(List<int> ids)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
- public void OnChangePage(int all, int current)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
- }
|