更新
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Cinemachine;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
@@ -15,24 +13,15 @@ namespace AibisDream
|
||||
// 物体索引
|
||||
[SerializeField] public BlockPuzzleGrid grid;
|
||||
[SerializeField] private Transform shapeRoot;
|
||||
[SerializeField] public BlockShapeRack shapeRack;
|
||||
[SerializeField] private Canvas canvas;
|
||||
|
||||
|
||||
[Header("临时按钮")]
|
||||
// 临时按钮
|
||||
[SerializeField] private Button submitButton;
|
||||
[SerializeField] private Button clearButton;
|
||||
[SerializeField] public BlockPuzzlePanel blockPuzzlePanel;
|
||||
[SerializeField] private ShapeRecycleSlot shapeRecycleSlot;
|
||||
|
||||
[Header("数据")]
|
||||
[SerializeField] private BlockPuzzleData puzzleData;
|
||||
[SerializeField] private bool initializeOnStart = true;
|
||||
|
||||
private BlockPuzzleValidator validator;
|
||||
|
||||
// 事件
|
||||
public event Action<ValidateResult> OnSubmit;
|
||||
public event Action<ValidateResult> OnPreview;
|
||||
private ShapeFactory shapeFactory;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -42,16 +31,11 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
CameraKit.Instance?.RegisterCamera(CameraEnum.BlockPuzzle, GetComponentInChildren<ICinemachineCamera>());
|
||||
canvas.worldCamera = Camera.main;
|
||||
submitButton.onClick.AddListener(SubmitGameResult);
|
||||
clearButton.onClick.AddListener(ResetGame);
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
CameraKit.Instance?.UnRegisterCamera(CameraEnum.BlockPuzzle);
|
||||
submitButton.onClick.RemoveListener(SubmitGameResult);
|
||||
clearButton.onClick.RemoveListener(ResetGame);
|
||||
}
|
||||
|
||||
public void Initialize(BlockPuzzleData puzzleData)
|
||||
@@ -66,23 +50,23 @@ namespace AibisDream
|
||||
// 初始化网格
|
||||
grid.Initialize(puzzleData.gridWidth, puzzleData.gridHeight, puzzleData.cellSize);
|
||||
// 初始化网格上图形
|
||||
shapeFactory = new ShapeFactory(shapeRoot);
|
||||
foreach (var shapeData in puzzleData.gridShapeDataInfos)
|
||||
{
|
||||
var shape = shapeRack.CreateBlockShape(shapeData.shapeKey);
|
||||
var shape = shapeFactory.CreateBlockShape(shapeData.shapeKey);
|
||||
shape.Rotate(shapeData.rotationAngle);
|
||||
grid.TrySnapToGrid(shape, shapeData.rootCell);
|
||||
shape.GetComponent<ShapeDragger>().IsDraggable = shapeData.isDraggable;
|
||||
}
|
||||
|
||||
grid.GridVisualizer.UpdateAllCellsVisual();
|
||||
grid.OnShapePlaced += PreCheckGameState;
|
||||
|
||||
// 初始化图形货架
|
||||
shapeRack.Init(puzzleData.shapeRackDataInfos);
|
||||
|
||||
// 加载验证器
|
||||
validator = ResourceKit.LoadAssetSync<BlockPuzzleValidator>(puzzleData.validatorName);
|
||||
|
||||
// 组装事件逻辑
|
||||
AssembleEventLogic();
|
||||
|
||||
Debug.Log("网格系统初始化完成");
|
||||
}
|
||||
|
||||
@@ -90,34 +74,84 @@ namespace AibisDream
|
||||
{
|
||||
var shapes = grid.GetShapes();
|
||||
var validateResult = validator.Validate(shapes);
|
||||
OnPreview?.Invoke(validateResult);
|
||||
}
|
||||
|
||||
private void SubmitGameResult()
|
||||
{
|
||||
var shapes = grid.GetShapes();
|
||||
var validateResult = validator.Validate(shapes);
|
||||
OnSubmit?.Invoke(validateResult);
|
||||
|
||||
// 如果验证通过, 则设置变量并弹出对话
|
||||
if (validateResult.isPass)
|
||||
{
|
||||
StorageSystem.Instance.SetValue("$block_puzzle_pass", validateResult.isExtraConditionPass);
|
||||
StorageSystem.Instance.SetValue("$block_puzzle_pass", true);
|
||||
DialogController.Instance.StartDialogNode("方块拼图完成");
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetGame()
|
||||
{
|
||||
ClearGame();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void ClearGame()
|
||||
{
|
||||
grid.Clear();
|
||||
shapeRack.Clear();
|
||||
// shapeRack.Clear();
|
||||
shapeRoot.DestroyAllChildren();
|
||||
}
|
||||
|
||||
// --------------------- 维修面板同步 -------------------
|
||||
|
||||
private string selectedShapeName;
|
||||
|
||||
/// <summary>
|
||||
/// 组装各系统之间相互逻辑
|
||||
/// </summary>
|
||||
private void AssembleEventLogic()
|
||||
{
|
||||
// 由面板触发
|
||||
blockPuzzlePanel.Panel.OnDeviceSelected += OnPanelShapeSelected;
|
||||
blockPuzzlePanel.OnSubmit += SubmitGameResult;
|
||||
// blockPuzzlePanel.
|
||||
|
||||
// 由网格触发
|
||||
grid.OnShapePlaced += PreCheckGameState;
|
||||
|
||||
// 由Shape触发
|
||||
shapeFactory.OnDragStart += OnShapeDragStart;
|
||||
shapeFactory.OnDragEnd += OnShapeDragEnd;
|
||||
// shapeFactory.OnDragUpdate += OnShapeRecycled;
|
||||
}
|
||||
|
||||
private void OnPanelShapeSelected(BlockShapeInfo shapeData)
|
||||
{
|
||||
// 在屏幕上更新选中的图形
|
||||
selectedShapeName = shapeData.shapeName;
|
||||
blockPuzzlePanel.ShowShapeInScreen(shapeData);
|
||||
}
|
||||
|
||||
public void OnValidateResult(ValidateResult validateResult)
|
||||
{
|
||||
// 先更新进度条
|
||||
|
||||
// 再更新校验结果,包括锁定按钮等UI
|
||||
|
||||
}
|
||||
|
||||
public void OnShapeDragStart(IBlockShape blockShape)
|
||||
{
|
||||
// 更新选中图形
|
||||
|
||||
// 回收抽屉高亮,半开
|
||||
blockPuzzlePanel.Panel.SetRecycleAvailable(true);
|
||||
}
|
||||
|
||||
public void OnShapeDragEnd(IBlockShape blockShape, bool isPlaced)
|
||||
{
|
||||
if (isPlaced)
|
||||
{
|
||||
// 关闭回收抽屉
|
||||
blockPuzzlePanel.Panel.SetRecycleAvailable(false);
|
||||
}
|
||||
// TODO: 如果吸附到回收处,应该播放动画,并提示回收成功
|
||||
}
|
||||
|
||||
// ---------------- 编辑器状态逻辑 ----------------
|
||||
|
||||
/// <summary>
|
||||
@@ -144,11 +178,11 @@ namespace AibisDream
|
||||
ClearGame();
|
||||
|
||||
grid.InitializeInEditor(puzzleData.gridWidth, puzzleData.gridHeight, puzzleData.cellSize);
|
||||
shapeRack.InitInEditor(puzzleData.shapeRackDataInfos);
|
||||
// shapeRack.InitInEditor(puzzleData.shapeRackDataInfos);
|
||||
|
||||
foreach (var shapeData in puzzleData.gridShapeDataInfos)
|
||||
{
|
||||
var shape = shapeRack.CreateBlockShape(shapeData.shapeKey);
|
||||
var shape = shapeFactory.CreateBlockShape(shapeData.shapeKey);
|
||||
shape.Rotate(shapeData.rotationAngle);
|
||||
grid.TrySnapToGrid(shape, shapeData.rootCell);
|
||||
}
|
||||
@@ -157,17 +191,17 @@ namespace AibisDream
|
||||
public void SaveConfig()
|
||||
{
|
||||
var gridShapeDataInfos = grid.ShapeDict?.Values.ToArray();
|
||||
var shapeRackDataInfos = shapeRack.blockShapeDataList?.ToArray();
|
||||
// var shapeRackDataInfos = shapeRack.blockShapeDataList?.ToArray();
|
||||
|
||||
puzzleData.gridShapeDataInfos = gridShapeDataInfos;
|
||||
puzzleData.shapeRackDataInfos = shapeRackDataInfos;
|
||||
// puzzleData.shapeRackDataInfos = shapeRackDataInfos;
|
||||
|
||||
BlockPuzzleKit.SaveBlockPuzzleData(puzzleData, puzzleData.puzzleName);
|
||||
}
|
||||
|
||||
public void CreateShapeInEditor(string shapeKey)
|
||||
{
|
||||
shapeRack.CreateBlockShape(shapeKey);
|
||||
shapeFactory.CreateBlockShape(shapeKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user