using System.Collections; using System.Collections.Generic; using UnityEngine; public class AttachableBlock : MonoBehaviour { [Header("Block Info")] [SerializeField] private BlockType blockType = BlockType.Regular; private SocketContainer socketContainer; private List connectedBlocks = new List(); private List attachedJoints = new List(); public List GetConnectedBlocks() => connectedBlocks; public List GetAttachedJoints() => attachedJoints; public void SetBlockType(BlockType BlockType) => blockType = BlockType; public void DisconnectFrom(AttachableBlock otherBlock) { if (connectedBlocks.Contains(otherBlock)) { connectedBlocks.Remove(otherBlock); } } public void UnregisterJoint(JointBlock joint) { if (attachedJoints.Contains(joint)) { attachedJoints.Remove(joint); } } void Awake() { socketContainer = GetComponent(); if (socketContainer == null) { socketContainer = gameObject.AddComponent(); } } public SocketContainer GetSocketContainer() => socketContainer; public void ConnectTo(AttachableBlock otherBlock, SocketPoint mySocket, SocketPoint theirSocket) { if (!connectedBlocks.Contains(otherBlock)) { connectedBlocks.Add(otherBlock); // Simple parenting connection (no physics joint yet) mySocket.SetOccupied(otherBlock.gameObject); theirSocket.SetOccupied(this.gameObject); } if (!otherBlock.GetConnectedBlocks().Contains(this)) { otherBlock.GetConnectedBlocks().Add(this); } } public void RegisterJoint(JointBlock joint) { if (!attachedJoints.Contains(joint)) { attachedJoints.Add(joint); } } } public enum BlockType { Regular, // Standard building block Link, // Block with holes (like a chain link) Gear, // Gear block Structural // Frame/support block }