/// <summary>惑星fromからtoへのパスを設定. カメラ設定用にPlayerも必要</summary> public void Initialize(Transform from, Transform to, Transform player) { // コンポーネントを取得. Rail = this.GetComponent <Rail>(); m_path = Rail.GetComponent <CinemachineSmoothPath>(); // パスの設定. SetWayPoints(from, to, out Vector3 start); transform.SetPositionAndRotation(start, Quaternion.identity); m_path.InvalidateDistanceCache(); Rail.PathDuration = Mathf.Max(m_path.PathLength / m_moveSpeed, m_minimumDuration); // 目標の設定. Rail.GoalPlanet = to; // カメラの設定. SetCameraParameters(player); }
public void Apply() { m_Waypoints = new Waypoint[points]; float angle = startAngle; float length = endAngle - startAngle; for (int i = 0; i < points; i++) { float t = (float)i / (float)points; m_Waypoints[i].position = new Vector3( Mathf.Sin(Mathf.Deg2Rad * angle) * (radius * 0.5f), t * (elevation * 0.5f), Mathf.Cos(Mathf.Deg2Rad * angle) * (radius * 0.5f)); angle += (length / (float)points); } path.m_Waypoints = m_Waypoints; path.InvalidateDistanceCache(); }
public void ProjectToGround(bool force = false, bool useCache = true) { if (!EnsurePathComponent()) { return; } var changed = false; //when a point is removed if (m_WaypointsCaches.Length > path.m_Waypoints.Length) { if (useCache) { CacheWaypoints(); } } for (int i = 0; i < path.m_Waypoints.Length; i++) { CinemachineSmoothPath.Waypoint waypoint = path.m_Waypoints[i]; if (useCache && !force) { if (m_WaypointsCaches.Length == path.m_Waypoints.Length) { //This waypoint hasn't changed, skipping raycast\ if (waypoint.position == m_WaypointsCaches[i].position) { continue; } } } var rayOrigin = path.transform.TransformPoint(waypoint.position); rayOrigin.y += projectionHeight; #if UNITY_EDITOR if (UnityEditor.Selection.activeGameObject == gameObject) { UnityEngine.Debug.DrawRay(rayOrigin, Vector3.down * projectionMaxDistance, Color.cyan, 0.1f); } #endif if (Physics.Raycast(rayOrigin, Vector3.down, out var hit, projectionMaxDistance, layerMask, QueryTriggerInteraction.Ignore)) { var newPos = path.transform.InverseTransformPoint(hit.point); if (newPos != waypoint.position) { changed = true; waypoint.position = newPos; path.m_Waypoints[i] = waypoint; } } } if (changed) { // Debug.Log("Changed"); path.InvalidateDistanceCache(); } if (useCache) { CacheWaypoints(); } }
void CameraWaypointsChanged(List <CinemachineSmoothPath.Waypoint> waypoints) { SmoothPath.m_Waypoints = waypoints.ToArray(); SmoothPath.InvalidateDistanceCache(); }