update handling of Lua assets

This commit is contained in:
aliaksei.kalosha
2025-04-12 18:16:57 +02:00
parent a07a715d19
commit ecb1422937
15 changed files with 930 additions and 18 deletions

View File

@@ -2,10 +2,14 @@ using UnityEngine;
namespace Splashedit.RuntimeCode
{
[CreateAssetMenu(fileName = "NewLuaScript", menuName = "Lua Script", order = 1)]
public class LuaFile : ScriptableObject
{
public TextAsset luaScript;
[SerializeField] private string luaScript;
public string LuaScript => luaScript;
public void Init(string luaCode)
{
luaScript = luaCode;
}
}
}

View File

@@ -8,13 +8,14 @@ namespace SplashEdit.RuntimeCode
[RequireComponent(typeof(Renderer))]
public class PSXObjectExporter : MonoBehaviour
{
public LuaFile luaFile;
public LuaFile LuaFile => luaFile;
public List<PSXTexture2D> Textures { get; set; } = new List<PSXTexture2D>(); // Stores the converted PlayStation-style texture
public PSXMesh Mesh { get; set; } // Stores the converted PlayStation-style mesh
public PSXMesh Mesh { get; protected set; } // Stores the converted PlayStation-style mesh
[Header("Export Settings")]
[FormerlySerializedAs("BitDepth")]
[SerializeField] private PSXBPP bitDepth = PSXBPP.TEX_8BIT; // Defines the bit depth of the texture (e.g., 4BPP, 8BPP)
[SerializeField] private LuaFile luaFile;
[Header("Gizmo Settings")]
[FormerlySerializedAs("PreviewNormals")]
[SerializeField] private bool previewNormals = false;

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Splashedit.RuntimeCode;
using UnityEditor;
using UnityEngine;
@@ -128,12 +129,12 @@ namespace SplashEdit.RuntimeCode
// Lua files
foreach (PSXObjectExporter exporter in _exporters)
{
if (exporter.luaFile != null)
if (exporter.LuaFile != null)
{
//if not contains
if (!luaFiles.Contains(exporter.luaFile))
if (!luaFiles.Contains(exporter.LuaFile))
{
luaFiles.Add(exporter.luaFile);
luaFiles.Add(exporter.LuaFile);
}
}
}
@@ -168,7 +169,7 @@ namespace SplashEdit.RuntimeCode
// Write placeholder for lua file data offset and record its position.
luaOffsetPlaceholderPositions.Add(writer.BaseStream.Position);
writer.Write((int)0); // 4-byte placeholder for mesh data offset.
writer.Write((uint)luaFile.luaScript.text.Length);
writer.Write((uint)luaFile.LuaScript.Length);
}
// GameObject section (exporters)
@@ -195,9 +196,9 @@ namespace SplashEdit.RuntimeCode
writer.Write((int)rotationMatrix[2, 2]);
writer.Write((ushort)exporter.Mesh.Triangles.Count);
if (exporter.luaFile != null)
if (exporter.LuaFile != null)
{
int index = luaFiles.IndexOf(exporter.luaFile);
int index = luaFiles.IndexOf(exporter.LuaFile);
writer.Write((short)index);
}
else
@@ -257,7 +258,7 @@ namespace SplashEdit.RuntimeCode
long luaDataOffset = writer.BaseStream.Position;
luaDataOffsets.Add(luaDataOffset);
writer.Write(luaFile.luaScript.bytes);
writer.Write(Encoding.UTF8.GetBytes(luaFile.LuaScript));
}
// Mesh data section: Write mesh data for each exporter.