public void Execute() { if (callbackList.Count == 0) { return; } executingCallbackList.Swap(ref callbackList); for (var i = 0; i < executingCallbackList.Count; i++) { var currentCallback = executingCallbackList[i]; if (currentCallback.isCancel) { continue; } try { //下一帧要继续执行这个函数,所以要加到callbackList中 var isNeedRemain = currentCallback.Execute(); if (isNeedRemain) { callbackList.Add(currentCallback); } } catch (Exception ex) { LogCat.LogErrorFormat("{0}, UpdateFrame Error {1}", GetType().Name, ex); } } executingCallbackList.Clear(); }
public (bool isCanCast, CfgSpellData cfgSpellData, Type spellClass) CheckIsCanCast(Unit sourceUnit, string spellId, Unit targetUnit, bool isControl) { var cfgSpellData = CfgSpell.Instance.get_by_id(spellId); Type spellClass = null; if (cfgSpellData == null) { LogCat.LogErrorFormat("spell_id(%d) is not exist!", spellId); return(false, null, null); } if (sourceUnit == null || (sourceUnit.IsDead() && !"触发".Equals(cfgSpellData.cast_type))) { return(false, null, null); } if (!sourceUnit.IsSpellCooldownOk(spellId)) { return(false, null, null); } if (!sourceUnit.CanBreakCurrentSpell(spellId, cfgSpellData)) { return(false, null, null); } var scope = cfgSpellData.target_type ?? "enemy"; //如果是混乱则找任何可以攻击的人 if (sourceUnit.IsConfused()) { scope = "all"; } var isOnlyAttackable = !"friend".Equals(scope); if (cfgSpellData.is_need_target) { if (targetUnit == null) { return(false, null, null); } Hashtable rangeInfo = new Hashtable(); rangeInfo["mode"] = "circle"; rangeInfo["radius"] = cfgSpellData.range; if (!Client.instance.combat.unitManager.__CheckUnit(targetUnit, sourceUnit.ToUnitPosition(), rangeInfo, sourceUnit.GetFaction(), scope, isOnlyAttackable)) { return(false, null, null); } } spellClass = TypeUtil.GetType(cfgSpellData.class_path_cs); if (spellClass.IsHasMethod("CheckIsCanCast") && !spellClass.InvokeMethod <bool>("CheckIsCanCast", false, sourceUnit, spellId, targetUnit, cfgSpellData, isControl) ) //静态方法CheckIsCanCast { return(false, null, null); } return(true, cfgSpellData, spellClass); }
private void OnDestroy() { if (assetCat != null) assetCat.SubRefCount(1, true); else LogCat.LogErrorFormat("{0} destroy but ont find assetCat", name); }
public static object DeserializeClass(Hashtable table, object context) { Type type = JsonSerializer.typeCache[Convert.ToInt64(table[STR_CLS_TYPE_ID])]; ArrayList arrayList = (ArrayList)table[STR_CLS_DATA_VALUE]; object obj = Activator.CreateInstance(type, true); JsonSerializer.AddToCache(obj, table); if (obj is ISerializable) { (obj as ISerializable).Deserialize(new SerializationInfo(arrayList, context), context); } else { int count = arrayList.Count; for (int i = 0; i < count; i++) { IDictionaryEnumerator iterator = ((Hashtable)arrayList[i]).GetEnumerator(); iterator.MoveNext(); string text = iterator.Key.ToString(); object value = iterator.Value; FieldInfo field = obj.GetType().GetFieldInfo(text, InstanceFlags); if (field != null) { object obj2 = JsonSerializer.Deserialize(value, field.FieldType, context); if (obj2 != null) { if (!obj2.GetType().IsSubTypeOf(field.FieldType)) { LogCat.LogWarningFormat("Type dismatch of [{0} [{1} <-> {2}] when DeserializeClass {3}", text, field.FieldType, obj2.GetType(), type ); } else { try { field.SetValue(obj, obj2); } catch (Exception e) { LogCat.LogErrorFormat(e.ToString(), new object[0]); } } } } } } return(obj); }
/// <summary> /// T要转化到的类型 /// 如TestConfig.asset每行的数据要转化为TestConfig.cs里面的数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <returns></returns> public T CreateRowInstance <T>(string id) where T : class { if (this.idList.Count != this.valueList.Count) //数量不等,报错 { LogCat.LogErrorFormat("AssetDataSource OnAfterDeserialize Failed! keys.Count:{0}, values.Count:{1}", idList.Count, this.valueList.Count); return(default(T)); } if (this.dataSourceItemListDict == null) { this.dataSourceItemListDict = new Dictionary <string, ExcelRow>(); for (int i = 0; i < this.idList.Count; i++) { this.dataSourceItemListDict[this.idList[i]] = this.valueList[i]; } } ExcelRow excelRow = null; T result = default(T); //最终的数据 if (this.dataSourceItemListDict.TryGetValue(id, out excelRow)) { result = Activator.CreateInstance(typeof(T), true) as T; Dictionary <string, MemberAccessor> accessorDict = MemberAccessorPool.instance.GetAccessors(typeof(T), BindingFlagsConst.Instance); for (int j = 0; j < this.headerList.Count; j++) //循环每一列 { ExcelHeader excelHeader = this.headerList[j]; object value = ExcelDatabaseUtil.Convert(excelRow.valueList[j].value, excelHeader.type); //转化对对应列所对应的类型的数据 MemberAccessor memberAccessor = null; if (accessorDict.TryGetValue(excelHeader.name, out memberAccessor)) { try { memberAccessor.SetValue(result, value); //将值设置到result中 } catch { LogCat.LogErrorFormat("The value \"{0}\" is {1} in config. Please check the type you defined. ", excelHeader.name, excelHeader.type); } } } return(result); } return(default(T)); }
public static Shader FindShader(string shaderName) { if (_cacheShaderDict.TryGetValue(shaderName, out var shader)) { return(shader); } shader = Shader.Find(shaderName); _cacheShaderDict[shaderName] = shader; if (shader == null) { LogCat.LogErrorFormat("缺少Shader:{0}", shaderName); } return(shader); }
/// <summary> /// 打包指定文件夹下的文件,并在指定路径创建zip文件 /// </summary> /// <param name="directoryPath">指定待打包的文件夹</param> /// <param name="zipFilePath">创建的zip文件完全路径</param> /// <returns>是否成功生成</returns> public static bool CreateZipFile(string directoryPath, string zipFilePath) { var isSuccess = false; if (!Directory.Exists(directoryPath)) { LogCat.LogErrorFormat("Cannot find directory '{0}'", directoryPath); return(false); } try { var fileNames = Directory.GetFiles(directoryPath); using (var zipOutputStream = new ZipOutputStream(File.Create(zipFilePath))) { zipOutputStream.SetLevel(9); // 压缩级别 0-9 //s.Password = "******"; //Zip压缩文件密码 var buffer = new byte[4096]; //缓冲区大小 foreach (var file in fileNames) { var entry = new ZipEntry(Path.GetFileName(file)) { DateTime = DateTimeUtil.NowDateTime() }; zipOutputStream.PutNextEntry(entry); using (var fileStream = File.OpenRead(file)) { int sourceBytes; do { sourceBytes = fileStream.Read(buffer, 0, buffer.Length); zipOutputStream.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); } } isSuccess = true; zipOutputStream.Finish(); zipOutputStream.Close(); } } catch (Exception ex) { isSuccess = false; LogCat.LogErrorFormat("Exception during processing {0}", ex); } return(isSuccess); }
public byte[] ReadBytes() { var num = ReadInt32(); if (num > 99999999 || num < 0) { LogCat.LogErrorFormat("ReadBytes error! length={0}", num); return(null); } var array = new byte[num]; Read(array, 0, num); return(array); }
public static object DeserializeRef(Hashtable table) { long num = Convert.ToInt64(table[STR_REF_ID]); object result = null; if (!JsonSerializer.deserializeCache.TryGetValue(num, out result)) { LogCat.LogErrorFormat("DeserializeRef {0} failed!", new object[] { num }); } return(result); }
private void Start() { db = new DoubleBuffer <string>(t => { LogCat.LogErrorFormat("consuming {0}", t); }, t => { LogCat.LogWarningFormat("producing {0}", t); }); CreateProduceThread("ProduceThread A", 500); CreateConsumeThread(); CreateProduceThread("ProduceThread B", 500); CreateProduceThread("ProduceThread C", 1000); ThreadManager.instance.Start(); //使用ThreadManager.Instace.Abort()退出所有线程 //菜单是CZMTool->退出所有线程 }
public void UnZipFile(string zipFilePath) { if (!File.Exists(zipFilePath)) { LogCat.LogErrorFormat("Cannot find file '{0}'", zipFilePath); return; } using (var s = new ZipInputStream(File.OpenRead(zipFilePath))) { ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { var directoryName = Path.GetDirectoryName(theEntry.Name); var fileName = Path.GetFileName(theEntry.Name); // create directory if (directoryName.Length > 0) { Directory.CreateDirectory(directoryName); } if (fileName != string.Empty) { using (var streamWriter = File.Create(theEntry.Name)) { var size = 2048; var data = new byte[size]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } } } } } }
public string ReadUTF8String() { var num = ReadInt32(); if (num == 0) { return(string.Empty); } if (num > 9999999 || num < 0) { LogCat.LogErrorFormat("ReadUTF8String error! length={0}", num); return(string.Empty); } var array = new byte[num]; inputStream.Read(array, 0, num); return(ByteUtil.ToString(array)); }
public void RemoveState(string stateName) { if (stateName.IsNullOrWhiteSpace()) { return; } int currentValue = this.stateDict.GetOrAddDefault(stateName, () => 0); currentValue -= 1; if (currentValue < 0) { LogCat.LogErrorFormat("{0} state_name = {1}", stateName, currentValue); } currentValue = Mathf.Max(0, currentValue); this.stateDict[stateName] = currentValue; if (currentValue == 0 && this.unit != null) { //第一次删除 if (stateName.Equals(StateConst.Hide)) { this.unit.UpdateHideState(); } if (stateName.Equals(StateConst.Expose)) { this.unit.UpdateHideState(); } if (stateName.Equals(StateConst.Silent)) { this.Broadcast(null, UnitEventNameConst.On_Unit_Is_Silent_Change, this.unit, !this.HasState(StateConst.Silent), this.HasState(StateConst.Silent)); } if (stateName.Equals(StateConst.Confused)) { this.Broadcast(null, UnitEventNameConst.On_Unit_Is_Confused_Change, this.unit, !this.HasState(StateConst.Confused), this.HasState(StateConst.Confused)); } this.unit.UpdateMixedStates(); } }
public Transform GetSocketTransform(string socketName, bool isIgnoreError = false) { if (graphicComponent.gameObject == null) { return(null); } if (socketName.IsNullOrWhiteSpace() || "main".Equals(socketName)) { return(graphicComponent.transform); } Transform socketTransform = null; if (!this.socketTransformDict.ContainsKey(socketName)) { socketTransform = graphicComponent.transform.FindChildRecursive(socketName); if (socketTransform != null) { this.socketTransformDict[socketName] = socketTransform; } } if (socketTransform == null) { if (!isIgnoreError) { LogCat.LogErrorFormat("Can't find socket({0}) in unit({1})", socketName, this.unitId); } else { LogCat.LogWarningFormat("Can't find socket({0}) in unit({1})", socketName, this.unitId); } return(graphicComponent.transform); } return(socketTransform); }
public void PlayAnimation(string animationName, float?blendTime = null, float?speed = null, Vector3?faceToPosition = null, bool isNotMoveStop = false) { float blendTimeValue = blendTime.GetValueOrDefault(0.1f); float speedValue = speed.GetValueOrDefault(1); if (this.animation != null) { if (AnimationNameConst.die.Equals(this.curAnimationName)) { return; } if (this.actionManager != null) { if (AnimationNameConst.walk.Equals(animationName) && !this.curAnimationName.IsNullOrWhiteSpace()) { this.actionManager.Stop(this.curAnimationName); this.curAnimationName = null; } if (AnimationNameConst.idle.Equals(animationName) && !this.curAnimationName.IsNullOrWhiteSpace()) { this.actionManager.Play(animationName, speedValue, -1, false); } else if (AnimationNameConst.walk.Equals(animationName)) { this.actionManager.Play(animationName, speedValue, 0, false); } else { this.actionManager.Play(animationName, speedValue, 0, true); this.curAnimationName = animationName; if (AnimationNameConst.die.Equals(animationName)) { this.actionManager.Stop(AnimationNameConst.idle); } } } else { if (AnimationNameConst.walk.Equals(animationName) && !this.curAnimationName.IsNullOrWhiteSpace()) { this.animation.Blend(this.curAnimationName, 0, blendTimeValue); this.curAnimationName = null; } var animationState = this.animation[animationName]; if (animationState != null) { LogCat.LogErrorFormat("animation is no exist: {0} , {1}", animationName, this.unitId); } var speed_threshold = 0.5f; if (AnimationNameConst.walk.Equals(animationName) && speedValue < speed_threshold) { animationState.speed = speed_threshold; this.animation.CrossFade(animationName, blendTimeValue); this.animation.Blend(animationName, speedValue / speed_threshold, blendTimeValue); } else { animationState.speed = speedValue; this.animation.CrossFade(animationName, blendTimeValue); } if (!(AnimationNameConst.idle.Equals(animationName) || AnimationNameConst.walk.Equals(animationName))) { if (this.curAnimationName.Equals(animationName)) { this.animation[animationName].time = 0; } this.curAnimationName = animationName; } } } else { this.animatorComp.PlayAnimation(animationName, true, speedValue); } if (faceToPosition != null) { var rotation = Quaternion.LookRotation(faceToPosition.Value - this.GetPosition()); if (!rotation.IsZero() && !isNotMoveStop) { this.MoveStop(rotation); } } }