コード例 #1
0
ファイル: AtlasCache.cs プロジェクト: jhe720311/superboy
    public AtlasMap GetAtlasMapByName(string name)
    {
        AtlasMap am = null;

        scache.TryGetValue(name, out am);
        return(am);
    }
コード例 #2
0
    static void Init()
    {
        m_AtlasInfoDic = new Dictionary <string, AtlasInfo>();
        m_PaddingDic   = new Dictionary <string, Vector4>();
        m_IsPolyDic    = new Dictionary <string, bool>();
        string pathAtlasMap = string.Format("{0}/{1}.asset", UIConfig.PATH_ATLAS_TP, UIConfig.ATLAS_MAP_NAME);

        //加载,todo:多平台加载
        m_AtlasMap = AssetDatabase.LoadAssetAtPath <AtlasMap>(pathAtlasMap);
        m_AtlasMap.Init();
    }
コード例 #3
0
ファイル: AtlasCache.cs プロジェクト: jhe720311/superboy
    protected void _LoadAtlas(GameObject prefab)
    {
        if (scache.ContainsKey(prefab.name))
        {
            return;
        }

        GameObject ao = GameObject.Instantiate(prefab) as GameObject;

        ao.transform.parent = transform;
        AtlasMap am = ao.GetComponent <AtlasMap>();

        cache.Add(prefab, am);
        scache.Add(prefab.name, am);
    }
コード例 #4
0
ファイル: MakeAtlas.cs プロジェクト: jhe720311/superboy
    static void loopAddSprite(DirectoryInfo dirInfo, AtlasMap atlasMap, string fileExt)
    {
        foreach (FileInfo pngFile in dirInfo.GetFiles(fileExt, SearchOption.TopDirectoryOnly))
        {
            string allPath = pngFile.FullName;

            string assetPath = allPath.Substring(allPath.IndexOf("Assets"));

            Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
            if (sprite == null)
            {
                continue;
            }
            atlasMap.AddSprite(sprite);
        }
    }
コード例 #5
0
ファイル: MakeAtlas.cs プロジェクト: jhe720311/superboy
    static private void makeAtlas( )
    {
        string spriteDir = Application.dataPath + "/Resources/Sprite";


        if (!Directory.Exists(spriteDir))
        {
            Directory.CreateDirectory(spriteDir);
        }

        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        DirectoryInfo dirInfo  = new DirectoryInfo(path);
        GameObject    newGo    = null;
        AtlasMap      atlasMap = null;

        FileInfo[] pngs = dirInfo.GetFiles("*.png", SearchOption.TopDirectoryOnly);
        FileInfo[] jpgs = dirInfo.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);
        if (pngs.Length > 0 || jpgs.Length > 0)
        {
            newGo    = new GameObject(dirInfo.Name);
            atlasMap = newGo.AddComponent <AtlasMap>();
        }
        else
        {
            return;
        }

        loopAddSprite(dirInfo, atlasMap, "*.png");
        loopAddSprite(dirInfo, atlasMap, "*.jpg");


        string allPath = spriteDir + "/" + dirInfo.Name + ".prefab";

        if (File.Exists(allPath))
        {
            File.Delete(allPath);
        }

        string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));

        PrefabUtility.CreatePrefab(prefabPath, newGo);

        GameObject.DestroyImmediate(newGo);
    }
コード例 #6
0
ファイル: AtlasCache.cs プロジェクト: jhe720311/superboy
    AtlasMap GetAtlasMap(GameObject prefab)
    {
        AtlasMap am = null;

        if (cache.TryGetValue(prefab, out am))
        {
            return(am);
        }

        GameObject ao = GameObject.Instantiate(prefab) as GameObject;

        ao.transform.parent = transform;
        am = ao.GetComponent <AtlasMap> ();
        if (am == null)
        {
            Debug.LogError("can not get atlias map from prefab");
            return(null);
        }
        cache.Add(prefab, am);
        return(am);
    }
コード例 #7
0
ファイル: AtlasEditor.cs プロジェクト: SingleShadowBlade/LOE
    static private void CreateAtlasMap()
    {
        var files = GetAtlasPath();

        //create atlas map asset
        foreach (var f in files)
        {
            var asset = AssetDatabase.LoadAllAssetsAtPath(f);
            var name  = System.IO.Path.GetFileName(f);
            name = name.Replace(".png", ".asset");
            var           allAtlasMap = AtlasMap.CreateInstance <AtlasMap>();//m_kAtlasAssetPath + name
            List <Sprite> sps         = new List <Sprite>();
            foreach (var o in asset)
            {
                if (o is Sprite)
                {
                    sps.Add((Sprite)o);
                }
            }

            allAtlasMap.spriteNames = new List <int>(sps.Count);
            allAtlasMap.sprites     = new Sprite[sps.Count];
            // allAtlasMap.texture = (Texture)AssetDatabase.LoadAssetAtPath(f, typeof(Texture));
            for (int i = 0; i < sps.Count; i++)
            {
                var sprite = sps[i];
                int hash   = Animator.StringToHash(sprite.name);
                allAtlasMap.spriteNames.Add(hash);
                allAtlasMap.sprites[i] = sprite;
            }

            string assetPath = m_kAtlasAssetPath + name;
            AssetDatabase.CreateAsset(allAtlasMap, assetPath);
            AssetDatabase.SaveAssets();
        }
        // var allAtlasMap =  AtlasMap.CreateInstance(m_kAtlasAssetPath);
        // read atlas info
    }