01-18-2018, 12:06 AM
(This post was last modified: 01-18-2018, 12:07 AM by syscrusher.)
(01-17-2018, 11:11 PM)_Aka_ Wrote: I will try to make this work in the coming week. I will let you know here about the result of my attempt.
Thanks. Let me know if you need a beta tester.
I have this working with an external script that simply exposes the needed parameter as a simple public float, initializes the float from the SplineController's own Position value at Start() time, then copies its own value to the SplineController's Position during Update(), LateUpdate(), or FixedUpdate() depending on which mode is selected.
For what it's worth, and in case it's helpful to anyone else, here's my working script, tested in Unity 2017.3.0f3 with Timeline.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FluffyUnderware.Curvy.Controllers;
/*
* Exposes the Position value of a Curvy SplineController as a write-only property
* in the Unity inspector, to allow it to be animated with Timeline.
* This implementation assumes Relative position and move mode becasue that allows
* the inspector to set a range and provide a slider for the value, which is
* useful in visualizing the animation while editing Timeline. Experimentation
* also suggests Relative mode is better for Timeline animations because you
* don't have to later update the Timeline curves or keyframe values if the
* Curvy spline's length is changed.
*
* This is proof-of-concept code, not intended for production use.
*
* Author: Scott Courtney ("Syscrusher")
* License: MIT License
*/
[RequireComponent(typeof(SplineController))]
public class CurvySplineControllerPosition : MonoBehaviour {
SplineController curvy;
[Range(0.0f, 1.0f)]
public float RelativePosition;
// Initialize and set the prerequisites on the SplineController.
void Start () {
curvy = GetComponent<SplineController>();
curvy.PositionMode = FluffyUnderware.Curvy.CurvyPositionMode.Relative;
curvy.MoveMode = FluffyUnderware.Curvy.CurvyController.MoveModeEnum.Relative;
RelativePosition = curvy.Position;
curvy.Play();
}
// Push our position setting to the SplineController object
void PushPosition() {
if (isActiveAndEnabled) {
curvy.Position = RelativePosition;
}
}
// Update is called once per frame
void Update () {
if (curvy.UpdateIn == FluffyUnderware.Curvy.CurvyUpdateMethod.Update) {
PushPosition();
}
}
void FixedUpdate() {
if (curvy.UpdateIn == FluffyUnderware.Curvy.CurvyUpdateMethod.FixedUpdate) {
PushPosition();
}
}
void LateUpdate() {
if (curvy.UpdateIn == FluffyUnderware.Curvy.CurvyUpdateMethod.LateUpdate) {
PushPosition();
}
}
}