Files
plugin-library/Assets/11.PointCloudTools/Editor/Script/CreatPointCloudWindow.cs

115 lines
4.1 KiB
C#
Raw Normal View History

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