//-------------------配置表关联----------------------- public void PrefabConfigAss(JsonData _jd) { m_prefabConfigDic = new Dictionary <string, PrefabDataType> (); foreach (JsonData elem in _jd) { PrefabDataType table = new PrefabDataType(); table.Id = elem["Id"].ToString(); table.Name = elem["Name"].ToString(); table.Path = elem["Path"].ToString(); m_prefabConfigDic[table.Name] = table; } }
// prefab路径生成 json格式 public static void CreatePrefab(string _type, string[] _SearchScope, string _OutFileName, string _OutPath = "Assets/StreamingAssets/") { var GUID = AssetDatabase.FindAssets("t:" + _type, _SearchScope); int len = GUID.Length; if (len == 0) { Debug.Log("error!!"); return; } var res = new string[len]; List <string> list = new List <string> () { "[" }; for (int i = 0; i < len; ++i) { PrefabDataType data = new PrefabDataType(); data.Id = i.ToString(); res[i] = AssetDatabase.GUIDToAssetPath(GUID[i]); data.Name = Path.GetFileNameWithoutExtension(res[i]); // 去后缀名字 string filePath = res[i].Replace("Assets/Resources/", string.Empty); int startIndex = filePath.LastIndexOf("."); data.Path = filePath.Remove(startIndex, filePath.Length - startIndex); string str = JsonMapper.ToJson(data); if (i != len - 1) { list.Add(str + ","); } else { list.Add(str); } } list.Add("]"); File.WriteAllLines(_OutPath + _OutFileName + ".txt", list.ToArray()); AssetDatabase.Refresh(); Debug.Log("succeed!!! Path is :" + _OutPath + _OutFileName); }