public static void NewSpriteAtlas() { string[] guids = Selection.assetGUIDs; sCurSelectObjs.Clear(); foreach (var id in guids) { string path = AssetDatabase.GUIDToAssetPath(id); Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object)); LogFile.Warn("path:" + path); //LogFile.Log("{0} is native Asset: {1}, is valid folder:{2}", path, AssetDatabase.IsNativeAsset(obj), AssetDatabase.IsValidFolder(path)); if (AssetDatabase.IsValidFolder(path) || obj as Sprite) { sCurSelectObjs.Add(obj); } } string p = EditorUtility.SaveFilePanel("新建 SpriteAtlas", "Assets/" + GameConfig.STR_RES_FOLDER, "NewSpriteAtlas", ".spriteatlas"); if (string.IsNullOrEmpty(p)) { return; } p = Tools.RelativeTo(p, Application.dataPath, true); SpriteAtlas atlas = new SpriteAtlas(); atlas.Add(sCurSelectObjs); AssetDatabase.CreateAsset(atlas, p); AssetDatabase.SaveAssets(); _clearStatus(); }
void unloadAssetBundleInternal(string abName, bool isThorough, int count) { AssetBundleInfo bundle = GetLoadedAssetBundle(abName); if (bundle == null) { return; } bundle.m_ReferencedCount = bundle.m_ReferencedCount - count; if (bundle.m_ReferencedCount <= 0) { if (bundle.m_ReferencedCount < 0) { LogFile.Warn("unloadAssetBundleInternal :" + abName + ", count :" + count + ", m_ReferencedCount:" + bundle.m_ReferencedCount); } if (m_LoadRequests.ContainsKey(abName)) { //TODO:在 Async Loading 结束后删除 return; //如果当前AB处于Async Loading过程中,卸载会崩溃,只减去引用计数即可 } bundle.m_AssetBundle.Unload(isThorough); m_LoadedAssetBundles.Remove(abName); Debug.Log(abName + " has been unloaded successfully"); } }
protected static bool _registerEvent(EventPairDic dic, string eventName, object obj, string funcName) { _deregisterEvent(dic, eventName, obj); Pair pair = new Pair(); pair.obj = obj; pair.eventName = eventName; pair.method = obj.GetType().GetMethod(funcName); if (null == pair.method) { LogFile.Warn("Register worning: Obj(" + obj + ") do not have method named \"" + funcName + "\""); return(false); } EventPairList list = null; monitorEnter(dic); if (!dic.TryGetValue(eventName, out list)) { list = new EventPairList(); dic.Add(eventName, list); } list.Add(pair); dic[eventName] = list; monitorExit(dic); return(true); }
void Start() { //初始化部分信息 init(); //第一次初始化GameResManager,完成后初始化多语言管理器 ResManager.Instance.Initialize(() => { LanguageManager.Init((bool ret) => { if (!ret) { LogFile.Warn("多语言管理器 LanguageManager初始化失败"); } if (GameConfig.HasDebugView && !string.IsNullOrEmpty(DebugViewRestPath)) { ShowDebugView(); } if (!string.IsNullOrEmpty(UpdateViewResPath)) { GameObject prefab = Resources.Load <GameObject>(UpdateViewResPath); if (null != prefab) { mUiMgr.ShowViewPrefab(prefab); } } }); }); }
void Start() { //初始化部分信息 init(); //第一次初始化GameResManager,完成后初始化多语言管理器 ResManager.Instance.Initialize(() => { LanguageManager.Init((bool ret) => { if (!ret) { LogFile.Warn("多语言管理器 LanguageManager初始化失败"); } if (GameConfig.HasDebugView && !string.IsNullOrEmpty(DebugViewResPath)) { ShowDebugView(); } if (!string.IsNullOrEmpty(UpdateViewResPath)) { mUiMgr.ShowView(GameConfig.BasicRes, UpdateViewResPath); } }); }); }
/// <summary> /// 对比服务器配置文件,记录新的文件 /// </summary> /// <param name="url">服务器地址 URL.</param> /// <param name="callback">Callback.</param> private void _compareNewFiles(string url, Action <long, string> callback) { if (null != callback) { if (GameConfig.UseAsb) { string sUrl = _confUrl(url); string pUrl = _confUrlWrite(); WWWTO streamWWW = WWWTO.ReadFileStr(sUrl, (rst, msg) => { if (rst) { mServConf = new ResConf(msg); WWWTO writableWWW = WWWTO.ReadFileStr(pUrl, (_rst, _msg) => { if (_rst) { //之前已经拷贝过资源 mCurConf = new ResConf(_msg); } else { mCurConf = new ResConf(""); } mTotalSize = 0; if (mServConf.CompareVer(mCurConf) > 0) { mNewFiles = mServConf.GetUpdateFiles(mCurConf); foreach (var f in mNewFiles) { mTotalSize += f.size; } callback(mTotalSize, mServConf.version); } else { LogFile.Log("没有检测到新版本资源,跳过更新步骤"); callback(mTotalSize, "没有检测到新版本资源,跳过更新步骤"); } }, null); writableWWW.Start(); } else { LogFile.Warn("资源配置文件" + sUrl + "丢失"); callback(-1, STR_CONFIG_MISSING); } }, null); streamWWW.Start(); } else { callback(0, "不使用Assetbundle不用拷贝/下载资源"); } } }
private void onRecive(int idx) { string fileName = SavePath + ".tmp" + idx; //LogFile.Log("onRecave idx:{0}, fileName:{1}", idx, fileName); byte[] buffer = new byte[BufferSize]; FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write); mPartDoneSize[idx] = fs.Length; if (!mPartialEnabled) { mPartDoneSize[idx] = 0; } try { //LogFile.Log("onRecave idx:{0}, readSize:{1}", idx, mPartDoneSize[idx]); if (mPartDoneSize[idx] < mPartSize[idx]) { //TODO:断点续传还有问题 //断点续传核心,设置本地文件流的起始位置 fs.Seek(mPartDoneSize[idx], SeekOrigin.Begin); mRequest.AddRange((int)mPartStartPos[idx], (int)(mPartStartPos[idx] + mPartSize[idx] - 1)); HttpWebResponse response = (HttpWebResponse)mRequest.GetResponse(); Stream stream = response.GetResponseStream(); //TODO:判断服务器是否支持读取范围 int length = stream.Read(buffer, 0, BufferSize); while (length > 0) { fs.Write(buffer, 0, length); mPartDoneSize[idx] += length; if (mPartDoneSize[idx] > mPartSize[idx]) { LogFile.Error(fileName + "下载出错,写入大小大于原文件分块"); } length = stream.Read(buffer, 0, BufferSize); //LogFile.WriteLine(string.Format("tmp{0}下载进度:{1}/{2}", idx, mPartDoneSize[idx], mPartSize[idx])); } //LogFile.WriteLine(string.Format("tmp{0}下载完成:{1}/{2}", idx, mPartDoneSize[idx], mPartSize[idx])); stream.Close(); stream.Dispose(); } else { //TODO:之前已经下载完成 mPartDoneSize[idx] = mPartSize[idx]; } fs.Close(); fs.Dispose(); } catch (Exception ex) { LogFile.Warn("download {0} error, msg:{1}", SavePath, ex.Message); fs.Close(); fs.Dispose(); } }
public void UnselectAll() { if (!EnableMuiltSelect) { LogFile.Warn("当前ScrollView为单选模式,请打开开关EnableMuiltSelect"); return; } //已经通知修改,不需要像上面的再写一次 changeSelectAll(false); }
public static Vector3 GenVector3ByStr(string vecStr) { Vector3 pos = Vector3.zero; string[] array = vecStr.Split(','); if (array.Length >= 2) { float[] _array = new float[array.Length]; for (int i = 0; i < array.Length; i++) { if (!float.TryParse(array[i], out _array[i])) { LogFile.Warn("GenVector3ByStr error -> vecStr:" + vecStr); return(pos); } } return(GenVector3(_array)); } switch (vecStr.ToLower()) { case "back": pos = Vector3.back; break; case "down": pos = Vector3.down; break; case "forward": pos = Vector3.forward; break; case "left": pos = Vector3.left; break; case "one": pos = Vector3.one; break; case "right": pos = Vector3.right; break; case "up": pos = Vector3.up; break; case "zero": pos = Vector3.zero; break; } return(pos); }
private bool _playBgm(AudioClip audioClip, float fadeOutTime) { if (null != audioClip) { if (audioClip.LoadAudioData()) { if (null != mBgmTween && mBgmTween.IsPlaying()) { mBgmTween.Kill(); mBgmTween = null; } if (mBgmSource.isPlaying) { //如果正在播放,先关闭之前播放的 mBgmTween = DOTween.Sequence().Append(DOTween.To(() => mCurBgmFade, (x) => { mCurBgmFade = x; mBgmSource.volume = mBgmVolume * mCurBgmFade; }, 0f, fadeOutTime / 2)) .AppendCallback(() => { mBgmSource.Stop(); mBgmSource.clip = audioClip; mBgmSource.loop = true; mBgmSource.Play(); }) .Append(DOTween.To(() => mCurBgmFade, (x) => { mCurBgmFade = x; mBgmSource.volume = mBgmVolume * mCurBgmFade; }, 1f, fadeOutTime / 2)) .Play(); } else { //如果没有播放,直接播放 mBgmSource.clip = audioClip; mBgmSource.volume = 0f; mBgmSource.loop = true; mBgmSource.Play(); mBgmTween = DOTween.To(() => mCurBgmFade, (x) => { mCurBgmFade = x; mBgmSource.volume = mBgmVolume * mCurBgmFade; }, 1f, fadeOutTime / 2) .Play(); } return(true); } else { LogFile.Warn("AudioClip LoadAudioData 失败,请检查。"); } } return(false); }
void OnDestroy() { if (Dispose()) { sInstance = null; } else { LogFile.Warn("单例组件清理失败"); } }
public void SwitchItems(int[] indexArr) { if (!EnableMuiltSelect) { LogFile.Warn("当前ScrollView为单选模式,请打开开关EnableMuiltSelect"); return; } for (int i = 0; i < indexArr.Length; i++) { switchItem(indexArr[i]); } onSelectStatusChanges(); }
public void UnselectItems(int[] indexArr) { if (!EnableMuiltSelect) { LogFile.Warn("当前ScrollView为单选模式,请打开开关EnableMuiltSelect"); return; } for (int i = 0; i < indexArr.Length; i++) { setItemSelected(indexArr[i], false); } onSelectStatusChanges(); }
/// <summary> /// 调用已经require或者doFile的lua全局函数(无参数) /// </summary> /// <param name="funcName">Func name.</param> public void CallGlobalFunc(string funcName) { LuaFunction func = GetFunction(funcName); if (null != func) { func.Call(); func.Dispose(); } else { LogFile.Warn("global lua func \"{0}\" do not found!"); } }
//public static string SetLanguage(int language, Action<bool> action, LuaFunction function) //{ // return SetLanguage((SystemLanguage)language, action, function); //} public static void SetLanguage(string language, Action <bool> action, LuaFunction function) { if (sLanguages.Contains(language)) { GameConfig.SetStr(GameDefine.STR_CUR_LANGUAGE, language); ResMgr.Instance.GetStrAsync(STR_BASE_ASB_PATH, "Language/" + language + ".bytes", (text) => { // TextAsset text = obj as TextAsset; bool ret = text != null; if (ret) { _resetLanguageData(text); } else { LogFile.Error("基础语言配置不存在:" + STR_BASE_ASB_PATH + "/Language/" + language + ".bytes"); } if (null != action) { action(ret); } if (null != function) { function.Call(ret); function.Dispose(); function = null; } ResManager.Instance.UnloadAssetBundle(STR_BASE_ASB_PATH); }); } else { LogFile.Warn("设置语言不存在:" + language + ",请初始化支持的语言"); if (null != action) { action(false); } if (null != function) { function.Call(false); function.Dispose(); function = null; } } }
void _onReadConf(bool rst, string msg) { if (rst) { mCotainPkgs = new List <string>(msg.Split(',')); } else { LogFile.Warn(msg); } if (null != mAllPkgNames) { mCotainCall(rst); } }
private void startAsync() { if (FuncStr.EndsWith("sprite", StringComparison.Ordinal)) { string spriteStr = ContentBefor as String; string[] _params = spriteStr.Split(','); if (_params.Length == 3) { GameSpriteAtlasManager.Instance.GetSpriteAsync(_params[0], _params[1], _params[2], (Sprite s) => { Content = s; if (null != mOnAsyncRst) { mOnAsyncRst(s); mOnAsyncRst = null; } ContentBefor = null; }); } else { LogFile.Warn("UIHandlerDataAsync error => can't get sprite:" + spriteStr); } return; } if (FuncStr.EndsWith("material", StringComparison.Ordinal)) { string str = ContentBefor as String; string[] _params = str.Split(','); if (_params.Length == 2) { GameResManager.Instance.GetAsync(_params[0], _params[1], (Material obj) => { Content = obj; if (null != mOnAsyncRst) { mOnAsyncRst(obj); mOnAsyncRst = null; } }); } else { LogFile.Warn("UIHandlerDataAsync error => can't get Material:" + str); } return; } }
void saveVersionCode() { int code = mCurConf.VersionCode; string key = GameDefine.STR_CONF_KEY_RES_VER_I; int curCode = GameConfig.GetInt(key); if (curCode < code) { GameConfig.SetInt(key, code); EventManager.NotifyMain(STR_EVENT_PKG_VERSION, mCurConf.version); } else { LogFile.Warn("保存 VersionCode 失败,当前包名:" + mPkgName + "; 新code:" + code + "; 当前 code:" + curCode); } }
public PlatformAnd() { if (Application.platform == RuntimePlatform.Android) { LogFile.Warn("PlatformAnd 开始"); AndroidJavaClass _class = new AndroidJavaClass("com.dekiven.gameframework.GF_PluginAndroid"); if (null != _class) { //_class.CallStatic("start"); mPluginObj = _class.CallStatic <AndroidJavaObject>("getInstance"); } if (null == mPluginObj) { LogFile.Error("GameFramework Android插件加载失败,请检查arr文件是否存在。"); } } }
public void LoadServConf(Action <Dictionary <string, string> > action, bool forceLoad = false) { if (null == mServConf || mServConf.Count == 0 || forceLoad) { LoadResServList((List <ResInfo> list) => { TimeOutWWW www = getTimeOutWWW(); List <string> files = new List <string>(); for (int i = 0; i < list.Count; i++) { files.Add(Tools.PathCombine(list[i].path, GameConfig.STR_ASB_MANIFIST + "/servConf.bytes")); } www.ReadFirstExistsStr("servConf", files, 0.2f, (bool rst, string msg) => { if (null == mServConf) { mServConf = new Dictionary <string, string>(); } else { mServConf.Clear(); } if (rst) { mServConf = Tools.SplitStr2Dic(msg, "\n", "|"); } else { LogFile.Warn("从资源服servConf.bytes失败"); } if (null != action) { action(mServConf); } }, null); }); } else { if (null != action) { action(mServConf); } } }
public void CheckServerRes(Action <bool, string> callback) { LoadServConf((Dictionary <string, string> conf) => { string tarUrl = Tools.GetUrlPathWriteabble(Tools.GetWriteableDataPath(), GameConfig.STR_ASB_MANIFIST); if (null != mResServList) { if (!Tools.GetBoolValue(conf, "isReview")) { checkService(mResServList, 0, tarUrl, callback); } } else { LogFile.Warn("服务器列表没有初始化"); } }); }
public T GetCompByName <T>(string name) where T : Component { int idx = mCompNames.IndexOf(name); if (!Equals(-1, idx)) { return(GetCompByIndex <T>(idx)); } else { LogFile.Warn( "{0}找不到name为{1}的组件。" , Tools.GetTransformName(transform, Camera.main.transform) , name ); } return(null); }
private static void _resetLanguageData(string text) { sDic.Clear(); //TODO: string[] lines = text.Split('\n'); for (int i = 0; i < lines.Length; i++) { string[] kv = Regex.Split(lines[i], sStrSplit, RegexOptions.IgnoreCase); if (kv.Length == 2) { sDic[kv[0].Replace("\n", "\\n")] = kv[1].Replace("\\n", "\n"); } else { LogFile.Warn("resetLanguageData error ----> line {0}: {1}", i, lines[i]); } } }
//TODO:考虑支持多个异步获取 public void GetAsync(string asbName, string assetName, Action <T> callback = null, LuaFunction luaFunction = null) { assetName = FixResName(assetName); T t = Get(asbName, assetName); if (null == t) { string groupName = CurGroup; mResMgr.LoadRes <T>(asbName, assetName, delegate(UnityEngine.Object obj) { t = obj as T; if (null != t) { _onLoad(asbName, assetName, t); if (null != callback) { callback(t); } if (null != luaFunction) { luaFunction.Call <T>(t); luaFunction.Dispose(); } } else { LogFile.Warn("GetAsync load:({0},{1})error.", asbName, assetName); } _addAsb2Group(asbName, groupName, new string[] { assetName, }); }); } else { if (null != callback) { callback(t); } if (null != luaFunction) { luaFunction.Call <T>(t); luaFunction.Dispose(); } } }
public void LoadScene(string asbName, string sceneName, bool sync, bool add, Action <float> callback = null, LuaFunction luaFunc = null) { ResManager.Instance.LoadScene(asbName, sceneName, sync, add, (float progress) => { if (progress.Equals(0)) { //开始载入场景时,计数+1 mCount.AddObj(curGroup, asbName, mCount.GetObj(asbName, sceneName) + 1); } if (progress.Equals(-1f)) { LogFile.Warn("加载场景失败, sceneName :{0} , asbName :{1}", sceneName, asbName); } if (null != callback) { callback(progress); } }, luaFunc); }
public T GetCompByIndex <T>(int index) where T : Component { T comp = null; if (index < Count) { comp = Components[index] as T; } else { LogFile.Warn( "{0}找不到index为{1},且类型是{2}的组件。" , Tools.GetTransformName(transform, Camera.main.transform) , index , typeof(T) ); } return(comp); }
private float _getAnimValue() { if (ViewAnimType.zoom == AnimType || ViewAnimDisType.pixelNum == AnimDisType) { return(AnimValue); } else { float v = 0f; Vector2 size = mRectTransform.rect.size; switch (AnimDisType) { case ViewAnimDisType.proportionParent: RectTransform rect = transform.parent as RectTransform; if (rect) { size = rect.rect.size; } else { LogFile.Warn(name + " has no parent with RectTransform! "); } break; case ViewAnimDisType.proportionScreen: size = Screen.safeArea.size; break; } switch (AnimType) { case ViewAnimType.move2Left: case ViewAnimType.move2Right: v = size.x * AnimValue; break; case ViewAnimType.moveDown: case ViewAnimType.moveUp: v = size.y * AnimValue; break; } return(v); } }
public static Rect GenRectByStr(string rectStr) { Rect rect = Rect.zero; string[] array = rectStr.Split(','); if (array.Length == 4) { float[] _params = new float[array.Length]; for (int i = 0; i < array.Length; i++) { if (!float.TryParse(array[i], out _params[i])) { LogFile.Warn("GenRectByStr error -> rectStr:" + rectStr); return(rect); } } return(GenRect(_params)); } return(rect); }
public static int[] GetIntArry(string content) { string[] array = content.Split(','); List <int> l = ObjPools.GetListInt(); for (int i = 0; i < array.Length; i++) { int v; if (!int.TryParse(array[i], out v)) { LogFile.Warn("GetIntArry error -> colorStr:" + content); } else { l.Add(v); } } int[] ret = l.ToArray(); ObjPools.Recover(l); return(ret); }
public void Load(string asbName, string[] names, string extral = null, bool isOrdered = false) { List <string> list = new List <string>(); foreach (var name in names) { string assetName = FixResName(name); if (null == Get(asbName, assetName)) { list.Add(assetName); } _addAsbInfo(asbName, assetName, extral, isOrdered); } string groupName = CurGroup; mResMgr.LoadRes <T>(asbName, names, delegate(UnityEngine.Object[] obj) { if (obj.Length == names.Length) { for (int i = 0; i < names.Length; i++) { T t = obj[i] as T; if (null != t) { _onLoad(asbName, names[i], t); } else { LogFile.Warn("load:({0},{1})error.", asbName, names[i]); } } } else { LogFile.Warn("load {0} error, names.count={1}, obj.Count={2}", asbName, names.Length, obj.Length); } _addAsb2Group(asbName, groupName, names); }); }