more refactoring

remove code duplication
remove magic constant
add new constant
add LICENSE.meta
This commit is contained in:
aliaksei.kalosha
2025-03-18 12:12:39 +01:00
parent e2a9c13fe5
commit f89ed71bd4
4 changed files with 61 additions and 58 deletions

View File

@@ -26,7 +26,7 @@ namespace SplashEdit.RuntimeCode
public void Export()
{
LoadData();
_psxData = Utils.LoadData(out selectedResolution, out dualBuffering, out verticalLayout, out prohibitedAreas);
_exporters = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
foreach (PSXObjectExporter exp in _exporters)
{
@@ -39,10 +39,7 @@ namespace SplashEdit.RuntimeCode
void PackTextures()
{
Rect buffer1 = new Rect(0, 0, selectedResolution.x, selectedResolution.y);
Rect buffer2 = verticalLayout ? new Rect(0, 256, selectedResolution.x, selectedResolution.y)
: new Rect(selectedResolution.x, 0, selectedResolution.x, selectedResolution.y);
(Rect buffer1, Rect buffer2) = Utils.BufferForResolution(selectedResolution, verticalLayout);
List<Rect> framebuffers = new List<Rect> { buffer1 };
if (dualBuffering)
@@ -111,24 +108,6 @@ namespace SplashEdit.RuntimeCode
Debug.Log(totalFaces);
}
public void LoadData()
{
_psxData = AssetDatabase.LoadAssetAtPath<PSXData>(_psxDataPath);
if (!_psxData)
{
_psxData = ScriptableObject.CreateInstance<PSXData>();
AssetDatabase.CreateAsset(_psxData, _psxDataPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
selectedResolution = _psxData.OutputResolution;
dualBuffering = _psxData.DualBuffering;
verticalLayout = _psxData.VerticalBuffering;
prohibitedAreas = _psxData.ProhibitedAreas;
}
void OnDrawGizmos()
{
Gizmos.DrawIcon(transform.position, "Packages/net.psxsplash.splashedit/Icons/PSXSceneExporter.png", true);

View File

@@ -1,3 +1,5 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace SplashEdit.RuntimeCode
@@ -41,4 +43,42 @@ namespace SplashEdit.RuntimeCode
return new Rect(X, Y, Width, Height);
}
}
public static class Utils
{
private static string _psxDataPath = "Assets/PSXData.asset";
public static (Rect, Rect) BufferForResolution(Vector2 selectedResolution, bool verticalLayout, Vector2 offset = default)
{
if (offset == default)
{
offset = Vector2.zero;
}
Rect buffer1 = new Rect(offset.x, offset.y, selectedResolution.x, selectedResolution.y);
Rect buffer2 = verticalLayout ? new Rect(offset.x, 256, selectedResolution.x, selectedResolution.y)
: new Rect(offset.x + selectedResolution.x, offset.y, selectedResolution.x, selectedResolution.y);
return (buffer1, buffer2);
}
/// <summary>
/// Loads stored PSX data from the asset.
/// </summary>
public static PSXData LoadData(out Vector2 selectedResolution, out bool dualBuffering, out bool verticalLayout, out List<ProhibitedArea> prohibitedAreas)
{
var _psxData = AssetDatabase.LoadAssetAtPath<PSXData>(_psxDataPath);
if (!_psxData)
{
_psxData = ScriptableObject.CreateInstance<PSXData>();
AssetDatabase.CreateAsset(_psxData, _psxDataPath);
AssetDatabase.SaveAssets();
}
selectedResolution = _psxData.OutputResolution;
dualBuffering = _psxData.DualBuffering;
verticalLayout = _psxData.VerticalBuffering;
prohibitedAreas = _psxData.ProhibitedAreas;
return _psxData;
}
}
}