mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
* build: migrate C# formatting and add offscreen editor test support Host IMGUI tests on a detached panel without creating a native editor window. * feat(core): decode native battle records, geometry and animation metadata Read the two game variants’ battle tables and model data, with binary-reader and original-resource coverage. * feat(battle): implement deterministic combat rules and action settlement Implement actors, inventory, formation, action timing, status interruption, AI, stage ownership and deterministic replay. Keep the domain and its regression suite independent of Unity. * feat(battle): project native HUD state and input commands Add the presentation assembly and tests for command routing, lineup selection, floating numbers and stage messages. * feat(rendering): add battle lighting, actor appearance and native shadows Support baked and toon lighting, actor and weapon rendering, display refresh rate and resource ownership. * feat(effects): drive battle effects through shared resource previews Bind battle control nodes to action owners. Share preview lighting, geometry and effect resources with the existing Unity editors. * refactor(game): isolate story battle targeting and actor lifetimes Preserve scene ownership, bound story battle targeting and stop debug attacks when their actor leaves the scene. * feat(editor): compile original game data into battle scenarios Build per-variant animation and ability catalogs, encounter music, scene lighting profiles, random parties, equipment and test inventory from the original resources. * feat(editor): play battle sessions with animated previews and synced media Drive the preview scene, camera, effects, hit feedback, result choreography, music and movies from simulation snapshots and events. * feat(editor): add the battle workbench, native HUD and input controls Expose scenario authoring, replay, diagnostics, responsive command menus and mouse, touch and gamepad targeting. Include the editor workflow and HUD integration tests.
67 lines
2.8 KiB
C#
67 lines
2.8 KiB
C#
// ------------------------------------------------------------------------
|
|
// Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
|
|
// See LICENSE file in the project root for license information.
|
|
// ------------------------------------------------------------------------
|
|
|
|
namespace Pal3.BattleEditor
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Engine.Extensions;
|
|
using UnityEngine;
|
|
|
|
public sealed partial class BattlePreview
|
|
{
|
|
private static Bounds ActorSelectionBounds(ActorView actor)
|
|
{
|
|
var bounds = new Bounds(actor.Model.Meshes[0].GameBoxBoundsMin.ToUnityPosition(), Vector3.zero);
|
|
foreach (var mesh in actor.Model.Meshes)
|
|
{
|
|
bounds.Encapsulate(mesh.GameBoxBoundsMin.ToUnityPosition());
|
|
bounds.Encapsulate(mesh.GameBoxBoundsMax.ToUnityPosition());
|
|
}
|
|
return bounds;
|
|
}
|
|
|
|
public bool TryActorSelectionPoint(string id, Rect viewport, out Vector2 point)
|
|
{
|
|
point = default;
|
|
return _actors.TryGetValue(id, out var actor) && actor.Visible && actor.Model?.Meshes.Length > 0 &&
|
|
View.Project(actor.Object.transform.TransformPoint(ActorSelectionBounds(actor).center), viewport, out point);
|
|
}
|
|
|
|
public string PickActor(Vector2 point, Rect viewport, IEnumerable<string> candidates)
|
|
{
|
|
if (!viewport.Contains(point))
|
|
return null;
|
|
Ray ray = View.ScreenRay(point, viewport);
|
|
float nearest = float.PositiveInfinity;
|
|
string picked = null;
|
|
foreach (string id in candidates)
|
|
{
|
|
if (!_actors.TryGetValue(id, out var actor) || !actor.Visible || actor.Model?.Meshes.Length is not > 0)
|
|
continue;
|
|
Transform transform = actor.Object.transform;
|
|
var localRay = new Ray(transform.InverseTransformPoint(ray.origin), transform.InverseTransformVector(ray.direction));
|
|
if (!ActorSelectionBounds(actor).IntersectRay(localRay, out float distance))
|
|
continue;
|
|
float depth = Vector3.Distance(ray.origin, transform.TransformPoint(localRay.GetPoint(distance)));
|
|
if (depth < nearest)
|
|
{
|
|
nearest = depth;
|
|
picked = id;
|
|
}
|
|
}
|
|
return picked;
|
|
}
|
|
|
|
public void SetSelection(IReadOnlyCollection<string> actors, double presentationSeconds)
|
|
{
|
|
float luminance = .65f + .35f * MathF.Sin((float)presentationSeconds * 7.8f);
|
|
foreach (var actor in _actors)
|
|
actor.Value.Renderer?.SetSelectionLuminance(actors.Contains(actor.Key) ? luminance : -1);
|
|
}
|
|
}
|
|
}
|