/// <summary> /// 检查更新资源 /// </summary> /// <returns></returns> IEnumerator UpdateResource() { m_updateState = 1; isDownloadDone = false; LoadCurrentMd5Table(); LoadHasUpdateSet(); bool bCheck = CheckOldMd5File(); bool bVersion = (currentVersion.Revised < onlineVersion.Revised); Debuger.LogError("是否需要更新资源= " + bVersion + ", 沙河目录的app版本 = " + currentVersion + ", 服务器上的app版本 = " + onlineVersion); if (!bCheck && !bVersion) { m_updateState = 3; isDownloadDone = true; yield break; } m_urlIndex = GameConfig.UpdateServer.Length - 1; m_loadOver = false; while (!m_loadOver && m_urlIndex > 0) { yield return(SingletonMono <GameFrameWork> .GetInstance().StartCoroutine(DownloadMD5File())); m_urlIndex++; } if (!m_loadOver) { m_updateState = 4; yield break; } DeleteUselessFiles(); GetDownloadFileList(); if (!isDownloadDone) { if (Util.IsCarrier) { if (TotalDownloadSize > 1048576) { AlertContextText.text = string.Format(Singleton <LanguageManager> .GetInstance().GetLanguage(LanguageId.DownloadSizeAlert), TotalDownloadSize / 1048576f); AlertObject.SetActive(true); EventTriggerListener.Get(CancelButton.gameObject).SetEventHandle(EnumTouchEventType.OnClick, (a, b, c) => { Application.Quit(); }); EventTriggerListener.Get(SureButton.gameObject).SetEventHandle(EnumTouchEventType.OnClick, (a, b, c) => { AlertObject.gameObject.SetActive(false); SingletonMono <GameFrameWork> .GetInstance().StartCoroutine(BeginDownloadResource()); }); } else { SingletonMono <GameFrameWork> .GetInstance().StartCoroutine(BeginDownloadResource()); } } else { SingletonMono <GameFrameWork> .GetInstance().StartCoroutine(BeginDownloadResource()); } } else { m_updateState = 3; } }
public static void LogError(string str) { Debuger.LogError(str); }
static bool TryParse(int indent, string val, Type type, out object outVal) { outVal = null; if (type.Equals(typeof(string))) { outVal = val; } else if (type.Equals(typeof(bool))) { bool temBool; if (StringUtil.TryParse(val, out temBool)) { outVal = temBool; } else { return(false); } } else if (type.Equals(typeof(int))) { int temInt; if (int.TryParse(val, out temInt)) { outVal = temInt; } else { return(false); } } else if (type.Equals(typeof(float))) { float temFloat; if (float.TryParse(val, out temFloat)) { outVal = temFloat; } else { return(false); } } else if (type.Equals(typeof(Vector3))) { Vector3 temV3; if (StringUtil.TryParse(val, out temV3, s_indentSplit[indent])) { outVal = temV3; } else { return(false); } } else if (type.IsEnum) { int temInt; if (int.TryParse(val, out temInt)) { outVal = Enum.ToObject(type, temInt); } else { outVal = Enum.Parse(type, val); } } else if (type.Equals(typeof(long))) { long temLong; if (long.TryParse(val, out temLong)) { outVal = temLong; } else { return(false); } } else if (type.Equals(typeof(double))) { double temDouble; if (double.TryParse(val, out temDouble)) { outVal = temDouble; } else { return(false); } } else if (type.IsArray)//数组 { string[] pp = val.Split(s_indentSplit[indent]); if (pp != null && pp.Length > 0) { Type elemType = type.GetElementType(); Array arr = Array.CreateInstance(elemType, pp.Length); object arrObj; for (int i = 0; i < pp.Length; ++i) { if (TryParse(indent + 1, pp[i], elemType, out arrObj)) { arr.SetValue(arrObj, i); } else { return(false); } } outVal = arr; } } else if (type.GetInterface("System.Collections.IList") != null) //list { string[] pp = val.Split(s_indentSplit[indent]); if (pp != null && pp.Length > 0) { MethodInfo m = type.GetMethod("get_Item");//list的索引器的返回值就是对应类型 if (m == null) { Debuger.LogError("找不到索引器 不能确定类型:" + type.Name); return(false); } IList list = (IList)Activator.CreateInstance(type); object arrObj; for (int i = 0; i < pp.Length; ++i) { if (TryParse(indent + 1, pp[i], m.ReturnType, out arrObj)) { list.Add(arrObj); } else { return(false); } } outVal = list; } } else { //如果有带一个string参数的构造函数 ConstructorInfo constructor = type.GetConstructor(stringParam); if (constructor != null) { outVal = Activator.CreateInstance(type, val); } //如果有个Init(string)函数,这个主要是用于一些类必须构造函数没有参数的情况 else { string[] pp = val.Split(s_indentSplit[indent]); MethodInfo initMethod = type.GetMethod("Init", stringArrParam); if (initMethod != null) { outVal = Activator.CreateInstance(type); initMethod.Invoke(outVal, new object[] { pp }); } else { return(false); } } } return(true); }
private void OnRoomReadyError(string msg, uint roomId) { Debuger.LogError(msg); }
public static void LoadAvatar(string wrapName, string skletonName, string hairName, string faceName, string bodyName, string cardName, string glassesName, string wingName, Action <Avatar> callback) { ResourceManager.Instance.LoadPrefabAsync(wrapName, wrapName, (obj, args) => { Avatar avatar = obj.GetComponent <Avatar>(); avatar.mIsSuit = false; if (avatar == null) { Debuger.LogError("other", "Avatar script is missing, please Check!"); if (callback != null) { callback(null); } } else { int num = 0; Action CheckPackageOver = () => { num++; if (num == (int)PartType.eMax) { if (callback != null) { callback(avatar); } } }; //加载骨骼 avatar.ChangePart(Avatar.PartType.eSkeleton, skletonName, () => { CheckPackageOver(); //加载头发 avatar.ChangePart(Avatar.PartType.eHair, hairName, () => { CheckPackageOver(); }); //加载脸部 avatar.ChangePart(Avatar.PartType.eFace, faceName, () => { CheckPackageOver(); }); //加载身体 avatar.ChangePart(Avatar.PartType.eBody, bodyName, () => { CheckPackageOver(); }); //加载牌 avatar.ChangePart(Avatar.PartType.eCard, cardName, () => { CheckPackageOver(); }); //加载眼镜 avatar.ChangePart(Avatar.PartType.eGlasses, glassesName, () => { CheckPackageOver(); }); //加载翅膀 avatar.ChangePart(Avatar.PartType.eWing, wingName, () => { CheckPackageOver(); }); }); } }); }
//删除一个子节点 protected virtual bool OnRemoveChild(string key) { Debuger.LogError("没有实现"); return(false); }
public string showUI(string name, bool force = false) { if (name.isNullOrEmpty()) { Debuger.LogError("showUI error, the name is null"); return(""); } GameObject go; string newName = name; if (uiInstanceDic.TryGetValue(name, out go)) { //已经创建了该面板 if (force) { //强制创建新面板(例如messagebox同时存在多个对象实例) for (int i = 0; i <= UIINSTANCEMAX; ++i) { newName = name + "_" + i; if (!uiInstanceDic.ContainsKey(newName)) { break; } if (i == UIINSTANCEMAX) { Debuger.LogError("showUI failed, the number of ui instance is to large"); return(""); } } } else { //无需创建新面板 go.SetActive(true); go.transform.SetAsLastSibling(); return(name); } } //创建 createUI(newName, (newGo) => { if (newGo != null) { if (uiInstanceDic.ContainsKey(newName)) { return; } uiInstanceDic.Add(newName, newGo); } else { Debuger.LogError("createUI failed"); } }); return(newName); }
//注意外部一定要传进来一个默认的碰撞点collidePos(比如target),内部不一定会修改这个值 public static bool Hit(Vector3 source, Vector3 dir, Vector3 target, float radius, RangeCfg cfg, float factor = 0f) { float offsetAngle; Vector3 offsetPos; if (factor == 0) { offsetAngle = cfg.beginOffsetAngle; offsetPos = cfg.begingOffsetPos; } else if (factor == 1f) { offsetAngle = cfg.endOffsetAngle; offsetPos = cfg.endOffsetPos; } else { offsetAngle = Mathf.Lerp(cfg.beginOffsetAngle, cfg.endOffsetAngle, factor); offsetPos = Vector3.Lerp(cfg.begingOffsetPos, cfg.endOffsetPos, factor); } //计算偏移后的点 dir.y = 0;//y方向无效 if (offsetAngle != 0) { dir = Quaternion.Euler(0, offsetAngle, 0) * dir; } if (dir == Vector3.zero)//没有方向??? { Debuger.LogError("没有方向"); return(false); } dir.y = 0; if (offsetPos != Vector3.zero) { source += Quaternion.LookRotation(dir) * offsetPos; } if (!HitHeight(source.y, target.y, cfg.heightLimit)) { return(false); } //开始2d相关计算 if (cfg.IngoreRadius)//有时候不希望计算半径 { radius = 0; } target.y = source.y; Vector3 link = target - source; Vector2 source2d = new Vector2(source.x, source.z); Vector2 target2d = new Vector2(target.x, target.z); Vector2 link2d = new Vector2(link.x, link.z); Vector2 dir2d = new Vector2(dir.x, dir.z); float disSq = link2d.sqrMagnitude; float radSq = radius * radius; //如果source在target圆上那么就已经碰撞了 if (disSq <= radSq) { return(true); } //不同类型的碰撞检测 if (cfg.type == enRangeType.circle) { //半径 if (disSq >= cfg.distance * cfg.distance + radSq + 2 * cfg.distance * radius)//a>(b+c) => a^2>(b+c)^2 { return(false); } //计算碰撞的点 //if (needCollidePos) //{ // Vector2 collide2d = source2d + link2d - link2d.normalized * radius; // collidePos.Set(collide2d.x, collidePos.y, collide2d.y); //} return(true); } else if (cfg.type == enRangeType.sector) { //半径 if (disSq >= cfg.distance * cfg.distance + radius * radius + 2 * cfg.distance * radius)//a>(b+c) => a^2>(b+c)^2 { return(false); } //夹角 float angle = Vector2.Angle(dir2d, link2d); if (angle <= cfg.angleLimit)//圆心在扇形内的情况,那么交点和圆一样计算 { ////计算碰撞的点 //if (needCollidePos) //{ // Vector2 collide2d = source2d + link2d - link2d.normalized * radius; // collidePos.Set(collide2d.x, collidePos.y, collide2d.y); //} return(true); } else if (radius == 0)//优化下,如果为0,则判断下扇形内就足够了 { return(false); } else//圆心在扇形外的情况 { //用相对于source方向同一边的扇形的边缘做碰撞检测 Vector3 dirAngle; if (Vector3.Cross(dir, link).y > 0) { dirAngle = Quaternion.Euler(new Vector3(0, cfg.angleLimit, 0)) * dir; } else { dirAngle = Quaternion.Euler(new Vector3(0, -cfg.angleLimit, 0)) * dir; } if (dirAngle.y != 0)//检错下 { Debuger.LogError("计算出来的方向不为2d的"); } //Debug.DrawRay(source + Vector3.up*1, dirAngle*20, Color.yellow, 3); //计算有没有交点 Vector2 dirAngle2d = new Vector2(dirAngle.x, dirAngle.z); Vector2 project2d = Util.Project(link2d, dirAngle2d); //投影在方向上的点(相对于source) Vector2 verticalDir2d = link2d - project2d; //垂线,投影在角色方向上的点到target(相对于source) //Vector3 project = new Vector3(project2d.x,source.y ,project2d.y); //Debug.DrawRay(source + project + Vector3.up * 1, new Vector3(verticalDir2d.x, 0, verticalDir2d.y) , Color.red, 3); float vDirSq = verticalDir2d.sqrMagnitude; if (vDirSq > radSq)//投影点在圆外,那么碰撞不到 { return(false); } if (vDirSq == radSq) //投影点在圆上 { if (angle < 90 && Vector2.Dot(project2d, dirAngle2d) < 0) //如果要求夹角是小于90的那么要判断方向是不是在主角前方 { return(false); } //if (needCollidePos) //{ // Vector2 collide2d = source2d + project2d; // collidePos.Set(collide2d.x, collidePos.y, collide2d.y); //} return(true); } else //投影点在圆内 { if (angle < 90 && Vector2.Dot(project2d, dirAngle2d) < 0)//如果要求夹角是小于90的那么要判断方向是不是在主角前方 { return(false); } //if (needCollidePos) //{ // float d = Mathf.Sqrt(radSq - vDirSq);//交点到投影点的距离,勾股定理求第三边,这里按照之前的判断是肯定能成直角三角形的 // Vector2 collide2d = source2d + project2d - project2d.normalized * d; // collidePos.Set(collide2d.x, collidePos.y, collide2d.y); //} return(true); } } } else if (cfg.type == enRangeType.rect) { //先计算出到角色方向上的投影点 Vector2 project2d = Util.Project(link2d, dir2d); //投影在方向上的点(相对于source) Vector2 verticalDir2d = link2d - project2d; //垂线,投影在角色方向上的点到target(相对于source) float vDirSq = verticalDir2d.sqrMagnitude; Vector3 project = new Vector3(project2d.x, source.y, project2d.y); Vector3 vertical = new Vector3(verticalDir2d.x, 0, verticalDir2d.y); //Debug.DrawRay(source +project+ Vector3.up * 1, vertical, Color.yellow, 3); //宽度限制 if (vDirSq >= cfg.rectLimit * cfg.rectLimit + radSq + 2 * cfg.rectLimit * radius)//a>(b+c) => a^2>(b+c)^2 { return(false); } //长度限制 float halfDis = cfg.distance / 2; //Vector2 center = source2d + dir2d.normalized*cfg.distance/2;//中心点,矩形的中心点 //Vector2 linkCenter2d = target2d-source2d; float hDir = Vector2.Dot(dir2d, project2d) < 0 ? project2d.magnitude + halfDis : Mathf.Abs(project2d.magnitude - halfDis); //算出投影点到中心点的距离 float hDirSq = hDir * hDir; if (hDirSq >= halfDis * halfDis + radSq + 2 * halfDis * radius) //a>(b+c) => a^2>(b+c)^2 { return(false); } //计算碰撞的点 //if (needCollidePos) //{ // Vector2 collide2d = source2d + link2d - link2d.normalized * radius; // collidePos.Set(collide2d.x, collidePos.y, collide2d.y); //} return(true); } else { Debuger.LogError("不能用ColliderUtil系统检测的类型:{0}", cfg.type); } return(false); }
void Awake() { //jlx2017.04.20-log:放在Awakw内部赋值tableCtrl和tableView tableView = LuaProxy.instance.getLuaTable(name + "View"); if (tableView == null) { Debuger.LogError("UIProxy tableView get error!"); return; } tableCtrl = LuaProxy.instance.getLuaTable(name + "Ctrl"); if (tableCtrl == null) { Debuger.LogError("createUI tableCtrl get error!"); return; } tableView["transform"] = transform; tableView["ctrl"] = tableCtrl; tableCtrl["transform"] = transform; tableCtrl["gameObject"] = gameObject; tableCtrl["view"] = tableView; LuaFunction viewInit = tableView.GetLuaFunction("onInit"); if (viewInit != null) { viewInit.Call(tableView); viewInit.Dispose(); viewInit = null; } LuaFunction viewAwake = tableView.GetLuaFunction("onCreate"); if (viewAwake != null) { viewAwake.Call(tableView); viewAwake.Dispose(); viewAwake = null; } LuaFunction ctrlInit = tableView.GetLuaFunction("onInit"); if (ctrlInit != null) { ctrlInit.Call(tableCtrl); ctrlInit.Dispose(); ctrlInit = null; } LuaFunction ctrlAwake = tableCtrl.GetLuaFunction("onCreate"); if (ctrlAwake != null) { ctrlAwake.Call(tableCtrl); ctrlAwake.Dispose(); ctrlAwake = null; } }
//每一帧有且只有一次被更新 //frame 当前帧 //loopCount 当前第几次动作循环 //trueframe 真实达到第几帧的 //end 真实是不是结束 //root 用于创建的时候计算位置用 public void UpdateFrame(int frame, int loop, bool isEnd, Transform root) { //检查销毁 if (endFrame > 0 && beginFrame + endFrame == frame && fxs.Count != 0) { Destroy(); } if (frame != beginFrame) { return; //不是这一帧 } if (prefab == null) { return; } if (loop > 0 && !loopCreate) { return; //已经循环过一次就不用创建了 } if (isEnd && (destroyIfAniEnd)) { return; //如果是动作结束销毁的,那么就不用创建了 } #if !ART_DEBUG //调试 if (onRuntimeCreate == null && canHide && !QualityMgr.instance.roleAniFx) { return; } #endif //不同元素属性创建不同特效 GameObject curPrefab = prefab; switch (this.parent.RuntimeElement) { case enAniFxElement.none: curPrefab = prefab; break; case enAniFxElement.fire: curPrefab = prefabFire; break; case enAniFxElement.ice: curPrefab = prefabIce; break; case enAniFxElement.thunder: curPrefab = prefabThunder; break; case enAniFxElement.dark: curPrefab = prefabDark; break; default: Debuger.LogError("动作特效 未知的元素类型:{0}", this.parent.RuntimeElement); break; } if (curPrefab == null) { curPrefab = prefab; } //1 创建特效 GameObject go = GameObjectPool.GetPool(GameObjectPool.enPool.Fx).GetImmediately(curPrefab.name, false); if (go == null) { //Debuger.LogError("逻辑错误动作绑定特效加载后为空");//这里只支持预加载,不支持异步加载,没有预加载过报错 return; } //2 设置位置和方向 Transform t = go.transform; if (type == enCreateType.bone)//绑定骨骼 { Transform target = GetTarget(root); if (follow) { t.SetParent(target, false); //t.localScale = Vector3.one; t.localPosition = offset; t.localEulerAngles = euler; } else { t.position = target.TransformPoint(offset); t.rotation = target.rotation * Quaternion.Euler(euler); } } else if (type == enCreateType.matrial)//绑定材质 { Transform target = root.Find("model/body_mesh"); if (target != null) { t.SetParent(target, false); //t.localScale = Vector3.one; t.localPosition = Vector3.zero; t.localEulerAngles = Vector3.zero; } target = root.Find("model/weapon_mesh"); if (target != null) { GameObject go2 = GameObjectPool.GetPool(GameObjectPool.enPool.Fx).GetImmediately(prefab.name, false); Transform t2 = go2.transform; t2.SetParent(target, false); t2.localPosition = Vector3.zero; t2.localEulerAngles = Vector3.zero; go2.SetActive(true);//设好了父节点了,这个时候再SetActive fxs.Add(go2); } } else { Debuger.LogError("未知的类型:{0}", type); } go.SetActive(true);//设好了父节点了,这个时候再SetActive //如果飞出物上没有任何销毁的脚本,那么提示下 if (!destroyIfAniEnd && endFrame <= 0 && !FxDestroy.HasDelay(go)) { Debuger.LogError("动作特效上没有绑销毁脚本,动作上也没有指定结束帧.特效名:{0}", go.name); } //加到列表中,方便管理 fxs.Add(go); //运行时创建回调 if (onRuntimeCreate != null) { onRuntimeCreate(go, onRuntimeCreateParam); } }
public override bool getValue(IoBuffer ioBuffer, System.Type type, byte flag, out object value) { value = null; if (ioBuffer.ReadSize < 4) { Debuger.LogError("可读字节长度不足" + 4); return(false); } int code = ioBuffer.ReadInt32(); //取键数 int fieldCount; if (!readVarInt32(ioBuffer, out fieldCount)) { return(false); } if (ioBuffer.ReadSize < 4) { Debuger.LogError("可读字节长度不足" + 4); return(false); } var objLen = ioBuffer.ReadInt32(); //减去objLen自己占用4字节 objLen -= 4; if (ioBuffer.ReadSize < objLen) { Debuger.LogError("可读字节长度不足" + objLen); return(false); } // 类型的获取 TypeDef def = ProtocolCoder.instance.getTypeDef(code); if (def == null) { Debuger.LogError("类型定义{0}不存在", type.Name); return(false); } if (def.type != type) { Debuger.LogError("类型不匹配。TypeDef:{0} Type:{1}", def.type.Name, type.Name); return(false); } value = System.Activator.CreateInstance(type); //先保存读取位置,如果后面有多余的字段,就跳过去 var readPos1 = ioBuffer.ReadPos; BeginParentLog(type.Name, fieldCount); var fieldCountInCfg = def.fields.Length; for (int i = 0; i < fieldCount; i++) { if (i < fieldCountInCfg) { FieldInfo fieldInfo = def.fields[i]; AddLogNewLine(fieldInfo.Name + ": ");//加个分隔符 object obj; if (!ProtocolCoder.instance.Decode(ioBuffer, fieldInfo.FieldType, out obj)) { return(false); } fieldInfo.SetValue(value, obj); AddLog(",");//加个分隔符 } else { Debuger.Log("实际数据成员数比配置的多,主类型:{0}", type.Name); //居然实现字段比描述的字段还多,看来对方加字段了,这里跳过这个对象剩余的数据吧 var readPos2 = ioBuffer.ReadPos; //对象总长度减去已读的长度 ioBuffer.Skip(objLen - (readPos2 - readPos1)); break; } } EndParentLog(); return(true); }
public void Remove(MaterialHandle h) { if (this == null) { return; //可能已经被销毁 } if (h.m_shareThing == null) //防止死锁 { return; } Cache(); int idx = m_materials.IndexOf(h.m_shareThing); if (idx == -1) { Debuger.LogError("逻辑错误,找不到shareThing"); h.m_shareThing = null;//防止死锁 return; } //从shareThing中删除 ShareThing st = m_materials[idx]; bool needChange = st.Get() == h; //如果最顶的不是h,那么肯定是不用改变render的材质的 st.Remove(h); //remove里执行了h.m_shareThing = null,必须保证在h.fx.Stop()之前执行,不然可能造成死锁 //Remove和stop可能会互相调用,要判断下内部已经做了判断 h.fx.Stop(); //不需要改材质 if (!needChange) { return; } //计算要改的材质 bool remove = false; Material newMat = null; MaterialHandle newH = st.Get <MaterialHandle>(); if (newH == null)//已经没有特效材质的情况,这个时候有原始材质就换回原始材质,没有就删除 { if ((bool)st.m_param2) { newMat = (Material)st.m_param; } else { m_materials.RemoveAt(idx); remove = true; } } else//有别的特效材质的情况 { newMat = newH.mat; } //真正把材质放到Render上 Material[] mats = m_render.sharedMaterials; int length = remove ? mats.Length - 1 : mats.Length; Material[] newMats = new Material[length]; int curIdx = 0; for (int i = 0; i < mats.Length; ++i) { if (i == idx) { if (remove == false) { newMats[curIdx] = newMat; } } else { newMats[curIdx] = mats[i]; } if (i != idx || remove == false) { ++curIdx; } } m_render.sharedMaterials = newMats; }
public MaterialHandle Add(MaterialFx fx) { Cache(); Material startMat = null; //获取原始材质 if (fx.m_type == MaterialFx.enType.replace || fx.m_type == MaterialFx.enType.modify) { if (fx.m_matIndex >= m_materials.Count || m_materials[fx.m_matIndex].m_param == null) { Debuger.LogError("找不到对应材质,或者要改变材质的render材质丢失 fx:{0} index:{1}", fx.name, fx.m_matIndex); return(null); } startMat = (Material)m_materials[fx.m_matIndex].m_param; } //创建新材质 Material newMat; if (fx.m_type == MaterialFx.enType.add || fx.m_type == MaterialFx.enType.replace) { if (fx.m_mat == null) { Debuger.LogError("材质没有填 fx:{0} ", fx.name); return(null); } if (fx.m_anis.Count == 0 && (fx.m_type == MaterialFx.enType.add || !fx.m_useOldTex))//不需要渐变的情况下材质不需要复制 { newMat = fx.m_mat; } else { newMat = new Material(fx.m_mat); newMat.name = fx.m_mat.name + "(Clone)"; } } else if (fx.m_type == MaterialFx.enType.modify) { newMat = new Material(startMat); newMat.name = startMat.name + "(Clone)"; } else { Debuger.LogError("未知的类型:{0}", fx.m_type); return(null); } //如果有多个(Clone)后缀,那只保留一下 //if (newMat.name.EndsWith("(Clone)(Clone)")) //newMat.name = newMat.name.Replace("(Clone)", "") + "(Clone)"; //替换新材质的贴图 if (fx.m_useOldTex && startMat != null) { Texture tex; if (startMat.HasProperty("_MainTex")) { tex = startMat.GetTexture("_MainTex"); } else if (startMat.HasProperty("_MainTexAlpha")) { tex = startMat.GetTexture("_MainTexAlpha"); } else { Debuger.LogError("找不到老材质的贴图 fx:{0} index:{1}", fx.name, fx.m_matIndex); return(null); } if (newMat.HasProperty("_MainTex")) { newMat.SetTexture("_MainTex", tex); } else if (newMat.HasProperty("_MainTexAlpha")) { newMat.SetTexture("_MainTexAlpha", tex); } else { Debuger.LogError("找不到新材质的贴图 fx:{0} index:{1}", fx.name, fx.m_matIndex); return(null); } } //添加到共享事物里进行管理 MaterialHandle handle = new MaterialHandle(fx, newMat, this); ShareThing st; int idx; if (fx.m_type == MaterialFx.enType.add) { st = new ShareThing(); st.m_param = null; //原始材质记录下来,在这里没有原始材质 st.m_param2 = false; //表明不是是角色创建的时候就有的材质 m_materials.Add(st); st.Add(handle); idx = m_materials.Count - 1; } else { st = m_materials[fx.m_matIndex]; st.Add(handle); idx = fx.m_matIndex; } //真正把材质放到Render上 bool needChange = handle == st.Get(); if (needChange) { Material[] mats = m_render.sharedMaterials; int length = Mathf.Max(idx + 1, mats.Length); Material[] newMats = new Material[length]; for (int i = 0; i < length; ++i) { if (i == idx) { newMats[i] = newMat; } else { newMats[i] = mats[i]; } } m_render.sharedMaterials = newMats; } return(handle); }
IEnumerator BeginDownloadResource() { System.Net.ServicePointManager.DefaultConnectionLimit = DOWNLOAD_COUNT; m_updateState = 2; m_urlIndex = 0; Debuger.LogError("开始下载时间 " + Time.realtimeSinceStartup); while (m_urlIndex < GameConfig.UpdateServer.Length) { SrcUrl = GameConfig.UpdateServer[m_urlIndex] + Platform.osDir + "/"; CurrentDownCount = 0; m_taskQueue.Clear(); m_redownloadList.Clear(); foreach (string s in m_downloadList) { string url = SrcUrl + s; string filepath = Platform.Path + s; DownloadTask task = new DownloadTask(url, s, filepath); task.callback = DownCallBack; m_taskQueue.Enqueue(task); } if (m_taskQueue.Count > 0) { for (int i = 0; i < 5; i++) { Thread thread = new Thread(ThreadProc); thread.Name = "download thread: " + i; thread.Start(); } while (CurrentDownCount != m_downloadList.Count) { yield return(null); } if (m_redownloadList.Count > 0) { m_downloadList.Clear(); foreach (string s in m_redownloadList) { m_downloadList.Add(s); } } else { Debuger.LogError("下载结束时间 " + Time.realtimeSinceStartup); if (newmd5Table.Count > 0) { SaveMD5Table(newmd5Table); } //清空hasupdate的内容 ClearResourceHasUpdate(); isDownloadDone = true; Debuger.LogError("下载完成.........."); RefAppVersion(currentVersion, onlineVersion); break; } } else { if (newmd5Table.Count > 0) { SaveMD5Table(newmd5Table); } ClearResourceHasUpdate(); isDownloadDone = true; Debuger.LogError("下载完成........"); RefAppVersion(currentVersion, onlineVersion); yield break; } m_urlIndex++; } m_updateState = 3; if (m_redownloadList.Count > 0) { m_updateState = 4; foreach (string file in m_redownloadList) { Debuger.LogError("下载文件出错 " + file); } } }
//修改一个子节点 protected virtual bool OnChangeChild(ISerializableObject item) { Debuger.LogError("没有实现"); return(false); }
public void ExecCreateAssetBunldes() { //取得在 Project 视图中选择的资源(包含子目录中的资源) Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); if (SelectedAsset == null) { EditorUtility.DisplayDialog("AssetBunlde", "Nothing is Selected", "Close"); return; } foreach (Object obj in SelectedAsset) { if (ABTools.MissingMono(obj)) { continue; } #if UNITY_IPHONE string targetPath = ABConfig.OutputFolderIPhone + obj.name + ABConfig.extensionName; #elif UNITY_STANDALONE_WIN string targetPath = ABConfig.OutputFolderWindows32 + obj.name + ABConfig.extensionName; #elif UNITY_ANDROID string targetPath = ABConfig.OutputFolderAndroid + obj.name + ABConfig.extensionName; #else string targetPath = ABConfig.OutputFolderWindows32 + obj.name + ABConfig.extensionName; #endif // UNITY_STANDALONE_WIN if (File.Exists(targetPath)) { File.Delete(targetPath); } #if UNITY_IPHONE //建立 AssetBundle if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, // | BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone)) { Debuger.Log(targetPath + "建立完成"); } else { Debuger.LogError(obj.name + "建立失败"); } #elif UNITY_STANDALONE_WIN //建立 AssetBundle if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, // | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows)) { Debuger.Log(targetPath + "建立完成"); } else { Debuger.LogError(obj.name + "建立失败"); } #elif UNITY_ANDROID //建立 AssetBundle if (BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies, // | BuildAssetBundleOptions.CompleteAssets, BuildTarget.Android)) { Debuger.Log(targetPath + "建立完成"); } else { Debuger.LogError(obj.name + "建立失败"); } #endif // UNITY_STANDALONE_WIN AssetDatabase.Refresh(); } EditorUtility.DisplayDialog("AssetBunlde", "BuildTarget.StandaloneWindows Over", "Close"); }
//删除一个子节点 protected virtual bool OnRemoveChild(int idx) { Debuger.LogError("没有实现"); return(false); }
//其他线程要打印信息的时候 public static void SafeLogError(string format, params object[] args) { Debuger.LogError(string.Format(format, args)); }
//清空所有子节点 protected virtual bool OnClearChild() { Debuger.LogError("没有实现"); return(false); }
static public void AddAniToRolePrefab() { GameObject model = Selection.activeGameObject; if (model == null) { Debuger.LogError("请先选中一个模型"); return; } string name = model.name; int postfix = name.IndexOf("@"); if (postfix != -1) { name = name.Substring(0, postfix); } Debuger.Log("要找的模型名:{0}", name); //拿之前的预制体和创建一个临时的对象(这里不支持覆盖,因为可能会导致绑定在动作上的特效的骨骼点丢失) string path = string.Format("Assets/FBX/Resources/{0}.prefab", name); GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (prefab == null) { EditorUtility.DisplayDialog("", string.Format("{0}不存在不能添加动作", path), "确定"); return; } string modelPath = AssetDatabase.GetAssetPath(model); Transform mod = prefab.transform.Find("model"); Animation ani = mod.GetComponent <Animation>(); UnityEngine.Object.DestroyImmediate(ani, true);//删除老的animation ani = mod.gameObject.AddComponent <Animation>(); ////删除掉所有老动作 //SerializedObject so = new SerializedObject(ani); //so.Update(); //SerializedProperty serializedProperty = so.FindProperty("m_Animation"); //serializedProperty.objectReferenceValue=null; //SerializedProperty serializedProperty2 = so.FindProperty("m_Animations"); //serializedProperty2.ClearArray(); //so.ApplyModifiedProperties(); //UnityEditor.AssetDatabase.Refresh(); //UnityEditor.AssetDatabase.SaveAssets(); //找到所有动作并加到临时对象的模型上 string dir = System.IO.Path.GetDirectoryName(modelPath); string filter = "t:AnimationClip";//string.Format("n:{0}@", model.name); string[] guids = AssetDatabase.FindAssets(filter, new string[] { dir }); foreach (string guid in guids) { string aniPath = AssetDatabase.GUIDToAssetPath(guid); GameObject aniPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(aniPath); if (aniPrefab == null) { Debuger.LogError("不能从{0}获取动作信息", aniPath); continue; } Animation a = aniPrefab.GetComponent <Animation>(); if (a == null) { Debuger.LogError("逻辑异常,获取不到animation2,可能设置有问题"); continue; } foreach (AnimationState st in a) { if (ani[st.name] != null) { continue; } ani.AddClip(st.clip, st.name); } } UnityEditor.EditorUtility.SetDirty(prefab); UnityEditor.AssetDatabase.Refresh(); UnityEditor.AssetDatabase.SaveAssets(); EditorUtility.DisplayDialog("", "完成", "确定"); }
private void OnJoinRoomError(string msg, uint roomId) { Debuger.LogError(msg); }
protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null) { // Check the window control state if (!this.IsWindowInControl(id)) { Debuger.Log("## UIManager has no control power of " + id.ToString()); return(null); } // If the window in shown list just return if (dicShownWindows.ContainsKey((int)id)) { return(null); } UIBaseWindow baseWindow = GetGameWindow(id); // If window not in scene start Instantiate new window to scene bool newAdded = false; if (!baseWindow) { newAdded = true; if (UIResourceDefine.windowPrefabPath.ContainsKey((int)id)) { string prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[(int)id]; GameObject prefab = Resources.Load <GameObject>(prefabPath); if (prefab != null) { GameObject uiObject = (GameObject)GameObject.Instantiate(prefab); NGUITools.SetActive(uiObject, true); // NOTE: You can add component to the window in the inspector // Or just AddComponent<UIxxxxWindow>() to the target baseWindow = uiObject.GetComponent <UIBaseWindow>(); if (baseWindow.ID != id) { Debuger.LogError(string.Format("<color=cyan>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id)); return(null); } // Get the window target root parent Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform); dicAllWindows[(int)id] = baseWindow; } } } if (baseWindow == null) { Debuger.LogError("[window instance is null.]" + id.ToString()); } // Call reset window when first load new window // Or get forceResetWindow param if (newAdded || (showData != null && showData.forceResetWindow)) { baseWindow.ResetWindow(); } if (showData == null || (showData != null && showData.executeNavLogic)) { // refresh the navigation data ExecuteNavigationLogic(baseWindow, showData); } // Adjust the window depth AdjustBaseWindowDepth(baseWindow); // Add common background collider to window AddColliderBgForWindow(baseWindow); return(baseWindow); }
private void OnStartGameError(string msg, int roomId) { Debuger.LogError(msg); }
public static void LogError(string log) { Debuger.LogError(log); }
private void ChangePartShareSkeletonReal(PartData partData, Action callback) { if (this == null) { //当加载完成的时候,avatar自身已经被销毁了,所以这里要做判断 if (callback != null) { callback(); } if (partData != null && partData.mObj != null) { AvatarManager.Instance.CachePart(partData); } Debuger.Log("other", "ChangePartShareSkeletonReal this is null"); return; } if (partData == null || partData.mObj == null) { if (callback != null) { callback(); } Debuger.Log("other", "ChangePartShareSkeletonReal partData is null"); return; } Transform parentTrans = GetPartParent(partData.mType); if (parentTrans != null) { partData.mObj.SetActive(true); mPartDic[partData.mType] = partData; partData.mObj.transform.SetParent(parentTrans, false); ResetTransform(partData.mObj); SkinnedMeshRenderer[] allmr = partData.mObj.GetComponentsInChildren <SkinnedMeshRenderer>(); if (allmr != null) { for (int m = 0; m < allmr.Length; m++) { if (allmr[m] != null && mPartDic[PartType.eSkeleton].mObj != null) { SkinnedMeshRenderer mr = allmr[m]; //首先缓存骨骼名字 List <string> bonesNameList; if (!partData.mBonesDict.TryGetValue(mr.gameObject.name, out bonesNameList)) { bonesNameList = new List <string>(); partData.mBonesDict[mr.gameObject.name] = bonesNameList; for (int i = 0; i < mr.bones.Length; i++) { if (mr.bones[i] == null) { Debuger.LogError("other", "ChangePartShareSkeletonReal mr.bones[i] is null please check!!!!"); break; } else { bonesNameList.Add(mr.bones[i].gameObject.name); } } } //将骨骼部件 替换到 指定的部件 Transform[] skeletonTrans = mPartDic[PartType.eSkeleton].mObj.GetComponentsInChildren <Transform>(); if (skeletonTrans != null && bonesNameList != null) { List <Transform> newBoneList = new List <Transform>(); for (int i = 0; i < bonesNameList.Count; i++) { for (int j = 0; j < skeletonTrans.Length; j++) { if (skeletonTrans[j] != null) { if (bonesNameList[i] == skeletonTrans[j].name) { newBoneList.Add(skeletonTrans[j]); break; } } else { Debuger.LogError("other", "ChangePartShareSkeletonReal mr.bones[i] skeletonTrans[j] is null"); } } } mr.bones = newBoneList.ToArray(); mr.updateWhenOffscreen = true; } else { Debuger.LogError("other", "ChangePartShareSkeletonReal skeletonTrans is null"); } } else { Debuger.LogError("other", "ChangePartShareSkeletonReal allmr is null"); } } } switch (partData.mType) { case PartType.eFace: { if (partData.mObj.GetComponent <Animator>() == null) { Animator animator = partData.mObj.AddComponent <Animator>(); animator.runtimeAnimatorController = SkeletonAnimator.runtimeAnimatorController; animator.avatar = SkeletonAnimator.avatar; animator.enabled = true; } else { Animator animator = partData.mObj.GetComponent <Animator>(); animator.enabled = true; } } break; } } if (callback != null) { callback(); } }
public void OnCGAnimStop() { Debuger.LogError("OnCGAnimStop"); CurrentState = NONE; }
public override bool getValue(IoBuffer ioBuffer, System.Type type, byte flag, out object value) { value = null; byte flagType = getFlagTypes(flag); if (flagType != Types.NUMBER) { Debuger.LogError("Types.NUMBER 类型解析出错 {0}", flag); return(false); } // 0000 #000 bool nevigate = ((flag & FLAG_0X08) != 0); // 0000 0### byte signal = getFlagSignal(flag); if (signal == INT32) { int i; if (!readVarInt32(ioBuffer, out i)) { return(false); } if (type == typeof(short)) { value = (short)(nevigate ? -i : i); } else if (type == typeof(byte)) { value = (byte)(nevigate ? -i : i); } else { value = nevigate ? -i : i; } } else if (signal == INT64) { long l; if (!readVarInt64(ioBuffer, out l)) { return(false); } value = nevigate ? -l : l; } else if (signal == FLOAT) { if (ioBuffer.ReadSize < 4) { Debuger.LogError("可读字节长度不足" + 4); return(false); } value = ioBuffer.ReadFloat(); } else if (signal == DOUBLE) { if (ioBuffer.ReadSize < 8) { Debuger.LogError("可读字节长度不足" + 8); return(false); } value = ioBuffer.ReadDouble(); } AddLog(value); return(true); }
//增加一个子节点 protected virtual bool OnAddChild(string key, ISerializableObject item) { Debuger.LogError("没有实现"); return(false); }
public static IPEndPoint GetHostEndPoint(string host, int port) { IPAddress address = null; if (IPAddress.TryParse(host, out address)) { #if TestIPv6 Debuger.Log("UdpSocket.GetHostEndPoint() TestIPv6: 如果已经是IP了,则封装成IPv6格式"); //已经是一个IP了。在外网下不应该出现IP的情况 if (!address.IsIPv6LinkLocal && !address.IsIPv6SiteLocal) { string tmp = "64:ff9b::" + address.ToString(); IPAddress addr_v6 = null; if (IPAddress.TryParse(tmp, out addr_v6)) { return(new IPEndPoint(addr_v6, port)); } else { Debuger.LogError("UdpSocket.GetHostEndPoint() TestIPv6,封装IPv6失败:" + tmp); } } #endif return(new IPEndPoint(address, port)); } else { //如果不是IP,就当作域名来处理 IPAddress[] ips = Dns.GetHostAddresses(host); //如果是IPv6环境,则会返回IPv6的地址,否则会返回IPv4的地址。 if (Debuger.EnableLog) { Debuger.Log("UdpSocket.GetHostEndPoint() Dns GetHostAddresses:"); for (int i = 0; i < ips.Length; i++) { Debuger.Log("[" + i + "] " + ips[i] + ", " + ips[i].AddressFamily); } } List <IPAddress> listIPv4 = new List <IPAddress>(); List <IPAddress> listIPv6 = new List <IPAddress>(); for (int i = 0; i < ips.Length; i++) { if (ips[i].AddressFamily == AddressFamily.InterNetwork) { listIPv4.Add(ips[i]); } else { listIPv6.Add(ips[i]); } } #if UNITY_ANDROID if (listIPv4.Count > 0) { return(new IPEndPoint(listIPv4[0], port)); } if (listIPv6.Count > 0) { return(new IPEndPoint(listIPv6[0], port)); } #else //加一个静态变量开关,方便以后用Lua设置 if (IOS_IPv6_First) { //IPv6优先 if (listIPv6.Count > 0) { return(new IPEndPoint(listIPv6[0], port)); } if (listIPv4.Count > 0) { return(new IPEndPoint(listIPv4[0], port)); } } else { //IPv4优先 if (listIPv4.Count > 0) { return(new IPEndPoint(listIPv4[0], port)); } if (listIPv6.Count > 0) { return(new IPEndPoint(listIPv6[0], port)); } } #endif } return(null); }
//广播事件,返回false表示有人否决 public static bool Fire(EventNotifier notifier, int msg, int code, object param1 = null, object param2 = null, object param3 = null) { if (notifier != null && notifier.isRemove)//已经删除的要再发送的时候报个错 { Debuger.LogError(string.Format("广播者已经被删除但是仍然fire:{0} {1} {2}", notifier.Id, msg, code)); return(true); } ++m_fireCount; bool ret = true; try { int key = msg * 100000 + code; Dictionary <int, EventObserver> obs; if (AllNotifier.observersByMsgCode.TryGetValue(key, out obs)) { if (obs.Count != 0)//如果不加这一行,会导致foreach里有GC Alloc { foreach (EventObserver observer in obs.Values) { if (observer.removeCounter > 0) { ++observer.removeCounter; if (observer.removeCounter > 10) { Debuger.LogError(string.Format("监听者者已经被删除但是仍然fire:{0} {1} {2} {3}", observer.Id, msg, code, Util.GetDelegateName(observer.GetDelegate()))); } continue; } observer.notifier = notifier;//这里全局监听的notifier是动态变化的 if (!observer.OnHandleFire(param1, param2, param3)) { ret = false; goto Label_Break; } } } } if (notifier.observersByMsgCode.TryGetValue(key, out obs)) { if (obs.Count != 0)//如果不加这一行,会导致foreach里有GC Alloc { foreach (EventObserver observer in obs.Values) { if (observer.removeCounter > 0) { ++observer.removeCounter; if (observer.removeCounter > 10) { Debuger.LogError(string.Format("监听者已经被删除但是仍然fire2:{0} {1} {2} {3}", observer.Id, msg, code, Util.GetDelegateName(observer.GetDelegate()))); } continue; } if (!observer.OnHandleFire(param1, param2, param3)) { ret = false; goto Label_Break; } } } } Label_Break :; } //catch (System.Exception err) //{ // Debuger.LogError(err.StackTrace + ":" + err.Message); //} finally { --m_fireCount; if (m_fireCount <= 0 && m_delayRemovesObservers.Count != 0) { for (int i = 0; i < m_delayRemovesObservers.Count; ++i) { Remove(m_delayRemovesObservers[i]); } m_delayRemovesObservers.Clear(); } if (m_fireCount <= 0 && m_delayRemovesNotifiers.Count != 0) { for (int i = 0; i < m_delayRemovesNotifiers.Count; ++i) { Remove(m_delayRemovesNotifiers[i]); } m_delayRemovesNotifiers.Clear(); } } return(ret); }