/// <summary> /// 使用传入射线与当前Avatar的所有Collider做碰撞检测 /// 返回第一个碰撞点, 也就是最外层的碰撞点 /// </summary> public bool GetHitPoint(SpacecraftEntity spacecraft, Ray ray, out Collider hitCollider, out Vector3 hitPoint) { hitCollider = null; // 这里使用Motion.HorizontAxix 的位置而不是transoform.position是因为HeroEntity.transform.position是服务器的位置, 是跳动的 // Motion.HorizontAxis的位置才是客户端插值后的位置 float rayDistance = RAYCAST_LENGTH; bool hit = false; hitPoint = spacecraft.transform.position; float nearestHitDistance = float.MaxValue; foreach (Collider collider in spacecraft.GetAllColliders()) { RaycastHit hitInfo; if (collider.Raycast(ray, out hitInfo, rayDistance)) { // 用射线与所有Collider求交, 找到距射线发射位置最近的碰撞点 // TODO 祝锐: 缓存一个最外层的最大的Collider, 不要每次遍历所有的Collider float sqrHitPointToOrigin = (hitInfo.point - ray.origin).sqrMagnitude; if (sqrHitPointToOrigin < nearestHitDistance) { nearestHitDistance = sqrHitPointToOrigin; hitPoint = hitInfo.point; hitCollider = collider; hit = true; } } } return(hit); }
/// <summary> /// 连线特效回调函数 /// </summary> /// <param name="obj"></param> private void OnLineEffectLoad(EffectController effect, System.Object usedata) { if (usedata != null) { SpacecraftAvatarComponent component = (SpacecraftAvatarComponent)usedata; uint ownerHeroID = component.m_Property.GetOwner().m_EntityFatherOwnerID; if (ownerHeroID != 0 && component.m_Property.GetHeroType() == KHeroType.htDisturbor) { SpacecraftEntity target = component.m_GameplayProxy.GetEntityById <SpacecraftEntity>(ownerHeroID) as SpacecraftEntity; effect.SetBeamTarget(component.m_Property.GetSkinTransform(), target.GetSkinTransform(), Vector3.zero, false, target.GetAllColliders()); /// TODO. /// 时间配合特效里的动画时间 UIManager.Instance.StartCoroutine(Excute(0.25f, () => { target.SendEvent(ComponentEventName.LineEffectEnd, null); })); } } }