public static Array RemoveAt(Array sourceArray, int index) { var elementType = sourceArray.GetType().GetElementType(); var sourceArrayLength = sourceArray.Length; if (sourceArrayLength == 0) { return(sourceArray); } int toRemoveIndex = index; if (toRemoveIndex < 0 || toRemoveIndex >= sourceArrayLength) { LogCat.LogError("index out of boundary"); return(sourceArray); } var array = Array.CreateInstance(elementType, sourceArrayLength - 1); if (toRemoveIndex != 0) { Array.Copy(sourceArray, 0, array, 0, toRemoveIndex); } if (toRemoveIndex != sourceArrayLength - 1) { Array.Copy(sourceArray, toRemoveIndex + 1, array, toRemoveIndex, sourceArrayLength - toRemoveIndex - 1); } return(array); }
public static object Field(string label, Type type, object fieldValue) { if (type == typeof(string)) { return(EditorGUILayout.TextField(label, (string)fieldValue)); } if (type == typeof(float)) { return(EditorGUILayout.FloatField(label, (float)fieldValue)); } if (type == typeof(int)) { return(EditorGUILayout.IntField(label, (int)fieldValue)); } if (type == typeof(Bounds)) { return(EditorGUILayout.BoundsField(label, (Bounds)fieldValue)); } if (type == typeof(Color)) { return(EditorGUILayout.ColorField(label, (Color)fieldValue)); } if (type == typeof(AnimationCurve)) { return(EditorGUILayout.CurveField(label, (AnimationCurve)fieldValue)); } if (type == typeof(Gradient)) { return(EditorGUILayout.GradientField(label, (Gradient)fieldValue)); } if (type == typeof(long)) { return(EditorGUILayout.LongField(label, (long)fieldValue)); } if (fieldValue is Object o) { using (new EditorGUILayoutBeginHorizontalScope()) { EditorGUILayout.LabelField(label, GUILayout.Width(100)); object result = EditorGUILayout.ObjectField(o, type); return(result); } } if (type == typeof(Rect)) { return(EditorGUILayout.RectField(label, (Rect)fieldValue)); } if (type == typeof(Vector2)) { return(EditorGUILayout.Vector2Field(label, (Vector2)fieldValue)); } if (type == typeof(Vector3)) { return(EditorGUILayout.Vector3Field(label, (Vector3)fieldValue)); } LogCat.LogError(string.Format("不支持该类型的field:{0}", type)); return(null); }
public AbstractComponent AddComponent(AbstractComponent component, string componentKey = null) { if (componentKey != null) { component.key = componentKey; } if (component.key != null && this.keyToComponentDict.ContainsKey(component.key)) { LogCat.error("duplicate add component:", component.key, component.GetType()); return(null); } bool isKeyUsingParentIdPool = componentKey == null; if (isKeyUsingParentIdPool) { componentKey = componentKeyIdPool.Get().ToString(); //再次检查键值 if (this.keyToComponentDict.ContainsKey(componentKey)) { LogCat.error("duplicate add component:", component.key, component.GetType()); return(null); } } component.key = componentKey; component.isKeyUsingParentIdPool = isKeyUsingParentIdPool; component.entity = this; _AddComponentRelationship(component); return(component); }
public AbstractEntity AddChildWithoutInit(string childKey, Type childType) { if (childKey != null && keyToChildDict.ContainsKey(childKey)) { LogCat.error("duplicate add child:{0},{1}", childKey, childType); return(null); } bool isKeyUsingParentIdPool = childKey == null; if (isKeyUsingParentIdPool) { childKey = childKeyIdPool.Get().ToString(); //再次检查键值 if (keyToChildDict.ContainsKey(childKey)) { LogCat.error("duplicate add child:{0},{1}", childKey, childType); return(null); } } var child = PoolCatManagerUtil.Spawn(childType) as AbstractEntity; child.key = childKey; child.isKeyUsingParentIdPool = isKeyUsingParentIdPool; return(AddChild(child)); }
public bool EmbedOff(Item item, Item embed) { if (item == null) { LogCat.error(string.Format("EmbedOff error: item is null")); return(false); } if (embed == null) { LogCat.error(string.Format("EmbedOff error: embed is null")); return(false); } if (!item.CheckEmbedOff(embed)) { return(false); } if (!item.EmbedOff(embed)) { return(false); } embed.SetEnv(this); this.AddItem(embed); return(true); }
public void Foreach(TKey key, Action <TValue> action, bool isIgnoreValueNull = true) { if (!this.ContainsKey(key)) { return; } List <TValue> valueList = this[key]; if (valueList == null) { return; } for (var i = 0; i < valueList.Count; i++) { TValue value = valueList[i]; if (isIgnoreValueNull && value == null) { continue; } try { action(value); } catch (Exception e) { LogCat.LogError(e); } } CheckAll(); }
///////////////////////Util//////////////////////////////// public bool UseItem(string idOrRid, Critter target) { var item = this.GetItem(idOrRid); if (item == null) { LogCat.error(string.Format("UseItem error:do not has {0}", idOrRid)); return(false); } if (!target.CheckUseItem(item)) { return(false); } item = item.CanFold() ? this.RemoveItems(item.GetId(), 1)[0] : this.RemoveItem(item); if (!target.UseItem(item)) { //失败,加回去 this.AddItem(item); return(false); } item.Destruct(); return(true); }
public static void AssetBundleClearPC() { LogCat.ClearLogs(); StdioUtil.ClearDir(FilePathConst.PersistentAssetBundleRoot); EditorUtilityCat.DisplayDialog("AssetBundle PC_Persistent Clear Finished", FilePathConst.PersistentAssetBundleRoot); }
//owner 发放任务的npc public bool AcceptMission(Mission mission, Doer owner) { var orgEnv = mission.GetEnv(); if (orgEnv != null) { LogCat.LogError(string.Format("{0} still belong to {1}", mission, orgEnv)); mission.Destruct(); return(false); } if (IsHasMission(mission.GetId())) { LogCat.LogError(string.Format("duplicate mission id![{0}]", mission)); mission.Destruct(); return(false); } var missions = this.oMissions.GetMissions_ToEdit(); mission.SetEnv(this); mission.SetOwner(owner); missions.Add(mission); if (!mission.OnAccept(this)) { mission.Destruct(); missions.Remove(mission); //失败,减回去 return(false); } // 检测完成任务 this.CheckAutoFinishMissions(); return(true); }
public void ForeachKV2OfKey1(TKey1 key1, Action <TKey2, TValue2> action) { if (!this.ContainsKey(key1)) { return; } Dictionary <TKey2, TValue2> dict2 = this[key1]; if (dict2 == null) { return; } foreach (KeyValuePair <TKey2, TValue2> kv2 in dict2) { try { action(kv2.Key, kv2.Value); } catch (Exception e) { LogCat.LogError(e); } } CheckAll(); }
public static void Test2() { int[][] grids = new AStarMapPath(StdioUtil.ReadTextFile("E:/WorkSpace/Unity/Test/Assets/tile/tileSet/fff.txt")) .grids; LogCat.log(grids); }
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); }
public List <Unit> RecommendCast(Unit sourceUnit, string spellId, List <Unit> targetUnitList, bool isControl) { if (sourceUnit == null || sourceUnit.IsDead()) { return(null); } if (targetUnitList == null) { return(null); } var cfgSpellData = CfgSpell.Instance.get_by_id(spellId); var spellClass = TypeUtil.GetType(cfgSpellData.class_path_cs); if (spellClass == null) { LogCat.error("spell code is not exist: ", cfgSpellData.class_path_cs); return(null); } List <Unit> newTargetUnitList = new List <Unit>(); for (var i = 0; i < targetUnitList.Count; i++) { var targetUnit = targetUnitList[i]; if (this.__IsUnitMatchCondition(sourceUnit, targetUnit, isControl, cfgSpellData, spellClass)) { newTargetUnitList.Add(targetUnit); } } return(newTargetUnitList); }
private void OnDestroy() { if (assetCat != null) assetCat.SubRefCount(1, true); else LogCat.LogErrorFormat("{0} destroy but ont find assetCat", name); }
//ProcessFrame is like "the Update of Timeline" public override void ProcessFrame(Playable playable, FrameData info, object arg) { //Insert logic per frame in here var inputPlayable = (ScriptPlayable <SimpleBehaviour>)playable.GetInput(0); LogCat.Log(message); }
/////////////////////////////////////////镶嵌物///////////////////////////////// public bool EmbedOn(Item item, Item embed) { if (item == null) { LogCat.error(string.Format("EmbedOn error: item is null")); return(false); } if (embed == null) { LogCat.error(string.Format("EmbedOn error: embed is null")); return(false); } if (!item.CheckEmbedOn(embed)) { return(false); } if (this.RemoveItem(embed) == null) { LogCat.error("EmbedOn error:can not remove item:{0}", item); return(false); } if (!item.EmbedOn(embed)) { //失败,加回去 this.AddItem(embed); return(false); } return(true); }
public void Initialize(string content) { if (content.IsNullOrWhiteSpace()) { LogCat.LogError("AssetBundleMap empty!!"); return; } fileContent = content; content = content.Replace("\r\n", "\n"); var mapList = content.Split('\n'); for (var i = 0; i < mapList.Length; i++) { var map = mapList[i]; if (map.IsNullOrWhiteSpace()) { continue; } var splits = map.Split(new[] { StringConst.String_Comma }, StringSplitOptions.None); if (splits.Length < 2) { LogCat.LogError("splitArr length < 2 : " + map); continue; } string assetBundleName = splits[0]; long bytes = splits[1].To <long>(); dict[assetBundleName] = bytes; } }
public void Initialize(string content) { if (content.IsNullOrWhiteSpace()) { LogCat.LogError("LuaPathMap empty!!"); return; } fileContent = content; content = content.Replace("\r\n", "\n"); var mapList = content.Split('\n'); for (var i = 0; i < mapList.Length; i++) { var map = mapList[i]; if (map.IsNullOrWhiteSpace()) { continue; } var splits = map.Split(new[] { StringConst.String_Comma }, StringSplitOptions.None); if (splits.Length < 2) { LogCat.LogError("splitArr length < 2 : " + map); continue; } var luaName = splits[0]; var luaPath = splits[1]; luaName2LuaPathDict[luaName] = luaPath; } }
public override bool Write(byte[] buffer, int offset, int length) { if (pos + length > base.length) { if (incLen <= 0) { incLen = 128; LogCat.LogError("KMemoryOutputStream write error with 0 increase length"); } var num = incLen; var num2 = base.length + num; while (pos + length >= num2) { num2 += num; } var dst = new byte[num2]; Buffer.BlockCopy(data, 0, dst, 0, base.length); data = dst; base.length = num2; } Buffer.BlockCopy(buffer, offset, data, pos, length); pos += length; return(true); }
public StopwatchScope(string name = StringConst.String_Empty) { this._name = name; _stopwatch = new Stopwatch(); _stopwatch.Start(); LogCat.LogFormat("{0} 开始统计耗时", this._name); }
public void Dispose() { _stopwatch.Stop(); var timeSpan = _stopwatch.Elapsed; LogCat.LogFormat("{0} 统计耗时结束,总共耗时{1}秒", this._name, timeSpan.TotalMilliseconds / 1000); }
public override void Start() { base.Start(); if ("被动".Equals(this.cfgSpellData.type)) { this.CounterIncrease(); // 被动默认不被消耗 } this.CounterIncrease(); this.targetUnitList = Client.instance.combat.spellManager.RecommendSpellRule(this.sourceUnit, this.targetUnit, this.cfgSpellData, this.originPosition.Value); this.targetUnit = this.targetUnitList.IsNullOrEmpty() ? null : this.targetUnitList[0]; if (this.IsHasMethod("OnStart")) { this.InvokeMethod("OnStart", false); } this.RegisterTriggerSpell(); this.Broadcast <Unit, Unit, SpellBase>(null, SpellEventNameConst.On_Spell_Start, this.sourceUnit, this.targetUnit, this); Client.instance.combat.spellManager.UnRegisterListener("on_start", this.sourceUnit, this, "RegisterTriggerSpell"); if (!this.cfgSpellData.action_name.IsNullOrWhiteSpace()) { // if not self.source_unit.action_dict or // not self.source_unit.action_dict[self.cfgSpellData.action_name] then // Error("action is not find", self.spell_id, self.source_unit.unit_id) // end // self.action = SpellAction.New(self.source_unit.action_dict[self.cfgSpellData.action_name], self.source_unit, self) // self.action:Play() } else { this.PlaySpellAnimation(); if (this.IsHasMethod("OnCast")) { //起手前摇 var castTimePct = this.GetAnimationTimePct(this.cfgSpellData.cast_time, 0); this.RegisterAnimationEvent(castTimePct, "__OnCast"); } //可打断后摇 var breakTimePct = this.GetAnimationTimePct(this.cfgSpellData.break_time, 1); this.RegisterAnimationEvent(breakTimePct , "PassBreakTime"); if ("触发".Equals(this.cfgSpellData.cast_type)) { var castTimePct = this.GetAnimationTimePct(this.cfgSpellData.cast_time, 0); var breakTimePctValue = this.GetAnimationTimePct(this.cfgSpellData.break_time, 1); if (breakTimePctValue < castTimePct) { LogCat.LogError("技能脱手时间比出手时间快"); } this.RegisterAnimationEvent(breakTimePctValue, "OnSpellAnimationFinished"); } } this.CounterDecrease(); }
public static void GameDataClear_cs() { LogCat.ClearLogs(); File.Delete(SerializeDataConst.SaveFilePathCS); File.Delete(SerializeDataConst.SaveFilePathCS2); EditorUtilityCat.DisplayDialog(string.Format("{0} Clear Finished\n{1} Clear Finished", SerializeDataConst.SaveFilePathCS, SerializeDataConst.SaveFilePathCS2)); }
public static void Test_CanPass2() { LogCat.log(AStarUtil.CanPass(new AStarMapPath(grids), new List <Vector2Int> { new Vector2Int(1, 1), new Vector2Int(2, 2), new Vector2Int(3, 3) }, AStarMapPathConst.Critter_Can_Pass_Obstacle_Types, AStarMapPathConst.User_Can_Pass_Terrain_Types)); }
public void Log(LogCatType logType, string log) { onLogAction?.Invoke(logType, log); if (logType == LogCatType.Error) { LogCat.LogError(log); } }
public static Action Test_GetNearestPoint() { Vector2Int point = AStarUtil.GetNearestPoint(new AStarMapPath(grids), new Vector2Int(0, 0), new Vector2Int(3, 3) , AStarMapPathConst.Critter_Can_Pass_Obstacle_Types, AStarMapPathConst.User_Can_Pass_Terrain_Types); LogCat.log(point); return(() => { AStarUtil.GUIShowPointList(0, 0, 9, 9, point); }); }
IEnumerator DOIE() { LogCat.log(1); yield return(new WaitForSeconds(5)); LogCat.log(2); yield return(new WaitForSeconds(5)); LogCat.log(3); }
public void RemoveAssetBundleCat(AssetBundleCat assetBundleCat) { if (assetBundleCat == null) { return; } LogCat.log(assetBundleCat.assetBundleName + " removed"); assetBundleCat.Get()?.Unload(true); //最关键的一步 assetBundleCatDict.RemoveByFunc((key, value) => value == assetBundleCat); }
public override void InitConfigList() { base.InitConfigList(); this.graphicComponent.gameObject.name = "test2"; config_list.Add(new Dictionary <string, object> { { "type", "InputItem" }, { "desc", "KKK" }, { "yes_callback", new Action(() => LogCat.LogWarning("KKK")) }, }); }