mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-27 03:53:01 +00:00
Merge pull request #16 from jakobwcrowe/megaminerzero
Minimizing Camera.main references (you usually don't want to reference Camera.main too often, plus it cased errors in fullscreen mode)
This commit is contained in:
commit
17f603b3ab
6 changed files with 32 additions and 18 deletions
|
@ -7,10 +7,17 @@ namespace RhythmHeavenMania.Common
|
|||
public class FollowMouse : MonoBehaviour
|
||||
{
|
||||
public Vector2 offset;
|
||||
public Camera cam;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (cam == null)
|
||||
cam = Camera.main;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
var pos = cam.ScreenToWorldPoint(Input.mousePosition);
|
||||
transform.position = new Vector3(pos.x - offset.x, pos.y - offset.y, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,18 @@ namespace RhythmHeavenMania.Common
|
|||
private Vector3 lastCamPos;
|
||||
public float textureUnitSizeX;
|
||||
|
||||
public Camera cam;
|
||||
public bool sprite = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (cam == null)
|
||||
cam = Camera.main;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
camTransform = Camera.main.transform;
|
||||
camTransform = cam.transform;
|
||||
lastCamPos = camTransform.position;
|
||||
/*if (sprite)
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped())
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main))
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera))
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
}
|
||||
}
|
||||
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPM, Input.mousePosition, Camera.main))
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPM, Input.mousePosition, Editor.instance.EditorCamera))
|
||||
{
|
||||
float increase = Input.mouseScrollDelta.y;
|
||||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
|
@ -82,7 +82,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
if (create == true)
|
||||
{
|
||||
tempoChange.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x + 0.08f, tempoChange.transform.position.y);
|
||||
tempoChange.transform.position = new Vector3(Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition).x + 0.08f, tempoChange.transform.position.y);
|
||||
tempoChange.transform.localPosition = new Vector3(Starpelly.Mathp.Round2Nearest(tempoChange.transform.localPosition.x, 0.25f), tempoChange.transform.localPosition.y);
|
||||
|
||||
Beatmap.TempoChange tempoC = new Beatmap.TempoChange();
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
{
|
||||
if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped())
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(raycastRect, Input.mousePosition, Camera.main))
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(raycastRect, Input.mousePosition, Editor.instance.EditorCamera))
|
||||
{
|
||||
float newTempo = Input.mouseScrollDelta.y;
|
||||
|
||||
|
@ -48,7 +48,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
startPosX = mousePos.x - transform.position.x;
|
||||
moving = true;
|
||||
lastPosX = transform.localPosition.x;
|
||||
|
@ -68,7 +68,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
if (moving)
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
transform.position = new Vector3(mousePos.x - startPosX, transform.position.y, 0);
|
||||
transform.localPosition = new Vector3(Mathf.Clamp(Starpelly.Mathp.Round2Nearest(transform.localPosition.x, 0.25f), 0, Mathf.Infinity), transform.localPosition.y);
|
||||
|
|
|
@ -409,12 +409,12 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
public bool CheckIfMouseInTimeline()
|
||||
{
|
||||
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineContent.transform.parent.gameObject.GetComponent<RectTransform>(), Input.mousePosition, Camera.main));
|
||||
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineContent.transform.parent.gameObject.GetComponent<RectTransform>(), Input.mousePosition, Editor.instance.EditorCamera));
|
||||
}
|
||||
|
||||
public bool MouseInRectTransform(RectTransform rectTransform)
|
||||
{
|
||||
return (rectTransform.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main));
|
||||
return (rectTransform.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -461,7 +461,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
if (dragNDrop)
|
||||
{
|
||||
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
var mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
g.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
|
||||
|
||||
Selections.instance.ClickSelect(eventObj);
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
moveTemp = new GameObject();
|
||||
moveTemp.transform.SetParent(this.transform.parent);
|
||||
|
||||
bool visible = rectTransform.IsVisibleFrom(Camera.main);
|
||||
bool visible = rectTransform.IsVisibleFrom(Editor.instance.EditorCamera);
|
||||
for (int i = 0; i < this.transform.childCount; i++)
|
||||
{
|
||||
if (i != 4)
|
||||
|
@ -77,12 +77,12 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
selected = Selections.instance.eventsSelected.Contains(this);
|
||||
entity = GameManager.instance.Beatmap.entities.Find(a => a.eventObj == this);
|
||||
|
||||
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main) && Timeline.instance.timelineState.selected;
|
||||
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera) && Timeline.instance.timelineState.selected;
|
||||
|
||||
#region Optimizations
|
||||
|
||||
// problem with long objects but im lazy right now
|
||||
bool visible = rectTransform.IsVisibleFrom(Camera.main);
|
||||
bool visible = rectTransform.IsVisibleFrom(Editor.instance.EditorCamera);
|
||||
|
||||
if (visible != lastVisible)
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
if (Timeline.instance.eventObjs.FindAll(c => c.moving).Count > 0 && selected)
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
// lastPos_ = transform.localPosition;
|
||||
|
||||
|
@ -168,7 +168,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
Vector2 mousePos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, out mousePos);
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Editor.instance.EditorCamera, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2(-mousePos.x + 0.15f, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, rectTransform.localPosition.x), sizeDelta.y);
|
||||
|
@ -182,7 +182,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
Vector2 mousePos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, out mousePos);
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Editor.instance.EditorCamera, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2(mousePos.x + 0.15f, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, Mathf.Infinity), sizeDelta.y);
|
||||
|
@ -237,7 +237,7 @@ namespace RhythmHeavenMania.Editor.Track
|
|||
|
||||
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
|
||||
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue