Пример #1
0
    // Make a GUIElement, will immediately render
    public FastGUIElement(
		Vector2 screenPos,	// Position on screen (relative to Position)
		Rect	atlasRect, 	// Atlas rectangle in pixels
		Position pos = Position.TOPLEFT)
    {
        // There is a fixed number of possible FastGUIElements
        frontendAtlas = PrimitiveLibrary.Get.m_Atlases[(int)TextureAtlas.AtlasID.FRONTEND];
        if (instanceCount + 1 > frontendAtlas.m_NumElements)
        {
            Debug.LogError ("Need to increase frontendAtlas.m_NumElements and PrimitiveLibrary.g_FrontendBatchSize");
            return;
        }
        textureIdx = instanceCount++;

        // Initialise the UVs
        frontendAtlas.m_UVSet[textureIdx] = new Vector4 (
            atlasRect.x / originalAtlasPixelsWidth,
            ((originalAtlasPixelsHeight - atlasRect.y) - atlasRect.height) / originalAtlasPixelsHeight, // Note quad render has bottom zeroed Vs
            (atlasRect.x + atlasRect.width) / originalAtlasPixelsWidth,
            (((originalAtlasPixelsHeight - atlasRect.y) - atlasRect.height) + atlasRect.height) / originalAtlasPixelsHeight);

        // Setup the quad
        quad = PrimitiveLibrary.Get.GetQuadDefinition (PrimitiveLibrary.QuadBatch.FRONTEND_BATCH);
        quad.m_TextureIdx = textureIdx;
        quad.m_Colour = Color.white;

        // Use UVs for size
        widthNormalised = frontendAtlas.m_UVSet[textureIdx].z - frontendAtlas.m_UVSet[textureIdx].x;
        heightNormalised = frontendAtlas.m_UVSet[textureIdx].w - frontendAtlas.m_UVSet[textureIdx].y;
        width = atlasRect.width;
        height = atlasRect.height;

        // The centre of the quad in world space which is mapped by camera to the safeSceen size
        if (pos == Position.TOPLEFT) {
            quad.m_Position.x = (-safeScreenWidth * .5f + screenPos.x) + (width * .5f);
            quad.m_Position.y = (+safeScreenHeight * .5f - screenPos.y) - (height * .5f);
        }
        else if (pos == Position.XYCENTRED) {
            quad.m_Position.x = (-safeScreenWidth * .5f + screenPos.x);
            quad.m_Position.y = (+safeScreenHeight * .5f - screenPos.y);
        }
        else if (pos == Position.XCENTRED) {
            quad.m_Position.x = (-safeScreenWidth * .5f + screenPos.x);
            quad.m_Position.y = (+safeScreenHeight * .5f - screenPos.y) - (height * .5f);
        }
        else if (pos == Position.YCENTRED) {
            quad.m_Position.x = (-safeScreenWidth * .5f + screenPos.x) + (width * .5f);
            quad.m_Position.y = (+safeScreenHeight * .5f - screenPos.y);
        }
        quad.m_Position.z = 0f;
        quad.m_Scale.x = width;
        quad.m_Scale.y = height;
        UpdatedQuad ();
        children = new List<FastGUIElement>();
    }
Пример #2
0
 void OnDisable()
 {
     if( Application.isPlaying )
     {
         if( m_QuadRenderer != null )
         {
             PrimitiveLibrary.Get.ReleaseQuadDefinition( m_QuadRenderer );
             m_QuadRenderer = null;
         }
     }
 }
Пример #3
0
 //-----------------------------------------------------------------------------
 // Method:	ReleaseQuadDef()
 // Desc:	Gives the definition back to this batch
 public static void ReleaseQuadDef( BatchedQuadDef definition )
 {
     definition.m_Active = false;
 }
Пример #4
0
    void OnDestroy()
    {
        PrimitiveLibrary.Get.ReleaseQuadDefinition( m_cursor );
        m_cursor = null;

        for( int x = 0; x<kNumPulsersX; x++ )
        {
            for( int y = 0; y<kNumPulsersY; y++ )
            {
                PrimitiveLibrary.Get.ReleaseQuadDefinition( m_pulsers[x, y] );
                m_pulsers[x, y] = null;
            }
        }
    }
Пример #5
0
    void Start()
    {
        m_cursor = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.FX_BATCH );

        m_cursor.m_TextureIdx = (int)(TextureAtlas.ParticleFX.SHINE);

        m_cursor.m_Scale.x = 2.0f;
        m_cursor.m_Scale.y = 2.0f;

        m_cursor.m_Colour = new Color( 0.2f, 0.9f, 1.0f, 1.0f );

        for( int x = 0; x<kNumPulsersX; x++ )
        {
            for( int y = 0; y<kNumPulsersY; y++ )
            {
                m_pulsers[x, y] = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.FX_BATCH );

                m_pulsers[x, y].m_TextureIdx = (int)(TextureAtlas.ParticleFX.GLOW);

                m_pulsers[x, y].m_Position.x = (float)x;
                m_pulsers[x, y].m_Position.y = (float)y;
                m_pulsers[x, y].m_Position.z = 0.0f;

                m_pulsers[x, y].m_Colour = new Color( 1.0f, 1.0f, 1.0f, 1.0f );

                m_translationField[x, y] = 0.0f;
                m_velocityField[x, y] = 0.0f;
                m_accelerationField[x, y] = 0.0f;
            }
        }

        float colourAngle;
        float r, g, b;
        for( int c = 0; c<3000; c++ )
        {
            colourAngle = ((float)c)*0.01f;
            r = Mathf.Abs( Mathf.Sin( colourAngle ) );
            g = Mathf.Abs( Mathf.Sin( colourAngle + Mathf.PI*0.666f ) );
            b = Mathf.Abs( Mathf.Sin( colourAngle + Mathf.PI*1.333f) );

            m_colourWheel[c] = new Color( r, g, b, 1.0f );
        }
    }
Пример #6
0
    void SetParticleQuad( ParticleDefinition def, BatchedQuadDef quad, float time )
    {
        float normalTime = time - def.m_StartTime;
        normalTime /= (def.m_EndTime - def.m_StartTime);

        if( normalTime < 0.0f )
        {
            def.m_Active = false;
            PrimitiveLibrary.Get.ReleaseQuadDefinition( quad );
            return;
        }

        bool releaseParticle = false;
        if( normalTime > 1.0f )
        {
            normalTime = 1.0f;
            releaseParticle = true;
        }

        float rotationTime = normalTime;
        if( m_RotationPower < 0 )
        {
            rotationTime = 1.0f - rotationTime;
            for( int p = 0; p<-m_RotationPower; p++ )
                rotationTime *= rotationTime;
            rotationTime = 1.0f - rotationTime;
        }
        else if( m_RotationPower > 0 )
        {
            for( int p = 0; p<m_RotationPower; p++ )
                rotationTime *= rotationTime;
        }
        float rotation = def.m_IntialRotation + rotationTime*def.m_RotationOverTime;

        float scaleTime = normalTime;
        if( m_ScalePower < 0 )
        {
            scaleTime = 1.0f - scaleTime;
            for( int p = 0; p<-m_ScalePower; p++ )
                scaleTime *= scaleTime;
            scaleTime = 1.0f - scaleTime;
        }
        else if( m_ScalePower > 0 )
        {
            for( int p = 0; p<m_ScalePower; p++ )
                scaleTime *= scaleTime;
        }
        float scale = def.m_InitialScale + scaleTime*def.m_ScaleOverTime;

        float colourTime = normalTime;
        if( m_ColourPower < 0 )
        {
            colourTime = 1.0f - colourTime;
            for( int p = 0; p<-m_ColourPower; p++ )
                colourTime *= colourTime;
            colourTime = 1.0f - colourTime;
        }
        else if( m_ColourPower > 0 )
        {
            for( int p = 0; p<m_ColourPower; p++ )
                colourTime *= colourTime;
        }
        Color col = m_Colour + colourTime*m_ColourOverTime;

        quad.m_Position = transform.position;
        quad.m_Rotation = rotation;
        quad.m_Scale = new Vector2( scale, scale );
        quad.m_Colour = col;

        if( releaseParticle )
        {
            def.m_Active = false;
            PrimitiveLibrary.Get.ReleaseQuadDefinition( quad );
            return;
        }
    }
Пример #7
0
    public void InitialiseDigits()
    {
        m_digits = new BatchedQuadDef[m_NumDigits];

        for( int d = 0; d<m_NumDigits; d++ )
        {
            m_digits[d] = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.NUMBERS_BATCH );

            if( m_digits[d] != null )
            {
                m_digits[d].m_Colour = m_Colour;
                m_digits[d].m_Scale = new Vector3( m_ScaleX, m_ScaleY, 0.0f );
                m_digits[d].m_Active = true;
                m_digits[d].m_TextureIdx = 0;
            }
        }

        if( m_Percentage )
        {
            m_percentageQuad = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.NUMBERS_BATCH );
            if( m_percentageQuad != null )
            {
                m_percentageQuad.m_Colour =  m_Colour;
                m_percentageQuad.m_Scale = new Vector3( m_ScaleX, m_ScaleY, 0.0f );
                m_percentageQuad.m_TextureIdx = (int)(TextureAtlas.Numbers.NUM_PERCENT);
                m_percentageQuad.m_Active = true;
            }
        }
        else
            m_percentageQuad = null;

        if( m_Multiplier )
        {
            m_multiplierQuad = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.NUMBERS_BATCH );
            if( m_multiplierQuad != null )
            {
                m_multiplierQuad.m_Colour =  m_Colour;
                m_multiplierQuad.m_Scale = new Vector3( m_ScaleX, m_ScaleY, 0.0f );
                m_multiplierQuad.m_TextureIdx = (int)(TextureAtlas.Numbers.NUM_TIMES);
                m_multiplierQuad.m_Active = true;
            }
        }
        else
            m_multiplierQuad = null;

        if( m_Colon )
        {
            m_colonQuad = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.NUMBERS_BATCH );
            if( m_colonQuad != null )
            {
                m_colonQuad.m_Colour =  m_Colour;
                m_colonQuad.m_Scale = new Vector3( m_ScaleX, m_ScaleY, 0.0f );
                m_colonQuad.m_TextureIdx = (int)(TextureAtlas.Numbers.NUM_COLON);
                m_colonQuad.m_Active = true;
            }
        }
        else
            m_colonQuad = null;

        m_oldScaleX = m_ScaleX;
        m_oldScaleY = m_ScaleY;

        //	Make sure it gets at least 1 update
        m_oldNumber = -999999;
    }
Пример #8
0
    void Start()
    {
        if( RL.m_Prototype.m_PlayerType == PrototypeConfiguration.PlayerTypes.BALDY )
            m_renderer = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.PLAYER_BATCH );
        else
            m_renderer = PrimitiveLibrary.Get.GetQuadDefinition( PrimitiveLibrary.QuadBatch.ELVIS_BATCH );

        m_renderer.m_Position = m_Position + new Vector3( 0.0f, m_yRendererOffset, 0.0f );
        m_renderer.m_Scale = new Vector3( m_quadSize, m_quadSize, m_quadSize );

        m_shadow = transform.FindChild( "Shadow" ).gameObject;
        m_shadowMaterial = m_shadow.renderer.sharedMaterial;

        ResetForLevel();
    }
Пример #9
0
    void OnDestroy()
    {
        if( m_renderer != null )
            PrimitiveLibrary.Get.ReleaseQuadDefinition( m_renderer );
        m_renderer = null;

        m_shadowMaterial.color = new Color( 1.0f, 1.0f, 1.0f, 1.0f );
    }
Пример #10
0
 //-----------------------------------------------------------------------------
 // Method:	ReleaseQuadDefinition()
 // Desc:	Hands the quad definition back to the quad batch
 public void ReleaseQuadDefinition( BatchedQuadDef def )
 {
     PrimitiveQuadBatch.ReleaseQuadDef( def );
 }