1

I'm surfing lot in google and spending more time but couldn't find the solution.

I tried converting PNG to bytes[] then attaching but no solution I found.

I have two PNG file one is full of Props like Hair, Dresses, Hand Glow, etc,.. another is undressed character. How to implement to show Glow, Hair and Dressed up Character. Simply I planned to Drag and Drop, Drag the hair and drop on head of the character to show.

How could I merge part of PNG[Hair, Glow, Dress..] file and drop on another Part of PNG[Head. Hand, Body...] file.

Shall I split different PNG files like Hair part alone, Glow part alone, Dress part alone.

Which is best way to do this Please give some link or project for reference or give some idea theoretically

NOTE: This only in 2D[PNG images] not 3D characters or materials.

Please refer this image enter image description here

Rasa Mohamed
  • 882
  • 1
  • 6
  • 14

1 Answers1

2

You don't want to merge them, you want to make them overlap.

public class CharacterSprite:MonoBehaviour{
    public Vector2 position;
    public Item itemValue;
}
public enum Item{ None, Hat, Eyes, Mouth,...}

Your character would have a ItemController:

public class ItemController:MonoBehaviour
{
    private CharacterSprite hat
    public void SetItem(CharacterSprite shSp){
       switch(shSp.itemValue){
          case Item.Hat:
              this.hat.gameObject.SetActive(false);
              this.shSp.gameObject.SetActive(true);
              this.hat = shSp;
              break;
          // other cases
       }
    }
}

This method would swap the current off and put the new one on.

But the layer on the SpriteRenderer is the important one there as you would expect the body to be 0, hair is 1 maybe eyes over the hair so 2 then the clothes and hats are 3 (maybe eyebrows are over hats, dunno), weapons should be seen over it all so 10 (this gives some leeway for other items in between).

I would consider this approach faster, safer and saving memory since you are keeping your sprites are they are and you are only overlapping them. You can easily make unique sprites from your atlas using the SpriteEditor. You just need to make your sprite as multiple.

Everts
  • 10,408
  • 2
  • 34
  • 45
  • 1
    Appreciates. how could I took sprite away from particular part of png i mean hair alone from png. consider now i apply a character to plane, we take dresses alone, 9 dresses are there, it would change one after one by pressing 'N' key. – Rasa Mohamed Dec 21 '15 at 15:46
  • how should we create sprite and taken from png. – Rasa Mohamed Dec 21 '15 at 15:48
  • 1
    Take a look at the SpriteEditor, you will be amazed of what you can do in no time. Upload the whole atlas with all sprites in one to unity and start cutting in smaller parts. You can define size and even better, the pivot point which defines the positioning. http://docs.unity3d.com/Manual/SpriteEditor.html – Everts Dec 21 '15 at 15:49
  • By your instruction I reached almost, One more prob `Cusortexture = GetComponent().sprite.texture; Cursor.SetCursor(Cusortexture, Vector2.zero, CursorMode.Auto); ` while mouse drag and drop i'm changing cursor as dress but what i'm getting is the whole PNG is changed as cursor not that particular dress. any help @fafase – Rasa Mohamed Dec 22 '15 at 10:04
  • Yep, coz the texture is the whole thing while the sprite uses a UV map to only consider the corresponding part of the texture. I would not change the cursor, more likely hide/show it and instead have a sprite with the current sprite following the mouse position. So you would hide it when you select a cloth, enable a sprite at mouse position, with selected cloth on it and following mouse position. Got it? – Everts Dec 22 '15 at 12:28
  • Hey @fafase, I'm almost near to finish now stucking in this part. Just I'm assigning diff. Sprite for diff. gamobjt in scene eg. Eye, Nose, Mouth for different GmObjt. how can I initiate Eye, Nose, Mouth in next scene. two levels for Face and Dress – Rasa Mohamed Dec 30 '15 at 18:06
  • If you mean you need to select in one scene and use the selection in another scene, you should store the selection in PlayerPrefs and retrieve all choices in next scene. I made a post a while ago on that topic, you can have a look https://unitygem.wordpress.com/leaderboard-and-saving-data/ – Everts Dec 30 '15 at 18:11
  • Great work fafase. I'll go through and get back with good result – Rasa Mohamed Dec 30 '15 at 18:17
  • Go to the unitygem blog page and then to the facebook page. You can use the PM from there. I will look at what you have to ask tomorrow :). – Everts Jan 17 '16 at 21:30