Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by hunvee3 · Nov 06, 2016 at 02:38 PM · texture2dparticlesystemgeneratedynamicallypacktextures

One Texture2D from multiple others

Hi guys!, I've been struggling to find a proper way to create a new Texture2D based on multiple others.

The Idea is that I dynamically load up a list of Textures2D form a certain folder (that's done). so I have this list of textures. What I want to do is to create a new Texture that has every texture on the list in such a way that it has 1 column and X rows where X is the count of the list.

That way I'll end up having one texture with every texture of the list in 1 column and I can use this to create a particles system.

So the problem is generating this master texture.

Can anybody help me do this?. Thanks!

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 hunvee3 · Feb 16, 2017 at 07:13 PM

alt textHello guys, for those who are following this question, I managed to solve this. It a little tricky though.

I'll leave you here the method that I use to create a master image. This is, it takes all pngs (you can modify this) files on the parameters path and merge them into one master png inside a folder called "output". The png files dont have to be the same width or height, but I recommend them to be. The resoulting image will be a png with 1 column and X rows. Its heght will be the sum of all the heights and the width will be the larger of them all. [See the pic]

I hope this helps.

 using System.Collections.Generic;
 using System.Drawing;  
 
   public static Texture2D MergeImages(string path)
     {
         string[] filesStrings = null;
         List<Image> images = new List<Image>();
         Bitmap outputImage = null;
         Texture2D outputtexture = null;
 
         if (path != null && path != "" && path != " " && System.IO.Directory.Exists(path))
         {
             filesStrings = System.IO.Directory.GetFiles(path, "*.png");
             Debug.Log(filesStrings.Length);
         }
         if (filesStrings.Length > 0)
         {
             int outputwidth = 0;
             int outputheight = 0;
             foreach (string filestring in filesStrings)
             {
                 Image imageToAdd = Image.FromFile(filestring);
                 images.Add(imageToAdd);
                 outputheight += imageToAdd.Height;
                 if (imageToAdd.Width > outputwidth)
                     outputwidth = imageToAdd.Width;
             }
             outputImage = new Bitmap(outputwidth, outputheight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
             using (System.Drawing.Graphics graphics = (System.Drawing.Graphics.FromImage(outputImage)))
             {
                 graphics.DrawImage(images[0], new Rectangle(new Point(), images[0].Size),
                     new Rectangle(new Point(), images[0].Size), GraphicsUnit.Pixel);
             }
             int heightAcum = images[0].Height;
             for (int i = 1; i < images.Count; i++)
             {
                 using (System.Drawing.Graphics graphics = (System.Drawing.Graphics.FromImage(outputImage)))
                 {
                     graphics.DrawImage(images[i], new Rectangle(new Point(0, heightAcum), images[i].Size),
                         new Rectangle(new Point(), images[i].Size), GraphicsUnit.Pixel);
                 }
                 heightAcum += images[i].Height;
             }
             path = path + "/Output";
             if (System.IO.Directory.Exists(path))
             {
                 System.IO.Directory.Delete(path, true);
                 System.IO.Directory.CreateDirectory(path);
             }
             else
             {
                 System.IO.Directory.CreateDirectory(path);
             }
             outputImage.Save(path + "/particlesMerge.png", System.Drawing.Imaging.ImageFormat.Png);
 
             outputtexture = LoadTexture(path)[0];
 
         }
 
         return outputtexture;
     }



untitled.png (170.6 kB)
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.

Follow this Question

Answers Answers and Comments

79 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How To change the 3DstartRotation of a ParticleSystem, using another GameObject Rotation? 1 Answer

how to make particle system collide with each other? 1 Answer

SetActive(true) restarts the particle emission 1 Answer

Particle System - Project objects not visible in the 'Select Mesh' window under 'Renderer' 0 Answers

Moving a singular particle to the cursor 0 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