internal void CalculateOffset() { if (offsetByCameraY) { limit.OffsetY = ViewEnv.OffsetFromRelativeY(0).y; } }
public static void Init(ActionList <float> updater, Camera main_, Camera ui_, Canvas canvas_) { Performance.RecordProfiler(nameof(ViewEnv)); Instance = new ViewEnv(); OnScreenSizeChange = new ActionList <int, int, float>(4, nameof(OnScreenSizeChange)); OnDrag = new ActionList <Vector3, Vector3>(8, nameof(OnDrag)); OnZoom = new ActionList <float>(8, nameof(OnZoom)); MainCamera = main_; //NOTE don't support overlay canvas, not quite controllable performance wise UICamera = ui_; MainCanvas = canvas_; _perspectiveProjectionFactor = (float)Math.Tan(MainCamera.fieldOfView * Mathf.Deg2Rad * 0.5f); CheckScreenSize(); CheckCanvas(); InitViewport(); ResetCoordinateSystem(); CanvasContent = MainCanvas.transform.AddChildRect("content"); CanvasOverlay = MainCanvas.transform.AddChildRect("overlay"); updater.Add(Instance.Update, Instance); Performance.End(nameof(ViewEnv)); }
public void Sync(Vector3 position) { _content.localPosition = ViewEnv.WorldToCanvasSpace(position); }
public void OnZoom(float _) { CalculateViewExtent(); ViewEnv.TryLimitPosition(); }
//TODO need to compensate view extent public void InitWithCorner(Vector3 posTopLeft, Vector3 posBottomRight) { var system = ViewEnv.CameraSystem; var vTL = system.WorldToSystemXY(posTopLeft); var vBR = system.WorldToSystemXY(posBottomRight); var center = new Vector2(0.5f * (vTL.x + vBR.x), 0.5f * (vTL.y + vBR.y)) + ViewEnv.OffsetFromRelativeY(0); var extent = new Vector2(0.5f * Mathf.Abs(vTL.x - vBR.x), 0.5f * Mathf.Abs(vTL.y - vBR.y)); Init(extent, center); }