Beispiel #1
0
    public void MoveDown()
    {
        if (!movingPhotos)
        {
            Debug.Log("Active row was: " + activePhoto.row);


            Vector3 moveVector = new Vector3(0.0f, photoYOffset, 0.0f);

            int activePhotoNewRow = activePhoto.row + 1;


            if (activePhotoNewRow < pictureLocations.Count)
            {
                Debug.Log("Moving to row " + activePhotoNewRow);


                float         photoFraction     = activePhoto.col / (float)pictureLocations[activePhoto.row].Count;
                int           activePhotoNewCol = (int)(pictureLocations[activePhotoNewRow].Count * photoFraction);
                CatalystPhoto newActivePhoto    = photos[activePhotoNewRow][activePhotoNewCol];
                float         angleDiff         = Mathf.Abs(activePhoto.angleBetweenPhotos - newActivePhoto.angleBetweenPhotos);

                Vector3 rotateVector = new Vector3(0.0f, angleDiff, 0.0f);

                StartCoroutine(MoveAndRotate(moveVector, rotateVector, 0.25f));

                activePhoto = newActivePhoto;
            }
        }
    }
Beispiel #2
0
    public void MoveRight()
    {
        if (!movingPhotos)
        {
            float   angleToRotate  = activePhoto.angleBetweenPhotos;
            Vector3 rotationVector = new Vector3(0.0f, -angleToRotate, 0.0f);

            StartCoroutine((Rotate(rotationVector, 0.25f)));

            int newActiveRow = activePhoto.row;
            int newActiveCol = activePhoto.col - 1;

            if (newActiveCol < 0)
            {
                newActiveCol = pictureLocations[newActiveRow].Count - 1;
            }

            activePhoto = photos[newActiveRow][newActiveCol];
        }
    }
Beispiel #3
0
    public void MoveLeft()
    {
        if (!movingPhotos)
        {
            float   angleToRotate  = activePhoto.angleBetweenPhotos;
            Vector3 rotationVector = new Vector3(0.0f, angleToRotate, 0.0f);

            Debug.Log("Angle: " + angleToRotate);
            StartCoroutine((Rotate(rotationVector, 0.25f)));

            int newActiveRow = activePhoto.row;
            int newActiveCol = activePhoto.col + 1;

            if (newActiveCol >= pictureLocations[newActiveRow].Count)
            {
                newActiveCol = 0;
            }

            activePhoto = photos[newActiveRow][newActiveCol];
        }
    }
Beispiel #4
0
    public void MoveUp()
    {
        if (!movingPhotos)
        {
            Vector3 moveVector = new Vector3(0.0f, -photoYOffset, 0.0f);

            int activePhotoNewRow = activePhoto.row - 1;

            if (activePhotoNewRow >= 0)
            {
                float photoFraction = activePhoto.col / (float)pictureLocations[activePhoto.row].Count;

                int           activePhotoNewCol = (int)Mathf.Floor(pictureLocations[activePhotoNewRow].Count * photoFraction);
                CatalystPhoto newActivePhoto    = photos[activePhotoNewRow][activePhotoNewCol];
                float         angleDiff         = Mathf.Abs(activePhoto.angleBetweenPhotos - newActivePhoto.angleBetweenPhotos);

                Vector3 rotateVector = new Vector3(0.0f, angleDiff, 0.0f);

                StartCoroutine(MoveAndRotate(moveVector, rotateVector, 0.25f));

                activePhoto = newActivePhoto;
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// Loads a picture from file.
    /// </summary>
    /// <returns></returns>
    private IEnumerator LoadPhotosFromFile(string photoPath)
    {
        List <Sprite> imageSprites = new List <Sprite>();

        if (pathIsExteral)
        {
            yield return(StartCoroutine(LoadImagesExtern(imageSprites, photoPath)));
        }
        else
        {
            yield return(StartCoroutine(LoadImagesIntern(imageSprites, photoPath)));
        }

        if (imageSprites.Count > 0)
        {
            // Loads the picture locations for the loaded images, based on number of pictures.
            LoadPictureLocations(imageSprites.Count);

            int imgNum = 0;

            // Loops through each loaded picture
            for (int row = 0; row < pictureLocations.Count; row++)
            {
                photos.Add(new List <CatalystPhoto>());

                for (int col = 0; col < pictureLocations[row].Count; col++)
                {
                    // Calculates size of picture.
                    Vector2 currentImageSize = new Vector2(imageSprites[imgNum].bounds.size.x, imageSprites[imgNum].bounds.size.y);

                    // Determines how much the photo needs to be scaled by to match final size.
                    Vector3 scaleFactor = new Vector3(finalImageSize.x / currentImageSize.x, finalImageSize.y / currentImageSize.y);

                    Debug.Log("Instantiating Image " + imgNum + " of " + imageSprites.Count);

                    ((GameObject)photoPrefab).SetActive(true);

                    // Instantiates the image in the scene.
                    GameObject photoObj = (GameObject)GameObject.Instantiate(photoPrefab, pictureLocations[row][col], new Quaternion());

                    ((GameObject)photoPrefab).SetActive(false);

                    // Places the sprite in the gameObject
                    photoObj.GetComponent <SpriteRenderer>().sprite = imageSprites[imgNum];

                    // Stores current scale of the object.
                    Vector3 photoScale = photoObj.transform.localScale;

                    // Reflects the image, because for some reason they spawn backwards
                    photoScale.x = -photoScale.x;

                    // Scale the images by the calculated scale factor, to make them match correct ratio.
                    photoScale.x *= scaleFactor.x;
                    photoScale.y *= scaleFactor.y;

                    // Uniformly resizes the image.
                    photoScale *= uniformImageScale;

                    // Resets the scale on the photo, should be correct ratio now.
                    photoObj.transform.localScale = photoScale;

                    // Adds a collider to the photo for selection.
                    photoObj.GetComponent <BoxCollider>().size = photoObj.GetComponent <SpriteRenderer>().sprite.bounds.size;

                    // Adds the photo to the final list of photos.
                    photos[row].Add(photoObj.GetComponent <CatalystPhoto>());

                    float angleBetweenPhotos = 360.0f / pictureLocations[row].Count;

                    if (pictureLocations[row].Count < 4)
                    {
                        angleBetweenPhotos = 45.0f;
                    }

                    photos[row][col].SetPhotoInfo(row, col, angleBetweenPhotos);

                    imgNum++;

                    // Wait for next frame to load next photo.
                    yield return(null);
                }
            }

            // Place the photos in the correct positions around the user.
            PlacePhotos();

            if (photos.Count > 1)
            {
                activePhoto = photos[1][0];
            }
            else
            {
                activePhoto = photos[0][0];
            }


            for (int row = 0; row < photos.Count; row++)
            {
                for (int col = 0; col < photos[row].Count; col++)
                {
                    photos[row][col].gameObject.SetActive(true);
                }
            }

            photosActive  = true;
            photosLoading = false;
        }
        else
        {
            Debug.LogWarningFormat("Unable to load {0} pictures from \"{1}\". Check the load number or path.", numPicsToLoad, photoPath);
        }
    }