2020-11-10 15:37:20 +00:00
|
|
|
|
using Gamecraft.Blocks.BlockGroups;
|
2020-11-10 22:08:27 +00:00
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-11-10 15:37:20 +00:00
|
|
|
|
using GamecraftModdingAPI.Blocks;
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A group of blocks that can be selected together. The placed version of blueprints.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BlockGroup
|
|
|
|
|
{
|
|
|
|
|
internal static BlueprintEngine _engine = new BlueprintEngine();
|
|
|
|
|
public int Id { get; }
|
2020-11-10 22:08:27 +00:00
|
|
|
|
private readonly Block sourceBlock;
|
2020-11-10 15:37:20 +00:00
|
|
|
|
|
|
|
|
|
internal BlockGroup(int id, Block block)
|
|
|
|
|
{
|
|
|
|
|
if (id == BlockGroupUtility.GROUP_UNASSIGNED)
|
|
|
|
|
throw new BlockException("Cannot create a block group for blocks without a group!");
|
|
|
|
|
Id = id;
|
2020-11-10 22:08:27 +00:00
|
|
|
|
sourceBlock = block;
|
2020-11-10 15:37:20 +00:00
|
|
|
|
}
|
2020-11-10 22:08:27 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The position of the block group. Calculated when GetBlocks() is used.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float3 Position { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The rotation of the block group. Calculated when GetBlocks() is used.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float3 Rotation { get; private set; }
|
2020-11-10 15:37:20 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-11-10 22:08:27 +00:00
|
|
|
|
/// Collects each block that is a part of this group. Also sets the position and rotation.
|
2020-11-10 15:37:20 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An array of blocks</returns>
|
|
|
|
|
public Block[] GetBlocks()
|
|
|
|
|
{
|
2020-11-10 22:08:27 +00:00
|
|
|
|
var ret = _engine.GetBlocksFromGroup(sourceBlock.Id, out var pos, out var rot);
|
|
|
|
|
Position = pos;
|
|
|
|
|
Rotation = ((Quaternion) rot).eulerAngles;
|
|
|
|
|
return ret;
|
2020-11-10 15:37:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes all of the blocks in this group from the world.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Remove()
|
|
|
|
|
{
|
|
|
|
|
_engine.RemoveBlockGroup(Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
|
|
|
|
GameEngineManager.AddGameEngine(_engine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|