コード例 #1
0
 internal void CalculateOffset()
 {
     if (offsetByCameraY)
     {
         limit.OffsetY = ViewEnv.OffsetFromRelativeY(0).y;
     }
 }
コード例 #2
0
 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));
 }
コード例 #3
0
 public void Sync(Vector3 position)
 {
     _content.localPosition = ViewEnv.WorldToCanvasSpace(position);
 }
コード例 #4
0
 public void OnZoom(float _)
 {
     CalculateViewExtent();
     ViewEnv.TryLimitPosition();
 }
コード例 #5
0
        //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);
        }