//mi pendejada
 public CPC_Point(Transform trans)
 {
     position          = trans.position;
     rotation          = trans.rotation;
     handleprev        = Vector3.back;
     handlenext        = Vector3.forward;
     curveTypeRotation = CPC_ECurveType.EaseInAndOut;
     rotationCurve     = AnimationCurve.EaseInOut(0, 0, 1, 1);
     curveTypePosition = CPC_ECurveType.Linear;
     positionCurve     = AnimationCurve.Linear(0, 0, 1, 1);
     chained           = true;
 }
 public CPC_Point(Vector3 pos, Quaternion rot)
 {
     position          = pos;
     rotation          = rot;
     handleprev        = Vector3.back;
     handlenext        = Vector3.forward;
     curveTypeRotation = CPC_ECurveType.EaseInAndOut;
     rotationCurve     = AnimationCurve.EaseInOut(0, 0, 1, 1);
     curveTypePosition = CPC_ECurveType.Linear;
     positionCurve     = AnimationCurve.Linear(0, 0, 1, 1);
     chained           = true;
 }
    void DrawWaypointList()
    {
        GUILayout.Label("Replace all lerp types");
        GUILayout.BeginVertical("Box");
        GUILayout.BeginHorizontal();
        allCurveType = (CPC_ECurveType)EditorGUILayout.EnumPopup(allCurveType, GUILayout.Width(Screen.width / 3f));
        if (GUILayout.Button(replaceAllPositionContent))
        {
            Undo.RecordObject(t, "Applied new position");
            foreach (var index in t.points)
            {
                index.curveTypePosition = allCurveType;
                if (allCurveType == CPC_ECurveType.Custom)
                {
                    index.positionCurve.keys = allAnimationCurve.keys;
                }
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUI.enabled       = allCurveType == CPC_ECurveType.Custom;
        allAnimationCurve = EditorGUILayout.CurveField(allAnimationCurve, GUILayout.Width(Screen.width / 3f));
        GUI.enabled       = true;
        if (GUILayout.Button(replaceAllRotationContent))
        {
            Undo.RecordObject(t, "Applied new rotation");
            foreach (var index in t.points)
            {
                index.curveTypeRotation = allCurveType;
                if (allCurveType == CPC_ECurveType.Custom)
                {
                    index.rotationCurve = allAnimationCurve;
                }
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.BeginHorizontal();
        GUILayout.Space(Screen.width / 2f - 20);
        GUILayout.Label("↓");
        GUILayout.EndHorizontal();
        serializedObject.Update();
        pointReorderableList.DoLayoutList();
        serializedObject.ApplyModifiedProperties();
        Rect r = GUILayoutUtility.GetRect(Screen.width - 16, 18);

        //r.height = 18;
        r.y -= 10;
        GUILayout.Space(-30);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(addPointContent))
        {
            Undo.RecordObject(t, "Added camera path point");
            switch (waypointMode)
            {
            case CPC_ENewWaypointMode.SceneCamera:
                t.points.Add(new CPC_Point(SceneView.lastActiveSceneView.camera.transform.position, SceneView.lastActiveSceneView.camera.transform.rotation));
                break;

            case CPC_ENewWaypointMode.LastWaypoint:
                if (t.points.Count > 0)
                {
                    t.points.Add(new CPC_Point(t.points[t.points.Count - 1].position, t.points[t.points.Count - 1].rotation)
                    {
                        handlenext = t.points[t.points.Count - 1].handlenext, handleprev = t.points[t.points.Count - 1].handleprev
                    });
                }
                else
                {
                    t.points.Add(new CPC_Point(Vector3.zero, Quaternion.identity));
                    Debug.LogWarning("No previous waypoint found to place this waypoint, defaulting position to world center");
                }
                break;

            case CPC_ENewWaypointMode.WaypointIndex:
                if (t.points.Count > waypointIndex - 1 && waypointIndex > 0)
                {
                    t.points.Add(new CPC_Point(t.points[waypointIndex - 1].position, t.points[waypointIndex - 1].rotation)
                    {
                        handlenext = t.points[waypointIndex - 1].handlenext, handleprev = t.points[waypointIndex - 1].handleprev
                    });
                }
                else
                {
                    t.points.Add(new CPC_Point(Vector3.zero, Quaternion.identity));
                    Debug.LogWarning("Waypoint index " + waypointIndex + " does not exist, defaulting position to world center");
                }
                break;

            case CPC_ENewWaypointMode.WorldCenter:
                t.points.Add(new CPC_Point(Vector3.zero, Quaternion.identity));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            selectedIndex = t.points.Count - 1;
            SceneView.RepaintAll();
        }
        GUILayout.Label("at", GUILayout.Width(20));
        EditorGUI.BeginChangeCheck();
        waypointMode = (CPC_ENewWaypointMode)EditorGUILayout.EnumPopup(waypointMode, waypointMode == CPC_ENewWaypointMode.WaypointIndex ? GUILayout.Width(Screen.width / 4) : GUILayout.Width(Screen.width / 2));
        if (waypointMode == CPC_ENewWaypointMode.WaypointIndex)
        {
            waypointIndex = EditorGUILayout.IntField(waypointIndex, GUILayout.Width(Screen.width / 4));
        }
        if (EditorGUI.EndChangeCheck())
        {
            PlayerPrefs.SetInt("CPC_waypointMode", (int)waypointMode);
        }
        GUILayout.EndHorizontal();
    }
    void SetupReorderableList()
    {
        pointReorderableList = new ReorderableList(serializedObject, serializedObject.FindProperty("points"), true, true, false, false);

        pointReorderableList.elementHeight *= 2;

        pointReorderableList.drawElementCallback = (rect, index, active, focused) =>
        {
            float startRectY = rect.y;
            if (index > t.points.Count - 1)
            {
                return;
            }
            rect.height -= 2;
            float fullWidth = rect.width - 16 * (hasScrollBar ? 1 : 0);
            rect.width   = 40;
            fullWidth   -= 40;
            rect.height /= 2;
            GUI.Label(rect, "#" + (index + 1));
            rect.y     += rect.height - 3;
            rect.x     -= 14;
            rect.width += 12;
            if (GUI.Button(rect, t.points[index].chained ? chainedContent : unchainedContent))
            {
                Undo.RecordObject(t, "Changed chain type");
                t.points[index].chained = !t.points[index].chained;
            }
            rect.x += rect.width + 2;
            rect.y  = startRectY;
            //Position
            rect.width = (fullWidth - 22) / 3 - 1;
            EditorGUI.BeginChangeCheck();
            CPC_ECurveType tempP = (CPC_ECurveType)EditorGUI.EnumPopup(rect, t.points[index].curveTypePosition);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(t, "Changed enum value");
                t.points[index].curveTypePosition = tempP;
            }
            rect.y += pointReorderableList.elementHeight / 2 - 4;
            //rect.x += rect.width + 2;
            EditorGUI.BeginChangeCheck();
            GUI.enabled = t.points[index].curveTypePosition == CPC_ECurveType.Custom;
            AnimationCurve tempACP = EditorGUI.CurveField(rect, t.points[index].positionCurve);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(t, "Changed curve");
                t.points[index].positionCurve = tempACP;
            }
            GUI.enabled = true;
            rect.x     += rect.width + 2;
            rect.y      = startRectY;

            //Rotation

            rect.width = (fullWidth - 22) / 3 - 1;
            EditorGUI.BeginChangeCheck();
            CPC_ECurveType temp = (CPC_ECurveType)EditorGUI.EnumPopup(rect, t.points[index].curveTypeRotation);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(t, "Changed enum value");
                t.points[index].curveTypeRotation = temp;
            }
            rect.y += pointReorderableList.elementHeight / 2 - 4;
            //rect.height /= 2;
            //rect.x += rect.width + 2;
            EditorGUI.BeginChangeCheck();
            GUI.enabled = t.points[index].curveTypeRotation == CPC_ECurveType.Custom;
            AnimationCurve tempAC = EditorGUI.CurveField(rect, t.points[index].rotationCurve);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(t, "Changed curve");
                t.points[index].rotationCurve = tempAC;
            }
            GUI.enabled = true;

            rect.y       = startRectY;
            rect.height *= 2;
            rect.x      += rect.width + 2;
            rect.width   = (fullWidth - 22) / 3;
            rect.height  = rect.height / 2 - 1;
            if (GUI.Button(rect, gotoPointContent))
            {
                pointReorderableList.index = index;
                selectedIndex = index;
                SceneView.lastActiveSceneView.pivot = t.points[pointReorderableList.index].position;
                SceneView.lastActiveSceneView.size  = 3;
                SceneView.lastActiveSceneView.Repaint();
            }
            rect.y += rect.height + 2;
            if (GUI.Button(rect, relocateContent))
            {
                Undo.RecordObject(t, "Relocated waypoint");
                pointReorderableList.index = index;
                selectedIndex = index;
                t.points[pointReorderableList.index].position = SceneView.lastActiveSceneView.camera.transform.position;
                t.points[pointReorderableList.index].rotation = SceneView.lastActiveSceneView.camera.transform.rotation;
                SceneView.lastActiveSceneView.Repaint();
            }
            rect.height = (rect.height + 1) * 2;
            rect.y      = startRectY;
            rect.x     += rect.width + 2;
            rect.width  = 20;

            if (GUI.Button(rect, deletePointContent))
            {
                Undo.RecordObject(t, "Deleted a waypoint");
                t.points.Remove(t.points[index]);
                SceneView.RepaintAll();
            }
        };

        pointReorderableList.drawHeaderCallback = rect =>
        {
            float fullWidth = rect.width;
            rect.width = 56;
            GUI.Label(rect, "Sum: " + t.points.Count);
            rect.x    += rect.width;
            rect.width = (fullWidth - 78) / 3;
            GUI.Label(rect, "Position Lerp");
            rect.x += rect.width;
            GUI.Label(rect, "Rotation Lerp");
            //rect.x += rect.width*2;
            //GUI.Label(rect, "Del.");
        };

        pointReorderableList.onSelectCallback = l =>
        {
            selectedIndex = l.index;
            SceneView.RepaintAll();
        };
    }