205 lines
7.2 KiB
C#
205 lines
7.2 KiB
C#
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 CreatMemberServerDomainEntity
|
|
{
|
|
private string ip;
|
|
|
|
private List<CreatMemberServerDomainEntity> domainList;
|
|
|
|
[HorizontalGroup] [ReadOnly] public string DomainName;
|
|
|
|
private bool IsValidPath => IsValidProjectPath(domainPath);
|
|
private bool IsValidIP => string.IsNullOrEmpty(ip);
|
|
|
|
[ReadOnly]
|
|
[InfoBox("当前用户在Unity项目中不存在,请检查该用户是否需要删除", InfoMessageType.Warning, "IsValidPath")]
|
|
[InfoBox("当前用户在服务器上不存在,暂不支持数据管理,仅支持数据配置", InfoMessageType.Warning, "IsValidIP")]
|
|
public string domainPath;
|
|
|
|
private ResDmainResponse resDmainResponse;
|
|
|
|
|
|
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] [HideLabel]
|
|
public ArtSceneData artSceneData;
|
|
|
|
public CreatMemberServerDomainEntity(List<CreatMemberServerDomainEntity> 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;
|
|
}
|
|
|
|
SetArtSceneData();
|
|
}
|
|
|
|
public void SetArtSceneData()
|
|
{
|
|
string artSceneDataPath =
|
|
$"Assets/Member/{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.ArrowDownCircle, IconAlignment = IconAlignment.RightEdge)]
|
|
[HideIf("@ IsValidIP")]
|
|
public void CreatDomain()
|
|
{
|
|
if (DomainName == "Main")
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "主包Main作用域无法再次创建", "确定");
|
|
return;
|
|
}
|
|
|
|
bool isOk = EditorUtility.DisplayDialog("提示", "是否检索并创建缺失目录", "是", "否");
|
|
if (isOk)
|
|
{
|
|
ArtServerManageWindow window = EditorWindow.GetWindow<ArtServerManageWindow>();
|
|
if (window != null)
|
|
{
|
|
window.CreateDomainDirectory(DomainName);
|
|
SetArtSceneData();
|
|
}
|
|
}
|
|
}
|
|
|
|
[HorizontalGroup(Width = 60)]
|
|
[Button("", Icon = SdfIconType.XCircle, IconAlignment = IconAlignment.RightEdge)]
|
|
[HideIf("@ IsValidIP")]
|
|
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")]
|
|
[HideIf("@ IsValidIP")]
|
|
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));
|
|
}
|
|
}
|
|
} |