void DrawWaypointEditor(Rect rect, int index)
        {
            // Needed for accessing string names of fields
            CinemachineSmoothPath.Waypoint def     = new CinemachineSmoothPath.Waypoint();
            SerializedProperty             element = mWaypointList.serializedProperty.GetArrayElementAtIndex(index);

            float hSpace = 3;

            rect.width -= hSpace; rect.y += 1;
            Vector2 numberDimension = GUI.skin.label.CalcSize(new GUIContent("999"));
            Rect    r = new Rect(rect.position, numberDimension);

            if (GUI.Button(r, new GUIContent(index.ToString(), "Go to the waypoint in the scene view")))
            {
                mWaypointList.index = index;
                SceneView.lastActiveSceneView.pivot = Target.EvaluatePosition(index);
                SceneView.lastActiveSceneView.size  = 4;
                SceneView.lastActiveSceneView.Repaint();
            }

            float      floatFieldWidth = EditorGUIUtility.singleLineHeight * 3f;
            GUIContent rollLabel       = new GUIContent("Roll");
            Vector2    labelDimension  = GUI.skin.label.CalcSize(rollLabel);
            float      rollWidth       = labelDimension.x + floatFieldWidth;

            r.x += r.width + hSpace; r.width = rect.width - (r.width + hSpace + rollWidth);
            EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.position), GUIContent.none);
            r.x += r.width + hSpace; r.width = rollWidth;
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = labelDimension.x;
            EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.roll), rollLabel);
            EditorGUIUtility.labelWidth = oldWidth;
        }
Example #2
0
    public void Reset()
    {
        int seed = int.Parse(_seed);

        for (int i = 0; i < _levelSections.Count; i++)
        {
            Destroy(_levelSections[i].gameObject);
        }

        _levelSections.Clear();
        _cameraWaypoints.Clear();
        _pressureWayoints.Clear();


        CinemachineSmoothPath.Waypoint newWaypoint = new CinemachineSmoothPath.Waypoint();
        newWaypoint.position = new Vector3(_pressureStartPosition.x, _pressureStartPosition.y, CameraDistance);
        _cameraWaypoints.Add(newWaypoint);
        OnCameraWaypointsChanged(_cameraWaypoints);

        _nextSection = SectionType.START_SECTION;
        Pressure.transform.position = _pressureStartPosition;
        Pressure.transform.rotation = _pressureStartRotation;
        _pseudoRandom = new System.Random(seed);

        LoadSection();
    }
Example #3
0
    private void LoadSection()
    {
        Vector3 oldSectionPosition;

        LevelSectionController newSection = Instantiate(LevelSections.Find(x => x.Section == _nextSection), transform);

        _levelSections.Add(newSection);
        if (newSection.Section != SectionType.START_SECTION)
        {
            oldSectionPosition            = _levelSections[_levelSections.Count - 2].transform.position;
            newSection.transform.position = new Vector3(oldSectionPosition.x + _levelSections[_levelSections.Count - 2].OffsetX,
                                                        oldSectionPosition.y + _levelSections[_levelSections.Count - 2].OffsetY,
                                                        0.0f);
        }

        CinemachineSmoothPath.Waypoint newWaypoint = new CinemachineSmoothPath.Waypoint();
        newWaypoint.position = new Vector3(newSection.CameraPathPoint.transform.position.x, newSection.CameraPathPoint.transform.position.y, CameraDistance);
        _cameraWaypoints.Add(newWaypoint);
        OnCameraWaypointsChanged(_cameraWaypoints);

        _pressureWayoints.Add(new Vector3(newSection.CameraPathPoint.transform.position.x, newSection.CameraPathPoint.transform.position.y, 0.0f));
        _pressureWayoints.Add(newSection.PressurePathPoint.transform.position);

        List <SectionType> possibleNextSections = newSection.PossibleNextSections;

        _nextSection = possibleNextSections[_pseudoRandom.Next(0, possibleNextSections.Count - 1)];
    }
        void DrawWaypointEditor(Rect rect, int index)
        {
            // Needed for accessing string names of fields
            CinemachineSmoothPath.Waypoint def     = new CinemachineSmoothPath.Waypoint();
            SerializedProperty             element = mWaypointList.serializedProperty.GetArrayElementAtIndex(index);

            float hSpace = 3;

            rect.width -= hSpace; rect.y += 1;
            Vector2 numberDimension = GUI.skin.label.CalcSize(new GUIContent("999"));
            Rect    r = new Rect(rect.position, numberDimension);

            if (GUI.Button(r, new GUIContent(index.ToString(), "Go to the waypoint in the scene view")))
            {
                if (SceneView.lastActiveSceneView != null)
                {
                    mWaypointList.index = index;
                    SceneView.lastActiveSceneView.pivot = Target.EvaluatePosition(index);
                    SceneView.lastActiveSceneView.size  = 4;
                    SceneView.lastActiveSceneView.Repaint();
                }
            }

            float      floatFieldWidth = EditorGUIUtility.singleLineHeight * 2f;
            GUIContent rollLabel       = new GUIContent("Roll");
            Vector2    labelDimension  = GUI.skin.label.CalcSize(rollLabel);
            float      rollWidth       = labelDimension.x + floatFieldWidth;

            r.x += r.width + hSpace; r.width = rect.width - (r.width + hSpace + rollWidth) - (r.height + hSpace);
            EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.position), GUIContent.none);

            r.x += r.width + hSpace; r.width = rollWidth;
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = labelDimension.x;

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.roll), rollLabel);
            EditorGUIUtility.labelWidth = oldWidth;
            EditorGUI.indentLevel       = indent;

            r.x += r.width + hSpace; r.height += 1; r.width = r.height;
            GUIContent setButtonContent = EditorGUIUtility.IconContent("d_RectTransform Icon");

            setButtonContent.tooltip = "Set to scene-view camera position";
            if (GUI.Button(r, setButtonContent, GUI.skin.label) && SceneView.lastActiveSceneView != null)
            {
                Undo.RecordObject(Target, "Set waypoint");
                CinemachineSmoothPath.Waypoint wp = Target.m_Waypoints[index];
                Vector3 pos = SceneView.lastActiveSceneView.camera.transform.position;
                wp.position = Target.transform.InverseTransformPoint(pos);
                Target.m_Waypoints[index] = wp;
            }
        }
        void InsertWaypointAtIndex(int indexA)
        {
            Vector3 pos  = Vector3.right;
            float   roll = 0;

            // Get new values from the current indexA (if any)
            int numWaypoints = Target.m_Waypoints.Length;

            if (indexA < 0)
            {
                indexA = numWaypoints - 1;
            }
            if (indexA >= 0)
            {
                int indexB = indexA + 1;
                if (Target.m_Looped && indexB >= numWaypoints)
                {
                    indexB = 0;
                }
                if (indexB >= numWaypoints)
                {
                    Vector3 delta = Vector3.right;
                    if (indexA > 0)
                    {
                        delta = Target.m_Waypoints[indexA].position - Target.m_Waypoints[indexA - 1].position;
                    }
                    pos  = Target.m_Waypoints[indexA].position + delta;
                    roll = Target.m_Waypoints[indexA].roll;
                }
                else
                {
                    // Interpolate
                    pos  = Target.transform.InverseTransformPoint(Target.EvaluatePosition(0.5f + indexA));
                    roll = Mathf.Lerp(Target.m_Waypoints[indexA].roll, Target.m_Waypoints[indexB].roll, 0.5f);
                }
            }
            Undo.RecordObject(Target, "Add waypoint");
            var wp = new CinemachineSmoothPath.Waypoint();

            wp.position = pos;
            wp.roll     = roll;
            var list = new List <CinemachineSmoothPath.Waypoint>(Target.m_Waypoints);

            list.Insert(indexA + 1, wp);
            Target.m_Waypoints = list.ToArray();
            Target.InvalidateDistanceCache();
            InternalEditorUtility.RepaintAllViews();
            mWaypointList.index = indexA + 1; // select it
        }
Example #6
0
    /*
     * Adds a waypoint to the DollyTrack with SEGMENT_LENGTH below the last one (y-axis).
     * Ex. Waypoints = [(0,0,0)] => Waypoints = [(0,0,0),(0, -SEGMENT_LENGTH, 0)]
     */
    public void AddSegmentPointToPath()
    {
        currentSegmentIndex++;

        CinemachineSmoothPath currentPath = (CinemachineSmoothPath)dolly.m_Path;
        int currentPathLength             = currentPath.m_Waypoints.Length;

        CinemachineSmoothPath.Waypoint[] newWayPoints = new CinemachineSmoothPath.Waypoint[currentPath.m_Waypoints.Length + 1];
        for (int i = 0; i < currentPath.m_Waypoints.Length; i++)
        {
            newWayPoints[i] = currentPath.m_Waypoints[i];
        }
        newWayPoints[currentPath.m_Waypoints.Length]          = new CinemachineSmoothPath.Waypoint();
        newWayPoints[currentPath.m_Waypoints.Length].position = new Vector3(dollyXPos, (-1) * currentSegmentIndex * SEGMENT_LENGTH);
        currentPath.m_Waypoints = newWayPoints;
    }
        void DrawPositionControl(int i)
        {
            CinemachineSmoothPath.Waypoint wp = Target.m_Waypoints[i];
            EditorGUI.BeginChangeCheck();
            Handles.color = Target.m_Appearance.pathColor;
            Quaternion rotation = (Tools.pivotRotation == PivotRotation.Local)
                ? Quaternion.identity : Quaternion.Inverse(Target.transform.rotation);
            float size = HandleUtility.GetHandleSize(wp.position) * 0.1f;

            Handles.SphereHandleCap(0, wp.position, rotation, size, EventType.Repaint);
            Vector3 pos = Handles.PositionHandle(wp.position, rotation);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Move Waypoint");
                wp.position           = pos;
                Target.m_Waypoints[i] = wp;
                Target.InvalidateDistanceCache();
            }
        }
        void DrawPositionControl(int i, Matrix4x4 localToWorld, Quaternion localRotation)
        {
            CinemachineSmoothPath.Waypoint wp = Target.m_Waypoints[i];
            Vector3 pos = localToWorld.MultiplyPoint(wp.position);

            EditorGUI.BeginChangeCheck();
            Handles.color = Target.m_Appearance.pathColor;
            Quaternion rotation = (Tools.pivotRotation == PivotRotation.Local)
                ? localRotation : Quaternion.identity;
            float size = HandleUtility.GetHandleSize(pos) * 0.1f;

            Handles.SphereHandleCap(0, pos, rotation, size, EventType.Repaint);
            pos = Handles.PositionHandle(pos, rotation);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Move Waypoint");
                wp.position           = Matrix4x4.Inverse(localToWorld).MultiplyPoint(pos);
                Target.m_Waypoints[i] = wp;
                Target.InvalidateDistanceCache();
                InspectorUtility.RepaintGameView(Target);
            }
        }
    private IEnumerator RunTest()
    {
        for (int i = 0; i < 20; i++)
        {
            var instance = layout.AddElement(ElementPrefab);

            var waypointsList = cameraPath.m_Waypoints.ToList();

            var lastWaypoint = waypointsList.Last();

            var newWaypoint = new CinemachineSmoothPath.Waypoint();
            newWaypoint.position = lastWaypoint.position + new Vector3(0, 0, instance.ElementHeight());

            waypointsList.Add(newWaypoint);

            cameraPath.m_Waypoints = waypointsList.ToArray();

            Camera.main.transform.DOMove(cameraPath.EvaluatePosition(waypointsList.Count), 1.5f).Play()
            .OnComplete(() => { Camera.main.transform.DOMove(cameraPath.EvaluatePosition(0), 1.5f).Play(); });

            yield return(new WaitForSecondsRealtime(5f));
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (calculateNow)
     {
         calculateNow = false;
         List <CinemachineSmoothPath.Waypoint> points = new List <CinemachineSmoothPath.Waypoint>();
         Vector3 center = transform.position;
         Vector3 point  = Vector3.forward * radius;
         CinemachineSmoothPath.Waypoint newPoint = new CinemachineSmoothPath.Waypoint();
         newPoint.position = point;
         newPoint.roll     = 5f;
         points.Add(newPoint);
         for (int i = 0; i < numPoints; i++)
         {
             point             = Quaternion.AngleAxis(360f / numPoints, Vector3.up) * point;
             newPoint          = new CinemachineSmoothPath.Waypoint();
             newPoint.position = point;
             newPoint.roll     = 5f;
             points.Add(newPoint);
         }
         smoothPath.m_Waypoints = points.ToArray();
     }
 }
        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();
            }
        }