Created
April 22, 2019 08:27
-
-
Save doodoori2/ea14dfec54771cfc0b098829dc5c03e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using UnityEngine; | |
| using Game.Helper; | |
| namespace Game.Components | |
| { | |
| // 스크롤 움직임에 맞춰서 상대적인 이동을 할 때 사용 (연출) | |
| // TODO TweenPosition을 주고 endpoint를 계속 바꿔주면 easing도 할수있지 않을까? | |
| public class UIScrollAnchor: MonoBehaviour { | |
| public float MovingScale = 0.0f; | |
| [System.NonSerialized] | |
| private Transform _scrollAnchor; | |
| [System.NonSerialized] | |
| private float _basePosition = 0.0f; | |
| [System.NonSerialized] | |
| private float _originPosition = 0.0f; | |
| public void Start() | |
| { | |
| _scrollAnchor = transform.GetParentUntil("BackgroundScroll"); | |
| if(_scrollAnchor == null) | |
| { | |
| Debug.LogError("ScrollAnchor == null", this); | |
| return; | |
| } | |
| var position = transform.InverseTransformPoint(_scrollAnchor.transform.position); | |
| _originPosition = transform.localPosition.x; | |
| _basePosition = position.x + _originPosition; | |
| } | |
| public void Update() | |
| { | |
| if(_scrollAnchor == null || Math.Abs(MovingScale) <= 0.00001f) | |
| { | |
| return; | |
| } | |
| var lx = (_basePosition - _scrollAnchor.transform.localPosition.x) * MovingScale + _originPosition; | |
| var lp = transform.localPosition; | |
| transform.localPosition = new Vector3(lx, lp.y, lp.z); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment