Files
JuegoSim/Assets/_Project/Scripts/Code/BlockExtensions/BlockEditContext.cs
T
2026-07-21 08:56:10 +03:00

66 lines
2.6 KiB
C#

using UnityEngine;
using UnityEngine.Rendering;
/// <summary>
/// Self-contained state for one block being edited (placed or repositioned).
/// </summary>
public class BlockEditContext
{
// Core data
public GameObject GhostObject { get; internal set; }
public Transform GhostTransform => GhostObject != null ? GhostObject.transform : null;
public GameObject SourceObject { get; internal set; } // null for new blocks
public BlockData BlockData { get; internal set; }
public Renderer[] GhostRenderers { get; internal set; }
// visual data
public bool AlignToSurfaceNormal { get; internal set; } = true;
public bool SnapRotation { get; internal set; } = false;
public float FollowSpeed { get; internal set; } = 20f;
public float HeightOffset { get; internal set; } = 0f;
public Color ValidTint { get; internal set; } = new Color(0.5f, 1f, 0.5f, 1f);
public Color InvalidTint { get; internal set; } = new Color(1f, 0.5f, 0.5f, 1f);
public Transform AttachPoint { get; internal set; }
// type data
public bool IsEditingExisting { get; internal set; }
public Vector3 OriginalPosition { get; internal set; }
public Quaternion OriginalRotation { get; internal set; }
public bool IsValidPlacement { get; internal set; } = true;
// editable state
public Vector3 SurfacePoint { get; internal set; }
public Vector3 SurfaceNormal { get; internal set; } = Vector3.up;
public Vector3 RotationAxis { get; internal set; } = Vector3.up;
// sockets
public SocketPoint TargetSocket { get; internal set; }
public SocketPoint MySocket { get; internal set; }
// block references
public Block Block { get; internal set; }
public JointBlock JointBlock { get; internal set; }
public SocketContainer Container { get; internal set; }
// Behaviors
public IGhostMovementStrategy CurrentStrategy { get; set; }
public ISnapBehavior SnapBehavior { get; set; }
public IPlacementHandler PlacementHandler { get; set; }
public IBlockValidator Validator { get; set; }
public IVisualFeedback VisualFeedback { get; set; }
public IRotateHandler RotationHandler { get; set; }
public bool IsActive => GhostObject != null && GhostObject.activeSelf;
public void SetRotationAxis(Vector3 axis) => RotationAxis = axis;
internal void SetFrameState(Vector3 surfacePoint, Vector3 surfaceNormal, SocketPoint mySocket, SocketPoint targetSocket)
{
SurfacePoint = surfacePoint;
SurfaceNormal = surfaceNormal;
MySocket = mySocket;
TargetSocket = targetSocket;
}
}