【m】框架大更新
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using EditorFramework;
|
||||
using Newtonsoft.Json;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class CreatArtServerDomainEntity
|
||||
{
|
||||
private string ip;
|
||||
|
||||
private List<CreatArtServerDomainEntity> domainList;
|
||||
|
||||
[HorizontalGroup] [ReadOnly] public string DomainName;
|
||||
|
||||
private bool IsValidPath => IsValidProjectPath(domainPath);
|
||||
|
||||
[ReadOnly] [InfoBox("当前路径在Unity项目中不存在,请检查路径是否需要删除", InfoMessageType.Error, "IsValidPath")]
|
||||
public string domainPath;
|
||||
|
||||
private ResDmainResponse resDmainResponse;
|
||||
|
||||
|
||||
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)]
|
||||
[HideLabel]
|
||||
public ArtSceneData artSceneData;
|
||||
public CreatArtServerDomainEntity(List<CreatArtServerDomainEntity> domainList)
|
||||
{
|
||||
this.domainList = domainList;
|
||||
}
|
||||
public void SetDomainData(string domainName, string domainPath, ResDmainResponse response, string ip)
|
||||
{
|
||||
resDmainResponse = response;
|
||||
DomainName = domainName;
|
||||
this.domainPath = domainPath;
|
||||
this.ip = ip;
|
||||
if (!resDmainResponse.IsEnable)
|
||||
{
|
||||
_endableBtnName = "启用";
|
||||
_endableBtnColor = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_endableBtnName = "禁用";
|
||||
_endableBtnColor = Color.red;
|
||||
}
|
||||
string artSceneDataPath =
|
||||
$"Assets/Art/{domainName}/Config/ArtSceneData.asset";
|
||||
ArtSceneData artSceneData =
|
||||
AssetDatabase.LoadAssetAtPath<ArtSceneData>(artSceneDataPath);
|
||||
if (artSceneData != null)
|
||||
{
|
||||
this.artSceneData = artSceneData;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:ArtSceneData 不存在,请检查路径{artSceneDataPath}");
|
||||
}
|
||||
}
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("", Icon = SdfIconType.ArrowRepeat, IconAlignment = IconAlignment.RightEdge)]
|
||||
public void CreatDomain()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域无法再次创建", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isOk = EditorUtility.DisplayDialog("提示", "是否检索并创建缺失目录", "是", "否");
|
||||
if (isOk)
|
||||
{
|
||||
ArtServerManageWindow.CreateDomainDirectory(DomainName);
|
||||
}
|
||||
}
|
||||
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("", Icon = SdfIconType.XCircle, IconAlignment = IconAlignment.RightEdge)]
|
||||
public async void CloseDomain()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域无法删除", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isOk = EditorUtility.DisplayDialog("提示", "是否删除此Art", "是", "否");
|
||||
if (isOk)
|
||||
{
|
||||
string url = $"{ip}/ResDomain/DeleteResDomain";
|
||||
var requst = new ResDmainRequst()
|
||||
{
|
||||
ProductName = Application.identifier,
|
||||
Platform = UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
DomainName = DomainName,
|
||||
};
|
||||
var resDmainMessageEntity =
|
||||
await WebRequestSystem.Post(url, JsonConvert.SerializeObject(requst));
|
||||
if (resDmainMessageEntity.code == 200)
|
||||
{
|
||||
BuildArtAssetWindow.RemoveBuildAssetWindow();
|
||||
EditorFrameworkUtils.DeleteAllChild(domainPath, FileAttributes.Normal);
|
||||
domainList.Remove(this);
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.SaveAssets();
|
||||
EditorUtility.DisplayDialog("提示", "删除成功", "确定");
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", $"删除失败,错误码:{resDmainMessageEntity.code}", "确定");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _endableBtnName = "";
|
||||
private Color _endableBtnColor = Color.white;
|
||||
private bool IsReadOnly = false; // 或者根据条件动态判断
|
||||
|
||||
[HorizontalGroup(Width = 60)]
|
||||
[Button("@ _endableBtnName", IconAlignment = IconAlignment.RightEdge)]
|
||||
[GUIColor("@ _endableBtnColor")]
|
||||
[DisableIf("@ IsReadOnly")]
|
||||
public async void IsEndable()
|
||||
{
|
||||
if (DomainName == "Main")
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "主包Main作用域设置", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
resDmainResponse.IsEnable = !resDmainResponse.IsEnable;
|
||||
|
||||
if (!resDmainResponse.IsEnable)
|
||||
{
|
||||
_endableBtnName = "启用";
|
||||
_endableBtnColor = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_endableBtnName = "禁用";
|
||||
_endableBtnColor = Color.red;
|
||||
}
|
||||
string url = $"{ip}/ResDomain/UpdateResDomain";
|
||||
var requst = new ResDmainUpdateRequst()
|
||||
{
|
||||
ProductName = Application.identifier,
|
||||
Platform = UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString(),
|
||||
DomainName = DomainName,
|
||||
IsEnabled = resDmainResponse.IsEnable,
|
||||
};
|
||||
IsReadOnly = true;
|
||||
//获取服务器版本
|
||||
var resDmainMessageEntity =
|
||||
await WebRequestSystem.Put(url, JsonConvert.SerializeObject(requst));
|
||||
IsReadOnly = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查给定路径是否在Unity项目中存在
|
||||
/// </summary>
|
||||
/// <param name="path">要检查的路径</param>
|
||||
/// <returns>路径是否存在</returns>
|
||||
private bool IsValidProjectPath(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
// 将相对路径转换为绝对路径进行检查
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
string projectPath = Path.GetFullPath(Application.dataPath + "/../");
|
||||
|
||||
// 确保路径在项目目录内
|
||||
if (!fullPath.StartsWith(projectPath))
|
||||
return false;
|
||||
|
||||
// 检查路径是否存在
|
||||
return !(Directory.Exists(path) || File.Exists(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user