示例#1
0
    public static MeshSprite Create(Transform parent, Vector3 position, Vector2 size, Material material, bool mirrorHorizontal = false, bool mirrorVertical = false)
    {
        GameObject spriteObject = new GameObject();

        spriteObject.name = "sprite";
        if (parent != null)
        {
            spriteObject.transform.parent = parent;
            spriteObject.layer            = parent.gameObject.layer;
        }
        spriteObject.transform.localPosition = position;

        MeshSprite sprite = spriteObject.AddComponent <MeshSprite>();

        sprite.UV = new Rect(0, 0, 1, 1);
        if (mirrorHorizontal)
        {
            sprite.UV.x     = 1;
            sprite.UV.width = -1;
        }
        if (mirrorVertical)
        {
            sprite.UV.y      = 1;
            sprite.UV.height = -1;
        }
        sprite.spriteScale = size;
        sprite.material    = material;
        if (material.HasProperty("_color"))
        {
            sprite.color = material.color;
        }
        return(sprite);
    }
    static public void AddSprite()
    {
        //Instantiate
        GameObject meshspriteobj = new GameObject();

        meshspriteobj.name = "meshspriteobj";
        MeshSprite spriteobj = meshspriteobj.AddComponent <MeshSprite> ();

        meshspriteobj.GetComponent <Renderer> ().material = new Material(Shader.Find("Unlit/Transparent"));

        spriteobj.meshSpriteMaker = CWALKSettingTools.S_MeshSpriteMaker;
    }