コード例 #1
0
        void LoadSpriteProxy(string name)
        {
            GameObject go = Resources.Load <GameObject>(string.Format("SpriteProxy/{0}", name));

            if (go == null)
            {
                return;
            }
            SpriteProxy proxy = go.GetComponent <SpriteProxy>();
            Dictionary <string, Sprite> dict = new Dictionary <string, Sprite>();

            foreach (Sprite s in proxy.sprites)
            {
                dict.Add(s.name, s);
            }
            _sprites.Add(name, dict);
        }
コード例 #2
0
        static void ReloadAndProxyAssets()
        {
            string spPath   = "Assets/Resources/";
            string spFolder = "SpriteProxy";

            if (!AssetDatabase.IsValidFolder(spPath + spFolder))
            {
                AssetDatabase.CreateFolder(spPath, spFolder);
            }
            string     spMgrResPath = spFolder + "/SpriteProxyManager";
            string     spMgrPath    = spPath + spMgrResPath + ".prefab";
            GameObject spMgrGO      = Resources.Load <GameObject>(spMgrResPath);

            if (spMgrGO == null)
            {
                spMgrGO = new GameObject("SpriteProxyManager", typeof(SpriteProxyManager));
                PrefabUtility.CreatePrefab(spMgrPath, spMgrGO);
            }
            SpriteProxyManager spMgr = spMgrGO.GetComponent <SpriteProxyManager>();

            foreach (KeyValuePair <string, KeyValuePair <string, bool> > pair in SpriteProxy)
            {
                KeyValuePair <string, bool> p = pair.Value;
                if (p.Value)
                {
                    string []  fileEntries = Directory.GetFiles(Application.dataPath + p.Key);
                    string     spGOResPath = spFolder + "/" + pair.Key;
                    string     spGOPath    = spPath + spGOResPath + ".prefab";
                    GameObject go          = Resources.Load <GameObject>(spGOResPath);
                    if (fileEntries.Length > 0)
                    {
                        if (go == null)
                        {
                            go = new GameObject(pair.Key, typeof(SpriteProxy));
                            go = PrefabUtility.CreatePrefab(spGOPath, go);
                        }
                        SpriteProxy sp = go.GetComponent <SpriteProxy>();
                        sp.sprites.Clear();
                        foreach (string fileName in fileEntries)
                        {
                            int    index     = fileName.LastIndexOf("/");
                            string localPath = "Assets" + p.Key + fileName.Substring(index);
                            Sprite s         = AssetDatabase.LoadAssetAtPath <Sprite>(localPath);
                            if (s != null)
                            {
                                sp.sprites.Add(s);
                            }
                        }
                        if (!spMgr.SpriteProxies.Contains(pair.Key))
                        {
                            spMgr.SpriteProxies.Add(pair.Key);
                        }
                    }
                    else
                    {
                        if (go != null)
                        {
                            AssetDatabase.DeleteAsset(spGOPath);
                            spMgr.SpriteProxies.Remove(pair.Key);
                        }
                    }
                }
            }
            if (SpriteProxy.Count > 0)
            {
                string str = "";
                foreach (KeyValuePair <string, KeyValuePair <string, bool> > pair in SpriteProxy)
                {
                    str += pair.Key + ": ";
                    KeyValuePair <string, bool> p = pair.Value;
                    str += string.Format("({0}, {1})", p.Key, p.Value) + ", ";
                }
                Debug.Log(str);
            }
        }