public TNode GetNode(BaseUnit unit) { if (unit == null) { return(null); } if (SeizeNodesUnit.ContainsKey(unit)) { TNode node = SeizeNodesUnit[unit]; return(node); } else { return(null); } }
public AudioSource PlayPlayerSFX(string clipName, BaseUnit player, Vector3?pos = null, bool isLoop = false, float maxDis = 60.0f) { if (clipName == null) { return(null); } if (player == null) { return(null); } if (!player.IsLocalPlayer()) { return(null); } return(PlaySFX(clipName, pos, isLoop, maxDis)); }
public ABPath Move(BaseUnit unit, Vector3 pos, float speed = 1.0f) { if (pos.IsInv()) { return(null); } if (UnitMoveCoroutineHandle.IsRunning) { BattleCoroutine.Kill(UnitMoveCoroutineHandle); Callback_OnMoveEnd?.Invoke(PreMoveUnit); } var path = StartABPath(unit.Pos, pos, null); UnitMoveCoroutineHandle = BattleCoroutine.Run(MoveAlongPath(unit, path, speed)); return(path); }
public TDBaseAlertData Add(string alertName, BaseUnit cast = null) { if (!Table.Contains(alertName)) { if (CommonAlert == alertName) { CLog.Error("请手动添加 CommonAlert"); } return(null); } TDBaseAlertData tempAlert = null; if (IsHaveCache(alertName)) { tempAlert = GetCache(alertName); CachesAlert.Remove(alertName); } else { tempAlert = Table.Find(alertName).Copy(); } tempAlert.Cast = cast?cast:LocalPlayer; if (tempAlert == null) { CLog.Error("未找到alert errorId=" + alertName); return(null); } //判断通知是否可以被合并 var mergeAlert = CanMerge(tempAlert); if (mergeAlert != null) { mergeAlert.OnMerge(); Callback_OnMerge?.Invoke(mergeAlert); } else { tempAlert.ID = IDMgr.GetNextId(); Data.Add(tempAlert); tempAlert.OnBeAdded(SelfBaseUnit); Callback_OnAdded?.Invoke(tempAlert); tempAlert.OnStart(); } return(tempAlert); }
IEnumerator <float> MoveAlongPath(BaseUnit unit, ABPath path, float speed) { if (path.error || path.vectorPath.Count == 0) { throw new ArgumentException("Cannot follow an empty path"); } PreMoveUnit = unit; Callback_OnMoveStart?.Invoke(unit); // Very simple movement, just interpolate using a catmull rom spline float distanceAlongSegment = 0; for (int i = 0; i < path.vectorPath.Count - 1; i++) { var p0 = path.vectorPath[Mathf.Max(i - 1, 0)]; // Start of current segment var p1 = path.vectorPath[i]; // End of current segment var p2 = path.vectorPath[i + 1]; var p3 = path.vectorPath[Mathf.Min(i + 2, path.vectorPath.Count - 1)]; var segmentLength = Vector3.Distance(p1, p2); while (distanceAlongSegment < segmentLength) { var interpolatedPoint = MathUtil.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength); var targetRot = Quaternion.LookRotation((p2 - p1).SetY(0), Vector3.up); unit.Rot = Quaternion.Slerp(unit.Rot, targetRot, Time.deltaTime * 10); unit.transform.position = interpolatedPoint; Callback_OnMovingAlone?.Invoke(unit, p0, p1, p2, p3); yield return(Timing.WaitForOneFrame); distanceAlongSegment += Time.deltaTime * speed; } distanceAlongSegment -= segmentLength; } Vector3 target = path.vectorPath[path.vectorPath.Count - 1]; unit.Pos = target; Callback_OnMoveEnd?.Invoke(unit); }
// 设置阻挡得Node,输入Null表示清空 public void SetBlockNode(BaseUnit unit, List <TNode> nodes) { if (unit == null) { return; } HashList <TNode> preNodes = null; if (BlockNodesUnit.ContainsKey(unit)) { preNodes = BlockNodesUnit[unit]; } //先清除之前残余得数据 if (preNodes != null) { foreach (var item in preNodes) { AllBlockers.Remove(item); if (BlockNodes.ContainsKey(item)) { BlockNodes[item].Remove(unit); } if (BlockNodes[item].Count == 0) { BlockNodes.Remove(item); } } BlockNodesUnit.Remove(unit); } if (nodes != null) { HashList <TNode> newHashSetNodes = new HashList <TNode>(nodes); foreach (var item in nodes) { AllBlockers.Add(item); if (!BlockNodes.ContainsKey(item)) { BlockNodes.Add(item, new HashList <BaseUnit>()); } BlockNodes[item].Add(unit); } BlockNodesUnit.Add(unit, newHashSetNodes); } }
public bool MoveToUnitQueue(BaseUnit unit) { if (unit == null) { return(false); } if (unit == SelfBaseUnit) { return(false); } if (unit.Pos.IsInv()) { return(false); } AStarMgr.AddMoveQueue(SelfBaseUnit, unit); return(true); }
protected override void OnSetPlayerBase(BaseUnit oldPlayer, BaseUnit newPlayer) { base.OnSetPlayerBase(oldPlayer, newPlayer); if (AlertMgr != null) { AlertMgr.Callback_OnAdded -= OnAlertAdded; AlertMgr.Callback_OnRemoved -= OnAlertRemoved; AlertMgr.Callback_OnMerge -= OnAlertMerge; AlertMgr.Callback_OnCommingTimeOut -= OnAlertCommingTimeOut; } AlertMgr = NewAlertMgr; AlertMgr.Callback_OnAdded += OnAlertAdded; AlertMgr.Callback_OnRemoved += OnAlertRemoved; AlertMgr.Callback_OnMerge += OnAlertMerge; AlertMgr.Callback_OnCommingTimeOut += OnAlertCommingTimeOut; RecreateAlerts(); }
public void Add(IBaseSenseMgr sense, BaseUnit unit) { if (!UnitsSense.ContainsKey(unit)) { UnitsSense.Add(unit, new HashList <string>()); } if (!TypedSenseUnits.ContainsKey(sense.SenseName)) { TypedSenseUnits.Add(sense.SenseName, new HashList <BaseUnit>()); } Units.Add(unit); UnitsSense[unit].Add(sense.SenseName); TypedSenseUnits[sense.SenseName].Add(unit); OnDetectionChange(unit); OnDetectionAdd(unit); }
public void AddMoveQueue(BaseUnit unit, BaseUnit target) { if (unit == null) { return; } if (target == null) { return; } if (MoveQueue.ContainsKey(unit)) { MoveQueue[unit] = target; return; } MoveQueue.Add(unit, target); }
//移动范围是否可以链接到目标 public bool IsCanConstantConnection(BaseUnit unit) { if (ConstantNodesMove == null || ConstantNodesMove.Count == 0) { return(false); } HashList <GraphNode> links = AStarMgr.GetConnectionsBlocker(unit); foreach (var item in links) { if (ConstantNodesMove.Contains(item)) { return(true); } } return(false); }
public virtual List <TData> Add(string[] buffName, BaseUnit caster = null, float step = 0.0f, TDBaseSkillData skill = null) { if (buffName == null) { return(null); } if (buffName.Length == 0) { return(null); } List <TData> ret = new List <TData>(); for (int i = 0; i < buffName.Length; ++i) { ret.Add(Add(buffName[i], caster, step, skill)); } return(ret); }
public static void SelectUnit(BaseUnit unit) { if (IsBlockSelectUnit) { return; } //选择一个单位后无法再次选择 if (IsInSelectUnitTime()) { return; } if (unit) { //检测这个是否可以被选择 if (!Ins.IsCanSelectUnit(unit)) { return; } } //检测是否重复选择 bool isRepeat = false; if (SelectedUnit == unit) { isRepeat = true; } else { SelectedUnit?.OnUnBeSelected(); } if (unit) { unit?.OnBeSelected(isRepeat); SelectedUnit = unit; } else { SelectedUnit = null; } SelectUnitTimer.Restart(); Ins?.OnSelectedUnit(SelectedUnit, isRepeat); }
// 移动到指定单位 public bool MoveIntoUnit(BaseUnit unit) { if (unit == null) { return(false); } if (unit.Pos.IsInv()) { return(false); } MoveTargetUnit = unit; IsCanUnitOverlap = true; MoveType = BasicMoveType2D.MoveIntoUnit; var targetNode = AStarMgr.GetNode(unit.Pos); var ret = _moveIntoNode(targetNode); IsTriggerDoTraversal = true; return(ret); }
public void ClearSeizeNode(TNode node, BaseUnit unit) { if (node == null) { return; } if (unit == null) { return; } //添加新的SeizeNode if (!SeizeNodes.ContainsKey(node)) { SeizeNodes.Add(node, new HashSet <BaseUnit>()); } SeizeNodes[node].Remove(unit); //设置SeizeNodesUnit SeizeNodesUnit.Remove(unit); }
// 移动一个单位到另一个单位的边上(随机位置) public bool RandArroundUnit(BaseUnit targetUnit, BaseUnit moveUnit, int range = 8) { var nodes = GetBFS(targetUnit.Pos, range, moveUnit.AStarMoveMgr.IsCanTraversal, true); HashList <GraphNode> RandNodes = new HashList <GraphNode>(); //节点数量太少,无法摆放军团 if (nodes.Count <= 1) { return(false); } //去掉中心Node nodes.RemoveAt(0); //获得备用Node GraphNode SpareNode = null; for (int i = nodes.Count - 1; i > 0; --i) { var item = nodes[i]; if (!IsHaveUnit(item) && !IsBlocker(item)) { SpareNode = item; RandNodes.Add(item); } } //获得随机Node GraphNode RandNode; RandNode = RandNodes.Rand(); //获得Final Node GraphNode FinalNode = IsHaveUnit(RandNode) || IsBlocker(RandNode) ? SpareNode : RandNode; if (FinalNode != null) { moveUnit.AStarMoveMgr.SetToNode(FinalNode); moveUnit.MoveMgr.RandRotationY(); return(true); } //进入递归 else { return(RandArroundUnit(targetUnit, moveUnit, range + 1)); } }
private void SetMoveTarget(TState state, BaseUnit unit, GraphNode node) { //正确性判断 if (unit != null && !MoveTargetStateToUnit.Contains(state)) { CLog.Error("错误!SetMoveTarget,unit != null,但state确是:" + state.ToString()); return; } else if (node != null && !MoveTargetStateToNode.Contains(state)) { CLog.Error("错误!SetMoveTarget,node != null,但state确是:" + state.ToString()); return; } //执行移动 if (IsMoveTargetState(state)) { MoveTarget_IsValid = true; MoveTarget_State = state; MoveTarget_Node = node; MoveTarget_Unit = unit; var endState = MoveTargetStateDatas[state].Item1; var isRange = MoveTargetStateDatas[state].Item2; var isAction = MoveTargetStateDatas[state].Item3; bool isInRange = isRange == null ? false : isRange.Invoke(); bool isInAction = isAction == null ? false : isAction.Invoke(); if (isInRange && isInAction) { ChangeState(endState, true, true); } else if (IsCanMove && !isInRange) { ExcuteMoveTarget(true); SetMoveTargetPosReal(Destination); SetMoveTargetPosPreview(null, null, Destination); } else { SetMoveTargetPosPreview(unit, node, null); ShowPath(true); } } }
public TData Add(TData buff, BaseUnit self) { MaxLayer = buff.MaxLayer > MaxLayer ? buff.MaxLayer : MaxLayer; if (MaxLayer <= 0) { return(null); } if (MaxLayer > Layer) { Buffs.Add(buff); buff.OnBeAdded(self); } else { Remove(buff); Buffs.Add(buff); buff.OnBeAdded(self); } return(buff); }
public TData Add(TData buff, BaseUnit self, BaseUnit caster, TDBaseSkillData fromSkill) { MaxLayer = buff.MaxLayer > MaxLayer ? buff.MaxLayer : MaxLayer; if (MaxLayer <= 0) { return(null); } if (MaxLayer > Layer) { BuffList.Add(buff); buff.OnBeAdded(self, caster, fromSkill); } else { Remove(buff); BuffList.Add(buff); buff.OnBeAdded(self, caster, fromSkill); } return(buff); }
public virtual bool OnExitUnit(BaseUnit arg1) { //退出后射线检测Unit RaycastHit hit; if (IsStayInUI && Util.MouseRayCast(out hit, SelectUnitLayerMask)) { BaseUnit unit = hit.collider.GetComponent <BaseUnit>(); OnEnterUnit(unit); return(false); } else { IsStayInUnit = false; HoverUnit = null; Callback_OnMouseExitUnit?.Invoke(arg1); return(true); } }
//创建一个HUDitem,HUDitem会在单位死亡后会自动销毁(DoDestroy) public THUD SpawnDurableHUD <THUD>(string prefabName, BaseUnit target = null) where THUD : UHUDBar { if (prefabName.IsInv()) { return(null); } GameObject tempGO = BaseGlobal.GRMgr.UI.Get(prefabName); if (tempGO != null) { var temp = HUDView.Jump(tempGO, target == null?SelfBaseUnit:target); if (temp == null) { return(null); } temp.SetFollowObj(GetNode(temp.NodeType)); return(temp as THUD); } return(null); }
//获得Blocker外围的一层链接Node public HashList <GraphNode> GetConnectionsBlocker(BaseUnit unit) { var blocker = GetBlocker(unit); if (blocker.Count == 0) { blocker.Add(GetNode(unit)); } HashList <GraphNode> ret = new HashList <GraphNode>(); foreach (var item in blocker) { item.GetConnections((x) => { if (!blocker.Contains(x)) { ret.Add(x); } }); } return(ret); }
// 移动到指定单位 public bool MoveIntoUnit(BaseUnit unit, float speed) { if (unit == null) { return(false); } if (unit.Pos.IsInv()) { return(false); } if (unit.MoveMgr == null) { return(false); } var node = unit.AStarMoveMgr.CurNode; if (node == null) { return(false); } IsCanUnitOverlap = true; return(StartPath((Vector3)node.position, speed)); }
// 移动到指定单位边上 public bool MoveToUnit(BaseUnit unit, float speed) { if (unit == null) { return(false); } if (unit == SelfBaseUnit) { return(false); } if (unit.Pos.IsInv()) { return(false); } GraphNode closetNode = AStarMgr.GetClosedNode(SelfBaseUnit, unit.Pos); if (closetNode == null) { return(false); } IsCanUnitOverlap = false; return(StartPath((Vector3)closetNode.position, speed)); }
public static string GetBuffStr(BaseUnit targetUnit, List <string> buff) { string final = ""; if (buff != null) { int index = 0; foreach (var item in buff) { if (index != 0) { final += "\n"; } final += Const.STR_DoubbleSpace + targetUnit.BuffMgr.GetTableDesc(item, true, Const.STR_DoubbleIndent, null, true); index++; } } if (final.IsInv()) { return(""); } return(Util.GetStr("Text_Reward_Buff", final)); }
//当前Unit的node是否可以连接到目标Unit的Blocker范围内,一般可以用来做攻击检测 public bool IsInBlockerRange(BaseUnit unit) { HashList <GraphNode> connection = new HashList <GraphNode>(); CurNode.GetConnections(connection.Add); HashList <GraphNode> targetUnitBlocker = AStarMgr.GetBlocker(unit); if (targetUnitBlocker != null) { foreach (var item in targetUnitBlocker) { if (connection.Contains(item)) { return(true); } } } else { CLog.Error("{0}:目标单位没有Blocker", unit.BaseConfig.GetName()); } return(false); }
public int GetMarkedByEnemyCount(BaseUnit owner, TTarget target) { if (owner == null) { return(0); } if (target == null) { return(0); } if (!target.IsLive) { return(0); } if (!TargetUnits.ContainsKey(target)) { return(0); } bool ret = Targets.Contains(target); int count = 0; if (ret) { foreach (var item in TargetUnits[target]) { if (!item.IsLive) { continue; } if (owner.IsEnemy(item)) { count++; } } } return(count); }
protected virtual void OnTouchDown(Vector3 mousePosition, int i) { LastMouseDownPos = Input.mousePosition; RaycastHit hit; MouseRayCast(out hit, SelectUnitLayerMask); { if (BaseUIUtils.CheckGuiObjects()) { return; } LastHitCollider = hit.collider; if (i == 1)//右键 { if (LastHitCollider != null) { BaseUnit tempUnit = LastHitCollider.GetComponent <BaseUnit>(); if (tempUnit != null) { RightClickUnit(tempUnit); } } } else if (i == 0)//左键 { if (LastHitCollider != null) { BaseUnit tempUnit = LastHitCollider.GetComponent <BaseUnit>(); if (tempUnit != null) { SelectUnit(tempUnit); LeftClickUnit(tempUnit); } } } } }
public bool IsMarkedByEnemy(BaseUnit owner, TTarget target) { if (owner == null) { return(false); } if (target == null) { return(false); } if (!target.IsLive) { return(false); } if (!TargetUnits.ContainsKey(target)) { return(false); } bool ret = Targets.Contains(target); if (ret) { foreach (var item in TargetUnits[target]) { if (!item.IsLive) { continue; } if (owner.IsEnemy(item)) { return(true); } } return(false); } return(false); }
public TData Merge(TData buff, BaseUnit self, BaseUnit caster, TDBaseSkillData fromSkill) { MaxLayer = buff.MaxLayer > MaxLayer ? buff.MaxLayer : MaxLayer; if (MaxLayer <= 0) { return(null); } TData newBuff = null; if (BuffList.Count == 0) { newBuff = Add(buff, self, caster, fromSkill); } else { newBuff = BuffList[0]; if (newBuff.MergeLayer >= MaxLayer) { return(newBuff); } newBuff.OnMerge(buff, caster, fromSkill); } return(newBuff); }