public override void Update() { if (_cameraTransform) { Vector3 position; Quaternion rotation; Vector3 size; if (InstanceManager.GetPosition(worldInstance, out position, out rotation, out size)) { position.y += size.y * 0.8f; } else { position = Vector3.zero; Hide(); } UIView view = GetUIView(); Vector3 screenPos = Camera.main.WorldToScreenPoint(position) * Mathf.Sign(Vector3.Dot(position - _cameraTransform.position, _cameraTransform.forward));; Vector3 scaledPos = screenPos / view.inputScale; Vector3 upperLeftTransform = UIPivotExtensions.UpperLeftToTransform(pivot, size, arbitraryPivotOffset); Vector3 guiPoint = view.ScreenPointToGUI(scaledPos) + new Vector2(upperLeftTransform.x, upperLeftTransform.y); relativePosition = guiPoint; } base.Update(); }
protected virtual void DoResizing(MouseEventArgs e) { if (isResizing) { if (e.CheckButtonsPressed(MouseButtons.Left)) { e.Handled = true; Ray ray = e.Ray; float enter = 0.0f; Plane detectionPlane = new Plane(windowPanel.GetUIView().uiCamera.transform.TransformDirection(Vector3.back), this.cachedLastPosition); detectionPlane.Raycast(ray, out enter); Vector3 mousePositionW = VectorExtensions.Quantize(ray.origin + ray.direction * enter, windowPanel.PixelsToUnits()); Vector3 transformVecToTopLeftW = UIPivotExtensions.TransformToUpperLeft((UIPivotPoint)windowPanel.Pivot, windowPanel.Size, windowPanel.ArbitaryPivotOffset); Vector3 point1S = windowPanel.GameObject.transform.position + transformVecToTopLeftW; Vector2 newSize = (mousePositionW - point1S) / windowPanel.PixelsToUnits(); newSize = new Vector2(newSize.x, -newSize.y); if (newSize.x < this.windowPanel.MinSize.x) { newSize.x = this.windowPanel.MinSize.x; } else if (newSize.x > this.windowPanel.MaxSize.x) { newSize.x = this.windowPanel.MaxSize.x; } if (newSize.y < this.windowPanel.MinSize.y) { newSize.y = this.windowPanel.MinSize.y; } else if (newSize.y > this.windowPanel.MaxSize.y) { newSize.y = this.windowPanel.MaxSize.y; } windowPanel.Size = newSize; this.cachedLastPosition = mousePositionW; this.OnResizing(); } else { StopResizing(); } } }