static public ArrayList Load() { string name = "PlayerInfoData.sav"; try { IFormatter serializer = new BinaryFormatter(); string path = PathKit.GetResourcesPath() + name; if (File.Exists(path)) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); datas = serializer.Deserialize(fs) as ArrayList; fs.Close(); Debug.Log("loaded playerinfo"); return(datas); } else { Debug.Log("找不到角色存档!"); return(null); } } catch (IOException e) { Debug.Log(e.ToString()); return(null); } }
IEnumerator beginMoveAssetBundle (string[] _list) { WWW loader; for (int i=0; i<_list.Length; i++) { string each = _list [i]; loader = new WWW (PathKit.GetStreamingAssetsPath (each)); yield return loader; PathKit.CreateDirIfNotExists (PathKit.GetURLPath (each, false, true)); FileStream fs = File.OpenWrite (PathKit.GetURLPath (each, false, true)); // new FileStream(PathKit.GetURLPath(each,false),FileMode.OpenOrCreate ,FileAccess.ReadWrite); fs.Write (loader.bytes, 0, loader.bytes.Length); fs.Close (); fs.Dispose (); // MonoBase.print (PathKit.GetURLPath (each, false, true) + " write ok!!!"); if (i == _list.Length - 1) GameManager.Instance.PrepareResourcesOK (); if (GameManager.Instance.guide != null) GameManager.Instance.guide.progress.text = (int)((float)(i + 1) / (float)_list.Length * 100) + "%"; } }
static public void LoadData(string name) { try { IFormatter serializer = new BinaryFormatter(); string path = PathKit.GetResourcesPath() + name; if (File.Exists(path)) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); datas = serializer.Deserialize(fs) as ArrayList; fs.Close(); CharBag.UpdateGoods(datas); Debug.Log("loaded bag"); } else { Debug.Log("找不到背包存档!"); } } catch (IOException e) { Debug.Log(e.ToString()); return; } }
/// <summary> /// 保存广播信息 应该是还未来得及显示的 /// </summary> public void M_saveRadioMsg(int radioType) { if (!radioInfoDic.ContainsKey(radioType)) { return; } string saveContent = string.Empty; RadioInfo radioInfo = radioInfoDic [radioType]; Queue <string> msgCache = radioInfo.msgCache; while (msgCache.Count > 0) { saveContent += ("#" + msgCache.Dequeue()); } if (saveContent == string.Empty) { return; } string path = ConfigGlobal.CONFIG_FOLDER + "/" + ConfigGlobal.CONFIG_RADIO_MSG; string holePath = PathKit.GetOSDataPath(path) + SUFFIX; FileStream fs = new FileStream(holePath, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.Flush(); sw.BaseStream.Seek(0, SeekOrigin.Begin); sw.Write(saveContent); sw.Close(); }
public void moveAssetBundle () { TextAsset ta = Resources.Load ("MoveList") as TextAsset; string[] _list = ta.text.Split (new string[]{"\r\n"}, System.StringSplitOptions.RemoveEmptyEntries); string rootDir = PathKit.GetURLPath ("", false, false); if (!Directory.Exists (rootDir)) { MonoBase.print (rootDir + " not exists!"); if (Application.platform == RuntimePlatform.WindowsPlayer) { Directory.CreateDirectory (rootDir); } else return; } //存在不再重复拷贝 if (File.Exists (PathKit.GetURLPath ("view/roleView", false, true))) { GameManager.Instance.PrepareResourcesOK (); return; } //如果存在就清空先 string[] _dirList = Directory.GetDirectories (rootDir); if (_dirList != null) foreach (string each in _dirList) Directory.Delete (each, true); //Directory.CreateDirectory (rootDir+"/Config"); GameManager.Instance.StartCoroutine (beginMoveAssetBundle (_list)); }
/// <summary> /// 创建文件 /// </summary> /// <param name="path">Path.</param> private void M_createFile(string path) { string holePath = PathKit.GetOSDataPath(path) + SUFFIX; FileStream fs = new FileStream(holePath, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.Flush(); sw.BaseStream.Seek(0, SeekOrigin.Begin); sw.Close(); }
public BulletCtrl CreateBulletEffect(CharacterData owner, CharacterData target, List <BuffCtrl> buffs, string Path, bool lastBullet) { passObj _obj = null; //if(owner.characterCtrl.activeAction.Skill.serverData.sample.sid==21113|| // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 22113|| // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 23113|| // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 24113|| // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 25113) {//关羽技能正反两面 // if (target.camp == 2) _obj = MonoBase.Create3Dobj(Path,"Guanyu_AOE_0"); // else _obj = MonoBase.Create3Dobj(Path ,"Guanyu_AOE_1"); //} else if (owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 22117 || // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 23117 || // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 24117 || // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 25117 || // owner.characterCtrl.activeAction.Skill.serverData.sample.sid == 26117|| // owner.characterCtrl.activeAction.Skill.serverData.sample.sid==21117) //{ // if (target.camp == 2) _obj = MonoBase.Create3Dobj(Path, "Xiaolongnv_AOE1"); // else _obj = MonoBase.Create3Dobj(Path, "Xiaolongnv_AOE2"); //} int[] tempSid = CommandConfigManager.Instance.doubleEffectSkillSids; int sidd = owner.characterCtrl.activeAction.Skill.serverData.sample.sid; for (int i = 0; i < tempSid.Length; i++) { if (sidd == tempSid[i]) { string fileNmae = PathKit.getFileName(Path); _obj = MonoBase.Create3Dobj(Path, fileNmae + (target.camp == 2 ? "1" : "2")); break; } } if (_obj == null) { _obj = MonoBase.Create3Dobj(Path); } //子弹类型数据在prefab上定义 //passObj _obj = MonoBase.Create3Dobj (Path); BulletCtrl _ctrl = _obj.obj.GetComponent <BulletCtrl> (); _ctrl.transform.parent = BattleManager.Instance.battleFieldRoom.transform; _ctrl.initBullet(target, owner, buffs, lastBullet); AddEffect(_ctrl); return(_ctrl); }
public void resourcesLoadTexture(Object obj) { if (obj == null) { return; } if (typeof(UITexture) == obj.GetType()) { if ((obj as UITexture).mainTexture != (Texture2D)Resources.Load(path)) { (obj as UITexture).mainTexture = (Texture2D)Resources.Load(path); } (obj as UITexture).gameObject.SetActive(true); callbackAfterLoad(obj, obj); } else if (typeof(GameObject) == obj.GetType()) { GameObject gameObj = obj as GameObject; if (gameObj.renderer != null && gameObj.renderer.material != null) { gameObj.renderer.material.mainTexture = (Texture2D)Resources.Load(path); } callbackAfterLoad(obj, obj); } else if (typeof(Transform) == obj.GetType()) { Object obj2 = Resources.Load(path); //如果路径无,再次尝试 if (obj2 == null) { string _name = PathKit.getFileName(path); obj2 = Resources.Load(path + "/" + _name) as GameObject; } GameObject tmp = GameObject.Instantiate(obj2) as GameObject; tmp.transform.parent = obj as Transform; tmp.transform.localScale = Vector3.one; tmp.transform.localPosition = Vector3.zero; callbackAfterLoad(obj, tmp); } }
/// <summary> /// 这个是需要保存的方法模板,不要直接用这个保存,需要使用每个class里面重写的保存方法 /// </summary> /// <param name="name">保存的文件名称</param> static public void SaveData(string name) { try { IFormatter serializer = new BinaryFormatter(); string path = PathKit.GetResourcesPath() + name; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); serializer.Serialize(fs, datas); fs.Close(); Debug.Log("Save!! " + path); } catch (IOException e) { Debug.Log(e.ToString()); return; } }
/// <summary> /// 读取缓存广播 /// </summary> private void M_readCacheMsg() { string path = ConfigGlobal.CONFIG_FOLDER + "/" + ConfigGlobal.CONFIG_RADIO_MSG; string newPath = PathKit.GetOSDataPath(path) + SUFFIX; if (!File.Exists(newPath)) { M_createFile(path); return; } else { using (StreamReader sr = new StreamReader(newPath, Encoding.UTF8)) { string str = sr.ReadLine(); if (str != null) { string[] strs = str.Split(new char[] { '#' }, System.StringSplitOptions.RemoveEmptyEntries); M_addRadioMsg(RADIO_MAIN_TYPE, strs); // 暂时只支持保存主界面广播 } } } }
//获取路径// public static string GetDataPath(string path) { return(PathKit.GetResourcesPath() + "StoryResources/" + path); }
//指定读取path包内的name文件 public static passObj Create3Dobj(string path, string fileName) { passObj lastObj = new passObj(); UnityEngine.Object _tmp = null; //开发时直接读取Resource资源 if (ResourcesManager.Instance.allowLoadFromRes) { if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { UnityEngine.Object obj = Resources.Load(path); if (obj == null) { string _name = PathKit.getFileName(path); if (string.IsNullOrEmpty(fileName)) { obj = Resources.Load(path + "/" + _name); } else { print(path + "/" + fileName); obj = Resources.Load(path + "/" + fileName); } } if (obj != null) { lastObj.obj = MonoBehaviour.Instantiate(obj) as GameObject; return(lastObj); } } } //从资源库里获取 ResourcesData res = ResourcesManager.Instance.getResource(path); if (res == null) { if (ResourcesManager.Instance.allowLoadFromRes) { _tmp = Resources.Load(path); //如果路径无,再次尝试 if (_tmp == null) { string _name = PathKit.getFileName(path); _tmp = Resources.Load(path + "/" + _name); } } } else { lastObj.data = res; if (string.IsNullOrEmpty(fileName)) { _tmp = res.ResourcesBundle.mainAsset; } else { _tmp = res.ResourcesBundle.Load(fileName); } // lastObj.data.MemoryData=_tmp; } if (_tmp == null) { return(lastObj); } lastObj.obj = MonoBehaviour.Instantiate(_tmp) as GameObject; return(lastObj); }
//获得配置文件完整路径 private string getConfigHolePath(string path) { return(PathKit.GetOSDataPath(path) + PathKit.SUFFIX); }
//读取一系列AssetBundle镜像,这会在内存划分一块区域存放; IEnumerator LoadAssetBundleImage (List<string> paths, CallBack<List<ResourcesData>> Callback, string key) { WWW loader = null; bool canCall = false;//判断是否最后一个 List<ResourcesData> _list = new List<ResourcesData> (); for (int i=0; i<paths.Count; i++) { //如果是最后一个 if (i == paths.Count - 1) { canCall = true; } //缓存进度 cacheProgress = ((float)i + 1f) / (float)paths.Count - 0.1f; if (GameManager.Instance.guide != null) { GameManager.Instance.guide.progress.text = ((int)((i) / (float)paths.Count * 100)).ToString () + "%"; } string each = paths [i]; if (string.IsNullOrEmpty (each)) continue; string _path = PathKit.GetURLPath (each, true, true); ResourcesData _tmp = new ResourcesData (); if (File.Exists (PathKit.GetURLPath (each, false, true)) && GameManager.Instance. ignoreUpdate==false) { _tmp.ResType = ResourcesData_type.AssetBundleRes; } else { //外部更新文件夹没有的话,尝试读取内部资源 if (!GameManager.Instance.allowLoadFromRes) { _path = PathKit.GetStreamingAssetsPath (each); } else { _path = ""; } } if (string.IsNullOrEmpty (_path) == false) { loader = new WWW (_path); yield return loader; if (loader.assetBundle == null) { // Debug.LogError (_path + " downLoad assetBundle is null "); } else { _tmp.ResourcesBundle = loader.assetBundle; _tmp.ResourcesPath = _path; _tmp.ResourcesName = each; _tmp.size = loader.bytes.LongLength; loader.Dispose (); if (allDataList.ContainsKey (key)) allDataList [key].Add (_tmp.ResourcesName, _tmp); changeSize (key, _tmp.size); _list.Add (_tmp); } } else { // Debug.LogError (each + " is empty path"); } if (Callback != null && canCall == true) { //缓冲完成后回调. cacheProgress = 1; Callback (_list); Callback = null; } } }
//获得配置目录文件夹路径 private string getConfigFolder(string path) { return(PathKit.GetOSDataPath(path)); }
public void pushTexture(Object obj) { if (obj == null) { return; } if (data != null || webImage != null) { //有网络资源用网络资源 Texture2D tmpTex = null; if (webImage != null) { tmpTex = webImage; } else if (data != null && data.ResourcesBundle != null) { // if (TextureManager.instance.debugMode) // Debug.Log (data.ResourcesPath); if (data.ResourcesBundle.mainAsset is Texture2D) { tmpTex = (Texture2D)data.ResourcesBundle.mainAsset; } } if (typeof(UITexture) == obj.GetType()) { if ((obj as UITexture).mainTexture == null || (obj as UITexture).mainTexture.GetHashCode() != tmpTex.GetHashCode()) { (obj as UITexture).mainTexture = tmpTex; } (obj as UITexture).gameObject.SetActive(true); callbackAfterLoad(obj, obj); } else if (typeof(GameObject) == obj.GetType()) { GameObject gameObj = obj as GameObject; if (gameObj.renderer != null && gameObj.renderer.material != null) { gameObj.renderer.material.mainTexture = tmpTex; } callbackAfterLoad(obj, obj); } else if (typeof(Transform) == obj.GetType()) { GameObject tmp = GameObject.Instantiate(data.ResourcesBundle.mainAsset) as GameObject; tmp.transform.parent = obj as Transform; tmp.transform.localScale = Vector3.one; tmp.transform.localPosition = Vector3.zero; callbackAfterLoad(obj, tmp); } } else if (ResourcesManager.Instance.allowLoadFromRes) { Texture2D tmpTex = null; if (webImage != null) { tmpTex = webImage; } else { tmpTex = Resources.Load(path) as Texture2D; } //直接资源读取咯 if (typeof(UITexture) == obj.GetType()) { if ((obj as UITexture).mainTexture != tmpTex) { (obj as UITexture).mainTexture = tmpTex; } (obj as UITexture).gameObject.SetActive(true); callbackAfterLoad(obj, obj); } else if (typeof(GameObject) == obj.GetType()) { GameObject gameObj = obj as GameObject; if (gameObj.renderer != null && gameObj.renderer.material != null) { gameObj.renderer.material.mainTexture = tmpTex; } callbackAfterLoad(obj, obj); } else if (typeof(Transform) == obj.GetType()) { Object obj2 = Resources.Load(path); //如果路径无,再次尝试 if (obj2 == null) { string _name = PathKit.getFileName(path); obj2 = Resources.Load(path + "/" + _name) as GameObject; } GameObject tmp = GameObject.Instantiate(obj2) as GameObject; tmp.transform.parent = obj as Transform; tmp.transform.localScale = Vector3.one; tmp.transform.localPosition = Vector3.zero; callbackAfterLoad(obj, tmp); } } }