Ejemplo n.º 1
0
        public static CatmullRomSpline3 Create(Transform t, List <Vector3> points, SplineTypes type)
        {
            CatmullRomSpline3 spline = t.GetComponent <CatmullRomSpline3>();

            if (spline == null)
            {
                spline = t.gameObject.AddComponent <CatmullRomSpline3>();
            }
            spline._type = type;
            spline._data = new List <ItemData>(points.Count);
            for (int i = 0; i < points.Count; ++i)
            {
                ItemData item = new ItemData();
                item.Position = points[i];
                spline._data.Add(item);
            }
            if (points.Count >= 2)
            {
                for (int i = 0, len = spline.SegmentCount; i < len; ++i)
                {
                    spline.UpdateSegment(i);
                }
            }
            spline._recalcSegmentsLength = true;
            return(spline);
        }
Ejemplo n.º 2
0
        protected override SplineMovement CreateCameraMovement()
        {
            if (!BoundsProvider.Bounds.Any())
            {
                throw new Exception("No bound objects available!");
            }

            var parentObject = BoundsProvider.Bounds.First();

            var moveModule = new SplineMovement();

            moveModule.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(FocusType);
            moveModule.EvaluateSpline        = SplineTypes.GetEvaluationFunction(SplineType);

            if (TargetObject == null)
            {
                TargetObject = new GameObject("Camera movement Target");
            }
            TargetObject.transform.parent        = parentObject.transform;
            TargetObject.transform.localPosition = TargetOffset;
            moveModule.TargetTransform           = TargetObject.transform;

            var startTime = Time.time - DelayOverage;
            var timeCurve = CurveFactory.GetCurve(TimeCurve);

            moveModule.RealtimeToLocalTime = (realTime) => (realTime - startTime) / Duration;
            moveModule.ModulateLocalTime   = (timeProportion) => timeCurve.Evaluate(timeProportion);


            //moveModule.OnMovementCompleted += ()=>Object.Destroy( targetObject );

            return(moveModule);
        }
Ejemplo n.º 3
0
        public SplineMovement GenerateTranslationMovement(float startTime)
        {
            var cameraMovement = new SplineMovement();

            cameraMovement.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(SplineComputeFocusFunctionTypes.Linear);
            cameraMovement.EvaluateSpline        = SplineTypes.GetEvaluationFunction(SplineEvaluationFunctionTypes.Bezier);

            TargetObject.transform.position = Position;
            TargetObject.transform.parent   = null;
            cameraMovement.TargetTransform  = TargetObject.transform;

            var timeCurve = CurveFactory.GetCurve("EaseBoth");

            cameraMovement.RealtimeToLocalTime = (realTime) => (realTime - startTime) / Duration;
            cameraMovement.ModulateLocalTime   = (timeProportion) => timeCurve.Evaluate(timeProportion);

            return(cameraMovement);
        }
Ejemplo n.º 4
0
        public SplineMovement GenerateLookMovement(float startTime)
        {
            var lookModule = new SplineMovement();

            //lookModule.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(FocusType);
            lookModule.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(SplineComputeFocusFunctionTypes.Linear);
            lookModule.EvaluateSpline        = SplineTypes.GetEvaluationFunction(SplineEvaluationFunctionTypes.Bezier);

            FacingObject.transform.parent        = SplineCameraControlLord.CameraParent.transform;
            FacingObject.transform.localPosition = Facing;
            lookModule.TargetTransform           = FacingObject.transform;

            var timeCurve = CurveFactory.GetCurve("EaseBoth");

            lookModule.RealtimeToLocalTime = (realTime) => (realTime - startTime) / Duration;
            lookModule.ModulateLocalTime   = (timeProportion) => timeCurve.Evaluate(timeProportion);

            return(lookModule);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates spline from supplied points.
        /// </summary>
        public static CubicSpline3 Create(IList <Vector3> points, SplineTypes type)
        {
            CubicSpline3 spline = new GameObject("CubicSpline3").AddComponent <CubicSpline3>();

            spline._type = type;
            spline._data = new List <ItemData>(points.Count);
            for (int i = 0; i < points.Count; ++i)
            {
                ItemData item = new ItemData();
                item.Position = points[i];
                spline._data.Add(item);
            }
            if (points.Count >= 2)
            {
                spline.BuildSpline();
            }
            spline._recalcSegmentsLength = true;
            return(spline);
        }
Ejemplo n.º 6
0
        protected override SplineMovement CreateLookMovement()
        {
            var lookModule = new SplineMovement();

            lookModule.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(FocusType);
            lookModule.EvaluateSpline        = SplineTypes.GetEvaluationFunction(SplineType);

            TargetObject.transform.parent        = SplineCameraControlLord.CameraParent.transform;
            TargetObject.transform.localPosition = TargetFacing;
            lookModule.TargetTransform           = TargetObject.transform;

            var startTime = Time.time - DelayOverage;
            var timeCurve = CurveFactory.GetCurve(TimeCurve);

            lookModule.RealtimeToLocalTime = (realTime) => (realTime - startTime) / Duration;
            lookModule.ModulateLocalTime   = (timeProportion) => timeCurve.Evaluate(timeProportion);

            //moveModule.OnMovementCompleted += ()=>Object.Destroy( targetObject );

            return(lookModule);
        }
Ejemplo n.º 7
0
        protected override void ConductOtherFunctionality()
        {
            var lookModule = new SplineMovement();

            //lookModule.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(FocusType);
            lookModule.ComputeImaginaryFocus = SplineFocusTypes.GetFocusFunction(SplineComputeFocusFunctionTypes.Linear);
            lookModule.EvaluateSpline        = SplineTypes.GetEvaluationFunction(SplineType);

            FacingObject.transform.parent        = SplineCameraControlLord.CameraParent.transform;
            FacingObject.transform.localPosition = TargetFacing;
            lookModule.TargetTransform           = FacingObject.transform;

            var startTime = Time.time - DelayOverage;
            //var timeCurve = CurveFactory.GetCurve(TimeCurve);
            var timeCurve = CurveFactory.GetCurve("EaseBoth");

            lookModule.RealtimeToLocalTime = (realTime) => (realTime - startTime) / Duration;
            lookModule.ModulateLocalTime   = (timeProportion) => timeCurve.Evaluate(timeProportion);

            //moveModule.OnMovementCompleted += ()=>Object.Destroy( FacingObject );

            SplineCameraControlLord.EnqueueLookMovement(lookModule);
        }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(_renderColor);

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Vertex Count", _spline.VertexCount.ToString());
        bool gotSelectedVertex = _selectedVertex != -1 && _selectedVertex < _spline.VertexCount;

        if (gotSelectedVertex)
        {
            EditorGUILayout.LabelField("Selected Vertex", _selectedVertex.ToString());
            Vector3 localPosition = _spline.GetVertex(_selectedVertex);
            Vector3 temp          = EditorGUILayout.Vector3Field("Local Position", localPosition);
            if (localPosition != temp)
            {
                MoveVertex(_selectedVertex, temp);
            }

            Vector3 worldPosition = _spline.transform.TransformPoint(localPosition);
            temp = EditorGUILayout.Vector3Field("World Position", worldPosition);
            if (worldPosition != temp)
            {
                temp = _spline.transform.InverseTransformPoint(temp);
                MoveVertex(_selectedVertex, temp);
            }
        }
        else
        {
            EditorGUILayout.LabelField("Vertex is not selected");
            GUI.enabled = false;
            EditorGUILayout.Vector3Field("Local Position", Vector3.zero);
            EditorGUILayout.Vector3Field("World Position", Vector3.zero);
            GUI.enabled = true;
        }

        EditorGUILayout.Space();
        SplineTypes prevType = _spline.SplineType;
        SplineTypes currType = (SplineTypes)EditorGUILayout.EnumPopup("SplineType", prevType);

        if (prevType != currType)
        {
            SetType(currType);
        }
        EditorGUILayout.PropertyField(_creationPlane);

        EditorGUILayout.Space();
        bool temp1 = GUILayout.Toggle(_adding == 1, _adding == 1 ?
                                      new GUIContent("Stop Adding", "Click to stop adding vertices") :
                                      new GUIContent("Add First", "Click to begin adding vertices to the beginning of the spline"), GUI.skin.button);

        if (temp1)
        {
            _adding = 1;
        }
        bool temp2 = GUILayout.Toggle(_adding == 2, _adding == 2 ?
                                      new GUIContent("Stop Adding", "Click to stop adding vertices") :
                                      new GUIContent("Add Last", "Click to begin adding vertices to the end of the spline"), GUI.skin.button);

        if (temp2)
        {
            _adding = 2;
        }
        if (!temp1 && !temp2)
        {
            _adding = 0;
        }

        GUI.enabled = gotSelectedVertex;
        {
            EditorGUILayout.Space();
            if (GUILayout.Button(new GUIContent("Split Before", "Insert new vertex between current and previous vertices")))
            {
                InsertBeforeVertex(_selectedVertex);
            }
            if (GUILayout.Button(new GUIContent("Split After", "Insert new vertex between current and next vertices")))
            {
                InsertAfterVertex(_selectedVertex);
            }

            EditorGUILayout.Space();
            if (GUILayout.Button(new GUIContent("Delete Vertex", "Click to delete currently selected vertex")))
            {
                DeleteVertex(_selectedVertex);
            }
        }
        GUI.enabled = true;
        if (GUILayout.Button(new GUIContent("Clear Spline", "Click to remove all vertices")))
        {
            Clear();
        }

        // This is used for testing. When everything is working right,
        // force updating should not affect the spline in any way,
        // becase all changes are handled inside spline methods, however
        // if pressing force update changes the spline, then there is
        // an error in the code.
        //if (GUILayout.Button("Force Update")) _spline._ForceUpdate();

        if (EditorGUI.EndChangeCheck())
        {
            SetSplineDirty();
        }
        serializedObject.ApplyModifiedProperties();
    }
 private void SetType(SplineTypes type)
 {
     RecordSpline("Set spline type");
     _spline.SplineType = type;
     SetSplineDirty();
 }