Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feature request: SplineController.Position as inspector property
#3
(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();
}
}
}
Reply


Messages In This Thread
RE: Feature request: SplineController.Position as inspector property - by syscrusher - 01-18-2018, 12:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 8 02-12-2024, 09:54 PM
Last Post: _Aka_

Forum Jump: