44
55namespace DuskModules . ScriptableObjects {
66
7- /// <summary> Reads from an Int variable to determine what mode it is in, and moves itself to match target. </summary>
8- public class ModeRelocator : MonoBehaviour {
9-
10- /// <summary> List of targets </summary>
11- [ Tooltip ( "The list of targets this relocator can move from and to." ) ]
12- public List < Transform > targets ;
7+ /// <summary> Reads from an Int variable to determine what mode it is in, and moves itself to match target. </summary>
8+ public class ModeRelocator : MonoBehaviour {
139
14- /// <summary> Current mode to use </summary>
15- [ Tooltip ( "The int value to use. Preferred to reference an IntVariable ScriptableObject ." ) ]
16- public IntReference mode ;
10+ /// <summary> List of targets </summary>
11+ [ Tooltip ( "The list of targets this relocator can move from and to ." ) ]
12+ public List < Transform > targets ;
1713
18- /// <summary> Speed to move position with. </summary>
19- [ Tooltip ( "The speed to use to move the position with." ) ]
20- public LerpMoveValue positionSpeed ;
21- /// <summary> Speed to move rotation with. </summary>
22- [ Tooltip ( "The speed to use to move the rotation with." ) ]
23- public LerpMoveValue rotationSpeed ;
24- /// <summary> Speed to move scale with. </summary>
25- [ Tooltip ( "The speed to use to move the scale with." ) ]
26- public LerpMoveValue scaleSpeed ;
14+ /// <summary> Current mode to use </summary>
15+ [ Tooltip ( "The int value to use. Preferred to reference an IntVariable ScriptableObject." ) ]
16+ public IntReference mode ;
2717
28- /// <summary> Whether it should ignore out of bounds indexes and keep last position </summary>
29- [ Tooltip ( "If true, any value falling outside of targets array bounds will be ignored. " +
30- "Use this to keep the last position for invalid indexes instead of clamping and taking the closest possible target index." ) ]
31- public bool ignoreOutOfBounds ;
32- /// <summary> Value the mode must be for it to match with target index 0. </summary>
33- [ Tooltip ( "The first valid value that can be used. The mode value set here will match with target index 0." ) ]
34- public int modeStartValue ;
18+ /// <summary> Speed to move position with. </summary>
19+ [ Tooltip ( "The speed to use to move the position with." ) ]
20+ public LerpMoveValue positionSpeed ;
21+ /// <summary> Speed to move rotation with. </summary>
22+ [ Tooltip ( "The speed to use to move the rotation with." ) ]
23+ public LerpMoveValue rotationSpeed ;
24+ /// <summary> Speed to move scale with. </summary>
25+ [ Tooltip ( "The speed to use to move the scale with." ) ]
26+ public LerpMoveValue scaleSpeed ;
3527
36- /// <summary> The mode to use </summary>
37- protected int useMode ;
28+ /// <summary> Whether it should ignore out of bounds indexes and keep last position </summary>
29+ [ Tooltip ( "If true, any value falling outside of targets array bounds will be ignored. " +
30+ "Use this to keep the last position for invalid indexes instead of clamping and taking the closest possible target index." ) ]
31+ public bool ignoreOutOfBounds ;
32+ /// <summary> Value the mode must be for it to match with target index 0. </summary>
33+ [ Tooltip ( "The first valid value that can be used. The mode value set here will match with target index 0." ) ]
34+ public int modeStartValue ;
3835
39- // Awaken and set to target immediatly.
40- protected virtual void Awake ( ) {
36+ /// <summary> The mode to use </summary>
37+ protected int useMode ;
38+
39+ // Awaken and set to target immediatly.
40+ protected virtual void Awake ( ) {
4141 useMode = Mathf . Clamp ( mode . value , 0 , targets . Count - 1 ) ;
42- Transform target = targets [ useMode ] ;
42+ Transform target = targets [ useMode ] ;
4343
44- transform . position = target . position ;
45- transform . rotation = target . rotation ;
44+ transform . localPosition = target . localPosition ;
45+ transform . localRotation = target . localRotation ;
4646 transform . localScale = target . localScale ;
47- }
47+ }
4848
49- // Move self to target mode
50- protected virtual void Update ( ) {
51- int modeValue = mode . value - modeStartValue ;
52- if ( ! ignoreOutOfBounds )
49+ // Move self to target mode
50+ protected virtual void Update ( ) {
51+ int modeValue = mode . value - modeStartValue ;
52+ if ( ! ignoreOutOfBounds )
5353 useMode = Mathf . Clamp ( modeValue , 0 , targets . Count - 1 ) ;
54- else if ( modeValue >= 0 && modeValue < targets . Count )
54+ else if ( modeValue >= 0 && modeValue < targets . Count )
5555 useMode = modeValue ;
5656
57- Transform target = targets [ useMode ] ;
58- Vector3 targetPos = target . position ;
59- Quaternion targetRot = target . rotation ;
60- Vector3 targetScale = target . localScale ;
57+ Transform target = targets [ useMode ] ;
58+ Vector3 targetPos = target . localPosition ;
59+ Quaternion targetRot = target . localRotation ;
60+ Vector3 targetScale = target . localScale ;
6161
62- if ( transform . position != targetPos )
63- transform . position = positionSpeed . Move ( transform . position , targetPos ) ;
64- if ( transform . rotation != targetRot )
65- transform . rotation = rotationSpeed . Move ( transform . localRotation , targetRot ) ;
66- if ( transform . localScale != targetScale )
62+ if ( transform . localPosition != targetPos )
63+ transform . localPosition = positionSpeed . Move ( transform . localPosition , targetPos ) ;
64+ if ( transform . localRotation != targetRot )
65+ transform . localRotation = rotationSpeed . Move ( transform . localRotation , targetRot ) ;
66+ if ( transform . localScale != targetScale )
6767 transform . localScale = scaleSpeed . Move ( transform . localScale , targetScale ) ;
68- }
68+ }
6969
70- }
70+ }
7171}
0 commit comments