void OnEnable()
    {
        switch (collectibleVariant)
        {
        case CollectibleVariant.Coin:
            Collider objectCollider = this.GetComponent <Collider> ();
            if (objectCollider != null)
            {
                objectCollider.enabled = true;
            }
            Collider[] objectColliders = GetComponentsInChildren <Collider> ();
            foreach (Collider collider in objectColliders)
            {
                //disable all colliders so it just falls off screen
                collider.enabled = true;
            }
            MeshRenderer objectMeshRenderer = this.GetComponent <MeshRenderer> ();
            objectMeshRenderer.enabled          = true;
            CollectibleParticleSystemGameObject = GameObject.Find("CoinParticleSystem");
            break;

        case CollectibleVariant.SequenceCoin:
            CollectibleParticleSystemGameObject = GameObject.Find("SequenceCoinParticleSystem");
            break;

        case CollectibleVariant.ExtraLife:
            CollectibleParticleSystemGameObject = GameObject.Find("ExtraLifeParticleSystem");
            break;

        case CollectibleVariant.mysteryItem:
            CollectibleParticleSystemGameObject = GameObject.Find("MysteryItemParticleSystem");

            //check whether the player has already gotten this mystery item. If they have, don't bother showing it in level again.
            GameObject PersistentGameObject    = GameObject.FindGameObjectWithTag("PersistentGameObject");
            persistedPlayerDataController ppdc = PersistentGameObject.GetComponent <persistedPlayerDataController> ();
            GameObject CurrentPlayer           = GameObject.FindWithTag("CurrentPlayer");
            if (CurrentPlayer != null)
            {
                CharacterInformationScript cis = CurrentPlayer.GetComponent <CharacterInformationScript> ();
                if (cis != null)
                {
                    if (cis.mysteryItemTrophyName == gameObject.name && ppdc.isTrophyUnlocked(cis.mysteryItemTrophyName))
                    {
                        Debug.Log("disabling mystery item " + cis.mysteryItemTrophyName + " as the player has already collected it:" + gameObject.name);
                        this.gameObject.SetActive(false);
                    }
                }
            }
            break;

        default:
            // do nothing
            break;
        }

        GetGameReferences();
    }
Exemplo n.º 2
0
    public static void SetCamera()
    {
        float currentAspectRatio = 0.0f;

        if (Screen.orientation == ScreenOrientation.LandscapeRight ||
            Screen.orientation == ScreenOrientation.LandscapeLeft)
        {
            //Debug.Log ("Landscape detected...");
            currentAspectRatio = (float)Screen.width / Screen.height;
        }
        else
        {
            //Debug.Log ("Portrait detected...?");
            if (Screen.height > Screen.width && _landscapeModeOnly)
            {
                currentAspectRatio = (float)Screen.height / Screen.width;
            }
            else
            {
                currentAspectRatio = (float)Screen.width / Screen.height;
            }
        }
        // If the current aspect ratio is already approximately equal to the desired aspect ratio,
        // use a full-screen Rect (in case it was set to something else previously)

        //Debug.Log ("currentAspectRatio = " + currentAspectRatio + ", wantedAspectRatio = " + wantedAspectRatio);

        if ((int)(currentAspectRatio * 100) / 100.0f == (int)(wantedAspectRatio * 100) / 100.0f)
        {
            cam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            if (backgroundCam)
            {
                Destroy(backgroundCam.gameObject);
            }
            return;
        }

        // Pillarbox
        if (currentAspectRatio > wantedAspectRatio)
        {
            // TR EDIT - Don't pillarbox.
            //float inset = 1.0f - wantedAspectRatio/currentAspectRatio;
            //cam.rect = new Rect(inset/2, 0.0f, 1.0f-inset, 1.0f);
        }
        // Letterbox
        else
        {
            float inset = 1.0f - currentAspectRatio / wantedAspectRatio;
            cam.rect = new Rect(0.0f, inset / 2, 1.0f, 1.0f - inset);
        }
        if (!backgroundCam)
        {
            // Make a new camera behind the normal camera which displays black; otherwise the unused space is undefined
            backgroundCam = new GameObject("BackgroundCam", typeof(Camera)).GetComponent <Camera>();
            //backgroundCam.renderingPath = RenderingPath.Forward;
            backgroundCam.depth      = int.MinValue;
            backgroundCam.clearFlags = CameraClearFlags.SolidColor;             //this is causing the tiled GPU warning but I dont think its bad enough to need to fix. At least in theory?
            //Color bgColor = new Color (139/255, 255/255, 77/255, 255/255);
//			Color bgColor = new Color (0, 0.301f, 0.098f, 1);
//			ColorHSV currentHSV = new ColorHSV (Color.white);
//			currentHSV.h = 99;
//			currentHSV.s = 255;
//			currentHSV.v = 39;
//			Color bgColor = ColorHSV.ToColor (currentHSV);
            // experiments with making the bars the same as the background colour (or any non-black color) made it look wrong, as
            // though the bars were supposed to be part of the level - but realised I had to do this as it was the only option to enforce the ratio.
            // ended up making it so that you can pick a colour for the camera background in the character information script, then its a different
            // colour for each character. TR
            GameObject CurrentPlayer = GameObject.FindWithTag("CurrentPlayer");
            if (CurrentPlayer != null)
            {
                CharacterInformationScript cis = CurrentPlayer.GetComponent <CharacterInformationScript> ();
                if (cis != null)
                {
                    backgroundCam.backgroundColor = cis.letterboxColor;
                }
            }
            else
            {
                Debug.LogError("could not find CurrentPlayer to set ratio background with!");
                //default
                backgroundCam.backgroundColor = Color.white;                 //don't make it black or it will look like a cutscene. White is safe.
            }
            //backgroundCam.backgroundColor = bgColor;
            backgroundCam.cullingMask = 0;
        }
    }