private IEnumerator LoadAssetbundle()
        {
            MonsterGroupAssetbundle = new WWW("file://" + Application.streamingAssetsPath + "/ScenceEditor/WindowsEditor/" + Application.loadedLevelName + "/Monster/" + Application.loadedLevelName + "Monster" + ".assetbundle");
            yield return(MonsterGroupAssetbundle);

            if (MonsterGroupAssetbundle.error != null)
            {
                Debug.Log(MonsterGroupAssetbundle.error);
            }
            if (MonsterGroupAssetbundle.isDone)
            {
                //转换资源
                //AssetBundle bundle = MonsterGroupAssetbundle.assetBundle;
                //  object[] List = bundle.LoadAll(typeof(UnityEngine.Object));
                MonsterGroupData = MonsterGroupAssetbundle.assetBundle.mainAsset as MonsterGroupDataObj;
            }
            else
            {
                LogManager.Log("加载失败");
            }
        }
Example #2
0
 public MonsterGroupDataObjMgr(MonsterGroupDataObj dataObj)
 {
     mGroupData = dataObj;
 }
        private void Done()
        {
            //实例化monsterdata
            MonsterGroupDataObj MonsterGroupDataobj = ScriptableObject.CreateInstance <MonsterGroupDataObj>();

            //添加数据给Monstergroupdata
            MonsterGroupDataobj.MonsterGroupDataList = new List <MonstersGroupData>();
            for (int i = 0; i < MonsterGroupDatamanager.transform.childCount; i++)
            {
                MonsterGroupDataobj.MonsterGroupDataList.Add(MonsterGroupDatamanager.transform.GetChild(i).GetComponent <MonsterGroup>().MonsterGroupdata);
                MonsterGroupDataobj.MonsterGroupDataList[i].MonsterGroupdata = new List <Monsterdata>();
                for (int j = 0; j < MonsterGroupDatamanager.transform.GetChild(i).childCount; j++)
                {
                    MonsterGroupDataobj.MonsterGroupDataList[i].MonsterGroupdata.Add(MonsterGroupDatamanager.transform.GetChild(i).GetChild(j).GetComponent <MonsterPoint>().Adddata());
                }
            }
            //SysData将创建为一个对象,这时在project面板上会看到这个对象
            //string saveurl = "Assets/StreamingAssets/ScenceEditor/" + Application.platform.ToString() + "/" + MonsterGroupDatamanager.SceneName + "/Monster/";
            //if (Directory.Exists(saveurl) == false)
            //    Directory.CreateDirectory(saveurl);
            //string name = saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".asset";
            //AssetDatabase.CreateAsset(MonsterGroupDataobj, name);
            //Object o = AssetDatabase.LoadAssetAtPath(name, typeof(MonsterGroupDataObj));
            //打包为SysData.assetbundle文件选择平台
#if UNITY_ANDROID
            Debug.Log("这里是安卓设备^_^");
            string saveurl = "Assets/StreamingAssets/ScenceEditor/" + "Android/" + MonsterGroupDatamanager.SceneName + "/Monster/";
            if (Directory.Exists(saveurl) == false)
            {
                Directory.CreateDirectory(saveurl);
            }
            string name = saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".asset";
            AssetDatabase.CreateAsset(MonsterGroupDataobj, name);
            Object o = AssetDatabase.LoadAssetAtPath(name, typeof(MonsterGroupDataObj));
            BuildPipeline.BuildAssetBundle(o, null, saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".assetbundle",
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.Android);

            BuildPipeline.BuildAssetBundle(o, null, "Assets/StreamingAssets/AssetBundle/Android/" + MonsterGroupDatamanager.SceneName + "Monster" + ".assetbundle",
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.Android);
#endif

#if UNITY_IPHONE
            Debug.Log("这里是苹果设备>_<");
            string saveurl = "Assets/StreamingAssets/ScenceEditor/" + "IPhonePlayer/" + MonsterGroupDatamanager.SceneName + "/Monster/";
            if (Directory.Exists(saveurl) == false)
            {
                Directory.CreateDirectory(saveurl);
            }
            string name = saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".asset";
            AssetDatabase.CreateAsset(MonsterGroupDataobj, name);
            Object o = AssetDatabase.LoadAssetAtPath(name, typeof(MonsterGroupDataObj));
            BuildPipeline.BuildAssetBundle(o, null, saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".assetbundle",
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.iPhone);

            BuildPipeline.BuildAssetBundle(o, null, "Assets/StreamingAssets/AssetBundle/IOS/" + MonsterGroupDatamanager.SceneName + "Monster" + ".assetbundle",
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.iPhone);
#endif

#if UNITY_STANDALONE_WIN
            Debug.Log("我是从Windows的电脑上运行的T_T");
            string saveurl = "Assets/StreamingAssets/ScenceEditor/" + "WindowsEditor/" + MonsterGroupDatamanager.SceneName + "/Monster/";
            if (Directory.Exists(saveurl) == false)
            {
                Directory.CreateDirectory(saveurl);
            }
            string name = saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".asset";
            AssetDatabase.CreateAsset(MonsterGroupDataobj, name);
            Object o = AssetDatabase.LoadAssetAtPath(name, typeof(MonsterGroupDataObj));
            BuildPipeline.BuildAssetBundle(o, null, saveurl + MonsterGroupDatamanager.SceneName + "Monster" + ".assetbundle",
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.StandaloneWindows);

            BuildPipeline.BuildAssetBundle(o, null, "Assets/StreamingAssets/AssetBundle/PC/" + MonsterGroupDatamanager.SceneName + "Monster" + ".assetbundle",
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.StandaloneWindows);
#endif
            string SavePath = "Assets/CEHUAYONG/ScenesPreb/" + MonsterGroupDatamanager.SceneName + "/";
            if (Directory.Exists(SavePath) == false)
            {
                Directory.CreateDirectory(SavePath);
            }
            PrefabUtility.CreatePrefab(SavePath + MonsterGroupDatamanager.name + ".prefab", MonsterGroupDatamanager.gameObject);
            AssetDatabase.Refresh();
            EditorUtility.DisplayDialog("", "保存完成", "OK");
            //删除面板上的临时对象
            //AssetDatabase.DeleteAsset(name);
        }