public TargetFollower RegisterNewFollower() //设置新的跟随者 { TargetFollower follower = new TargetFollower(this); //目标跟随为当前这个目标 m_Followers.Add(follower); //目标跟随添加一个新跟随者 return(follower); //返回新跟随者 }
// Use this for initialization void Start() { m_trackedController = TrackedController.GetController(m_handedness); m_animator = GetComponent <Animator> (); m_targetFollower = GetComponent <TargetFollower> (); m_networkhand = GetComponent <NetworkHand> (); }
/// <summary> /// 由怪物调用此函数来注册玩家附近的一个TargetFollower /// 怪物找到了目标,便会调用此函数来注册 /// </summary> /// <returns></returns> public TargetFollower RegisterNewFollower() { TargetFollower follower = new TargetFollower(this); m_Followers.Add(follower); return(follower); }
public void Shoot(MonsterView monster, ProjectileController controller) { Vector3 pos = controller.View.transform.position; controller.View.transform.position = Utils.GetTopPoint(gameObject, -0.5f); TargetFollower follower = controller.View.GetComponent <TargetFollower>(); follower.Target = monster.gameObject; }
/// <summary> /// 有怪物来调用此函数来取消注册玩家附近的一个TargetFollower /// 1. 此怪物disable的时候, 取消注册 /// 2. 怪物丢失目标,取消注册 /// </summary> /// <param name="follower"></param> public void UnregisterFollower(TargetFollower follower) { if (follower.assignedSlot != -1) // 该follower已经分配过位置了 { m_FreeArcs[follower.assignedSlot] = true; // 没有怪物占用此follower了 } m_Followers.Remove(follower); }
public void UnregisterFollower(TargetFollower follower) { if (follower.assignedSlot != -1) { m_FreeArcs[follower.assignedSlot] = true; } m_Followers.Remove(follower); }
public override void OnEnter() { if (control == null) { control = SimpleQuadController.ActiveController; motor = control.controller; follower = control.follower; gimbal = control.gimbal; } }
public void UnregisterFollower(TargetFollower follower) //注销跟随者 { if (follower.assignedSlot != -1) //如果跟随者的分配位置不等于-1 { m_FreeArcs[follower.assignedSlot] = true; //启用跟随者的分配位置变为自由弧 } //如果等于-1 m_Followers.Remove(follower);//移除这个跟随者 }
void OnCollisionStay(Collision collision) { if (follower == null) { follower = GetComponent <TargetFollower>(); } if (follower.Target == collision.gameObject) { Controller.OnMonsterHit(collision.gameObject.GetComponent <MonsterView>()); Destroy(gameObject); } }
public void SetupAutority() { isAuthority = true; m_targetFollower = GetComponent <TargetFollower> (); m_trackedController = TrackedController.GetController(m_handedness); if (m_handedness == OVRInput.Controller.LTouch) { m_targetFollower.target = PlayerObjectAccess.Instance.leftHandTarget; } else if (m_handedness == OVRInput.Controller.RTouch) { m_targetFollower.target = PlayerObjectAccess.Instance.rightHandTarget; } }
protected virtual void Start() { rBody = GetComponent <Rigidbody2D> (); if (camera2D == null) { camera2D = GameObject.FindObjectOfType <Camera2DController>(); } cameraFollowBehaviour = camera2D.transform.GetComponent <TargetFollower>(); cameraFollowBehaviour.Target = transform; moveDir = new float[] { 0, 0 }; faceDir = new float[] { 0, -1 }; }
/// <summary> /// 获取一个位置 /// </summary> /// <param name="follower"></param> /// <returns></returns> public int GetFreeArcIndex(TargetFollower follower) { bool found = false; // 标记变量, 表示是否在玩家附近找到这样一个点 Vector3 wanted = follower.requiredPoint - transform.position; // 0 - 玩家的位置 Vector3 rayCastPosition = transform.position + Vector3.up * 0.4f; wanted.y = 0; float wantedDistance = wanted.magnitude;// 模 wanted.Normalize(); // 想要的点距离玩家面向的角度 float angle = Vector3.SignedAngle(wanted, Vector3.forward, Vector3.up); if (angle < 0) { angle = 360 + angle; } int wantedIndex = Mathf.RoundToInt(angle / arcDegree); // 四舍五入 获取想要的点在玩家周围一些预先分号的点中的序号 if (wantedIndex >= m_WorldDirection.Length) // 如果角度超出范围, 则重新分配 { wantedIndex -= m_WorldDirection.Length; } int choosenIndex = wantedIndex; // 在玩家位置上 的 略高一点(高0.4f左右) ,向预设点的方向发出wantedDistance长的射线, 检测碰撞体 // 没有检测到碰撞体, 则证明该位置是可以分配的, // 如果有碰撞体, 则证明该位置不可分配 RaycastHit hit; if (!Physics.Raycast(rayCastPosition, GetDirection(choosenIndex), out hit, wantedDistance)) { found = m_FreeArcs[choosenIndex]; // 如果可以分配 , 确定这个位置是否已经被分配过了 } if (!found) // 如果仍然是没有找到 { //we are going to test left right with increasing offset int offset = 1; int halfCount = arcsCount / 2; while (offset <= halfCount) { int leftIndex = wantedIndex - offset; // 找wantedIndex左边的点 int rightIndex = wantedIndex + offset; // 找wantedIndex右边的点 // 临界条件判定 if (leftIndex < 0) { leftIndex += arcsCount; } if (rightIndex >= arcsCount) { rightIndex -= arcsCount; } // 先对其左侧的点做射线检测 if (!Physics.Raycast(rayCastPosition, GetDirection(leftIndex), wantedDistance) && m_FreeArcs[leftIndex]) {// 如果这个点没有被占用 && 没有被碰撞体占据 choosenIndex = leftIndex; found = true; break; } // 再对其右侧的点做射线检测 if (!Physics.Raycast(rayCastPosition, GetDirection(rightIndex), wantedDistance) && m_FreeArcs[rightIndex]) {// 如果这个点没有被占用 && 没有被碰撞体占据 choosenIndex = rightIndex; found = true; break; } offset += 1; } } // 如果还没有找到, 则返回-1, 告诉调用者附近没有坑了 if (!found) {//we couldn't find a free direction, return -1 to tell the caller there is no free space return(-1); } m_FreeArcs[choosenIndex] = false;// 这个位置已经被占据 return(choosenIndex); }
//if it changed position the new one will be picked. //如果它改变了位置,新的将被选中 public int GetFreeArcIndex(TargetFollower follower)//获取跟随者的自由弧索引 { bool found = false; Vector3 wanted = follower.requiredPoint - transform.position; //预计位置=需要点-当前位置 Vector3 rayCastPosition = transform.position + Vector3.up * 0.4f; //射线投射位置=当前位置+上方位置的0.4倍 wanted.y = 0; //将预计位置的y值设置为0 float wantedDistance = wanted.magnitude; //预计距离为预计的长度 wanted.Normalize(); //用来将wanted中字符的不同表示方法统一为同样的形式 float angle = Vector3.SignedAngle(wanted, Vector3.forward, Vector3.up); //??? if (angle < 0) //如果计算结果小于0 { angle = 360 + angle; //结果加360 } int wantedIndex = Mathf.RoundToInt(angle / arcDegree); //结果四舍五入赋给需要索引 if (wantedIndex >= m_WorldDirection.Length) //如果大于等于我的世界位置长度 { wantedIndex -= m_WorldDirection.Length; //减去我的世界位置 } int choosenIndex = wantedIndex; //选择索引=需要索引 RaycastHit hit; //定义一个射线 if (!Physics.Raycast(rayCastPosition, GetDirection(choosenIndex), out hit, wantedDistance)) { //如果没有从射线投射位置到预计距离,沿选择索引的方向这样的射线 found = m_FreeArcs[choosenIndex]; //found为选择索引的自由弧的bool值 } if (!found) //如果没有found值 { //we are going to test left right with increasing offset //我们要测试左向右偏移 int offset = 1; int halfCount = arcsCount / 2; while (offset <= halfCount) //当offset小于等于弧数的一半时 { int leftIndex = wantedIndex - offset; //向左偏移 int rightIndex = wantedIndex + offset; //向右偏移 if (leftIndex < 0) { leftIndex += arcsCount; //如果向左偏移索引量小于0,重新计算索引量 } if (rightIndex >= arcsCount) { rightIndex -= arcsCount; //如果向右偏移索引大于等于弧数,重新计算 } if (!Physics.Raycast(rayCastPosition, GetDirection(leftIndex), wantedDistance) && m_FreeArcs[leftIndex]) //如果没有从射线投射位置到预计位置向左偏移,沿左偏移选择索引的方向这样的射线 { choosenIndex = leftIndex; //将左偏移索引赋给选择索引 found = true; //found调整为true break; } if (!Physics.Raycast(rayCastPosition, GetDirection(rightIndex), wantedDistance) && m_FreeArcs[rightIndex]) //如果没有从射线投射位置到预计位置向右偏移,沿右偏移选择索引的方向这样的射线 { choosenIndex = rightIndex; //将右偏移索引赋给选择索引 found = true; //found调整为true break; } offset += 1;//offset次数+1 } } if (!found) //如果没有found值 { //we couldn't find a free direction, return -1 to tell the caller there is no free space //找不到空闲方向,返回-1告诉呼叫方没有空闲空间 return(-1); //返回-1 } m_FreeArcs[choosenIndex] = false; //关闭选择索引的自由弧 return(choosenIndex); //返回选择索引 }
void Awake() { grid = FindObjectOfType<GridBehavior>(); follower = GetComponent<TargetFollower>(); }
void Awake() { instance = this; follower = new TargetFollower(cam.transform, player); radius = (container.sizeDelta.x / 2) - BorderOffScreen; }
public int GetFreeArcIndex(TargetFollower follower) { bool found = false; Vector3 wanted = follower.requiredPoint - transform.position; Vector3 rayCastPosition = transform.position + Vector3.up * 0.4f; wanted.y = 0; float wantedDistance = wanted.magnitude; wanted.Normalize(); float angle = Vector3.SignedAngle(wanted, Vector3.forward, Vector3.up); if (angle < 0) { angle = 360 + angle; } int wantedIndex = Mathf.RoundToInt(angle / arcDegree); if (wantedIndex >= m_WorldDirection.Length) { wantedIndex -= m_WorldDirection.Length; } int choosenIndex = wantedIndex; RaycastHit hit; if (!Physics.Raycast(rayCastPosition, GetDirection(choosenIndex), out hit, wantedDistance)) { found = m_FreeArcs[choosenIndex]; } if (!found) //we are going to test left right with increasing offset { int offset = 1; int halfCount = arcsCount / 2; while (offset <= halfCount) { int leftIndex = wantedIndex - offset; int rightIndex = wantedIndex + offset; if (leftIndex < 0) { leftIndex += arcsCount; } if (rightIndex >= arcsCount) { rightIndex -= arcsCount; } if (!Physics.Raycast(rayCastPosition, GetDirection(leftIndex), wantedDistance) && m_FreeArcs[leftIndex]) { choosenIndex = leftIndex; found = true; break; } if (!Physics.Raycast(rayCastPosition, GetDirection(rightIndex), wantedDistance) && m_FreeArcs[rightIndex]) { choosenIndex = rightIndex; found = true; break; } offset += 1; } } if (!found) //we couldn't find a free direction, return -1 to tell the caller there is no free space { return(-1); } m_FreeArcs[choosenIndex] = false; return(choosenIndex); }
void Awake() { follower = GetComponent<TargetFollower>(); }