• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by superp · Aug 29, 2014 at 07:37 AM · animation

have to keep png files for animation?

I created animation within Unity using series of png files. It is about 10 seconds long, but things in it move faster so there are many png files making up that 10 seconds. there are about 10 animations created this way. the resources folder that contain png files is now about 100mb. Is there a way to reduce its size other than reducing quality of png files?

also, do i have to keep png files around or is there a way to compress that to a single file in Unity?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hav_ngs_ru · Aug 29, 2014 at 07:54 AM

Actually, unity compresses your files when build project, and final weight depends on your project setting (it may recompress your PNGs to any other format for you).

To compress all frames in one file you may use atlases (one image with many frames, frames switches by changing UV coordinates). My solution to use such animations is below:

 using UnityEngine;
 using System.Collections;
 
 // spritesheet textures animations controller
 public class AnimatedTextureController : _MonoBehaviour {
     public float animationCycleTime;
     public int texTilesX, texTilesY;
     public bool autoPlay;
     public bool billboardingOn = false;
     
     protected Renderer animatedRenderer;
     protected Transform cameraTransform;
     protected bool stopSignal;
     protected bool isPlaying;
     protected bool playOnce;
 
     public virtual void Play(bool in_playOnce = false) {
         //Debug.Log ("PLAY: isPlaying="+isPlaying+"  stopSignal="+stopSignal);
         playOnce = in_playOnce;
         if(!isPlaying) {
             stopSignal = false;
             StartCoroutine(AnimateTexture());        
         }
     }
     public virtual void PlayOnce() {
         Play(true);    
     }    
     public virtual void Stop() {
         //Debug.Log ("STOP: isPlaying="+isPlaying+"  stopSignal="+stopSignal);
         if(isPlaying)
             stopSignal = true;
     }
     public virtual bool IsPlaying() {
         return isPlaying;
     }
     // ----------
     protected virtual void Awake () {
         InitController();
         ApplyScale(new Vector2(1.0f / texTilesX, 1.0f / texTilesY));
 
         isPlaying = false;
         stopSignal = false;
     }
     protected virtual void Start() {
         if(autoPlay)
             Play ();
     }
     protected virtual void InitController() {
         cameraTransform = Camera.main.transform;
         animatedRenderer = renderer;
         animatedRenderer.enabled = false;
     }
 
     private IEnumerator AnimateTexture() {
         AnimationEnable ();
         isPlaying = true;
         for(int i = texTilesY-1; i>-1 && !stopSignal; i--) {
             for(int j = 0; j < texTilesX && !stopSignal; j++) {
                 ApplyOffset(new Vector2(1.0f / texTilesX * j, 1.0f / texTilesY * i));
                 yield return new WaitForSeconds(animationCycleTime / (texTilesX * texTilesY)); 
                 if(i == 0 && j == texTilesX-1 && !playOnce) //reset cycle, if !playOnce
                     i = texTilesY; 
             }
         }
         AnimationDisable();
         isPlaying = false;
         stopSignal = false;
         OnFinish();
     }
     
     protected virtual void AnimationEnable() {
         animatedRenderer.enabled = true;
     }
     protected virtual void AnimationDisable() {
         animatedRenderer.enabled = false;
     }
     protected virtual void ApplyOffset(Vector2 offset) {
         animatedRenderer.material.mainTextureOffset = offset;
     }
     protected virtual void ApplyScale(Vector2 scale) {
         animatedRenderer.material.mainTextureScale = scale;
     }
             
             
     protected virtual void Update() {
         if(billboardingOn) 
             transform.rotation = cameraTransform.rotation;
     }
 
     protected virtual void OnFinish() {
     }    
     
     
 
 }
 


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

How to select an animation clip by index number? 7 Answers

Handling Build-up of Root Motion Errors Over Time 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges