66 lines
1.7 KiB
C#
66 lines
1.7 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> devices = new List<GameObject>();//把最开始生成在场景中的模型存入链表
|
|
|
|
|
|
public Dictionary<string, int> model = new Dictionary<string, int>();
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public void AddObj(GameObject obj)
|
|
{
|
|
devices.Add(obj);//把生成的预设体放入链表当中
|
|
}
|
|
public void Addobj1(GameObject obj)
|
|
{
|
|
deviceimages1.Add(obj.GetComponent<Modeldata>().modelequipment);//把场景中存在的的模型放入链表当众
|
|
}
|
|
|
|
|
|
public void RemoveObj(GameObject obj)
|
|
{
|
|
if (devices.Contains(obj))
|
|
{
|
|
devices.Remove(obj);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|