Files
HauntedBloodlines/Assets/HTraceWSGI/Scripts/PipelinesConfigurator/ConfiguratorUtiles.cs
2025-05-29 22:31:40 +03:00

90 lines
2.8 KiB
C#

#if UNITY_EDITOR
using System;
using System.Collections; // UNITY 6
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
namespace HTraceWSGI.Scripts.PipelinesConfigurator
{
public static class ConfiguratorUtils
{
public static string GetFullHdrpPath()
{
string targetPathStandart = Path.Combine(Directory.GetCurrentDirectory(), "Library", "PackageCache");
string hdrpPathStandart = Directory.GetDirectories(targetPathStandart)
.FirstOrDefault(name => name.Contains("high-definition") && !name.Contains("config"));
string targetPathCustom = Path.Combine(Directory.GetCurrentDirectory(), "Packages");
string hdrpPathCustom = Directory.GetDirectories(targetPathCustom)
.FirstOrDefault(name => name.Contains("high-definition") && !name.Contains("config"));
if (string.IsNullOrEmpty(hdrpPathStandart) && string.IsNullOrEmpty(hdrpPathCustom))
{
Debug.LogError($"HDRP path was not found there: {hdrpPathStandart}\n and there:\n{hdrpPathCustom}");
}
return string.IsNullOrEmpty(hdrpPathStandart) ? hdrpPathCustom : hdrpPathStandart;
}
public static string GetHTraceFolderPath()
{
//string filePath = AssetDatabase.GetAssetPath(MonoScript.FromMonoBehaviour(this));
string filePath = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
string htraceFolder = Directory.GetParent(Directory.GetParent(Path.GetDirectoryName(filePath)).FullName).FullName;
return htraceFolder;
}
public static string GetUnityAndHdrpVersion()
{
return $"Unity {Application.unityVersion}, HDRP version {GetHdrpVersion()}";
}
public static string GetHdrpVersion()
{
string fullHdrpPath = GetFullHdrpPath();
if (string.IsNullOrEmpty(fullHdrpPath))
return string.Empty;
string pathPackageJson = Path.Combine(fullHdrpPath, "package.json");
string[] packageJson = File.ReadAllLines(pathPackageJson);
string hdrpVersion = string.Empty;
foreach (string line in packageJson)
{
if (line.Contains("version"))
{
hdrpVersion = line.Replace("version", "").Replace(" ", "").Replace(":", "").Replace(",", "").Replace("\"", "");
break;
}
}
return hdrpVersion;
}
public static int GetMajorHdrpVersion()
{
string hdrpVersion = GetHdrpVersion();
string[] split = hdrpVersion.Split('.');
return Convert.ToInt32(split[0]);
}
public static int GetMinorHdrpVersion()
{
string hdrpVersion = GetHdrpVersion();
string[] split = hdrpVersion.Split('.');
return Convert.ToInt32(split[1]);
}
public static int GetPatchHdrpVersion()
{
string hdrpVersion = GetHdrpVersion();
string[] split = hdrpVersion.Split('.');
return Convert.ToInt32(split[2]);
}
}
}
#endif