HeavenStudioPlus/Assets/Scripts/LevelEditor/Timeline/TimelineZoom.cs
Zeo e50e4e39e0
Mass Text Update (#615)
* Air Rally Text Update

* Blue Bear Text Update

* Board Meeting Text Update

* Built To Scale DS Text Update

also changed Air Rally's assetbundle tag from "normal" to "keep"

* Catchy Tune Text Update

also changed some minor wording in Board Meeting and Built To Scale DS

* Cheer Readers Text Update

* The Clappy Trio Text Update

* Coin Toss Text Update

* Crop Stomp Text Update

* DJ School Text Update

* Dog Ninja Text Update

* Double Date Text Update

* Drumming Practice Text Update

* Fan Club Text Update

* Fireworks Text Update

* Second Contact Text Update

* Flipper-Flop Text Update

also fix an error in Catchy Tune

* Fork Lifter Text Update

* Glee Club Text Update

* Karate Man Text Update

also minor updates to other games

* Kitties! Text Update

* Launch Party Text Update

* Lockstep Text Update

* Marching Orders Text Update

* Meat Grinder Text Update

also fixed an error in Second Contact

* Mr. Upbeat Text Update

* Munchy Monk Text Update

* Octopus Machine Text Update

* Pajama Party Text Update

* Quiz Show Text Update

also changed some wording in meat grinder

* Rhythm Rally Text Update

* Rhythm Somen Text Update

that was easy

* Rhythm Tweezers Text Update

* Ringside Text Update

* Rockers Text Update

this sucked

* Samurai Slice DS Text Update

* See Saw Text Update

* Sneaky Spirits Text Update

* Spaceball Text Update

* Space Dance Text Update

* Space Soccer Text Update

* Splashdown Text Update

* Tambourine Text Update

* Tap Trial Text Update

* Tap Troupe Text Update

* The Dazzles Text Update

* Toss Boys Text Update

* Tram & Pauline Text Update

also added translation for Fireworks

* Tunnel Text Update

* Wizard's Waltz Text Update

* Working Dough Text Update

* fix compiler errors

* fix editor offset bug(?)

* fix missing param in second contact

* Ball Redispense text

* remove space soccer swing

* Trick on the Class Text Update

* Non-Game Text Update

* fix pre-function sorting

* camera shake ease

* remove a bunch of prints

* rhythm tweezers bug fix

* Update Credits.txt

* ssds nop samurai bop

* swap order of shake properties

* Update FirstContact.cs

---------

Co-authored-by: minenice55 <star.elementa@gmail.com>
2024-01-15 02:04:10 +00:00

132 lines
No EOL
4.3 KiB
C#

using UnityEngine;
using UnityEngine.EventSystems;
namespace HeavenStudio.Editor.Track
{
public class TimelineZoom : MonoBehaviour
{
public Vector3 Scale => _scale;
[SerializeField] private float minScale = 0.5f;
[SerializeField] private float maxScale => float.MaxValue;
[SerializeField] private Vector2 initialScale = Vector2.one;
private Vector3 _scale;
private Vector2 relMousePos;
private RectTransform rectTransform;
private void Awake()
{
initialScale = transform.localScale;
rectTransform = transform as RectTransform;
_scale.Set(initialScale.x, initialScale.y, 1);
rectTransform.localScale = _scale;
}
private void Update()
{
var scrollDeltaY = Input.mouseScrollDelta.y;
if (scrollDeltaY != 0)
{
if (Timeline.instance.MouseInTimeline)
OnScroll(scrollDeltaY);
}
}
public void OnScroll(float scrollDeltaY)
{
if (Conductor.instance.NotStopped()) return;
relMousePos = rectTransform.anchoredPosition;
Vector2 relativeMousePosition;
var cam = Editor.instance.EditorCamera;
if (cam == null)
{
Debug.LogError("Camera not set!");
return;
}
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, cam, out relativeMousePosition);
if (scrollDeltaY > 0)
{
if (Input.GetKey(KeyCode.LeftControl))
{
Zoom(0.25f * _scale.y, relativeMousePosition, false);
}
else
{
Zoom(0.25f * _scale.x, relativeMousePosition, true);
}
}
else if (scrollDeltaY < 0)
{
if (Input.GetKey(KeyCode.LeftControl))
{
var incre = -0.2f * _scale.y;
if (_scale.y + incre > minScale - 0.1f)
Zoom(-0.2f * _scale.y, relativeMousePosition, false);
}
else
{
var incre = -0.2f * _scale.x;
if (_scale.x + incre > minScale - 0.1f)
Zoom(-0.2f * _scale.x, relativeMousePosition, true);
}
}
}
public void Zoom(float incre, Vector2 relativeMousePosition, bool horiz)
{
if (!(_scale.x < maxScale)) return;
if (horiz)
{
var newScale = Mathf.Clamp(_scale.x + incre, minScale, maxScale);
_scale.Set(newScale, _scale.y, 1);
relativeMousePosition = new Vector2(relativeMousePosition.x, 0);
relMousePos -= (relativeMousePosition * incre);
rectTransform.localScale = _scale;
rectTransform.anchoredPosition = relMousePos;
rectTransform.localScale =
new Vector3(Mathf.Clamp(rectTransform.localScale.x, minScale, Mathf.Infinity),
rectTransform.localScale.y);
Timeline.instance.OnZoom(newScale);
}
else
{
var newScale = Mathf.Clamp(_scale.y + incre, 1.0f, maxScale);
_scale.Set(_scale.x, newScale, 1);
relativeMousePosition = new Vector2(0, relativeMousePosition.y);
relMousePos -= (relativeMousePosition * incre);
rectTransform.localScale = _scale;
rectTransform.anchoredPosition = relMousePos;
rectTransform.localScale =
new Vector3(rectTransform.localScale.x,
Mathf.Clamp(rectTransform.localScale.y, 1.0f, Mathf.Infinity));
Timeline.instance.OnZoomVertical(newScale);
}
}
public void SetNewPos(float newX)
{
relMousePos = new Vector2(newX, relMousePos.y);
}
public void ResetZoom()
{
_scale.Set(1, 1, 1);
rectTransform.localScale = _scale;
Timeline.instance.OnZoom(_scale.x);
}
}
}