Beispiel #1
0
    IEnumerator Rotate(byte rot)
    {
        Debug.Log(rot);
        var sold = Clear();

        yield return(new WaitForSeconds(0.1f));

        foreach (var shp in sold)
        {
            int     newpos  = RotateCalcNewColliderPos(0, BlockData.AssemblePos(shp.Key.x, shp.Key.y, shp.Key.z), rot);
            ColPriv newType = CollideData.GetRotation(shp.Value, rot);
            this.partType = newType;
            var pposition = new Vector3Int(BlockData.GetX(newpos), BlockData.GetY(newpos), BlockData.GetZ(newpos));
            buildonly = (ColPrivAlterations)((int)partType & ~0xFF) == ColPrivAlterations.IGNORE_FOR_COLLISION;

            ResetGhost();

            yield return(new WaitForEndOfFrame());// WaitForSeconds(.1f);

            shapes.Add(new KeyValuePair <Vector3Int, ColPriv>(pposition, partType));
            ghost.transform.position = pposition;
            GameObject g = Instantiate(ghost);
            g.GetComponent <MeshRenderer>().material = whitetrans;
            if (buildonly)
            {
                g.GetComponent <MeshRenderer>().material = lightgreen;
            }
            if (!manifest.ContainsKey(pposition))
            {
                manifest[pposition] = new List <GameObject>();
            }
            manifest[pposition].Add(g);
        }
    }
Beispiel #2
0
    public static int RotateCalcNewColliderPos(int partPlacement, int colliderOffset, byte rotation)
    {
        //  Debug.Log(">"+rotation);
        int x    = BlockData.GetX(colliderOffset);
        int y    = BlockData.GetY(colliderOffset);
        int z    = BlockData.GetZ(colliderOffset);
        int temp = 0;

        // AROUND Z AXIS
        switch (rotation & 0x3)
        {
        case 1:
            temp = y;
            y    = x;
            x    = -temp;
            break;

        case 2:
            x = -x;
            y = -y;
            break;

        case 3:
            temp = y;
            y    = -x;
            x    = temp;
            break;
        }

        // AROUND X AXIS
        switch ((rotation >> 4) & 0x3)
        {
        case 1:
            temp = z;
            z    = y;
            y    = -temp;
            break;

        case 2:
            z = -z;
            y = -y;
            break;

        case 3:
            temp = y;
            y    = z;
            z    = -temp;
            break;
        }

        // AROUND Y AXIS
        switch ((rotation >> 2) & 0x3)
        {
        case 1:
            temp = x;
            x    = z;
            z    = -temp;
            break;

        case 2:
            x = -x;
            z = -z;
            break;

        case 3:
            temp = z;
            z    = x;
            x    = -temp;
            break;
        }
        // Debug.Log(">Z " + (z < 0));
        return(BlockData.AssemblePos(x + BlockData.GetX(partPlacement), y + BlockData.GetY(partPlacement), z + BlockData.GetZ(partPlacement)));
    }