private bool OnSelect(AgentObjectBlackBoard blackBoard) { var lstAgentObj = ResetObjectPool <List <AgentObject> > .Instance.GetObject(); m_dicSelectFunc[(int)m_cCompositeData.selectType].Invoke(blackBoard.host, lstAgentObj); var lstSelectInfo = ResetObjectPool <List <SelectAgentObjInfo> > .Instance.GetObject(); var lstSelectInfoResult = ResetObjectPool <List <SelectAgentObjInfo> > .Instance.GetObject(); OnSelectChild(blackBoard, lstAgentObj, ref lstSelectInfo); ResetObjectPool <List <AgentObject> > .Instance.SaveObject(lstAgentObj); for (int i = 0; i < lstSelectInfo.Count; i++) { var selectObjInfo = lstSelectInfo[i]; if (m_nMaxSelectCount < m_cCompositeData.totalObjMaxCount) { SelectAgentObjCountInfo selectInfo = new SelectAgentObjCountInfo(selectObjInfo.agentObj.id, selectObjInfo.agentObj.agentType, 0); for (int j = 0; j < m_lstSelectInfo.Count; j++) { var info = m_lstSelectInfo[j]; if (info.id == selectObjInfo.agentObj.id && info.agentType == selectObjInfo.agentObj.agentType) { selectInfo = info; break; } } if (selectInfo.count < m_cCompositeData.oneObjMaxCount) { if (selectInfo.count == 0) { m_lstSelectInfo.Add(selectInfo); } selectInfo.count++; //通过选择器 lstSelectInfoResult.Add(selectObjInfo); } } } for (int i = 0; i < lstSelectInfoResult.Count; i++) { var selectObjInfo = lstSelectInfoResult[i]; selectObjInfo.agentObjCount = lstSelectInfoResult.Count; ExecuteChilds(blackBoard, selectObjInfo); } m_nMaxSelectCount += lstSelectInfoResult.Count; if (m_nMaxSelectCount >= m_cCompositeData.oneObjMaxCount) { return(false); } ResetObjectPool <List <SelectAgentObjInfo> > .Instance.SaveObject(lstSelectInfo); ResetObjectPool <List <SelectAgentObjInfo> > .Instance.SaveObject(lstSelectInfoResult); return(true); }
private void ExecuteChilds(AgentObjectBlackBoard blackBoard, SelectAgentObjInfo selectObjInfo) { blackBoard.selectAgentObjInfo = selectObjInfo; int count = m_lstChild.Count; for (int i = 0; i < count; i++) { m_lstChild[i].OnTick(blackBoard); } blackBoard.selectAgentObjInfo.Reset(); }
protected override void OnSelectChild(AgentObjectBlackBoard blackBoard, List <AgentObject> lst, ref List <SelectAgentObjInfo> result) { if (lst.Count == 0) { return; } AgentObject host = blackBoard.host; TSVector lastPosition = host.lastPosition; TSVector lastForward = host.lastForward; if (!string.IsNullOrEmpty(m_cLastPosToCurPosData.hangPoint)) { blackBoard.host.GetHangPoint(m_cLastPosToCurPosData.hangPoint, host.lastPosition, host.lastForward, out lastPosition, out lastForward); } TSVector curPosition = host.curPosition; TSVector curForward = host.curForward; if (!string.IsNullOrEmpty(m_cLastPosToCurPosData.hangPoint)) { blackBoard.host.GetHangPoint(m_cLastPosToCurPosData.hangPoint, host.curPosition, host.curForward, out curPosition, out curForward); } //检测lastPosition到curPosition这条之间碰撞到的代理 for (int i = 0; i < lst.Count; i++) { var agentObj = lst[i]; if (agentObj.gameCollider != null) { TSVector hitPoint; if (agentObj.gameCollider.CheckLine(lastPosition, curPosition - lastPosition, out hitPoint)) { SelectAgentObjInfo info = new SelectAgentObjInfo(); info.agentObj = agentObj; info.hitPoint = hitPoint; TSVector direct = agentObj.gameCollider.center - curPosition;; if (direct.IsZero()) { direct = curForward; } info.hitDirect = direct; result.Add(info); } } } }
public override BTResult OnTick(AgentObjectBlackBoard blackBoard) { if (m_bIsEnd) { m_sTime = 0; m_sLastSelectTime = 0; m_nMaxSelectCount = 0; m_bIsEnd = false; m_lstSelectInfo.Clear(); OnEnter(blackBoard); } if (m_sLastSelectTime >= m_cCompositeData.oneDuration) { if (m_cCompositeData.oneDuration > 0) { m_sLastSelectTime -= m_cCompositeData.oneDuration; } else { m_sLastSelectTime = 0; } bool succ = OnSelect(blackBoard); if (!succ) { m_bIsEnd = true; return(BTResult.Success); } } if (m_sTime >= m_cCompositeData.totalDuration) { m_bIsEnd = true; m_lstSelectInfo.Clear(); OnExit(blackBoard); return(BTResult.Success); } m_sTime += blackBoard.deltaTime; m_sLastSelectTime += blackBoard.deltaTime; return(BTResult.Running); }
protected virtual void OnExit(AgentObjectBlackBoard blackBoard) { }
protected virtual void OnSelectChild(AgentObjectBlackBoard blackBoard, List <AgentObject> lst, ref List <SelectAgentObjInfo> result) { }
public virtual BTActionResult OnRun(AgentObjectBlackBoard blackBoard) { return(BTActionResult.Running); }
public virtual void OnExit(AgentObjectBlackBoard blackBoard) { }
public virtual BTResult OnTick(AgentObjectBlackBoard blackBoard) { return(base.OnTick(blackBoard)); }