88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using Cysharp.Threading.Tasks.Triggers;
|
|
using LitJson;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XFrame.Core.Utils;
|
|
|
|
public class DragManager : MonoSingleton<DragManager>
|
|
{
|
|
public List<Modelequipment> deviceimages1 = new List<Modelequipment>();//把最终场景中存在的模型放入链表当中
|
|
public List<GameObject> deviceimages = new List<GameObject>();//把最开始生成在场景中的模型存入链表
|
|
public List<string> modellist = new List<string>();//存入最开始场景生成模型的名字
|
|
|
|
public Dictionary<string,int> model = new Dictionary<string,int>();
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
//public void AddModeData(string str, GameObject gameObject)
|
|
//{
|
|
// GameObject obj = null;
|
|
// if (model.TryGetValue(str, out obj))
|
|
// return;
|
|
|
|
// model.Add(str, gameObject);
|
|
//}
|
|
public void AddObj(GameObject obj)
|
|
{
|
|
deviceimages.Add(obj);//把生成的预设体放入链表当中
|
|
}
|
|
public void Addobj1(GameObject obj)
|
|
{
|
|
deviceimages1.Add(obj.GetComponent<Modeldata>().modelequipment);//把场景中存在的的模型放入链表当众
|
|
}
|
|
public void Addtext(string name)
|
|
{
|
|
modellist.Add(name);//把UI上模型对应的名字存入链表
|
|
}
|
|
|
|
public string Modelinformation()
|
|
{
|
|
string josn = Newtonsoft.Json.JsonConvert.SerializeObject(deviceimages1);//把对象转json
|
|
Debug.Log(josn);
|
|
|
|
|
|
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Modelequipment>>(josn);//把json序列化成对象
|
|
list.ForEach(item =>//ForEach方法快速遍历
|
|
{
|
|
var obj = Resources.Load<GameObject>(item.str);//获取对应的需预设体路径
|
|
GameObject game = Instantiate(obj);//生成预设体
|
|
game.transform.localPosition = new Vector3(item.x, item.y, item.z);//赋给对应模型的位置
|
|
});
|
|
return josn;
|
|
}
|
|
|
|
}
|
|
//public class DragManager : MonoSingleton<DragManager>
|
|
//{
|
|
// public Deviceimage prefab;
|
|
|
|
// start()
|
|
// {
|
|
// for deviceimages
|
|
// Deviceimage d = instance (prefab)
|
|
// d.setvalue(Set, De, deviceimages[i].name ,)
|
|
// }
|
|
|
|
// public void Set()
|
|
// {
|
|
|
|
// }
|
|
|
|
// public void De()
|
|
// {
|
|
|
|
|
|
// }
|
|
//}
|