示例#1
0
        public static AssetDesc CreateDesc(string assetPath)
        {
            string unixStyle = SysUtil.ToUnixPath(SysUtil.TrimHeadTailSeparators(assetPath));
            string filename  = Path.GetFileNameWithoutExtension(unixStyle);
            string ext       = Path.GetExtension(unixStyle);

            if (string.IsNullOrEmpty(filename))
            {
                Logging.Instance.Log("CreateDesc() failed (invalid asset path): {0}.", assetPath);
                return(null);
            }

            string fullpath = Path.Combine(GState.AssetRoot, SysUtil.ToWindowsPath(unixStyle));

            if (!File.Exists(fullpath))
            {
                Logging.Instance.Log("CreateDesc() failed (file not found): {0}.", assetPath);
                return(null);
            }

            string digest = SysUtil.GetFileMD5AsString(fullpath);

            if (string.IsNullOrEmpty(digest))
            {
                Logging.Instance.Log("CreateDesc() failed (md5 calculating failed): {0}.", fullpath);
                return(null);
            }

            AssetType type = AssetType.Unknown;

            if (ext.ToLower() == "png")
            {
                type = AssetType.PNG;
            }

            AssetDesc desc = new AssetDesc();

            desc.LinkTime = DateTime.Now;
            desc.Name     = filename + "_" + desc.LinkTime.ToString("yyyyMMdd_HHmmss");
            desc.Type     = type;
            desc.Path     = unixStyle;
            desc.Digest   = digest;
            return(desc);
        }
示例#2
0
        public static TextureRenderInfo BuildSingleTexture(Gwen.Renderer.Tao renderer, string url)
        {
            if (!ResProtocol.IsSingleTexture(url))
            {
                return(null);
            }

            AssetDesc desc = Scene.Instance.GetAssetDesc(url);

            if (desc == null)
            {
                return(null);
            }

            string fullpath = Path.Combine(GState.AssetRoot, SysUtil.ToWindowsPath(desc.Path));

            if (!File.Exists(fullpath))
            {
                return(null);
            }

            Gwen.Texture t;
            t = new Gwen.Texture(renderer);
            if (t == null)
            {
                return(null);
            }

            t.Load(fullpath);
            if (t.Failed)
            {
                return(null);
            }

            TextureRenderInfo tri = new TextureRenderInfo();

            tri.u1      = 0;
            tri.v1      = 0;
            tri.u2      = 1;
            tri.v2      = 1;
            tri.texture = t;
            return(tri);
        }
示例#3
0
        public static Size GetImageSize(string assetPath)
        {
            string fullpath = Path.Combine(GState.AssetRoot, SysUtil.ToWindowsPath(assetPath));

            if (!File.Exists(fullpath))
            {
                Logging.Instance.Log("CreateDesc() failed (file not found): {0}.", assetPath);
                return(Size.Empty);
            }

            try
            {
                return(Image.FromFile(fullpath).Size);
            }
            catch (Exception)
            {
                return(Const.ZERO_SIZE);
            }
        }