123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ModelManager : Singleton<ModelManager>
- {
- // public Dictionary<string, ModelItem> modellist = new Dictionary<string, ModelItem>();
- public Dictionary<int, ModelList> modellist = new Dictionary<int, ModelList>();
-
- public GameObject materialLibrary;
- public List<ModelList> Models;
- public void init(string message)
- {
- GameManager.Instance.text.text = " 获取素材列表";
- JObject jObject = JObject.Parse(message);
- string data = jObject["data"].ToString();
- JObject dataObject = JObject.Parse(data);
- string single = dataObject["single"].ToString();
- string library = dataObject["library"].ToString();
- string combination = dataObject["combination"].ToString();
- materialLibrary = new GameObject("MaterailLibrary");
- // 把三个素材库数据转成素材列表
- AddDicModelList(single);
- AddDicModelList(library);
- AddDicModelList(combination);
-
- //ModelList model = GetModelList(687);
- //model.name = "AAAAAAAAA";
- //Debug.Log(" New ModelList" + model.name + " Old ModelList " + modellist[687].name);
- }
- private void AddDicModelList(string message)
- {
- Debug.Log("AddDicModelList=1==>"+message);
- if (!string.IsNullOrWhiteSpace(message))
- {
- Models = JsonConvert.DeserializeObject<List<ModelList>>(message);
- int len = Models.Count;
- for (int i = 0; i < len; i++)
- {
- if (Models.Count - 1 < len && (Models[i].type == 0))
- Models.Remove(Models[i]);
- }
- Debug.Log(Models.Count + " AddDicModelList " + message);
- for (int i = 0; i < Models.Count; i++)
- {
- modellist.Add(Models[i].id, Models[i]);
- StartModelList(Models[i], materialLibrary);
- // DownLoadModel(ModelList[i]);
- }
- }
- }
- /// <summary>
- /// 初始化 ModelList , 根据ModelList生成组合素材
- /// </summary>
- /// <param name="modelList"></param>
- /// <param name="parent"> </param>
- public void StartModelList( ModelList modelList, GameObject parent )
- {
- modelList.materalLibrary = parent.transform;
- for (int j = 0; j < modelList.materialList.Count; j++)
- {
- modelList.materialList[j].updateTime = modelList.updateTime;
- Debug.Log("modelList.Model==>"+ modelList.Model.name);
- modelList.materialList[j].init(modelList.Model);
- // DownLoadModel(modelList);
- }
- }
- /// <summary>
- /// 从素材库中查找指定素材
- /// </summary>
- /// <param name="id"> 素材ID </param>
- /// <returns></returns>
- public ModelList GetModelList(int id)
- {
- ModelList ml = (ModelList)modellist[id].Clone();
-
- if (modellist.ContainsKey(id))
- return ml;
- else
- return null;
- }
-
- private void DownLoadModel(ModelList list)
- {
- for (int i = 0; i < list.materialList.Count; i++)
- {
- if (list.materialList[i].Model != null)
- Debug.Log(" 检测下载 " + list.materialList[i].name);
- }
- }
- }
|