public void JsonToString(string obj_json) { //string Path = "C:\\Users\\Administrator\\Desktop\\9186\\Garen.obj"; //Debug.Log(File.ReadAllText("C:\\Users\\Administrator\\Desktop\\9186\\Garen.obj")); //读取路径下的文件的所有文本值 string obj_str = (string)JsonConvert.DeserializeObject(obj_json);//反序列化 //Debug.Log(obj_str); GameObject obj = ObjFormatAnalyzerFactory.AnalyzeToGameObject(obj_str); //if (obj == null) Debug.Log("空"); Instance(obj); }
public void LoadObj(string path, List <Vector3> postion, List <Vector3> eulerAngles, List <Vector3> scale) { //yield return new WaitForSeconds(1);//改成0s可能造成UI不稳定,不知道为啥 if (File.Exists(path)) { var tmp = path.Split(new char[] { '.', '/', '\\' }); var name = tmp[tmp.Length - 2]; var obj = new GameObject(name); model3d.GetComponent <Model3dController>().AddSon(obj); //将obj的父亲设置为model3d obj.tag = Macro.UNSELECTED; //将tag设置为未选中 //obj.GetComponent<SkinnedMeshRenderer>().material = panelModel_PointsInformationController.GetMaterial(); obj.AddComponent <Model3dItemController>(); //添加该脚本 obj.AddComponent <ItemController>().SetModelType(ItemController.ModelType.OBJ_MODEL_ROOT).path = path; //添加该脚本 if (postion != null && eulerAngles != null && scale != null) { SetTransform(obj, postion[0], eulerAngles[0], scale[0]); } var rootSvi = Instantiate(prefabScrollViewItem, new Vector3(0, 0, 0), Quaternion.identity); rootSvi.GetComponent <ScrollViewItemController>().Init(obj, scrollViewModelsContent, name); int i = 1; var re = ObjFormatAnalyzerFactory.AnalyzeToGameObject(path, true); foreach (var item in re) { //model3d.GetComponent<Model3dController>().AddSon(item);//将解析出来的obj的父亲设置为model3d //item.transform.position = postion; //item.transform.eulerAngles = eulerAngles; //item.transform.localScale = scale; item.AddComponent <Model3dItemController>(); //添加该脚本 item.AddComponent <ItemController>().SetModelType(ItemController.ModelType.OBJ_MODEL); //设置类型和obj文件路径 item.transform.SetParent(obj.transform); if (postion != null && eulerAngles != null && scale != null) { SetTransform(item, postion[i], eulerAngles[i], scale[i]); i++; } var scrollViewItem = Instantiate(prefabScrollViewItem, new Vector3(0, 0, 0), Quaternion.identity); scrollViewItem.GetComponent <ScrollViewItemController>().Init(item, scrollViewModelsContent); rootSvi.GetComponent <ScrollViewItemController>().AddSon(scrollViewItem); } } else { Debug.Log("no such model!"); } }
public GameObject LoadObjToShowItemView(string path) { //yield return new WaitForSeconds(1);//改成0s可能造成UI不稳定,不知道为啥 if (File.Exists(path)) { var objs = ObjFormatAnalyzerFactory.AnalyzeToGameObject(path, false); if (objs.Count == 0) { return(null); } var re = new GameObject(); foreach (var item in objs) { item.transform.SetParent(re.transform); item.layer = Macro.SHOW_ITEM; } return(re); } else { Debug.Log("no such model!"); } return(null); }