Files
plugin-library/Assets/11.PointCloudTools/Editor/Script/CreatPointCloudWindow.cs
2025-10-15 12:10:54 +08:00

116 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Stary.Evo.Editor.Entity;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace Stary.Evo.Editor
{
public class CreatPointCloudWindow : OdinEditorWindow
{
[MenuItem("Evo/创建PointCloud场景")]
static async void Init()
{
// Get existing open window or if none, make a new one:
CreatPointCloudWindow window = (CreatPointCloudWindow)EditorWindow.GetWindow(typeof(CreatPointCloudWindow));
window.Show();
window.identifier = Application.identifier;
}
[TitleGroup("创建")][InfoBox("场景名称")] public string sceneName;
[TitleGroup("创建")][InfoBox("场景描述")] public string sceneDesc;
[TitleGroup("创建"),ReadOnly] public string identifier;
[TitleGroup("创建")]
[Button("创建场景", ButtonSizes.Large)]
public async void CreatDomain()
{
if (string.IsNullOrEmpty(sceneName)||string.IsNullOrEmpty(sceneDesc))
{
EditorUtility.DisplayDialog("提示", "sceneName和sceneDesc不能为空", "确定");
return;
}
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return;
}
var sceneWorkEntity = new SceneWorkEntity
{
sceneName = sceneName,
identifier = identifier,
sceneDesc = sceneDesc,
};
string postData = JsonConvert.SerializeObject(sceneWorkEntity);
ResultMessageEntity entity = await WebRequestSystem.Post($"{ip}/SceneWork/AddScene",postData);
if (entity.code ==200)
{
var sceneWorkResponse = JsonConvert.DeserializeObject<SceneWorkResponses>(entity.data.ToString());
SceneWorkEntities.Add(new CreatPointCloudEntity(this)
{
sceneName = sceneWorkResponse.sceneName,
identifier = sceneWorkResponse.identifier,
sceneDesc = sceneWorkResponse.sceneDesc,
isActive = sceneWorkResponse.isActivate=="true",
id = sceneWorkResponse.id,
});
EditorUtility.DisplayDialog("提示", "创建成功", "确定");
}
}
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
HideRemoveButton = true,HideAddButton = true)]
[TitleGroup("预览场景")] public List<CreatPointCloudEntity> SceneWorkEntities;
protected override async void Initialize()
{
base.Initialize();
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return;
}
ResultMessageEntity entity = await WebRequestSystem.Get(ip,"/SceneWork/GetScenebyAll");
if (entity.code ==200)
{
var sceneWorkResponses = JsonConvert.DeserializeObject<List<SceneWorkResponses>>(entity.data.ToString());
SceneWorkEntities = sceneWorkResponses.Select(x => new CreatPointCloudEntity(this)
{
sceneName = x.sceneName,
identifier = x.identifier,
sceneDesc = x.sceneDesc,
isActive = x.isActivate=="true",
id = x.id,
}).ToList();
}
}
}
[Serializable]
public class SceneWorkEntity
{
/// <summary>
/// 场景名称
/// </summary>
public string sceneName { get; set; }
/// <summary>
/// 场景识别码
/// </summary>
public string identifier { get; set; }
/// <summary>
/// 场景描述
/// </summary>
public string sceneDesc { get; set; }
public bool isActivate { get; set; }
}
}