Author Topic: Load SpriteRenderers From Atlas?  (Read 10890 times)

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #15 on: August 11, 2014, 04:01:52 AM »
Yes. Thanks.
But if the 2DSprite also can use the way to be changed as UISprite ? By using  something like Atlas for sprite to change 2D Sprite ?
My Idea is In 2DUISprite has one member, this member is one list of Unity 2DSprite, just like Atlas for UISprite. By change the name to change the 2DUISprite.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Change2DSprite : MonoBehaviour
{
    public List<Sprite> SpriteListAtlas = new List<Sprite>();
    public UI2DSprite mySprite;
    void Change2DSprite(string newSpriteName)
    {
        for (int i = 0; i < SpriteListAtlas.Count; i++)
        {
            if (SpriteListAtlas.name == newSpriteName)
            {
                mySprite.sprite2D = SpriteListAtlas;
            }
        }
    }

}
 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #16 on: August 12, 2014, 12:15:07 AM »
A 2D sprite atlassing is what Unity does under the hood and is completely invisible to you (although Window -> Sprite Packer lets you view them). It's like saying you want an atlas of Texture2D types. Well, that's UIAtlas for you. If you want an atlas with a list of sprites inside, you'll need to use an NGUI atlas or keep your own list.

Also... Resources.Load<UnityEngine.Sprite>("your sprite texture");

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #17 on: September 09, 2014, 08:01:46 PM »
Hi

When I tried the panel (shrunk down to 0.01) and then added the sprite game object below it I ran into a problem.

It was still rendering the sprite on the UI camera as a UI element. Am I missing something else?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load SpriteRenderers From Atlas?
« Reply #18 on: September 10, 2014, 01:15:59 AM »
Layer of the game object is what controls which camera will draw it.