示例#1
0
    private void UpdateSequence(int newSequenceIndex, bool newSpriteFlip)
    {
        int   progressIndex    = 0;
        float progressTime     = 0f;
        int   newSpriteIndex   = -1;
        float newSpriteElapsed = 0f;

        if ((newSequenceIndex > -1) && (newSequenceIndex < totalSequences) && (firstIndexPerSequence != null) &&
            (lastIndexPerSequence != null) && (speedPerSequence != null) && (loopPerSequence != null) && (fakeLightPerSequence != null))
        {
            if (keepSequenceProgress && (spriteIndex > -1) && (firstIndex > -1))
            {
                progressIndex        = spriteIndex - firstIndex;
                progressTime         = spriteElapsed;
                keepSequenceProgress = false;
            }
            sequenceIndex    = newSequenceIndex;
            firstIndex       = firstIndexPerSequence[sequenceIndex];
            lastIndex        = lastIndexPerSequence[sequenceIndex];
            spriteDuration   = speedPerSequence[sequenceIndex];
            loop             = loopPerSequence[sequenceIndex];
            fakeLight        = fakeLightPerSequence[sequenceIndex];
            spriteFlip       = newSpriteFlip;
            newSpriteIndex   = firstIndex + progressIndex;
            newSpriteElapsed = progressTime;
            UpdateSprite(newSpriteIndex, newSpriteElapsed);
        }
        else
        {
            /*halmeida - somebody is trying an UpdateAnimation after a Clear().*/
            over = true;
        }
    }
示例#2
0
    private void ExtractSpritesAndLights()
    {
        GameObject        sequenceObject = null;
        AnimationSequence sequence       = null;

        Sprite[]  sequenceSprites         = null;
        Sprite[]  sequenceSpriteNormals   = null;
        Vector2[] sequencePixelOffsetsOne = null;
        Vector2[] sequencePixelOffsetsTwo = null;
        int       length    = 0;
        int       oldLength = 0;

        Sprite[]            newSprites            = null;
        Sprite[]            newSpriteNormals      = null;
        Vector2[]           newFocusOffsetsOne    = null;
        Vector2[]           newFocusOffsetsTwo    = null;
        bool[]              newFocusOneValidities = null;
        bool[]              newFocusTwoValidities = null;
        bool                sequenceExtracted     = false;
        Sprite              newSprite             = null;
        Sprite              newSpriteNormal       = null;
        float               newPixelsPerUnit      = 0f;
        Vector2             newPixelOffset        = Vector2.zero;
        bool                validFocusOffsetOne   = false;
        bool                validFocusOffsetTwo   = false;
        float               framesPerSecond       = 0f;
        FakeLightParameters fakeLightSpecs        = null;
        FakeLight           fakeLight             = null;

        sprites            = null;
        spriteNormals      = null;
        focusOffsetsOne    = null;
        focusOffsetsTwo    = null;
        focusOneValidities = null;
        focusTwoValidities = null;
        for (int i = 0; i < totalSequences; i++)
        {
            sequenceExtracted = false;
            sequenceObject    = sequenceObjects[i];
            if (sequenceObject != null)
            {
                sequence = sequenceObject.GetComponent <AnimationSequence>();
                if (sequence != null)
                {
                    sequenceSprites         = sequence.sprites;
                    sequenceSpriteNormals   = sequence.spriteNormals;
                    sequencePixelOffsetsOne = sequence.pixelOffsetsOne;
                    sequencePixelOffsetsTwo = sequence.pixelOffsetsTwo;
                    if (sequenceSprites != null)
                    {
                        length = sequenceSprites.Length;
                        if (length > 0)
                        {
                            if (sprites == null)
                            {
                                oldLength = 0;
                            }
                            else
                            {
                                oldLength = sprites.Length;
                            }
                            if (sequenceSpriteNormals != null)
                            {
                                if (sequenceSpriteNormals.Length != length)
                                {
                                    sequenceSpriteNormals = null;
                                }
                            }
                            length                = oldLength + length;
                            newSprites            = new Sprite[length];
                            newSpriteNormals      = new Sprite[length];
                            newFocusOffsetsOne    = new Vector2[length];
                            newFocusOffsetsTwo    = new Vector2[length];
                            newFocusOneValidities = new bool[length];
                            newFocusTwoValidities = new bool[length];
                            for (int j = 0; j < oldLength; j++)
                            {
                                newSprites[j]            = sprites[j];
                                newSpriteNormals[j]      = spriteNormals[j];
                                newFocusOffsetsOne[j]    = focusOffsetsOne[j];
                                newFocusOffsetsTwo[j]    = focusOffsetsTwo[j];
                                newFocusOneValidities[j] = focusOneValidities[j];
                                newFocusTwoValidities[j] = focusTwoValidities[j];
                            }
                            for (int j = oldLength; j < length; j++)
                            {
                                newSprite       = sequenceSprites[j - oldLength];
                                newSprites[j]   = newSprite;
                                newSpriteNormal = null;
                                if (sequenceSpriteNormals != null)
                                {
                                    newSpriteNormal = sequenceSpriteNormals[j - oldLength];
                                }
                                newSpriteNormals[j] = newSpriteNormal;
                                validFocusOffsetOne = false;
                                validFocusOffsetTwo = false;
                                if (newSprite != null)
                                {
                                    newPixelsPerUnit = newSprite.pixelsPerUnit;
                                    if (newPixelsPerUnit != 0f)
                                    {
                                        if (sequencePixelOffsetsOne != null)
                                        {
                                            if (sequencePixelOffsetsOne.Length > (j - oldLength))
                                            {
                                                newPixelOffset        = sequencePixelOffsetsOne[j - oldLength];
                                                newPixelOffset.x      = newPixelOffset.x / newPixelsPerUnit;
                                                newPixelOffset.y      = newPixelOffset.y / newPixelsPerUnit;
                                                newFocusOffsetsOne[j] = newPixelOffset;
                                                validFocusOffsetOne   = true;
                                            }
                                        }
                                        if (sequencePixelOffsetsTwo != null)
                                        {
                                            if (sequencePixelOffsetsTwo.Length > (j - oldLength))
                                            {
                                                newPixelOffset        = sequencePixelOffsetsTwo[j - oldLength];
                                                newPixelOffset.x      = newPixelOffset.x / newPixelsPerUnit;
                                                newPixelOffset.y      = newPixelOffset.y / newPixelsPerUnit;
                                                newFocusOffsetsTwo[j] = newPixelOffset;
                                                validFocusOffsetTwo   = true;
                                            }
                                        }
                                    }
                                }
                                if (!validFocusOffsetOne)
                                {
                                    newFocusOffsetsOne[j] = Vector2.zero;
                                }
                                if (!validFocusOffsetTwo)
                                {
                                    newFocusOffsetsTwo[j] = Vector2.zero;
                                }
                                newFocusOneValidities[j] = validFocusOffsetOne;
                                newFocusTwoValidities[j] = validFocusOffsetTwo;
                            }
                            sprites                  = newSprites;
                            spriteNormals            = newSpriteNormals;
                            focusOffsetsOne          = newFocusOffsetsOne;
                            focusOffsetsTwo          = newFocusOffsetsTwo;
                            focusOneValidities       = newFocusOneValidities;
                            focusTwoValidities       = newFocusTwoValidities;
                            newSprites               = null;
                            newSpriteNormals         = null;
                            newFocusOffsetsOne       = null;
                            newFocusOffsetsTwo       = null;
                            newFocusOneValidities    = null;
                            newFocusTwoValidities    = null;
                            firstIndexPerSequence[i] = oldLength;
                            lastIndexPerSequence[i]  = length - 1;
                            framesPerSecond          = (sequence.framesPerSecond < 1) ? 1 : sequence.framesPerSecond;
                            speedPerSequence[i]      = 1f / framesPerSecond;
                            loopPerSequence[i]       = sequence.loop;
                            fakeLightPerSequence[i]  = null;
                            if (sequence.hasFakeLight)
                            {
                                fakeLightSpecs = sequenceObject.GetComponent <FakeLightParameters>();
                                if (fakeLightSpecs != null)
                                {
                                    fakeLight = new FakeLight(fakeLightSpecs.color, fakeLightSpecs.startingRadius, fakeLightSpecs.startingIntensity);
                                    fakeLight.ConfigureStretches(fakeLightSpecs.radiusSpeedPerStretch, fakeLightSpecs.intensitySpeedPerStretch,
                                                                 fakeLightSpecs.durationPerStretch);
                                    fakeLightPerSequence[i] = fakeLight;
                                }
                            }
                            sequenceExtracted = true;
                        }
                    }
                }
            }
            if (!sequenceExtracted)
            {
                firstIndexPerSequence[i] = -1;
                lastIndexPerSequence[i]  = -1;
                speedPerSequence[i]      = 0f;
                loopPerSequence[i]       = false;
                fakeLightPerSequence[i]  = null;
            }
        }
    }
示例#3
0
    public virtual void Clear(bool renderingComponentInitialized = true)
    {
        FakeLight fakeLight = null;

        if (renderingComponentInitialized)
        {
            FeedRenderingComponent(null, null, false);
        }
        ClearRenderingComponent();
        sequenceObjects       = null;
        totalSequences        = 0;
        sequenceIndex         = -1;
        sprites               = null;
        sprite                = null;
        spriteNormals         = null;
        spriteNormal          = null;
        focusOffsetsOne       = null;
        focusOffsetsTwo       = null;
        focusOffsetOne        = Vector2.zero;
        focusOffsetTwo        = Vector2.zero;
        focusOneValidities    = null;
        focusTwoValidities    = null;
        focusOneValidity      = false;
        focusTwoValidity      = false;
        spriteIndex           = -1;
        spriteElapsed         = 0f;
        spriteFlip            = false;
        spriteWidth           = 0f;
        firstIndexPerSequence = null;
        lastIndexPerSequence  = null;
        speedPerSequence      = null;
        loopPerSequence       = null;
        if (fakeLightPerSequence != null)
        {
            for (int i = 0; i < fakeLightPerSequence.Length; i++)
            {
                fakeLight = fakeLightPerSequence[i];
                if (fakeLight != null)
                {
                    fakeLight.Clear();
                    fakeLightPerSequence[i] = null;
                }
            }
        }
        fakeLightPerSequence = null;
        firstIndex           = -1;
        lastIndex            = -1;
        spriteDuration       = 0f;
        loop = false;
        keepSequenceProgress = false;
        status             = INVALID_STATUS;
        previousStatus     = INVALID_STATUS;
        over               = false;
        forceSpriteFeeding = false;
        fadeSpeed          = 0f;
        fadeImmediately    = false;
        fadedToTransparent = false;
        fadedToOpaque      = false;
        opaqueAlpha        = 0f;
        currentAlpha       = 0f;
        paused             = false;
        ClearShadows();
        if (particleController != null)
        {
            particleController.Clear();
            particleController = null;
        }
        childSeparation     = DisplayDepthManager.ELEMENT_TO_ELEMENT_OFFSET / MAX_ANIMATORS_WITHIN_LAYER;
        childObjectBack     = null;
        childObjectFront    = null;
        childTransformBack  = null;
        childTransformFront = null;
        ClearChildAnimators();
    }
示例#4
0
        private void OnPreRenderMy(Camera camera)

        /* { }
         * void OnWillRenderObject()*/
        //private void OnPreRender()
        { //m_renderCamera = Camera.current;
          //if (!MainRender(camera)) return;
          // if (Application.isPlaying && !visible) return;
            if (!camera || camera.gameObject.layer == 7)
            {
                return;
            }
            if (!__this || !enabled)
            {
                Camera.onPreRender -= OnPreRenderMy;
                return;
            }
            if (!IsVisible)
            {
                return;
            }



            m_renderCamera = camera;
            if (cameraCounterPreRender)
            {
                cameraCounterPreRender = false;
                ++CameraIndexPreRender;
            }

            /*int count = 0;
             * foreach (var item in cache_GET_RENDER_TEXTURE) {
             * foreach (var v2 in item.Value) {
             *  count += v2.Valu;
             * }
             * }
             * Debug.Log( count );*/



        #if UNITY_EDITOR
            if (!compiler)
            {
                return;
            }
            if (!compiler.material)
            {
                return;
            }
            if (!RENDERER)
            {
                return;
            }
            if (!RENDERER.sharedMaterial)
            {
                return;
            }

            //RestoreMat();

            TryCreateTempMaterials();


            if (CameraIndexPreRender == -1)
            {
                return;
            }
            //CopyMat( material, editor_cache_materials[this] );
            //EditorJsonUtility.FromJsonOverwrite( EditorJsonUtility.ToJson( material ), editor_cache_materials[this] );

            /* if (restoreMat != RE_NDERER.sharedMaterial && !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(RE_NDERER.sharedMaterial)))
             * {
             *   restoreMat = RE_NDERER.sharedMaterial;
             *   SetDirty(this);
             * }*/
            //__compiler.OverrideMaterial = RE_NDERER.sharedMaterial = editor_cache_materials[gameObject];
        #endif


            // var M = RENDERER.sharedMaterial;

            if (!setter_cache.ContainsKey(RENDERER.sharedMaterial))
            {
                setter_cache.Add(RENDERER.sharedMaterial, new MaterialSetter()
                {
                    RENDERER = RENDERER, material = RENDERER.sharedMaterial, compiler = compiler
                });
            }
            var M = setter_cache[RENDERER.sharedMaterial];

            do
            {
                if (!USE_FAKE_LIGHTING)
                {
                    if (!DirectionLight)
                    {
                        break;
                    }
                    if (Application.isPlaying && m_OldDirection == DirectionLight.forward)
                    {
                        break;
                    }

                    // if (!compiler.HasProperty(_LightDir)) break;

                    m_OldDirection = DirectionLight.forward;
                    // m_v3 = -DirectionLight.TransformDirection( 0, 0, 1 ).normalized;
                    m_v3 = DirectionLight.forward;
                    m_v4.Set(m_v3.x, m_v3.y, m_v3.z, 0);
                    M.SetVector(_LightDir, m_v4);
                }
                else
                {
                    if (!FakeLight)
                    {
                        break;
                    }
                    if (!__FakeLightComponent)
                    {
                        __FakeLightComponent = FakeLight.GetComponent <FastWaterModel20FakeLight>();
                    }
                    if (!__FakeLightComponent)
                    {
                        break;
                    }
                    if (Application.isPlaying && m_OldDirection == FakeLight.forward && m_OldColor == __FakeLightComponent.color)
                    {
                        break;
                    }


                    // if (!compiler.HasProperty(_LightDir)) break;
                    // if (!compiler.HasProperty(_LightColor0Fake)) break;

                    m_OldDirection = FakeLight.forward;
                    m_v3           = FakeLight.TransformDirection(0, 0, 1).normalized;
                    m_v4.Set(m_v3.x, m_v3.y, m_v3.z, 0);
                    M.SetVector(_LightDir, m_v4);

                    m_OldColor = __FakeLightComponent.color;
                    M.SetColor(_LightColor0Fake, __FakeLightComponent.color);
                }
            } while (false);



            // if (!lastOrto.ContainsKey(M)) lastOrto.Add(M, null);
            // if (!needOrto.ContainsKey(camera)) needOrto.Add(camera, false);

            bool CHECKORTO = M.lastOrto != m_renderCamera.orthographic;
        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                CHECKORTO = true;
            }
        #endif


            if (CHECKORTO)
            {
                M.lastOrto = m_renderCamera.orthographic;
            }


            //


            /*   if (IsKeywordEnabled(ULTRA_FAST_MODE))
             *   {
             *       var res = bakedRotation ?? (bakedRotation = transform.rotation.eulerAngles.y * Mathf.Deg2Rad).Value;
             *       if (!Application.isPlaying) res = transform.rotation.eulerAngles.y / 180 * Mathf.PI;
             *       M.SetFloat(_ObjecAngle, 0);
             *   }*/
            // Debug.Log((Application.isPlaying ? (Time.time / 16) : ((float)((EditorApplication.timeSinceStartup / 16) % (512 / 16)))) % (512 / 16));


            DO_FRACTIME(M);



            if (Application.isPlaying)
            {
                M.SetVector(_ObjectScale, localScale ?? (localScale = transform.localScale).Value);
            }
            else
            {
                M.SetVector(_ObjectScale, transform.localScale);
            }

            if (M.lastOrto == true)
            { //Debug.Log(camera.gameObject.layer + " " + camera);
                M.SetFloat(_MyNearClipPlane, m_renderCamera.nearClipPlane);
                M.SetFloat(_MyFarClipPlane, m_renderCamera.farClipPlane);
            }
            // return;
            if (IsKeywordEnabled(ALLOW_MANUAL_DEPTH) && (m_renderCamera.depthTextureMode & DepthTextureMode.Depth) == 0)
            { //lastDepth = camera;
                m_renderCamera.depthTextureMode |= DepthTextureMode.Depth;
                //  Debug.Log(gameObject.name);
            }

            //if (!IsKeywordEnabled(SKIP_3DVERTEX_ANIMATION))
            { /* VertexMin.Set(VertexSize.x, 0, VertexSize.y);
               * VertexMax.Set(VertexSize.z, 0, VertexSize.w);
               * VertexMin = transform.TransformPoint(VertexMin);
               * VertexMax = transform.TransformPoint(VertexMax);
               * VertexSizeResult.Set( VertexMin.x, VertexMin.z, -VertexMin.x + VertexMax.x, -VertexMin.z + VertexMax.z);*/
                M.SetVector(_VertexSize, VertexSize);
            }

            ///UpdateMaterials();
            ///UpdateMaterials();
            if (IsKeywordEnabled(REFLECTION_PLANAR))
            {
                DoPlanarReflection(Mathf.RoundToInt(compiler.GetFloat(_ReflectionTex_temp_size)));
            }

            //refraction
            if (IsKeywordEnabled(REFRACTION_BAKED_FROM_TEXTURE))
            { //external
                M.SetTexture(_RefractionTex, backed_refraction);
            }
            if (IsKeywordEnabled(REFRACTION_BAKED_VIA_SCRIPT) || IsKeywordEnabled(REFRACTION_BAKED_ONAWAKE))
            { //internal
                var t = GET_RENDER_TEXTURE(BakeOrUpdateType.Refraction) ?? emptyTexture;
                // var gett = GetComponent<FastWaterModel20ManualBaking>().t1;
                // Shader.SetGlobalTexture( _RefractionTex_temp, gett );
                // material.SetTexture( _RefractionTex_temp, gett );

                /*#if !TEST_GLES20
                 *              if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2 && Application.isPlaying)
                 #else
                 *              if (true)
                 #endif*/
                //#if USE_TEX2D_CONVERTER
                if (UseTextureConverter)
                {
                    M.SetTexture(_RefractionTex_temp, t.texture_gles20);
                }
                //#else
                else
                {
                    M.SetTexture(_RefractionTex_temp, t.texture);
                }
                //#endif
            }
            //zdepth
            if (IsKeywordEnabled(BAKED_DEPTH_EXTERNAL_TEXTURE))
            { //external
                M.SetTexture(_BakedData, backed_zdepth);
            }


            if (IsKeywordEnabled(BAKED_DEPTH_VIASCRIPT) || IsKeywordEnabled(BAKED_DEPTH_ONAWAKE) || SECOND_DEPTH_NEED())
            { //internalAS
                var t = GET_RENDER_TEXTURE(BakeOrUpdateType.ZDepth) ?? emptyTexture;

                /*#if !TEST_GLES20
                 *              if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2 && Application.isPlaying)
                 #else
                 *              if (true)
                 #endif*/
                //#if USE_TEX2D_CONVERTER
                if (UseTextureConverter)
                {
                    M.SetTexture(_BakedData_temp, t.texture_gles20);
                }
                //#else
                else
                {
                    M.SetTexture(_BakedData_temp, t.texture);
                }
                //#endif
            }

            // camera.clearFlags = CameraClearFlags.Nothing;
            // GameObject.FindObjectsOfType<Text>().First(t => t.gameObject.name == "LOG").text = M.lastDownSamling.ToString();
            // M. material.EnableKeyword("WATER_DOWNSAMPLING");
            // M.SetFloat(DOWNSAMPLING_SAMPLE_SIZE, 0.5f);

            if (M.lastDownSamling /* && CameraIndexPreRender != -1 && camera.targetTexture*/ != 0)
            {
                var buffer = FastWaterModel20FrameBuffer.AddRequestorRuntime(this, camera, IsKeywordEnabled(FORCE_OPAQUE));

                /* if (buffer.LastTexture)
                 * {   M.SetTexture(_LastFrame, buffer.LastTexture);
                 * }*/
                if (buffer.LastTexture2)
                {
                    Shader.SetGlobalTexture(_LastFrame2, buffer.LastTexture2);
                    // M.SetTexture(_LastFrame2, buffer.LastTexture2);
                }

                switch (M.lastDownSamling)
                { //case 1:  M.SetFloat(DOWNSAMPLING_SAMPLE_SIZE, 0.5f); break;
                case 1:  M.SetFloat(DOWNSAMPLING_SAMPLE_SIZE, 0.25f); break;

                case 2:  M.SetFloat(DOWNSAMPLING_SAMPLE_SIZE, 0.5f); break;

                case 3:  M.SetFloat(DOWNSAMPLING_SAMPLE_SIZE, 0.75f); break;
                }
            }

            /* var trt = GET_RENDER_TEXTURE(BakeOrUpdateType.LastFrame, camera.targetTexture.width, heightSize: camera.targetTexture.height, camera: CameraIndexPreRender).texture;
             *   M.SetTexture(_LastFrame, trt);
             *
             *   Debug.Log(camera.targetTexture);*/
            //Debug.Log(camera.targetTexture);
            //
            ///UpdateMaterials();
            ///UpdateMaterials();

            // __compiler.OverrideMaterial = null;
        }