void ObjectToJson() { string path = Path.Combine(Application.streamingAssetsPath, "2.txt"); path = path.Replace(@"\", @"/"); ModelBaseInfo mbi = new ModelBaseInfo() { name = "活塞连杆组", code = "huosailianganzu", content = "活塞的基本构造可分顶部,头部和裙部三部分", modeltype = "AB", mp3 = "music", tip = "tip", ModuleInforList = new List <ModuleInfo>() { new ModuleInfo { name = "123", type = "run", code = "code", content = "活塞的基本构造可分顶部", mp3 = "讲解音频路径" } } }; string jsonStr = JsonMapper.ToJson(mbi); if (!File.Exists(path)) { File.Create(path); } //byte[] byteContent=Encoding.UTF8.GetBytes(jsonStr); File.WriteAllText(path, jsonStr); #if UNITY_EDITOR //UnityEditor.AssetDatabase.ImportAsset("StreamingAssets/2.txt"); UnityEditor.AssetDatabase.Refresh(); UnityEditor.EditorApplication.isPlaying = false; #endif }
void JsonToObject() { string path = Path.Combine(Application.streamingAssetsPath, "1.txt"); string jsonStr = File.ReadAllText(path); Debug.Log(jsonStr); ModelBaseInfo mbi = JsonMapper.ToObject <ModelBaseInfo>(jsonStr); Debug.Log(mbi.mp3); }
/// <summary> /// 把已经加载的模型资源与Node进行关联 /// </summary> /// <param name="modelPath"></param> /// <param name="node"></param> /// <param name="modelInfo"></param> void AssignModelToNode(string modelPath, ModelNode node, ModelBaseInfo modelInfo) { foreach (var frameName in modelInfo.frames) { var framePath = string.Format("{0}/{1}", modelPath, frameName); var frame = GetFrame(framePath); node.AssignFrame(ModelNode.NameToId(frameName), frame); } foreach (var animationName in modelInfo.actions.Keys) { var animationPath = string.Format("{0}/{1}", modelPath, animationName); var animation = GetAnimation(animationPath); node.AssignAnimation(ModelNode.NameToId(animationName), animation); } }