屏幕问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using AibisDream.FixSystem;
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -11,8 +12,6 @@ namespace AibisDream
|
||||
[SerializeField] private UniversalScreen blockPuzzleScreen;
|
||||
[SerializeField] private BlockPuzzlePart blockPuzzlePart;
|
||||
|
||||
public event Action OnSubmit;
|
||||
|
||||
// ---------------------- 维修部分 ----------------------
|
||||
public BlockPuzzlePart Panel => blockPuzzlePart;
|
||||
|
||||
@@ -34,6 +33,18 @@ namespace AibisDream
|
||||
// TODO: 设备状态后面实现
|
||||
}
|
||||
|
||||
public void ClearShapeInScreen()
|
||||
{
|
||||
blockPuzzleScreen.SetImage("设备缩略图", null);
|
||||
|
||||
blockPuzzleScreen.SetText("设备名称", "待选择");
|
||||
blockPuzzleScreen.SetText("设备描述", null);
|
||||
|
||||
blockPuzzleScreen.SetText("PWR", "0");
|
||||
blockPuzzleScreen.SetText("NOISE", "0");
|
||||
blockPuzzleScreen.SetText("HEAT", "0");
|
||||
}
|
||||
|
||||
// ---------------------- 对话功能 ----------------------
|
||||
|
||||
public void RunLine(LineSyncToken syncToken)
|
||||
@@ -50,15 +61,11 @@ namespace AibisDream
|
||||
private void OnEnable()
|
||||
{
|
||||
DialogUIManager.Instance.RegisterScreenView(DialogViewType.Log, this);
|
||||
|
||||
blockPuzzlePart.LockButton.onClick.AddListener(() => OnSubmit?.Invoke());
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DialogUIManager.Instance.UnRegisterScreenView(DialogViewType.Log);
|
||||
|
||||
blockPuzzlePart.LockButton.onClick.RemoveAllListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using System.Linq;
|
||||
using AibisDream.Framework;
|
||||
using System;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -107,8 +108,8 @@ namespace AibisDream
|
||||
{
|
||||
// 由面板触发
|
||||
blockPuzzlePanel.Panel.OnDeviceSelected += OnPanelShapeSelected;
|
||||
blockPuzzlePanel.OnSubmit += SubmitGameResult;
|
||||
// blockPuzzlePanel.
|
||||
blockPuzzlePanel.Panel.OnSubmit.AddListener(SubmitGameResult);
|
||||
blockPuzzlePanel.Panel.OnPopUp.AddListener(PopUpShape);
|
||||
|
||||
// 由网格触发
|
||||
grid.OnShapePlaced += PreCheckGameState;
|
||||
@@ -116,7 +117,7 @@ namespace AibisDream
|
||||
// 由Shape触发
|
||||
shapeFactory.OnDragStart += OnShapeDragStart;
|
||||
shapeFactory.OnDragEnd += OnShapeDragEnd;
|
||||
// shapeFactory.OnDragUpdate += OnShapeRecycled;
|
||||
shapeFactory.OnDragUpdate += OnShapeDragUpdate;
|
||||
}
|
||||
|
||||
private void OnPanelShapeSelected(BlockShapeInfo shapeData)
|
||||
@@ -139,19 +140,60 @@ namespace AibisDream
|
||||
// 更新选中图形
|
||||
|
||||
// 回收抽屉高亮,半开
|
||||
blockPuzzlePanel.Panel.SetRecycleAvailable(true);
|
||||
shapeRecycleSlot.PreRecycle();
|
||||
shapeRecycleSlot.SetRecycleAvaliable(true);
|
||||
}
|
||||
|
||||
public void OnShapeDragEnd(IBlockShape blockShape, bool isPlaced)
|
||||
{
|
||||
if (isPlaced)
|
||||
{
|
||||
// 关闭回收抽屉
|
||||
blockPuzzlePanel.Panel.SetRecycleAvailable(false);
|
||||
}
|
||||
//
|
||||
|
||||
// TODO: 如果吸附到回收处,应该播放动画,并提示回收成功
|
||||
}
|
||||
|
||||
public void OnShapeDragUpdate(IBlockShape blockShape)
|
||||
{
|
||||
// 更新回收槽状态
|
||||
shapeRecycleSlot.UpdateSlotState(blockShape);
|
||||
}
|
||||
|
||||
public void PopUpShape()
|
||||
{
|
||||
if (selectedShapeName == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 弹出形状
|
||||
var blockShape = shapeFactory.CreateBlockShape(selectedShapeName);
|
||||
shapeRecycleSlot.PopUpShape(blockShape);
|
||||
blockShape.GetComponent<ShapeDragger>().CurrentState = DragState.Idle;
|
||||
|
||||
// 删除按钮
|
||||
blockPuzzlePanel.Panel.RemoveDeviceButton(selectedShapeName);
|
||||
selectedShapeName = null;
|
||||
blockPuzzlePanel.ClearShapeInScreen();
|
||||
}
|
||||
|
||||
// --------------------- 吸附校验 ---------------------
|
||||
|
||||
public bool TrySnapToRecycleSlot(BlockShape blockShape)
|
||||
{
|
||||
// 先判断是否吸附到回收槽
|
||||
if (shapeRecycleSlot.CurrentState == PositionState.Open)
|
||||
{
|
||||
shapeRecycleSlot.RecycleShape(blockShape);
|
||||
// TODO: 向面板添加回收的形状
|
||||
blockPuzzlePanel.Panel.OnDeviceRecycle(blockShape);
|
||||
// 延时后进行销毁
|
||||
ActionKit.Delay(1.0f, () => {
|
||||
shapeFactory.RecycleBlockShape(blockShape);
|
||||
}).Start(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------- 编辑器状态逻辑 ----------------
|
||||
|
||||
/// <summary>
|
||||
@@ -201,6 +243,10 @@ namespace AibisDream
|
||||
|
||||
public void CreateShapeInEditor(string shapeKey)
|
||||
{
|
||||
if (shapeFactory == null)
|
||||
{
|
||||
shapeFactory = new ShapeFactory(shapeRoot);
|
||||
}
|
||||
shapeFactory.CreateBlockShape(shapeKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class ShapeCreateButton : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _image;
|
||||
[SerializeField] private TMP_Text _text;
|
||||
[SerializeField] private Button _button;
|
||||
|
||||
public UnityEvent OnClicked => _button.onClick;
|
||||
|
||||
public void SetInfo(BlockShapeInfo blockShapeInfo)
|
||||
{
|
||||
_image.sprite = blockShapeInfo.GetButtonImage();
|
||||
_text.text = blockShapeInfo.shapeName;
|
||||
gameObject.name = blockShapeInfo.shapeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fae2a3bab01b11147a06ea3a105dcc2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,25 +7,42 @@ namespace AibisDream
|
||||
{
|
||||
public class ShapeDragger : MonoBehaviour, IBlockShapeDragger, IInteraction
|
||||
{
|
||||
[Header("拖拽设置")]
|
||||
#region 编辑器字段
|
||||
[SerializeField] private bool isDraggable = true;
|
||||
|
||||
[SerializeField] private float dragScale = 1.1f;
|
||||
// [SerializeField] private float dragScale = 1.1f;
|
||||
|
||||
[SerializeField] private int dragLayerId;
|
||||
[SerializeField] private int dragLayerOrder;
|
||||
|
||||
[SerializeField] private int idleLayerId;
|
||||
[SerializeField] private int idleLayerOrder;
|
||||
#endregion
|
||||
|
||||
// 拖拽状态
|
||||
private DragState _currentState = DragState.Idle;
|
||||
private DragState _currentState = DragState.Placed;
|
||||
public DragState CurrentState
|
||||
{
|
||||
get => _currentState;
|
||||
set
|
||||
{
|
||||
if (value == _currentState) return;
|
||||
// 处理状态切换
|
||||
HandleStateChange(value);
|
||||
_currentState = value;
|
||||
}
|
||||
}
|
||||
private SnapResult _snapResult;
|
||||
|
||||
// 组件引用
|
||||
private BlockShape _blockShape;
|
||||
private EventTriggerEx _eventTrigger;
|
||||
|
||||
public DragState CurrentState => _currentState;
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
|
||||
public bool IsDraggable { get => isDraggable; set => isDraggable = value; }
|
||||
public IBlockPuzzleGrid TargetGrid => BlockPuzzleSystem.Instance.grid;
|
||||
public IBlockShape BlockShape => _blockShape;
|
||||
|
||||
|
||||
// 事件
|
||||
public event Action<IBlockShape> OnDragStart;
|
||||
public event Action<IBlockShape> OnDragUpdate;
|
||||
@@ -35,6 +52,7 @@ namespace AibisDream
|
||||
{
|
||||
_blockShape = GetComponent<BlockShape>();
|
||||
_eventTrigger = GetComponent<EventTriggerEx>();
|
||||
_spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
RegisterEvent();
|
||||
}
|
||||
@@ -53,7 +71,7 @@ namespace AibisDream
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_currentState == DragState.Dragging)
|
||||
if (CurrentState == DragState.Dragging)
|
||||
{
|
||||
UpdateDrag();
|
||||
}
|
||||
@@ -67,7 +85,7 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
// 如果当前物体不在拖拽中则进入拖拽逻辑
|
||||
if (_currentState == DragState.Idle || _currentState == DragState.Placed)
|
||||
if (CurrentState == DragState.Idle || CurrentState == DragState.Placed)
|
||||
{
|
||||
StartDrag();
|
||||
}
|
||||
@@ -86,52 +104,36 @@ namespace AibisDream
|
||||
TargetGrid?.TryRemoveShapeFromGrid(_blockShape);
|
||||
TargetGrid?.ResetPreviewGrid();
|
||||
|
||||
_currentState = DragState.Dragging;
|
||||
|
||||
// 处理层级和缩放
|
||||
HandleDragStart();
|
||||
CurrentState = DragState.Dragging;
|
||||
|
||||
OnDragStart?.Invoke(_blockShape);
|
||||
}
|
||||
|
||||
private void HandleDragStart()
|
||||
{
|
||||
// 调整缩放和层级
|
||||
transform.localScale = dragScale * Vector3.one;
|
||||
}
|
||||
|
||||
public void CancelDrag()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void EndDrag()
|
||||
{
|
||||
TargetGrid?.ResetPreviewGrid();
|
||||
OnDragEnd?.Invoke(_blockShape, CurrentState == DragState.Placed);
|
||||
// 先吸附到回收槽
|
||||
var recycled = BlockPuzzleSystem.Instance.TrySnapToRecycleSlot(_blockShape);
|
||||
if (recycled)
|
||||
{
|
||||
CurrentState = DragState.Idle;
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果吸附到了就靠过去
|
||||
// 再吸附到网格
|
||||
TargetGrid?.ResetPreviewGrid();
|
||||
if (_snapResult.canSnap)
|
||||
{
|
||||
_currentState = DragState.Placed;
|
||||
CurrentState = DragState.Placed;
|
||||
transform.localScale = Vector3.one;
|
||||
|
||||
TargetGrid.TrySnapToGrid(_blockShape, _snapResult.RootCell);
|
||||
|
||||
// 处理Cursor
|
||||
_eventTrigger.OnPointerUp(null);
|
||||
OnDragEnd?.Invoke(_blockShape, _currentState == DragState.Placed);
|
||||
}
|
||||
|
||||
// TODO: 无法吸附直接不处理
|
||||
|
||||
// else
|
||||
// {
|
||||
// _currentState = DragState.Idle;
|
||||
// // transform.position = _originalPosition;
|
||||
// transform.localScale = Vector3.one;
|
||||
|
||||
// // BlockPuzzleSystem.Instance.shapeRack.RecycleBlockShape(_blockShape);
|
||||
// }
|
||||
// TODO: 都没吸附到,则恢复原位
|
||||
|
||||
TargetGrid.GridVisualizer.UpdateAllCellsVisual();
|
||||
}
|
||||
@@ -154,6 +156,24 @@ namespace AibisDream
|
||||
|
||||
OnDragUpdate?.Invoke(_blockShape);
|
||||
}
|
||||
private void HandleStateChange(DragState newState)
|
||||
{
|
||||
switch (newState)
|
||||
{
|
||||
case DragState.Idle:
|
||||
_spriteRenderer.sortingOrder = dragLayerOrder;
|
||||
_spriteRenderer.sortingLayerID = dragLayerId;
|
||||
break;
|
||||
case DragState.Dragging:
|
||||
_spriteRenderer.sortingOrder = dragLayerOrder;
|
||||
_spriteRenderer.sortingLayerID = dragLayerId;
|
||||
break;
|
||||
case DragState.Placed:
|
||||
_spriteRenderer.sortingOrder = idleLayerOrder;
|
||||
_spriteRenderer.sortingLayerID = idleLayerId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetMouseWorldPosition()
|
||||
{
|
||||
|
||||
@@ -35,11 +35,13 @@ namespace AibisDream
|
||||
dragger.OnDragStart += OnShapeDragStart;
|
||||
dragger.OnDragEnd += OnShapeDragEnd;
|
||||
dragger.OnDragUpdate += OnShapeDragUpdate;
|
||||
|
||||
return blockShape;
|
||||
}
|
||||
|
||||
private void OnShapeDragStart(IBlockShape blockShape)
|
||||
{
|
||||
blockShape.ShapeDragger.transform.SetParent(_shapeRoot);
|
||||
OnDragStart?.Invoke(blockShape);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace AibisDream
|
||||
|
||||
public void OpenForRecycle()
|
||||
{
|
||||
// TODO: 回收槽完全弹出
|
||||
// 回收槽完全弹出
|
||||
mover.SetToOpen();
|
||||
// TODO: 边缘发光提示
|
||||
}
|
||||
|
||||
public void CloseForRecycle()
|
||||
{
|
||||
// TODO: 回收槽回到半关闭
|
||||
// 回收槽回到半关闭
|
||||
mover.SetToHalf();
|
||||
// TODO: 边缘发光提示
|
||||
}
|
||||
@@ -36,8 +36,8 @@ namespace AibisDream
|
||||
{
|
||||
// 将 shape 放到回收槽
|
||||
PutShapeInSlot(shape);
|
||||
// TODO: 播放回收动画
|
||||
|
||||
// 播放回收动画
|
||||
mover.SetToClose();
|
||||
// TODO: 销毁Shape
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace AibisDream
|
||||
// 将 shape 添加到回收槽
|
||||
PutShapeInSlot(shape);
|
||||
// TODO: 播放弹出动画
|
||||
mover.SetToOpen();
|
||||
}
|
||||
|
||||
// ----------------------- 状态校验 -----------------------
|
||||
@@ -72,42 +73,26 @@ namespace AibisDream
|
||||
{
|
||||
if (!openArea.Contains(shape.GetGlobalCenterPosition()))
|
||||
{
|
||||
// TODO: 回到半关闭状态
|
||||
CloseForRecycle();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 半关闭状态下的判断
|
||||
if (mover.GetCurrentState() == PositionState.Half)
|
||||
{
|
||||
Debug.Log("Half: " + halfArea.Contains(shape.GetGlobalCenterPosition()));
|
||||
if (halfArea.Contains(shape.GetGlobalCenterPosition()))
|
||||
{
|
||||
// TODO: 回到开启状态
|
||||
OpenForRecycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void PutShapeInSlot(BlockShape shape)
|
||||
{
|
||||
shape.transform.SetParent(transform);
|
||||
shape.transform.SetParent(mover.transform);
|
||||
Vector3 centerPosition = shape.GetCenterPosition();
|
||||
shape.transform.localPosition = -centerPosition;
|
||||
}
|
||||
|
||||
private void SetMoverState(ShapeRecycleSlotState state)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public enum ShapeRecycleSlotState
|
||||
{
|
||||
Close,
|
||||
Half,
|
||||
Open
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ namespace AibisDream
|
||||
{
|
||||
Idle, // 空闲
|
||||
Dragging, // 拖拽中
|
||||
Snapping, // 吸附中
|
||||
Placed // 已放置
|
||||
}
|
||||
|
||||
@@ -70,11 +69,6 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
void EndDrag();
|
||||
|
||||
/// <summary>
|
||||
/// 取消拖拽(返回原位置)
|
||||
/// </summary>
|
||||
void CancelDrag();
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否可以放置到指定位置
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user