コード例 #1
0
    private static Rect getSize(TPAtlasTexture tx)
    {
        Rect r = new Rect();

        float biggestSide;

        if (tx.width > tx.height)
        {
            biggestSide = tx.width;
        }
        else
        {
            biggestSide = tx.height;
        }


        float scale = TexturePackerStyles.TEXTURE_RECT_SIZE / biggestSide;

        r.width  = tx.width * scale;
        r.height = tx.height * scale;


        r.x = (TexturePackerStyles.TEXTURE_RECT_SIZE - r.width) / 2f + box_padding;
        r.y = (TexturePackerStyles.TEXTURE_RECT_SIZE - r.height) / 2f + box_padding;


        return(r);
    }
コード例 #2
0
	void Awake() {
		play = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("play");
		
		//Warning to Get Texture2D from atlas, should remain the same size which was generated,
		//that's why we using another atlas here
		unityTexture = TPackManager.getAtlas(Atlases.EXAMPLE2).getUnityTexture("play");
	}
コード例 #3
0
ファイル: TPAtlas.cs プロジェクト: stervets/bomber
    //--------------------------------------
    // INITIALIZE
    //--------------------------------------

    public TPAtlas(string json, Texture atlas, string name)
    {
        _atlas = atlas;
        _name  = name;

        IDictionary JSON   = TPMiniJSON.Json.Deserialize(json) as IDictionary;
        IDictionary frames = JSON["frames"] as IDictionary;

        IDictionary meta = JSON["meta"] as IDictionary;
        IDictionary size = meta["size"] as IDictionary;

        _height = System.Convert.ToSingle(size["h"]);
        _width  = System.Convert.ToSingle(size["w"]);

        _meta           = new TPMeta();
        _meta.atlasSize = new Size2D(_width, _height);
        _meta.imageSize = new Size2D(atlas.width, atlas.height);
        _meta.scale     = System.Convert.ToSingle(meta["scale"]);
        _meta.format    = System.Convert.ToString(meta["format"]);


        TPAtlasTexture f;

        foreach (string cKey in frames.Keys)
        {
            f = new TPAtlasTexture(cKey, frames[cKey] as IDictionary <string, System.Object>, this);
            _frames.Add(cKey, f);
        }
    }
コード例 #4
0
ファイル: TPMeshAnimation.cs プロジェクト: guerre50/sTreeps
 protected virtual void applayUV()
 {
     if (frames.Length > 0)
     {
         TPAtlasTexture tx = getTexture(frames[0]);
         showFrame(tx);
     }
 }
コード例 #5
0
ファイル: AtlasGUIExample.cs プロジェクト: guerre50/sTreeps
    void Awake()
    {
        play = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("play");

        //Warning to Get Texture2D from atlas, should remain the same size which was generated,
        //that's why we using another atlas here
        unityTexture = TPackManager.getAtlas(Atlases.EXAMPLE2).getUnityTexture("play");
    }
コード例 #6
0
    //--------------------------------------
    // PUBLIC METHODS
    //--------------------------------------

    public static Rect RenderNode(int index, TPAtlas antlas, string name)
    {
        Vector2 itemPos = new Vector2();

        itemPos.y = 25f;

        if (index + 1 > colItemsCount)
        {
            itemPos.y += Mathf.FloorToInt(index / colItemsCount) * TexturePackerStyles.TEXTURE_RECT_SIZE * 1.7f;
            index      = index % colItemsCount;
        }

        itemPos.x = itemsSpace / 2f + (index) * (itemsSpace + box_size);



        GUILayout.BeginArea(new Rect(itemPos.x, itemPos.y, box_size, box_size * 2f), ""); {
            if (TexturePackerAtlasEditor.selection.Contains(name))
            {
                drawColordeBox(box_size, box_size, Color.green);

                /*	GUILayout.BeginArea (new Rect (box_padding, box_padding  , TexturePackerStyles.TEXTURE_RECT_SIZE, TexturePackerStyles.TEXTURE_RECT_SIZE), ""); {
                 *              drawColordeBox (TexturePackerStyles.TEXTURE_RECT_SIZE, TexturePackerStyles.TEXTURE_RECT_SIZE);
                 *      } GUILayout.EndArea ();
                 */
            }
            else
            {
                drawColordeBox(box_size, box_size);
            }


            TPAtlasTexture tx = antlas.getTexture(name);
            tx.draw(getSize(tx), true);


            string texNmae = string.Empty;

            if (TPEditorData.isExtensionsEnabled)
            {
                texNmae = tx.name;
            }
            else
            {
                texNmae = tx.nameNoExtention;
            }


            string imageInfo = texNmae + "\n(" + tx.width + "x" + tx.height + ")";
            GUILayout.Label(imageInfo, TexturePackerStyles.imageLableStyle, TexturePackerStyles.FixedWidthHeight(110f, 40f));
        } GUILayout.EndArea();



        return(new Rect(itemPos.x, itemPos.y, box_size, box_size));
    }
コード例 #7
0
    public void showFrame(int index)
    {
        if (frames.Count == 0)
        {
            GetComponent <Renderer>().material = null;
            return;
        }
        //index--;
        TPFameInfo frame = frames[index];


        meshTexture.atlas   = frame.atlasPath;
        meshTexture.texture = frame.textureName;

        GetComponent <Renderer>().material = GetMaterial(frame.atlasPath);

        meshTexture.applayUV();

        TPAtlasTexture texture = GetAtlasTExture(index);
        Vector3        size    = new Vector3();

        size.x = texture.spriteSourceSize.w;
        size.y = texture.spriteSourceSize.h;
        size.z = size.x;

        transform.localScale = size / texture.scale;

        Vector3 pos = new Vector3();

        pos.x = texture.spriteSourceSize.x - texture.sourceSize.w * anim.pivotCenterX;
        pos.y = -texture.spriteSourceSize.y + texture.sourceSize.h * anim.pivotCenterY;
        pos.z = 0;

        transform.localPosition = pos / texture.scale;

        if (meshTexture.originalMesh.name.Equals("TPPlaneCentred"))
        {
            Vector3 p = transform.localPosition;
            p.y -= transform.localScale.y / 2f;
            p.x += transform.localScale.x / 2f;
            transform.localPosition = p;
        }

        if (index == 0)
        {
            _textureName = texture.nameNoExtention;
        }

        if (opacity != 1f)
        {
            materialColor.a = opacity;
            color           = materialColor;
        }
    }
コード例 #8
0
ファイル: TPAtlas.cs プロジェクト: stervets/bomber
    public TPAtlasTexture getTexture(string textureName)
    {
        TPAtlasTexture tx = findTexture(textureName);

        if (tx == null)
        {
            Debug.LogWarning("Texture " + textureName + " not found in " + _name + " atlas");
        }

        return(tx);
    }
コード例 #9
0
ファイル: AtlasGUIExample.cs プロジェクト: guerre50/sTreeps
    void OnGUI()
    {
        play.draw(new Rect(0, 0, play.width * 0.5f, play.height * 0.5f));

        play.draw(new Rect(0, 75, play.width, play.height));

        GUI.DrawTexture(new Rect(0, 225, unityTexture.width, unityTexture.height), unityTexture);


        TPAtlasTexture tex = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("f_share");

        tex.draw(new Rect(200, 0, 122, 42));


        TPackManager.getAtlas(Atlases.EXAMPLE).draw(new Rect(200, 100, 122, 42), "t_share.png");
    }
コード例 #10
0
    //--------------------------------------
    // PRIVATE METHODS
    //--------------------------------------

    protected void showFrame(TPAtlasTexture texture)
    {
        Rect frame;

        if (texture == null)
        {
            frame = new Rect(0, 0, 1, 1);
        }
        else
        {
            if (texture.isRotated)
            {
                frame = new Rect();

                frame.x      = 0 - texture.coords.y - texture.coords.height;
                frame.y      = texture.coords.x;
                frame.width  = texture.coords.height;
                frame.height = texture.coords.width;
                isRotated    = true;
            }
            else
            {
                frame     = texture.coords;
                isRotated = false;
            }
        }


        if (useSharedMesh && Application.isPlaying)
        {
            if (storedMeshes.Contains(original) || storedMeshes.Contains(sharedMesh))
            {
                return;
            }
            else
            {
                storedMeshes.Add(original);
            }
        }



        setTile(frame.width, frame.height);
        setOffset(frame.x, frame.y);
    }
コード例 #11
0
ファイル: TPAtlas.cs プロジェクト: stervets/bomber
    public Texture2D getUnityTexture(string textureName)
    {
        if (_unityTextures.ContainsKey(textureName))
        {
            return(_unityTextures[textureName]);
        }

        TPAtlasTexture tx = findTexture(textureName);

        if (tx == null)
        {
            Debug.LogWarning("Texture " + textureName + " not found in " + _name + " atlas");
            return(null);
        }

        _unityTextures.Add(textureName, tx.generateTexture());

        return(_unityTextures[textureName]);
    }
コード例 #12
0
    void Awake()
    {
        anim       = TPGUIAnimation.Create();
        Scaledanim = TPGUIAnimation.Create();

        for (int i = 1; i < 7; i++)
        {
            TPAtlasTexture frame = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("fireball_000" + i.ToString());
            anim.addFrame(frame);
            Scaledanim.addFrame(frame);
        }

        anim.pos  = new Vector2(200, 200);
        anim.loop = true;
        anim.fps  = 25;
        anim.Play();

        Scaledanim.pos   = new Vector2(300, 200);
        Scaledanim.loop  = true;
        Scaledanim.fps   = 25;
        Scaledanim.scale = 0.5f;
        Scaledanim.Play();
    }
コード例 #13
0
ファイル: TPGUIAnimation.cs プロジェクト: guerre50/sTreeps
 public void addFrame(TPAtlasTexture texture)
 {
     frames.Add(texture);
     _totalFrames = frames.Count;
 }
コード例 #14
0
	private static Rect getSize(TPAtlasTexture tx) {
		Rect r = new Rect ();

		float biggestSide;
		if(tx.width > tx.height) {
			biggestSide = tx.width;
		} else {
			biggestSide = tx.height;
		}


		float scale = TexturePackerStyles.TEXTURE_RECT_SIZE / biggestSide;

		r.width = tx.width * scale;
		r.height = tx.height * scale;
		
	
		r.x = (TexturePackerStyles.TEXTURE_RECT_SIZE - r.width) / 2f  + box_padding;
		r.y = (TexturePackerStyles.TEXTURE_RECT_SIZE - r.height) / 2f + box_padding;
	

		return r;
	}
コード例 #15
0
ファイル: OmniAnimation.cs プロジェクト: jwatsn/OmniDigUnity
    void OnEnable()
    {
        atlas = TPackManager.getAtlas ("World");
        aTexture = atlas.getTexture(atlas.frameNames [index]);
        //aTexture.calculateVars();

        boundsTexture = atlas.getTexture("MAT_Dirt");
    }
コード例 #16
0
ファイル: TPMeshTexture.cs プロジェクト: guerre50/sTreeps
    public virtual void applayUV()
    {
        TPAtlasTexture tx = getTexture(texture);

        showFrame(tx);
    }