Example #1
0
    Vector3 getAxisToRotateAround(Rotation rotation, CubePart middle)
    {
        switch (rotation)
        {
        case Rotation.R2:
        case Rotation.R:
            return(Vector3.right);

        case Rotation.L2:
        case Rotation.L:
            return(Vector3.left);

        case Rotation.U2:
        case Rotation.U:
            return(Vector3.up);

        case Rotation.D2:
        case Rotation.D:
            return(Vector3.down);

        case Rotation.B2:
        case Rotation.B:
            return(Vector3.forward);

        case Rotation.F2:
        case Rotation.F:
            return(Vector3.back);

        default:
            throw new BadProgrammingException("Unable to handle given rotation.");
        }
    }
Example #2
0
 internal RunningRotation(Rotation rotation, CubePart[] parts, CubePart middle, Vector3 rotateAround, float rotateSpeed)
 {
     this.rotation     = rotation;
     this.parts        = parts;
     this.middle       = middle;
     this.rotateAround = rotateAround;
     this.rotateSpeed  = rotateSpeed;
     this.totalRotated = 0f;
 }
Example #3
0
    void Start()
    {
        Debug.Log("Starting cube.");

        cubeParts = (CubePart[])GameObject.FindObjectsOfType(typeof(CubePart));
        Debug.Log("Found " + cubeParts.Length + " CubeParts.");

        middles = GameObject.FindGameObjectWithTag("Middle").GetComponentsInChildren <CubePart> ();
        Debug.Log("Found " + middles.Length + " middles.");

        center = GameObject.FindGameObjectWithTag("Center").GetComponent <CubePart> ();
        Debug.Log((center != null ? "Found" : "Did not find") + " center.");

        Main.Start();
    }
Example #4
0
        /// <summary>
        /// Import a single cube part into the cube designer from the Content\Cubes folder.
        /// </summary>
        public void Import(string path)
        {
            try
            {
                var contentPath = path.MakeContentRelative();
                if (contentPath == string.Empty)
                {
                    return;
                }

                // Find or create cube metadata.
                var          metadataPath = Path.ChangeExtension(path, ".metadata");
                CubeMetadata cmd;
                if (File.Exists(metadataPath))
                {
                    cmd = Serializer.ReadXML <CubeMetadata>(CubeMetadata.CubeMetadataSerializer, metadataPath);
                    cmd.LoadContent(MainGame);
                }
                else
                {
                    cmd = new CubeMetadata()
                    {
                        ContentPath = contentPath
                    };
                    cmd.LoadContent(MainGame);
                    cmd.Serialize(metadataPath);
                    $"Creating {Path.GetFileName(metadataPath)}...".Log();
                }

                // Deduce part type from path.
                var      _part = contentPath.Split('\\')[1];
                CubePart part  = (CubePart)Enum.Parse(typeof(CubePart), _part, true);

                // Add to part specific collection.
                if (part == CubePart.Top)
                {
                    CubeTopCollection.Add(new CubeDesignerItem(this, path, cmd));
                }
                else if (part == CubePart.Base)
                {
                    CubeBaseCollection.Add(new CubeDesignerItem(this, path, cmd));
                }
            }
            catch (Exception e)
            {
                e.Message.Log();
            }
        }
Example #5
0
    // Do a rotation
    void startRotation()
    {
        Rotation rotation = rotations.Dequeue();

        Debug.Log("Perform rotation: " + rotation);

        // Find side to rotate in relation to center cube
        CubePart[] toRotate = getCubePartsToRotate(rotation);
        Debug.Log("Found " + toRotate.Length + " parts to rotate.");

        // Find middle cube to rotate around
        // TODO: Store these in a rotation to cubepart hashmap from the start
        CubePart middle = null;

        foreach (CubePart mp in middles)
        {
            middle = Array.Find(toRotate, cp => cp == mp);

            if (middle != null)
            {
                break;
            }
        }

        if (middle == null)
        {
            throw new BadProgrammingException("Could not find a middle to rotate around.");
        }

        Vector3 rotateAround = getAxisToRotateAround(rotation, middle);

        float rotateSpeed = getRotateSpeed(rotation);

        rotating        = true;
        runningRotation = new RunningRotation(rotation, toRotate, middle, rotateAround, rotateSpeed);
    }