Exemple #1
0
    private void Spawn(List <Vector2Int> positions, Vector2Int offset)
    {
        List <IsoCube> newCubes = new List <IsoCube>();

        foreach (Vector2Int v in positions)
        {
            GameObject newCube = Instantiate(CubePrefab);
            newCube.transform.position = Grid.CellToWorld(new Vector3Int(v.x + offset.x, v.y + offset.y, 0));
            newCube.transform.SetParent(Field);
            IsoCube controller = newCube.GetComponentInChildren <IsoCube>();
            controller.Init(this);
            newCubes.Add(controller);
        }

        Color color = Colors.Evaluate(UnityEngine.Random.value);

        foreach (IsoCube cube1 in newCubes)
        {
            cube1.SetColor(color);
            foreach (IsoCube cube2 in newCubes)
            {
                cube1.Connect(cube2);
            }
            _cubes.Add(cube1);
        }
    }
Exemple #2
0
 public void DropCube(IsoCube isoCube, int delay)
 {
     isoCube.GetComponent <Collider2D>().enabled        = false;
     isoCube.GetComponent <IsoLayerBehaviour>().enabled = false;
     isoCube.transform.parent.gameObject.AddComponent <Rigidbody>();
     _cubes.Remove(isoCube);
     Destroy(isoCube.transform.parent.gameObject, delay);
 }
Exemple #3
0
    public void Disconnect(IsoCube cube)
    {
        if (!_connectedCubes.ContainsKey(cube))
        {
            return;
        }

        _connectedCubes.Remove(cube);
    }
Exemple #4
0
    private bool CanMove(Vector2Int aimVector)
    {
        Vector3Int aimCell = Position + new Vector3Int(aimVector.x, aimVector.y, 0);

        IsoCube aimCellCube = _map.GetCube(aimCell);

        if (aimCellCube == null || _connectedCubes.ContainsKey(aimCellCube))
        {
            return(true);
        }

        return(false);
    }
Exemple #5
0
    public void Connect(IsoCube cube)
    {
        if (_connectedCubes.ContainsKey(cube))
        {
            return;
        }

        _connectedCubes.Add(cube, Vector3Int.zero);
        if (cube != this)
        {
            cube.Connect(this);
        }
    }