public DirType CalcWanderMoveDir(Vector2 selfPos, GazeSurroundCom gazeSurroundCom, Vector2 targetPos) { float distance = Vector2.Distance(selfPos, targetPos); //太近 if (distance < gazeSurroundCom.gazeRange.x) { if (selfPos.x - targetPos.x > 0) { return(DirType.Right); } else { return(DirType.Left); } } //太远 if (distance > gazeSurroundCom.gazeRange.y) { if (selfPos.x - targetPos.x > 0) { return(DirType.Left); } else { return(DirType.Right); } } return(gazeSurroundCom.moveDir); }
protected override void OnExit(NodeData wData, int runningStatus) { EntityWorkData workData = wData as EntityWorkData; //组件 AnimCom animCom = workData.MEntity.GetCom <AnimCom>(); animCom.SetDefaultAnim(); GazeSurroundCom gazeSurroundCom = workData.MEntity.GetCom <GazeSurroundCom>(); gazeSurroundCom.Disable(); }
protected override void OnEnter(NodeData wData) { EntityWorkData workData = wData as EntityWorkData; //参数 ParamData paramData = workData.GetParam(); int gazeUid = paramData.GetInt(); Vector2 gazeRange = paramData.GetVect2(); //组件 GazeSurroundCom gazeSurroundCom = workData.MEntity.GetCom <GazeSurroundCom>(); gazeSurroundCom.gazeUid = gazeUid; gazeSurroundCom.gazeRange = gazeRange; gazeSurroundCom.Enable(); }
protected override void HandleComs(List <BaseCom> comList) { GazeSurroundCom gazeSurroundCom = GetCom <GazeSurroundCom>(comList[0]); TransformCom transCom = GetCom <TransformCom>(comList[1]); PropertyCom propertyCom = GetCom <PropertyCom>(comList[2]); if (gazeSurroundCom.gazeUid <= 0) { return; } Entity gazeEntity = ECSLocate.ECS.GetEntity(gazeSurroundCom.gazeUid); if (gazeEntity == null) { return; } Vector2 selfPos = transCom.GetPos(); Vector2 targetPos = gazeEntity.GetCom <TransformCom>().GetPos(); //方向 if (selfPos.x - targetPos.x > 0) { transCom.ReqDir = DirType.Left; } else { transCom.ReqDir = DirType.Right; } //移动 gazeSurroundCom.moveDir = CalcWanderMoveDir(selfPos, gazeSurroundCom, targetPos); Vector3 delta = new Vector3(gazeSurroundCom.moveDir == DirType.Right ? 1 : -1, 0, 0); delta = delta * propertyCom.MoveSpeed.Curr * Time.deltaTime; transCom.ReqMove = delta; }