//-------------------------------------------------------------------------------------------------------------
    //
    //-------------------------------------------------------------------------------------------------------------
    IEnumerator LoadAssetPatchInfo(string url)
    {
        WWW www = new WWW(url);

        // Wait for download to complete
        yield return(www);

        if (www.size == 0)
        {
            dfInterfaceManager.Instance.UpdatePatchStateString("패치정보를 찾을 수 없습니다.");

            dfGameManager.Instance.PatchEnd();

            yield break;
        }


        XMLInStream inStream = new XMLInStream(www.text);

        int assetBundleCount = 0;

        inStream.List("assetbundleinfo", delegate(XMLInStream countStream)
        {
            countStream.Content("count", out assetBundleCount);
        });

        inStream.List("assetbundle", delegate(XMLInStream bundleInfoStream)
        {
            AssetBundleInfo bundleInfo = new AssetBundleInfo();

            bundleInfoStream.Content("bundlename", out bundleInfo._bundleName);
            bundleInfoStream.Content("objectname", out bundleInfo._objectName);
            bundleInfoStream.Content("objecttype", out bundleInfo._objectType);
            bundleInfoStream.Content("version", out bundleInfo._version);


            _assetBundelInfoList.Add(bundleInfo);
        });

        if (assetBundleCount != _assetBundelInfoList.Count)
        {
            //출력 - 패치정보가 올바르지 않습니다.

            yield break;
        }

        if (_assetBundelInfoList.Count > 0)
        {
            StartCoroutine(LoadBundleCoroutine());
        }
    }
Esempio n. 2
0
    static void BuildAllUnits()
    {
        DirectoryInfo dInfo = new DirectoryInfo("Assets/ExternalRes/Unit");

        if (!dInfo.Exists)
        {
            Debug.Log("不存在目录");
            return;
        }
        DirectoryInfo assetDire = new DirectoryInfo(".");

        //读取配置文件
        Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>();
        TextAsset   textAsset = AssetDatabase.LoadAssetAtPath("Assets/ExternalRes/Config/UnitConfig.xml", typeof(TextAsset)) as TextAsset;
        XMLInStream stream    = new XMLInStream(textAsset.text);

        stream.List("item", delegate(XMLInStream itemStream)
        {
            UnitConfig ufg = new UnitConfig(itemStream);
            if (!UnitConfigs.ContainsKey(ufg.ResourceIcon))
            {
                UnitConfigs.Add(ufg.ResourceIcon, ufg);
            }
        });

        DirectoryInfo[] unitsDires = dInfo.GetDirectories();
        for (int i = 0, n = unitsDires.Length; i < n; i++)
        {
            dInfo = unitsDires[i];
            FileInfo[] fileInfoArr = dInfo.GetFiles("*_SkeletonData.asset");
            for (int j = 0, m = fileInfoArr.Length; j < m; j++)
            {
                FileInfo fInfo = fileInfoArr[j];
                //Debug.Log(fInfo.FullName);
                //Debug.Log(fInfo.Name);
                string relativePath = fInfo.FullName.Replace(assetDire.FullName, "");
                relativePath = relativePath.Remove(0, 1);
                //Debug.Log("relativePath=" + relativePath);
                Object o = AssetDatabase.LoadAssetAtPath(relativePath, typeof(Object));

                if (o == null)
                {
                    Debug.LogWarning("null");
                }
                string guid     = AssetDatabase.AssetPathToGUID(relativePath);
                string skinName = EditorPrefs.GetString(guid + "_lastSkin", "");

                if (!UnitConfigs.ContainsKey(dInfo.Name))
                {
                    Debug.LogFormat("{0},没有相关配置,忽略", dInfo.Name);
                    continue;
                }

                Debug.LogFormat("正在处理 name={0}", dInfo.Name);
                UnitConfig ufg = UnitConfigs[dInfo.Name];

                try
                {
                    if (ufg.isEnemy)
                    {
                        InstantiateSkeletonEnemy((SkeletonDataAsset)o, skinName);
                    }
                    else
                    {
                        InstantiateSkeletonUnit((SkeletonDataAsset)o, skinName);
                    }
                }
                catch (System.Exception e)
                {
                    Debug.LogFormat("{0} 处理失败,重新处理。msg={1}", dInfo.Name, e.Message);
                    j--;
                }
                SceneView.RepaintAll();
            }
        }
    }
Esempio n. 3
0
    public static Object InstantiateSkeletonUnit(SkeletonDataAsset skeletonDataAsset, Skin skin = null)
    {
        if (!File.Exists("Assets/ExternalRes/Unit/Unit.json"))
        {
            return(null);
        }

        JSONNode jsonConfig = null;

        using (FileStream fs = new FileStream("Assets/ExternalRes/Unit/Unit.json", FileMode.Open))
        {
            string     sr     = new StreamReader(fs).ReadToEnd();
            JSONParser parser = new JSONParser();
            jsonConfig = parser.Parse(new FlashCompatibleTextReader(sr));
        }

        //读取配置文件
        Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>();
        TextAsset   textAsset = AssetDatabase.LoadAssetAtPath("Assets/ExternalRes/Config/UnitConfig.xml", typeof(TextAsset)) as TextAsset;
        XMLInStream stream    = new XMLInStream(textAsset.text);

        stream.List("item", delegate(XMLInStream itemStream)
        {
            UnitConfig ufg = new UnitConfig(itemStream);
            if (!UnitConfigs.ContainsKey(ufg.ResourceIcon))
            {
                UnitConfigs.Add(ufg.ResourceIcon, ufg);
            }
        });

        string path  = AssetDatabase.GetAssetPath(skeletonDataAsset);
        string fpath = path.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller");
        string mpath = path.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller.meta");

        if (File.Exists(fpath))
        {
            File.Delete(fpath);
            File.Delete(mpath);
            Debug.Log("删除旧的Controller:" + fpath);
        }
        fpath = path.Replace("_SkeletonData", "").Replace(".asset", ".prefab");
        mpath = path.Replace("_SkeletonData", "").Replace(".asset", ".prefab.meta");
        if (File.Exists(fpath))
        {
            File.Delete(fpath);
            File.Delete(mpath);
            Debug.Log("删除旧的Prefab:" + fpath);
        }

        skeletonDataAsset.controller = null;
        // 创建状态机
        SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset, jsonConfig);
        // 创建Animator Object
        GameObject go = GenerateAnimatorObject(skeletonDataAsset, skin);

        // 伙伴RectTransform
        go.AddComponent <RectTransform>();
        RectTransform rt = go.GetComponent <RectTransform>();

        rt.pivot = new Vector2(0.5f, 0);
        // 伙伴UnitSoundBehaviour
        UnitSoundBehaviour usb = go.AddComponent <UnitSoundBehaviour>();

        //伙伴UnitIdleChangeBehaviour
        go.AddComponent <UnitIdleChangeBehaviour>();
        // 创建Audio Object
        string name = path.Replace("Assets/ExternalRes/Unit/", "").Replace("_SkeletonData.asset", "");

        name = name.Substring(name.IndexOf("/") + 1);
        if (UnitConfigs.ContainsKey(name))
        {
            usb.SetSoundSource(AutoPrefab.GenerateAudioObject(go, UnitConfigs[name]));
        }
        // 创建Prefab
        string dataPath   = AssetDatabase.GetAssetPath(skeletonDataAsset);
        string prefabPath = dataPath.Replace("_SkeletonData", "").Replace(".asset", ".prefab");
        Object prefab     = AutoPrefab.GenerateUnitPrefab(go, prefabPath);

        // 销毁Animator Object
        Object.DestroyImmediate(go);
        // 设置asset bundle name
        AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(prefab)).assetBundleName = "units/" + name;
        return(prefab);
    }
    static private List <AssetBundleBuild> BuildUnitAssetBundles(BuildAssetBundleOptions opt,
                                                                 BuildTarget biuldTarget,
                                                                 Dictionary <string, AssetBundleInfo> assetInfoDict,
                                                                 string outputPath)
    {
        Debug.Log("處理資源: Unit");

        //讀取UnitConfig配置文件,只有這個文件配置的Unit才會記錄在reslist.json裡

        string      text   = File.ReadAllText(string.Format("{0}/Config/UnitConfig.xml", ASSET_BUNDLE_SRC_DIR));
        XMLInStream stream = new XMLInStream(text);

        Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>();

        stream.List("item", delegate(XMLInStream itemStream)
        {
            UnitConfig ufg = new UnitConfig(itemStream);

            //注意這裡用的是ResourceIcon字段
            if (!UnitConfigs.ContainsKey(ufg.ResourceIcon))
            {
                UnitConfigs.Add(ufg.ResourceIcon, ufg);
            }
        });

        List <AssetBundleBuild> ret = new List <AssetBundleBuild>();

        //生成prefab的AssetBundle
        foreach (var pair in UnitConfigs)
        {
            DirectoryInfo dInfo = new DirectoryInfo(string.Format("{0}/Unit/{1}", ASSET_BUNDLE_SRC_DIR, pair.Key));

            //這裡注意轉成小寫
            string assetbundlename = "unit/" + pair.Key.ToLower();
            if (!dInfo.Exists)
            {
                // 如果UnitConfig配置裡沒有的字段,需要從reslist.json裡清理掉
                if (assetInfoDict.ContainsKey(assetbundlename))
                {
                    assetInfoDict.Remove(assetbundlename);
                }
                continue;
            }

            AssetBundleBuild abb = new AssetBundleBuild();
            abb.assetBundleName = assetbundlename;
            string[] assetNames = { string.Format("{0}/Unit/{1}/{2}.prefab", ASSET_BUNDLE_SRC_DIR, pair.Key, pair.Key) };
            abb.assetNames = assetNames;
            ret.Add(abb);
        }

        //生成UnitImg的AssetBundle
        foreach (var pair in UnitConfigs)
        {
            //夥伴圖1
            string p1 = string.Format("{0}/UnitImg1/{1}.png", ASSET_BUNDLE_SRC_DIR, pair.Key);
            //夥伴圖2
            string   p2              = string.Format("{0}/UnitImg2/{1}.png", ASSET_BUNDLE_SRC_DIR, pair.Key);
            FileInfo img1Info        = new FileInfo(p1);
            FileInfo img2Info        = new FileInfo(p2);
            string   assetbundlename = string.Format("unitimg/{0}img", pair.Key.ToLower());
            if (!img1Info.Exists && !img2Info.Exists)
            {
                continue;
            }

            AssetBundleBuild abb = new AssetBundleBuild();
            abb.assetBundleName = assetbundlename;
            string[] assetNames = { p1, p2 };
            abb.assetNames = assetNames;
            ret.Add(abb);
        }

        return(ret);
    }