예제 #1
0
    void Update()
    {
        // Check if there were any objects hit by our reticle-ray cast in the scene. If so, check whether or not
        // it has a TextureCycler component.
        if (Raycaster.getInstance().anythingHitByRay())
        {
            GameObject objHitByRay = Raycaster.getInstance().getObjectHitByRay();
            string     objHitTag   = objHitByRay.tag;

            Debug.Log(objHitTag);

            // Check that there was a valid object hit by the raycast. Raycaster.getInstance().getObjectHitByRay()
            // returns null if no objects were hit by ray cast on this frame. Objects responding to input must have
            // one of the increment/decrement/slideshow tags set to be affected and cycled by raycast.
            if (objHitByRay != null && isTagValidButton(objHitTag))
            {
                if (TextureObject != null)
                {
                    for (int i = 0; i < TextureObject.Length; ++i)
                    {
                        TextureCycler objToCycleCycler = TextureObject[i].GetComponent <TextureCycler>();

                        // Cycle the textures on it!
                        if (objToCycleCycler != null)
                        {
                            if (ButtonsDefineCyclerMode)
                            {
                                objToCycleCycler.setTextureCycleMode(mapTagToModeIndex(objHitTag));
                            }

                            objToCycleCycler.cycleTextures();
                        }
                    }
                }
            }
            else if (mapTagToModeIndex(objHitTag) == 2)
            {
                togglePause();
            }
            else if (mapTagToModeIndex(objHitTag) == 3)
            {
                Debug.Log("Restart clicked");
                Application.LoadLevel(Application.loadedLevel);
            }
        }

        if (ScreenFaderSphere.getInstance() && !mFirstTextureReady && TextureLoader.getInstance().isFinishedLoadingFirstTexture())
        {
            mFirstTextureReady = true;
            ScreenFaderSphere.getInstance().fadeToTransparent();
        }
    }
        //Handle the Click event
        private void HandleClick()
        {
            Debug.Log("Show click state");
            m_Renderer.material = m_ClickedMaterial;

            for (int i = 0; i < TextureObject.Length; ++i)
            {
                TextureCycler objToCycleCycler = TextureObject[i].GetComponent <TextureCycler>();

                // Cycle the textures on it!
                if (objToCycleCycler != null)
                {
                    if (ButtonsDefineCyclerMode)
                    {
                        objToCycleCycler.setTextureCycleMode(0);
                    }

                    objToCycleCycler.cycleTextures();
                }
            }
        }
예제 #3
0
    // Used to read and load a texture2D from an Android device - from a specific folder.
    // mCurrTexture is set to null when the index indicates we want to use default textures; in this case
    // we just return the mStartingTexture[mCurrentTextureIndex]. Otherwise, if we are loading a texture from
    // the device, mCurrTexture will be set to the texture read.
    public IEnumerator LoadTextureAtIndex(int textureIndex, bool firstTime, TextureCycler cyclerToCallback)
    {
        if (mAndroidEnvironment && !string.IsNullOrEmpty(mLocalStorageDirPath) && System.IO.Directory.Exists(mLocalStorageDirPath) &&
            (textureIndex >= mStartingTextures.Length &&
             textureIndex < (mTextureFileNames.Count + mStartingTextures.Length)))
        {
            // Append each texture name (as the name appears inside mLocalStoragePath) before each load.
            int    startingTextureOffset = mStartingTextures == null ? 0 : mStartingTextures.Length;
            string currTexturePath       = mLocalStorageDirPath + mTextureFileNames[textureIndex - startingTextureOffset];

            // Add "file:///" to the beginning of the absolute path so the WWW object knows its a file protocol.
            WWW textureWWW = new WWW("file:///" + currTexturePath);

            if (textureWWW.error != null)
            {
                Debug.Log(name + textureWWW.url + " error: " + textureWWW.error);
            }
            else
            {
                // Yield return from the coroutine while the texture is loading.
                while (!textureWWW.isDone)
                {
                    yield return(null);
                }

                // Destroy the old texture member variable before creating a new one to save memory.
                if (mCurrTexture != null)
                {
                    Texture2D.Destroy(mCurrTexture);
                }

                // Create a new texture2D and load the WWW contents into it
                // Note: this call is blocking on the UI thread, so we fade in and out to mask load times.
                mCurrTexture          = new Texture2D(4, 4, TextureFormat.DXT1, false);
                mCurrTexture.wrapMode = TextureWrapMode.Repeat;
                textureWWW.LoadImageIntoTexture(mCurrTexture);

                // Clean up the WWW object and call the GC each time we load a texture from device.
                // This is to avoid memory allocation issues.
                textureWWW.Dispose();
                textureWWW = null;
                System.GC.Collect();

                if (cyclerToCallback != null)
                {
                    cyclerToCallback.applyReadyTexture();
                    ScreenFaderSphere.getInstance().fadeToTransparent();

                    // Check if this is the first texture loaded, if so set this flag so that
                    // the texture cycler can know when it's ready.
                    if (firstTime)
                    {
                        mFinishedFirstTexture = true;
                    }
                }
            }
        }
        else
        {
            mCurrTextureIndex = textureIndex;
            mCurrTexture      = null;
            cyclerToCallback.applyReadyTexture();

            if (ScreenFaderSphere.getInstance())
            {
                ScreenFaderSphere.getInstance().fadeToTransparent();
            }
        }
    }