private static XPlayerPrefsData Load() { try { string path = XGamePath.SavePath(tag); if (!File.Exists(path)) { File.Create(path).Close(); return(new XPlayerPrefsData()); } StreamReader sr = File.OpenText(path); string json = sr.ReadToEnd(); if (string.IsNullOrEmpty(json)) { return(new XPlayerPrefsData()); } XPlayerPrefsData data = JsonMapper.ToObject <XPlayerPrefsData>(json); return(data); } catch (System.Exception e) { Debug.LogError("==>" + e.Message + "\n" + e.StackTrace); return(null); } }
public static void Save() { lock (data) { if (issaving) { return; } Loom.QueueOnMainThread(() => { try { issaving = true; string json = JsonMapper.ToJson(data); string path = XGamePath.SavePath(tag); FileStream fs = File.Open(path, FileMode.Open, FileAccess.Write); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json); fs.SetLength(0); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close(); issaving = false; } catch (System.Exception e) { issaving = true; Debug.LogError("==>" + e.Message + "\n" + e.StackTrace); } }); } }
public static void Save() { string path = XGamePath.GetLevelDataJsonPath(FileName); if (_ins == null) { _ins = new GameConfigData(); } string json = JsonMapper.ToJson(_ins); try { if (File.Exists(path)) { File.Delete(path); } byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json); FileStream fs = File.Open(path, FileMode.CreateNew, FileAccess.Write); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close(); Debuger.Log("GameConfig", "Save", string.Format("保存成功 路径={0},json={1}", path, json)); } catch (Exception e) { Debuger.Log("GameConfig", "Save", e + "==>" + e.Data); } }
public static void Save(LevelMapData data) { string FilePath = XGamePath.GetLevelDataJsonPath(LevelMap_FileName); //string FilePath = Path.Combine(Application.dataPath, "FakeResources/Data/LevelConfig/" + data.Name + ".json"); LevelLoader.data = data; //Debug.Log("LevelMapData.Save==>" + FilePath); string json = JsonMapper.ToJson(data); string path = string.Format(FilePath, data.Name); try { if (File.Exists(path)) { File.Delete(path); } byte[] bytes = Encoding.UTF8.GetBytes(json); FileStream fs = File.Create(path); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close(); } catch (Exception e) { Debug.Log(e + "==>" + e.Data); } }
public static Font GetFont(string fontname) { string path = XGamePath.GetFontPath(fontname); Font font = Load <Font>(path); return(font); }
public static LevelMapData Load() { if (data != null) { return(data); } string path = XGamePath.GetLevelDataJsonPath(LevelMap_FileName); //Debug.Log("LevelMapData.Load==>" + path); if (File.Exists(path)) { try { StreamReader fs = File.OpenText(path); string json = fs.ReadToEnd(); //ResMgr.Log(json); fs.Close(); data = JsonMapper.ToObject <LevelMapData>(json); return(data); } catch (Exception e) { Debug.Log(e + "==>" + e.Data); } } else { Debug.Log("file not exist"); } return(null); }
public static T Read <T>(string sheetname) where T : class, IMessage, new() { int hash = sheetname.GetHashCode(); if (m_ConfigDic.ContainsKey(hash)) { return(m_ConfigDic[hash] as T); } string path = XGamePath.GetBinPath(sheetname); if (File.Exists(path)) { byte[] bytes = File.ReadAllBytes(path); CodedInputStream cis = new CodedInputStream(bytes); T t = new T(); t.MergeFrom(cis); m_ConfigDic.Add(hash, t); return(t); } else { Debug.LogError("配置表读取错误,sheetname==>" + sheetname + ",path==>" + path); return(default(T)); } }
public static UIAtlas GetLevelAtlas(string atlasname) { string path = XGamePath.GetAtlasPath(atlasname); GameObject go = Load <GameObject>(path); UIAtlas ua = go.GetComponent <UIAtlas>(); return(ua); }
public static void GetAtlasAsync(string atlasname, Action <UIAtlas> callback) { string path = XGamePath.GetAtlasPath(atlasname); LoadAsync <GameObject>(path, (o) => { Log(Tag, "GetAtlasAsync", path); UIAtlas ua = o.GetComponent <UIAtlas>(); callback(ua); }); }
public void AsyncLoad(string path, Action <AssetBundle> callback, bool isdepend = false) { if (m_manifest == null) { ResMgr.Log(Tag, "AsyncLoad", "manifest is null"); return; } string abname; if (isdepend) { abname = path; } else { abname = XGamePath.Path2ResName(path); } int hash = abname.GetHashCode(); AbAbstractLoader loader = null; if (m_Ab_Dic.TryGetValue(hash, out loader)) { if (callback != null) { callback(loader.Bundle); } return; } string[] depends = AbMgr.GetInstance().GetDepends(abname); for (int i = 0; i < depends.Length; i++) { ResMgr.Log(Tag, "AsyncLoad|depends", depends[i]); int hash2 = depends[i].GetHashCode(); AbAbstractLoader loader2 = null; if (m_Ab_Dic.TryGetValue(hash2, out loader2)) { continue; } if (m_loading_Dic.ContainsKey(hash2)) { AbAsyncLoader asyncloader = m_loading_Dic[hash2] as AbAsyncLoader; asyncloader.request.priority++; continue; } AbMgr.GetInstance().AsyncLoad(depends[i], null, true); } loader = new AbAsyncLoader(path, abname, callback); path = XGamePath.GetStreamingAbPath(abname); loader.LoadAsset(path); m_loading_Dic.Add(hash, loader as AbAsyncLoader); }
public IEnumerator Init() { ResMgr.Log(Tag, "Init", "Start Async Init"); string path = XGamePath.GetStreamingAbPath(m_manifest_name); ResMgr.Log(Tag, "Init", "==>" + path); if (File.Exists(path)) { //同步加载 //FileStream fs = File.Open(path, FileMode.Open); //m_manifest_ab = AssetBundle.LoadFromStream(fs); //m_manifest = m_manifest_ab.LoadAsset<AssetBundleManifest>("AssetBundleManifest"); //if (m_Ab_Dic.Count > 0) //{ // Debug.LogError("不应该发生的事情发生了"); //} //m_Ab_Dic.Clear(); //loader = new AbSyncLoader(); //异步加载 AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path); yield return(request); if (request.isDone) { m_manifest = request.assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); if (m_Ab_Dic.Count > 0) { ResMgr.LogError(Tag, "Init", "this should never happen !!!!"); } //string[] depends = m_manifest.GetAllAssetBundles(); //foreach (var item in depends) //{ // Debug.Log("depends log ==>" + item); //} m_Ab_Dic.Clear(); ResMgr.Log(Tag, "Init", "load manifest success"); } else { ResMgr.Log(Tag, "Init", "load manifest fail"); } } else { ResMgr.Log(Tag, "Init", "manifest not exist"); } }
public static void DeleteAll() { try { XPlayerPrefsData data = new XPlayerPrefsData(); string json = JsonMapper.ToJson(data); string path = XGamePath.SavePath(tag); FileStream fs = File.Open(path, FileMode.OpenOrCreate); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close(); XPlayerPrefs.data = data; } catch (System.Exception e) { Debug.LogError("==>" + e.Message + "\n" + e.StackTrace); } }
private static void BuildAll() { AssetDatabase.Refresh(); if (Directory.Exists(XGamePath.OutputPath)) { Directory.Delete(XGamePath.OutputPath, true); } Directory.CreateDirectory(XGamePath.OutputPath); AssetDatabase.Refresh(); string path = XGamePath.GetResRoot();//Application.dataPath+ "/FakeResources/Prefabs/abtest";// AssetCollector.Collecttions(path); BinCollector.Collecttions(Application.dataPath + "/Data/", XGamePath.OutputPath); ShaderCollector.Collecttions(Application.dataPath + "/Shaders/"); var options = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle; BuildPipeline.BuildAssetBundles(XGamePath.OutputPath, options, EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); }
private static void Init() { string path = XGamePath.GetLevelDataJsonPath(FileName); if (File.Exists(path)) { try { StreamReader fs = File.OpenText(path); string json = fs.ReadToEnd(); fs.Close(); _ins = JsonMapper.ToObject <GameConfigData>(json); } catch (Exception e) { Debuger.Log("GameConfig", "load", e + "==>" + e.Data); } } else { Debuger.Log("GameConfig", "load", "file not exist"); } }
private static void SetTag() { AssetCollector.Collecttions(XGamePath.GetResRoot()); AssetCollector.AllSetTag(); }
private static IEnumerator TakephotoIE(Image im) { float sheight, swidth; int capx = 0; int capy = 0; int capwidth = 0; int capheight = 0; //sheight = Screen.currentResolution.height; //swidth = Screen.currentResolution.width; sheight = ca.rect.height; swidth = ca.rect.width; Vector3 v3 = Camera.main.WorldToScreenPoint(im.transform.position); //Debug.Log(v3); //Debug.Log(im.rectTransform.rect.position); //Debug.Log(im.rectTransform.rect.yMax); float rate = Mathf.Min(Screen.width / swidth, Screen.height / sheight); capwidth = (int)(im.rectTransform.rect.width * 1.0f / swidth * Screen.width); capheight = (int)(im.rectTransform.rect.height * 1.0f / sheight * Screen.height); //capwidth = (int)(im.rectTransform.rect.width * 1.0f * rate); //capheight = (int)(im.rectTransform.rect.height * 1.0f * rate); capx = (int)(v3.x - capwidth * im.rectTransform.pivot.x); capy = (int)(v3.y - capheight * im.rectTransform.pivot.y); //Debug.Log("capwidth" + capwidth); //Debug.Log("capheight" + capheight); //Debug.Log("capx" + capx); //Debug.Log("capy" + capy); //Debug.Log("sheight" + sheight); //Debug.Log("swidth" + swidth); //Debug.Log("Screen.width" + Screen.width); //Debug.Log("Screen.height" + Screen.height); if (capwidth + capx > Screen.width) { Debug.Log("1"); capwidth = Screen.width - capx; } else if (capx < 0) { Debug.Log("2"); capwidth = Screen.width + capx < 0 ? 0 : Screen.width + capx; } if (capheight + capy > Screen.height) { Debug.Log("3"); capheight = Screen.height - capy; } else if (capy < 0) { Debug.Log("4"); capheight = Screen.height + capy < 0 ? 0 : Screen.height + capy; } yield return(new WaitForEndOfFrame()); Texture2D t; t = new Texture2D(capwidth, capheight, TextureFormat.RGB24, false); //需要正确设置好图片保存格式 t.ReadPixels(new Rect(capx, capy, capwidth, capheight), 0, 0, false); //按照设定区域读取像素;注意是以左下角为原点读取 t.Compress(false); t.Apply(); //二进制转换,保存到手机 byte[] byt = t.EncodeToPNG(); string filepath = XGamePath.SavePath("temp.png");// + "/" + "temp.png"; if (File.Exists(filepath)) { File.Delete(filepath); } FileStream fs = File.Create(filepath); fs.Write(byt, 0, byt.Length); fs.Close(); fs.Dispose(); co = null; #if !UNITY_EDITOR && UNITY_IOS _SavePhoto(filepath); #endif }
public AssetBundle SyncLoad(string path, bool isdepend = false) { if (m_manifest == null) { return(null); } string abname; if (isdepend) { abname = path; } else { abname = XGamePath.Path2ResName(path); } string fullpath = XGamePath.GetStreamingAbPath(abname); int hash = abname.GetHashCode();//path.GetHashCode(); string[] depends = AbMgr.GetInstance().GetDepends(abname); for (int i = 0; i < depends.Length; i++) { ResMgr.Log(Tag, "SyncLoad|depends", depends[i]); int hash2 = depends[i].GetHashCode(); AbAbstractLoader loader2 = null; if (m_Ab_Dic.TryGetValue(hash2, out loader2)) { continue; } if (m_loading_Dic.ContainsKey(hash2)) { AbAsyncLoader asyncloader = m_loading_Dic[hash2] as AbAsyncLoader; asyncloader.request.priority++; continue; } AbMgr.GetInstance().SyncLoad(depends[i], true); } AbAbstractLoader loader; if (m_Ab_Dic.TryGetValue(hash, out loader)) { switch (loader.State) { case AbBundleState.success: return(loader.Bundle); case AbBundleState.loading: if (!loader.isSync) { //todo 转同步加载 } break; case AbBundleState.none: default: break; } return(loader.Bundle); } loader = new AbSyncLoader(fullpath, abname); loader.LoadAsset(fullpath); m_Ab_Dic.Add(hash, loader); return(m_Ab_Dic[hash].Bundle); }