Exemple #1
0
    // Generate atlas
    private void GenerateAtlas(AnimationClipRegeneration a_eRegeneration)
    {
        int iFrameCount = this.FrameCount;

        if (globalAtlas != null)          // global atlas
        {
            string[] oTextureGUIDs = this.GetAllFramesTextureGUIDs( );

            if (a_eRegeneration == AnimationClipRegeneration.RegenerateAll ||
                (a_eRegeneration == AnimationClipRegeneration.RegenerateAlsoAtlasIfNeeded &&
                 (globalAtlas.UnappliedSettings || globalAtlas.Contains(oTextureGUIDs) == false)))
            {
                globalAtlas.ApplySettings( );
            }

            globalAtlas.AddTextures(oTextureGUIDs);
        }
        else         // Atlas per frame
        {
            HashSet <Uni2DTextureAtlas> oFrameAtlases = new HashSet <Uni2DTextureAtlas>( );

            for (int iFrameIndex = 0; iFrameIndex < iFrameCount; ++iFrameIndex)
            {
                Uni2DAnimationFrame rFrame      = frames[iFrameIndex];
                Uni2DTextureAtlas   rFrameAtlas = rFrame.atlas;
                if (rFrameAtlas != null)
                {
                    string oFrameTextureGUID = rFrame.textureContainer != null ? rFrame.textureContainer.GUID : null;

                    if (a_eRegeneration == AnimationClipRegeneration.RegenerateAll ||
                        (a_eRegeneration == AnimationClipRegeneration.RegenerateAlsoAtlasIfNeeded &&
                         (rFrameAtlas.UnappliedSettings || rFrameAtlas.Contains(oFrameTextureGUID) == false)))
                    {
                        oFrameAtlases.Add(rFrameAtlas);
                    }

                    rFrameAtlas.AddTextures(new string[1] {
                        oFrameTextureGUID
                    });
                }
            }

            // Regenerate atlases
            foreach (Uni2DTextureAtlas rFrameAtlas in oFrameAtlases)
            {
                rFrameAtlas.ApplySettings( );
            }
        }
    }
Exemple #2
0
    // Apply settings from inspector
    public void ApplySettings(AnimationClipRegeneration a_eRegeneration = AnimationClipRegeneration.RegenerateAlsoAtlasIfNeeded)
    {
        m_eSavedWrapMode    = wrapMode;
        m_fSavedFrameRate   = frameRate;
        m_rSavedGlobalAtlas = globalAtlas;

        if (a_eRegeneration != AnimationClipRegeneration.RegenerateNothing)
        {
            Generate(a_eRegeneration);                  // Generate frames infos (and atlas if needed/asked)

            CopyFrames(frames, m_oSavedFrames);         // frames -> m_oFrames (apply)
        }

        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets( );
    }
Exemple #3
0
    // Generate
    private void Generate(AnimationClipRegeneration a_eRegeneration)
    {
        GenerateAllFramesInfos( );

        GenerateAtlas(a_eRegeneration);
    }
	// Generate atlas
	private void GenerateAtlas( AnimationClipRegeneration a_eRegeneration )
	{
		int iFrameCount = this.FrameCount;

		if( globalAtlas != null ) // global atlas
		{
			string[ ] oTextureGUIDs = this.GetAllFramesTextureGUIDs( );

			if( a_eRegeneration == AnimationClipRegeneration.RegenerateAll
				|| ( a_eRegeneration == AnimationClipRegeneration.RegenerateAlsoAtlasIfNeeded
					&& ( globalAtlas.UnappliedSettings || globalAtlas.Contains( oTextureGUIDs ) == false ) ) )
			{
				globalAtlas.ApplySettings( );
			}

			globalAtlas.AddTextures( oTextureGUIDs );
		}
		else // Atlas per frame
		{
			HashSet<Uni2DTextureAtlas> oFrameAtlases = new HashSet<Uni2DTextureAtlas>( );

			for( int iFrameIndex = 0; iFrameIndex < iFrameCount; ++iFrameIndex )
			{
				Uni2DAnimationFrame rFrame = frames[ iFrameIndex ];
				Uni2DTextureAtlas rFrameAtlas = rFrame.atlas;
				if( rFrameAtlas != null )
				{
					string oFrameTextureGUID = rFrame.textureContainer != null ? rFrame.textureContainer.GUID : null;

					if( a_eRegeneration == AnimationClipRegeneration.RegenerateAll
						|| ( a_eRegeneration == AnimationClipRegeneration.RegenerateAlsoAtlasIfNeeded
							&& ( rFrameAtlas.UnappliedSettings || rFrameAtlas.Contains( oFrameTextureGUID ) == false ) ) )
					{
						oFrameAtlases.Add( rFrameAtlas );
					}
	
					rFrameAtlas.AddTextures( new string[ 1 ]{ oFrameTextureGUID } );
				}
			}

			// Regenerate atlases
			foreach( Uni2DTextureAtlas rFrameAtlas in oFrameAtlases )
			{
				rFrameAtlas.ApplySettings( );
			}
		}
	}
	// Generate
	private void Generate( AnimationClipRegeneration a_eRegeneration )
	{
		GenerateAllFramesInfos( );

		GenerateAtlas( a_eRegeneration );
	}
	// Apply settings from inspector
	public void ApplySettings( AnimationClipRegeneration a_eRegeneration = AnimationClipRegeneration.RegenerateAlsoAtlasIfNeeded )
	{
		m_eSavedWrapMode    = wrapMode;
		m_fSavedFrameRate   = frameRate;
		m_rSavedGlobalAtlas = globalAtlas;
		
		if( a_eRegeneration != AnimationClipRegeneration.RegenerateNothing )
		{
			Generate( a_eRegeneration );	// Generate frames infos (and atlas if needed/asked)

			CopyFrames( frames, m_oSavedFrames );	// frames -> m_oFrames (apply)
		}

		EditorUtility.SetDirty( this );
		AssetDatabase.SaveAssets( );
	}