// GetCurrentPosition protected override void GetCurrentPosition(Vector2 touchPos) { defaultPosition = currentPosition = joystickBackgroundRT.position; if (enableAxisX) { currentPosition.x = GuiCamera.ScreenToWorldPoint(touchPos).x; } if (enableAxisY) { currentPosition.y = GuiCamera.ScreenToWorldPoint(touchPos).y; } }
private static void CreateTouchManager() { if (FindObjectOfType <TouchManagerSpriteRenderer>() && !tckGUIobj) { tckGUIobj = FindObjectOfType <TouchManagerSpriteRenderer>().gameObject; } if (tckGUIobj) { return; } tckGUIobj = new GameObject(mainGOName, typeof(TouchManagerSpriteRenderer)); GuiCamera.CreateCamera(tckGUIobj.transform, 1, 10f); }
// GetCurrentPosition protected override void GetCurrentPosition(Vector2 touchPos) { if (enableAxisX) { currentPosition.x = GuiCamera.ScreenToWorldPoint(touchPos).x; } if (enableAxisY) { currentPosition.y = GuiCamera.ScreenToWorldPoint(touchPos).y; } sizeX = myData.touchzoneRect.sizeDelta.x / 2f; sizeY = myData.touchzoneRect.sizeDelta.y / 2f; defaultPosition = myData.touchzoneRect.position; }
// UpdatePosition protected override void GetCurrentPosition(Vector2 touchPos) { if (enableAxisX) { currentPosition.x = GuiCamera.ScreenToWorldPoint(touchPos).x; } if (enableAxisY) { currentPosition.y = GuiCamera.ScreenToWorldPoint(touchPos).y; } sizeX = myData.touchzoneSprite.bounds.extents.x; sizeY = myData.touchzoneSprite.bounds.extents.y; defaultPosition = myData.touchzoneSprite.bounds.center; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create the UI Manager. UIManager uiManager = new UIManager(this); // Register the controllers. uiManager.RegisterElementNamespace(Assembly.GetExecutingAssembly(), "Example.Elements"); // Create the UI camera. camera = uiManager.CreateGuiCamera(); camera.SamplerState = SamplerState.PointClamp; // Load the root. mainMenu = uiManager.CreateUIRoot <MainMenu>("Gui\\TestLayout", random); }
// CheckPosition internal bool CheckTouchPosition(Vector2 touchPos) { touchPos = GuiCamera.ScreenToWorldPoint(touchPos); if (touchPos.x < touchzoneSprite.bounds.max.x && touchPos.y < touchzoneSprite.bounds.max.y && touchPos.x > touchzoneSprite.bounds.min.x && touchPos.y > touchzoneSprite.bounds.min.y) { return(true); } else { return(false); } }
// CheckTouchPosition internal bool CheckTouchPosition(Vector2 touchPos) { touchPos = GuiCamera.ScreenToWorldPoint(touchPos); if (touchPos.x < touchzoneRect.position.x + touchzoneRect.sizeDelta.x / 4.5f && touchPos.y < touchzoneRect.position.y + touchzoneRect.sizeDelta.y / 4.5f && touchPos.x > touchzoneRect.position.x - touchzoneRect.sizeDelta.x / 4.5f && touchPos.y > touchzoneRect.position.y - touchzoneRect.sizeDelta.y / 4.5f) { return(true); } else { return(false); } }
/// <summary> /// Initializes the control. /// </summary> protected override void Initialize() { _contentManager = new ContentManager(Services, "Content"); _camera = new GuiCamera(GraphicsDevice, this.Handle, ClientSize.Width, ClientSize.Height); _camera.UpdateMode = GuiCameraUpdateMode.Pan; _camera.Update(); _scene = _contentManager.Load <Scene>("Scene1"); _renderers = new Renderer[] { new RayTracingRenderer(GraphicsDevice, _scene, _camera, ClientSize.Width, ClientSize.Height), new XnaRenderer(_contentManager, GraphicsDevice, _scene, _camera) }; UpdateScene(); Application.Idle += new EventHandler(Application_Idle); }
private static void CreateTouchManager() { if (FindObjectOfType <TouchManagerUgui>() && !tckGUIobj) { tckGUIobj = FindObjectOfType <TouchManagerUgui>().gameObject; } if (tckGUIobj) { return; } tckGUIobj = new GameObject(mainGOName, typeof(Canvas), typeof(GraphicRaycaster), typeof(CanvasScaler), typeof(TouchManagerUgui)); tckGUIobj.layer = LayerMask.NameToLayer("UI"); GuiCamera.CreateCamera(tckGUIobj.transform, 32, 100f); tckGUIobj.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceCamera; tckGUIobj.GetComponent <Canvas>().worldCamera = GuiCamera.guiCamera; tckGUIobj.GetComponent <CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; }
//main tooltip edge of screen guard and movement - camera public void OnScreenSpaceCamera(bool refreshCanvasesBeforeGettingSize = false) { baseTooltipPos.z = canvas.planeDistance; newTTPos = GuiCamera.ScreenToViewportPoint(baseTooltipPos - offset); adjustedNewTTPos = GuiCamera.ViewportToWorldPoint(newTTPos); adjustedPivot = originalPivot; _rectTransform.pivot = originalPivot; gameObject.SetActive(true); if (refreshCanvasesBeforeGettingSize) { RefreshTooltipSize(); } //consider scaled dimensions when comparing against the edges CalcTooltipVerticalDimensions(true); CalcTooltipHorizontalDimensions(true); //get screen bounds in the canvas's rect RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, Vector2.zero, GuiCamera, out screenLowerLeft); RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, new Vector2(Screen.width, Screen.height), GuiCamera, out screenUpperRight); BorderAdjustments(true); _rectTransform.pivot = adjustedPivot; //failed attempt to circumvent issues caused when rotating the camera adjustedNewTTPos = transform.rotation * adjustedNewTTPos; transform.position = adjustedNewTTPos; adjustedTTLocalPos = transform.localPosition; adjustedTTLocalPos.z = 0; transform.localPosition = adjustedTTLocalPos; _inside = true; }
protected override void OnLoad(EventArgs e) { GL.Enable(EnableCap.DepthTest); _graphicsDevice = new GraphicsDevice(this); VSync = VSyncMode.On; _graphicsDevice.ClearColor = new Color4(0.1f, 0.2f, 0.5f, 1.0f); _3DCamera = new LookAtCamera(_graphicsDevice, new Vector3(0, 5, 10), Vector3.UnitY, Vector3.UnitZ); _screenCamera = new GuiCamera(_graphicsDevice); _graphicsDevice.Camera = _3DCamera; _graphicsDevice.DebugBatch.WorldCamera = _3DCamera; _graphicsDevice.DebugBatch.ScreenCamera = _screenCamera; ContentManager content = new ContentManager(new ServiceProvider(), @"..\..\..\Content\"); content.RegisterTypeReader <BitmapFont>(new SpriteFontReader(Shaders.FontShader)); content.RegisterTypeReader <Model>(new ModelReader()); _font = content.Get <BitmapFont>(@"SourceCodePro16.meb").Content as BitmapFont; _graphicsDevice.DebugBatch.DefaultFont = _font; _dwarf = content.Get <Model>("dwarf1.meb").Content as Model; }
protected override void OnLoad(EventArgs e) { //WindowState = OpenTK.WindowState.Fullscreen; //WindowBorder = OpenTK.WindowBorder.Hidden; GL.Enable(EnableCap.DepthTest); _graphicsDevice = new GraphicsDevice(this); VSync = VSyncMode.On; _graphicsDevice.ClearColor = new Color4(0.1f, 0.2f, 0.5f, 1.0f); _3DCamera = new LookAtCamera(_graphicsDevice, new Vector3(0, 0, -5), Vector3.UnitY, Vector3.UnitZ); _screenCamera = new GuiCamera(_graphicsDevice); _graphicsDevice.Camera = _3DCamera; _graphicsDevice.DebugBatch.WorldCamera = _3DCamera; _graphicsDevice.DebugBatch.ScreenCamera = _screenCamera; ContentManager content = new ContentManager(new ServiceProvider(), @"..\..\..\Content\"); content.RegisterTypeReader <BitmapFont>(new SpriteFontReader(Shaders.FontShader)); content.RegisterTypeReader <Texture2D>(new Texture2DReader()); content.RegisterTypeReader <Model>(new ModelReader()); _font = content.Get <BitmapFont>(@"SourceCodePro16.meb").Content as BitmapFont; _graphicsDevice.DebugBatch.DefaultFont = _font; string vsSrc = @"#version 330 in vec3 Position; in vec3 Normal; in vec2 TexCoord; uniform mat4 WorldViewProj; out vec2 fragTexCoord; out vec3 fragNormal; out vec3 position; void main() { fragTexCoord = TexCoord; fragNormal = Normal; position = (WorldViewProj * vec4(Position, 1)).xyz; gl_Position = WorldViewProj * vec4(Position, 1); } "; string fsSrc = @"#version 330 #extension GL_ARB_explicit_attrib_location : require uniform sampler2D Texture; in vec2 fragTexCoord; in vec3 fragNormal; in vec3 position; layout(location = 0) out vec4 diffuseOutput; layout(location = 1) out vec4 posOutput; layout(location = 2) out vec4 normOutput; void main() { diffuseOutput = texture(Texture, fragTexCoord); posOutput.xyz = position; normOutput = vec4(fragNormal * 0.5 + 0.5, 1); } "; _defferedShader = new Program(vsSrc, fsSrc); _depthTexture = Texture2D.CreateEmpty(_graphicsDevice.Width, _graphicsDevice.Height, PixelInternalFormat.DepthComponent24, PixelFormat.DepthComponent, PixelType.UnsignedInt); _diffuseTexture = Texture2D.CreateEmpty(_graphicsDevice.Width, _graphicsDevice.Height); _normalTexture = Texture2D.CreateEmpty(_graphicsDevice.Width, _graphicsDevice.Height); _positionTexture = Texture2D.CreateEmpty(_graphicsDevice.Width, _graphicsDevice.Height); _fbo = new FrameBuffer(_graphicsDevice); _fbo.Attach(_diffuseTexture, FramebufferAttachment.ColorAttachment0); _fbo.Attach(_positionTexture, FramebufferAttachment.ColorAttachment1); _fbo.Attach(_normalTexture, FramebufferAttachment.ColorAttachment2); _fbo.Attach(_depthTexture, FramebufferAttachment.DepthAttachment); _fbo.Unbind(); Utilities.CheckGLError(); _spriteBatch = new SpriteBatch(_graphicsDevice); _dwarf = content.Get <Model>("\\dwarf1.meb").Content as Model; _dwarfWorld = Matrix4.Scale(0.5f) * Matrix4.CreateTranslation(0, -1.5f, 0); }
//Update Transparency And Position for Dynamic Joystick protected override void UpdateTransparencyAndPosition(Vector2 touchPos) { joystickImage.color = joystickBackgroundImage.color = ElementTransparency.colorHalfSprite; joystickRT.position = joystickBackgroundRT.position = GuiCamera.ScreenToWorldPoint(touchPos); }
// GetCurrentPosition protected override void GetCurrentPosition(Vector2 touchPos) { defaultPosition = currentPosition = myData.touchzoneRect.position; currentPosition.x = GuiCamera.ScreenToWorldPoint(touchPos).x; currentPosition.y = GuiCamera.ScreenToWorldPoint(touchPos).y; }
//main tooltip edge of screen guard and movement - camera public void OnScreenSpaceCamera(bool refreshCanvasesBeforeGettingSize = false) { shiftingVector.x = xShift; shiftingVector.y = YShift; baseTooltipPos.z = canvas.planeDistance; newTTPos = GuiCamera.ScreenToViewportPoint(baseTooltipPos - shiftingVector); adjustedNewTTPos = GuiCamera.ViewportToWorldPoint(newTTPos); gameObject.SetActive(true); if (refreshCanvasesBeforeGettingSize) { RefreshTooltipSize(); } //consider scaled dimensions when comparing against the edges width = transform.lossyScale.x * _rectTransform.sizeDelta[0]; height = transform.lossyScale.y * _rectTransform.sizeDelta[1]; // check and solve problems for the tooltip that goes out of the screen on the horizontal axis RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, Vector2.zero, GuiCamera, out screenLowerLeft); RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, new Vector2(Screen.width, Screen.height), GuiCamera, out screenUpperRight); //check for right edge of screen borderTest = (adjustedNewTTPos.x + width / 2); if (borderTest > screenUpperRight.x) { shifterForBorders.x = borderTest - screenUpperRight.x; adjustedNewTTPos.x -= shifterForBorders.x; } //check for left edge of screen borderTest = (adjustedNewTTPos.x - width / 2); if (borderTest < screenLowerLeft.x) { shifterForBorders.x = screenLowerLeft.x - borderTest; adjustedNewTTPos.x += shifterForBorders.x; } // check and solve problems for the tooltip that goes out of the screen on the vertical axis //check for lower edge of the screen borderTest = (adjustedNewTTPos.y - height / 2); if (borderTest < screenLowerLeft.y) { shifterForBorders.y = screenLowerLeft.y - borderTest; adjustedNewTTPos.y += shifterForBorders.y; } //check for upper edge of the screen borderTest = (adjustedNewTTPos.y + height / 2); if (borderTest > screenUpperRight.y) { shifterForBorders.y = borderTest - screenUpperRight.y; adjustedNewTTPos.y -= shifterForBorders.y; } //failed attempt to circumvent issues caused when rotating the camera adjustedNewTTPos = transform.rotation * adjustedNewTTPos; transform.position = adjustedNewTTPos; adjustedTTLocalPos = transform.localPosition; adjustedTTLocalPos.z = 0; transform.localPosition = adjustedTTLocalPos; _inside = true; }