This commit is contained in:
2025-10-15 12:10:54 +08:00
parent eee39611a8
commit d426b37e83
8 changed files with 388 additions and 4 deletions

View File

@@ -65,7 +65,8 @@ namespace Stary.Evo.Editor
}
}
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
HideRemoveButton = true,HideAddButton = true)]
[TitleGroup("预览场景")] public List<CreatPointCloudEntity> SceneWorkEntities;
protected override async void Initialize()
{

View File

@@ -0,0 +1,332 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Stary.Evo;
using Stary.Evo.Editor;
using Stary.Evo.Editor.Entity;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
public class CreatPointModelWindow : OdinEditorWindow
{
private static List<string> _modelTypes;
public static List<string> ScenarioTypes;
[MenuItem("Evo/创建ModelLibrary")]
private static async void Init()
{
_modelTypes = await GetModelTypes();
ScenarioTypes = await GetScenarioTypes();
// Get existing open window or if none, make a new one:
CreatPointModelWindow window = (CreatPointModelWindow)EditorWindow.GetWindow(typeof(CreatPointModelWindow));
window.Show();
}
protected override void OnEnable()
{
base.OnEnable();
documentFileid = EditorPrefs.GetString("documentFileid");
modelType = EditorPrefs.GetString("modelType");
scenarioType = EditorPrefs.GetString("scenarioType");
}
[TitleGroup("创建")] [HorizontalGroup("创建/数据")] [HideLabel] [InfoBox("Model名称")]
public string modelName;
[TitleGroup("创建")]
[HorizontalGroup("创建/数据")]
[HideLabel]
[InfoBox("Model描述")]
[ValueDropdown("GetModelType")]
[OnValueChanged("SetModelType")]
public string modelType;
[TitleGroup("创建")]
[HorizontalGroup("创建/数据")]
[HideLabel]
[InfoBox("Scenario描述")]
[ValueDropdown("GetScenarioType")]
[OnValueChanged("SetScenarioType")]
public string scenarioType;
[TitleGroup("上传")] [HorizontalGroup("上传/文件")] [HideLabel] [ReadOnly] [InfoBox("文件所对应数据库id")]
public string documentFileid;
private List<string> GetModelType() => _modelTypes;
private List<string> GetScenarioType() => ScenarioTypes;
private void SetModelType() => EditorPrefs.SetString("modelType", modelType);
private void SetScenarioType() => EditorPrefs.SetString("scenarioType", scenarioType);
[TitleGroup("上传")]
[Button("创建Model", ButtonSizes.Large)]
public async void CreatModel()
{
if (string.IsNullOrEmpty(modelName) || string.IsNullOrEmpty(modelType) || string.IsNullOrEmpty(scenarioType) ||
string.IsNullOrEmpty(documentFileid))
{
EditorUtility.DisplayDialog("提示", "modelName和modelType和scenarioType和documentFileid不能为空", "确定");
return;
}
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return;
}
var pointModelEntity = new
{
Name = modelName,
ModelType = modelType,
ScenarioType = scenarioType,
DocumentFileid = documentFileid,
};
string postData = JsonConvert.SerializeObject(pointModelEntity);
ResultMessageEntity entity = await WebRequestSystem.Post($"{ip}/ModelLibrary/AddModel", postData);
if (entity.code == 200)
{
EditorUtility.DisplayDialog("提示", "创建成功", "确定");
modelName = "";
documentFileid = "";
EditorPrefs.SetString("documentFileid", "");
EditorPrefs.SetString("modelType", "");
EditorPrefs.SetString("scenarioType", "");
}
else if (entity.code == 4009)
{
EditorUtility.DisplayDialog("提示", $"创建失败,存在相同名称元素", "确定");
}
}
[TitleGroup("上传")]
[VerticalGroup("上传/文件/上传")]
[HideLabel]
[Sirenix.OdinInspector.FilePath(AbsolutePath = false, Extensions = "$modelType")]
[OnValueChanged("UpdateModel")]
public string modelPath;
[TitleGroup("上传")] [VerticalGroup("上传/文件/上传")] [ReadOnly] [HideLabel, ProgressBar(0, 100f)]
public float modelUpdateInterval = 0f;
public async void UpdateModel()
{
if (string.IsNullOrEmpty(modelPath))
{
EditorUtility.DisplayDialog("提示", "modelPath不能为空", "确定");
return;
}
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return;
}
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { modelPath },
(progress) =>
{
modelUpdateInterval = progress * 100f;
if (progress >= 1)
{
EditorUtility.DisplayDialog("提示", $"上传成功!", "确定");
}
});
if (messageEntity.code == 200)
{
List<ResultMessageEntity> resultMessageEntities =
JsonConvert.DeserializeObject<List<ResultMessageEntity>>(messageEntity.data.ToString());
if (resultMessageEntities.Count > 0)
{
foreach (var resultMessageEntity in resultMessageEntities)
{
var data = JsonConvert.DeserializeObject(resultMessageEntity.data.ToString()) as JObject;
documentFileid = data["id"].ToString();
EditorPrefs.SetString("documentFileid", documentFileid);
}
}
}
}
[FormerlySerializedAs("PointModelEntities")]
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
HideRemoveButton = true, HideAddButton = true)]
[TitleGroup("预览模型")]
public List<PointModelEntity> pointModelEntities;
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, "/ModelLibrary/FindModelAll");
if (entity.code == 200)
{
var modelLibraryResponses =
JsonConvert.DeserializeObject<List<ModelLibraryResponses>>(entity.data.ToString());
pointModelEntities = modelLibraryResponses.Select(x => new PointModelEntity(this)
{
id = x.id,
Name = x.Name,
ModelType = x.ModelType,
ScenarioType = x.ScenarioType,
DocumentFileid = x.DocumentFileid,
}).ToList();
}
}
private static async UniTask<List<string>> GetModelTypes()
{
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return null;
}
ResultMessageEntity entity = await WebRequestSystem.Get(ip, "/ModelLibrary/FindModelType");
if (entity.code == 200)
{
var modelTypes = JsonConvert.DeserializeObject<string[]>(entity.data.ToString());
return modelTypes.ToList();
}
else
{
return null;
}
}
private static async UniTask<List<string>> GetScenarioTypes()
{
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return null;
}
ResultMessageEntity entity = await WebRequestSystem.Get(ip, "/SceneWork/FindScenarioType");
if (entity.code == 200)
{
var scenarioTypes = JsonConvert.DeserializeObject<List<string>>(entity.data.ToString());
return scenarioTypes;
}
else
{
return null;
}
}
[Serializable]
public class PointModelEntity
{
private readonly CreatPointModelWindow window;
/// <summary>
/// id
/// </summary>
[HideInInspector] public string id;
/// <summary>
/// 模型名称
/// </summary>
[TitleGroup("$id")] [HorizontalGroup("$id/数据")] [HideLabel] [InfoBox("模型名称")]
public string Name;
/// <summary>
/// 模型标签
/// </summary>
[TitleGroup("$id")] [HorizontalGroup("$id/数据")] [HideLabel] [InfoBox("模型标签")] [ValueDropdown("GetModelType")]
public string ModelType;
/// <summary>
/// 场景标签
/// </summary>
[TitleGroup("$id")] [HorizontalGroup("$id/数据")] [HideLabel] [InfoBox("场景标签")] [ValueDropdown("GetScenarioType")]
public string ScenarioType;
/// <summary>
/// 文件id
/// </summary>
[TitleGroup("$id")] [HorizontalGroup("$id/数据")] [HideLabel] [ReadOnly] [InfoBox("文件id")]
public string DocumentFileid;
public PointModelEntity(CreatPointModelWindow window)
{
this.window = window;
}
[TitleGroup("$id")]
[HorizontalGroup("$id/button")]
[Button("", Icon = SdfIconType.ArrowUpCircleFill, IconAlignment = IconAlignment.RightEdge)]
public async void UpdatePointCloud()
{
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return;
}
var pointModelEntity = new
{
Name = Name,
ModelType = ModelType,
ScenarioType = ScenarioType,
DocumentFileid = DocumentFileid,
};
string body = JsonConvert.SerializeObject(pointModelEntity);
ResultMessageEntity entity = await WebRequestSystem.Put($"{ip}/ModelLibrary/UpdateModel", body);
if (entity.code == 200)
{
EditorUtility.DisplayDialog("提示", $"更新成功{pointModelEntity}", "确定");
}
}
[TitleGroup("$id")]
[HorizontalGroup("$id/button")]
[Button("", Icon = SdfIconType.XCircle, IconAlignment = IconAlignment.RightEdge)]
public async void DeletePointCloud()
{
string ip = EditorPrefs.GetString("ip");
if (string.IsNullOrEmpty(ip))
{
EditorUtility.DisplayDialog("提示", "ip不能为空", "确定");
return;
}
ResultMessageEntity entity = await WebRequestSystem.Delete(ip, $"/ModelLibrary/DeleteModelbyid/{id}");
if (entity.code == 200)
{
window.pointModelEntities.Remove(this);
EditorUtility.DisplayDialog("提示", "删除成功", "确定");
}
}
private List<string> GetModelType()
{
return window.GetModelType();
}
private List<string> GetScenarioType()
{
return window.GetScenarioType();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63cfd397008223c4cae6325df57adc06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
namespace Stary.Evo.Editor.Entity
{
public class ModelLibraryResponses
{
/// <summary>
/// id
/// </summary>
public string id { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 模型类别
/// </summary>
public string ModelType { get; set; }
/// <summary>
/// 使用场景类别
/// </summary>
public string ScenarioType { get; set; }
/// <summary>
/// 产品包路径
/// </summary>
public string DocumentFileid { get; set; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 12a06324569c4a8588564b00a09af17f
timeCreated: 1759202524

View File

@@ -2,7 +2,8 @@
"name": "com.pointcloud.reditor",
"rootNamespace": "",
"references": [
"GUID:d1a793c2b6959e04ea45b972eaa369c8"
"GUID:d1a793c2b6959e04ea45b972eaa369c8",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [
"Editor"

View File

@@ -5,7 +5,12 @@
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:f3fa071c399c4383a9ff8115e53dfefc",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:d1a793c2b6959e04ea45b972eaa369c8"
"GUID:d1a793c2b6959e04ea45b972eaa369c8",
"com.audiocore.runtime",
"GUID:fad681b9bfe621d4fa07f4f69c311443",
"GUID:006be2ba6588a8b4989d3724bb01d8b7",
"GUID:ff70fce64a3314305977bdf5610ed86b",
"GUID:ec45849e30ba03e4dab386099d8c697b"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -1,6 +1,6 @@
{
"name": "com.pointcloud",
"version": "1.0.3",
"version": "1.0.4",
"displayName": "11.PointCloudTools",
"description": "点云开发工具",
"unity": "2021.3",