cement daddy
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
using Core;
|
||||
using Minigames.StatueDressup.Data;
|
||||
using Minigames.StatueDressup.Utils;
|
||||
using UI.DragAndDrop.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Minigames.StatueDressup.DragDrop
|
||||
{
|
||||
/// <summary>
|
||||
/// Individual decoration item that can be dragged from menu to statue slots
|
||||
/// </summary>
|
||||
public class DecorationItem : DraggableObject
|
||||
{
|
||||
[Header("Decoration Data")]
|
||||
[SerializeField] private DecorationData decorationData;
|
||||
[SerializeField] private Image decorationImage;
|
||||
|
||||
private Vector2 _iconSize;
|
||||
private Vector2 _authoredSize;
|
||||
private Vector2 _originalMenuPosition;
|
||||
private bool _isInMenu = true;
|
||||
|
||||
// Properties
|
||||
public DecorationData Data => decorationData;
|
||||
public DecorationCategory Category => decorationData?.Category ?? DecorationCategory.Hats;
|
||||
public bool IsInMenu => _isInMenu;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (decorationData != null)
|
||||
{
|
||||
_iconSize = decorationData.IconSize;
|
||||
_authoredSize = decorationData.AuthoredSize;
|
||||
|
||||
// Set initial icon size
|
||||
if (RectTransform != null)
|
||||
{
|
||||
RectTransform.sizeDelta = _iconSize;
|
||||
}
|
||||
|
||||
// Set sprite
|
||||
if (decorationImage != null && decorationData.DecorationSprite != null)
|
||||
{
|
||||
decorationImage.sprite = decorationData.DecorationSprite;
|
||||
}
|
||||
}
|
||||
|
||||
// Store original menu position
|
||||
if (RectTransform != null)
|
||||
{
|
||||
_originalMenuPosition = RectTransform.anchoredPosition;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set decoration data (for spawned instances)
|
||||
/// </summary>
|
||||
public void SetDecorationData(DecorationData data)
|
||||
{
|
||||
decorationData = data;
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
_iconSize = data.IconSize;
|
||||
_authoredSize = data.AuthoredSize;
|
||||
|
||||
// Update visual
|
||||
if (decorationImage != null && data.DecorationSprite != null)
|
||||
{
|
||||
decorationImage.sprite = data.DecorationSprite;
|
||||
}
|
||||
|
||||
// Set icon size
|
||||
if (RectTransform != null)
|
||||
{
|
||||
RectTransform.sizeDelta = _iconSize;
|
||||
}
|
||||
|
||||
Logging.Debug($"[DecorationItem] Set data: {data.DecorationName}, iconSize={_iconSize}, authoredSize={_authoredSize}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDragStartedHook()
|
||||
{
|
||||
Logging.Debug($"[DecorationItem] OnDragStarted: {decorationData?.DecorationName}");
|
||||
|
||||
// Scale to authored size when dragging starts
|
||||
if (RectTransform != null)
|
||||
{
|
||||
TweenAnimationUtility.AnimateScale(transform, Vector3.one, 0.2f);
|
||||
|
||||
// Animate size delta to authored size
|
||||
RectTransform.sizeDelta = _authoredSize;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDragEndedHook()
|
||||
{
|
||||
Logging.Debug($"[DecorationItem] OnDragEnded: {decorationData?.DecorationName}, currentSlot={CurrentSlot?.name}");
|
||||
|
||||
// If not placed in a slot, return to menu
|
||||
if (CurrentSlot == null)
|
||||
{
|
||||
ReturnToMenu();
|
||||
}
|
||||
else
|
||||
{
|
||||
_isInMenu = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return item to menu with animation
|
||||
/// </summary>
|
||||
private void ReturnToMenu()
|
||||
{
|
||||
Logging.Debug($"[DecorationItem] Returning to menu: {decorationData?.DecorationName}");
|
||||
|
||||
_isInMenu = true;
|
||||
|
||||
if (RectTransform != null)
|
||||
{
|
||||
// Animate back to icon size
|
||||
RectTransform.sizeDelta = _iconSize;
|
||||
TweenAnimationUtility.AnimateScale(transform, Vector3.one, 0.2f);
|
||||
|
||||
// Animate back to original position
|
||||
TweenAnimationUtility.AnimateAnchoredPosition(RectTransform, _originalMenuPosition, 0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set original menu position (called by menu controller)
|
||||
/// </summary>
|
||||
public void SetOriginalMenuPosition(Vector2 position)
|
||||
{
|
||||
_originalMenuPosition = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31a82dde0ffb439e86b79499b9daa92b
|
||||
timeCreated: 1763745531
|
||||
@@ -0,0 +1,125 @@
|
||||
using Core;
|
||||
using Minigames.StatueDressup.Data;
|
||||
using Minigames.StatueDressup.Utils;
|
||||
using UI.DragAndDrop.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Minigames.StatueDressup.DragDrop
|
||||
{
|
||||
/// <summary>
|
||||
/// Slot on the statue where decorations can be placed
|
||||
/// </summary>
|
||||
public class StatueDecorationSlot : DraggableSlot, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[Header("Slot Configuration")]
|
||||
[SerializeField] private DecorationCategory allowedCategory;
|
||||
[SerializeField] private bool isPermanent = true; // Can't remove once placed
|
||||
|
||||
[Header("Glow Effect")]
|
||||
[SerializeField] private GameObject glowEffect;
|
||||
[SerializeField] private float glowPulseAmount = 1.1f;
|
||||
[SerializeField] private float glowPulseDuration = 0.8f;
|
||||
|
||||
private bool _isGlowing;
|
||||
private Pixelplacement.TweenSystem.TweenBase _glowTween;
|
||||
|
||||
// Properties
|
||||
public DecorationCategory AllowedCategory => allowedCategory;
|
||||
public bool IsPermanent => isPermanent;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Hide glow effect initially
|
||||
if (glowEffect != null)
|
||||
{
|
||||
glowEffect.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public new void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
// Only glow when dragging a matching decoration
|
||||
if (eventData.pointerDrag != null)
|
||||
{
|
||||
var decoration = eventData.pointerDrag.GetComponent<DecorationItem>();
|
||||
if (decoration != null && decoration.Category == allowedCategory && !IsOccupied)
|
||||
{
|
||||
StartGlow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
StopGlow();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start glow effect
|
||||
/// </summary>
|
||||
private void StartGlow()
|
||||
{
|
||||
if (_isGlowing || glowEffect == null)
|
||||
return;
|
||||
|
||||
_isGlowing = true;
|
||||
glowEffect.SetActive(true);
|
||||
|
||||
Logging.Debug($"[StatueDecorationSlot] Starting glow on {name}");
|
||||
|
||||
// Pulse animation
|
||||
_glowTween = TweenAnimationUtility.StartGlowPulse(glowEffect.transform, glowPulseAmount, glowPulseDuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop glow effect
|
||||
/// </summary>
|
||||
private void StopGlow()
|
||||
{
|
||||
if (!_isGlowing || glowEffect == null)
|
||||
return;
|
||||
|
||||
_isGlowing = false;
|
||||
|
||||
Logging.Debug($"[StatueDecorationSlot] Stopping glow on {name}");
|
||||
|
||||
// Stop pulse animation
|
||||
if (_glowTween != null)
|
||||
{
|
||||
TweenAnimationUtility.StopTweens(glowEffect.transform);
|
||||
_glowTween = null;
|
||||
}
|
||||
|
||||
glowEffect.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override to check category matching (uses base CanAccept)
|
||||
/// </summary>
|
||||
public new bool CanAccept(DraggableObject draggable)
|
||||
{
|
||||
// First check base conditions
|
||||
if (!base.CanAccept(draggable))
|
||||
return false;
|
||||
|
||||
// Then check category matching
|
||||
if (draggable is DecorationItem decoration)
|
||||
{
|
||||
bool matches = decoration.Category == allowedCategory;
|
||||
Logging.Debug($"[StatueDecorationSlot] CanAccept: {decoration.Data?.DecorationName}, " +
|
||||
$"category={decoration.Category}, allowed={allowedCategory}, matches={matches}");
|
||||
return matches;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Clean up glow on disable
|
||||
StopGlow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f68e3749518141b6bc818938dd8dc57d
|
||||
timeCreated: 1763745550
|
||||
Reference in New Issue
Block a user