public override UnitPosition Select(IEventArgs args) { UnitPosition up = pos.Select(args); Vector3 position = UnityPositionUtil.ToVector3(up); RaycastHit hitInfo; if (SingletonManager.Get <MapConfigManager>().InWater(position)) { Ray ray = new Ray(position, Vector3.up); bool hit = Physics.Raycast(ray, out hitInfo, 10000, UnityLayerManager.GetLayerMask(EUnityLayerName.WaterTrigger)); if (hit) { return(UnityPositionUtil.FromVector(hitInfo.point - new Vector3(0, waterDelta, 0))); } } else { Ray ray = new Ray(position, Vector3.down); bool hit = Physics.Raycast(ray, out hitInfo, 10000, UnityLayers.SceneCollidableLayerMask | UnityLayerManager.GetLayerMask(EUnityLayerName.WaterTrigger)); if (hit) { if (hitInfo.collider.transform.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.WaterTrigger)) { return(UnityPositionUtil.FromVector(hitInfo.point - new Vector3(0, waterDelta, 0))); } else { return(UnityPositionUtil.FromVector(hitInfo.point)); } } } return(up); }
public override UnitPosition Select(IEventArgs args) { UnitPosition up = pos.Select(args); Vector3 fromV = UnityPositionUtil.ToVector3(up); Vector3 toV = new Vector3(up.GetX(), -10000, up.GetZ()); Ray r = new Ray(fromV, new Vector3(toV.x - fromV.x, toV.y - fromV.y, toV.z - fromV.z)); RaycastHit hitInfo; bool hited = Physics.Raycast(r, out hitInfo); if (hited) { if (SingletonManager.Get <MapConfigManager>().InWater(new Vector3(hitInfo.point.x, hitInfo.point.y - 0.1f, hitInfo.point.z))) { hitInfo.point = new Vector3(fromV.x, hitInfo.point.y - waterDelta, fromV.z); } //Debug.LogFormat("hit {0},{1},{2}", hitInfo.point.x, hitInfo.point.y, hitInfo.point.z); return(UnityPositionUtil.FromVector(hitInfo.point)); } return(up); }