/// <summary> /// Send Raycast to detect windows and then check the window type by TAG /// </summary> void SendRaycast() { RaycastHit hit; Vector3 fromPosition = source.transform.position; Vector3 toPosition = destination.transform.position; Vector3 direction = toPosition - fromPosition; if (Physics.Raycast(source.transform.position, direction, out hit)) { UnityEngine.Debug.DrawRay(source.transform.position, direction, Color.blue); if (hit.collider.gameObject.tag == "Desktop") { CursorOnDesktop(hit); } else { lockCursor(true); } if (hit.collider.gameObject.tag == "WebWindow") { CursorOnWebWindow(hit); } else { if (LastWebWindow != null) { LastWebWindow.OnMouseExit(); LastWebWindow = null; } } if (hit.collider.gameObject.tag == "WebWindowUi") { CursorOnWindowUi(hit); } else { if (LastInputField != null) { LastInputField.OnDeselect(new BaseEventData(EventSystem.current)); } if (lastOverBtn != null) { lastOverBtn.GetComponent <Renderer>().material = blueMaterial; } } if (hit.collider.gameObject.tag == "Borders") { destination.transform.position = hit.point; cursor.transform.up = hit.normal; cursor.transform.position = destination.transform.position; cursor.transform.position += hit.normal * 0.0001f; } } }
/// <summary> /// When the Raycast hits the WebWindow window. /// /// <param name="hit">The RaycastHit point</param> /// </summary> void CursorOnWebWindow(RaycastHit hit) { destination.transform.position = hit.point; cursor.transform.up = hit.normal; cursor.transform.position = destination.transform.position; cursor.transform.position += hit.normal * 0.0001f; if (LastWebWindow == null) { LastWebWindow = hit.collider.gameObject.GetComponent <SimpleWebBrowser.WebBrowser>(); LastWebWindow.OnMouseEnter(); } else { if (LastWebWindow.Port != hit.collider.gameObject.GetComponent <SimpleWebBrowser.WebBrowser>().Port) { LastWebWindow.OnMouseExit(); LastWebWindow = hit.collider.gameObject.GetComponent <SimpleWebBrowser.WebBrowser>(); LastWebWindow.OnMouseEnter(); } } }
// Start is called before the first frame update void Awake() { //make image transparent Color c = Color.white; c.a = 0f; PlaceholderImg.color = c; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN SimpleWebBrowser.WebBrowser wb = WindowsBrowserView.GetComponent <SimpleWebBrowser.WebBrowser>(); wb.InitialURL = url; WindowsBrowserView.SetActive(true); EventTrigger.Entry PointerDownEvent = new EventTrigger.Entry(); PointerDownEvent.eventID = EventTriggerType.PointerDown; PointerDownEvent.callback.AddListener((data) => { wb.OnMouseDownOverride(data); }); trigger.triggers.Add(PointerDownEvent); EventTrigger.Entry PointerUpEvent = new EventTrigger.Entry(); PointerUpEvent.eventID = EventTriggerType.PointerUp; PointerUpEvent.callback.AddListener((data) => { wb.OnMouseUpOverride(data); }); trigger.triggers.Add(PointerUpEvent); #elif UNITY_ANDROID BrowserView bv = AndroidBrowserView.GetComponent <BrowserView>(); bv.startUrl = url; AndroidBrowserView.SetActive(true); EventTrigger.Entry PointerClickEvent = new EventTrigger.Entry(); PointerClickEvent.eventID = EventTriggerType.PointerDown; PointerClickEvent.callback.AddListener((data) => { bv.OnClick(data); }); trigger.triggers.Add(PointerClickEvent); #endif }
/// <summary> /// When the Raycast hits the WindowUi (Titlebar). /// /// <param name="hit">The RaycastHit point</param> /// </summary> void CursorOnWindowUi(RaycastHit hit) { destination.transform.position = hit.point; cursor.transform.up = hit.normal; cursor.transform.position = destination.transform.position; cursor.transform.position += hit.normal * 0.01f; if (hit.collider.gameObject.name == "UrlFieldBG" && Input.GetMouseButtonDown(0)) { UnityEngine.Debug.Log("UrlFieldBG Mouse"); LastInputField = hit.collider.gameObject.GetComponentInParent <InputField>(); LastInputField.Select(); LastInputField.ActivateInputField(); } else if (hit.collider.gameObject.name == "BBtn" && Input.GetMouseButtonDown(0)) { SimpleWebBrowser.WebBrowser WebWindow = hit.collider.gameObject.GetComponentInParent <SimpleWebBrowser.WebBrowser>(); WebWindow.GoBackForward(false); UnityEngine.Debug.Log("BBtn"); } else if (hit.collider.gameObject.name == "FBtn" && Input.GetMouseButtonDown(0)) { SimpleWebBrowser.WebBrowser WebWindow = hit.collider.gameObject.GetComponentInParent <SimpleWebBrowser.WebBrowser>(); WebWindow.GoBackForward(true); UnityEngine.Debug.Log("FBtn"); } else if (hit.collider.gameObject.name == "CloseBtn") { if (lastOverBtn != null) { lastOverBtn.GetComponent <Renderer>().material = blueMaterial; } lastOverBtn = hit.collider.gameObject; hit.collider.gameObject.GetComponent <Renderer>().material = grayMaterial; if (Input.GetMouseButtonDown(0)) { DataController.Instance.RemoveWindowData(hit.collider.gameObject.transform.parent.gameObject); Destroy(hit.collider.gameObject.transform.parent.gameObject); } } else if (hit.collider.gameObject.name == "RotationBtn") { if (lastOverBtn != null) { lastOverBtn.GetComponent <Renderer>().material = blueMaterial; } lastOverBtn = hit.collider.gameObject; hit.collider.gameObject.GetComponent <Renderer>().material = grayMaterial; if (Input.GetMouseButtonDown(0)) { isMouseDragRotation = true; dragTarget = hit.collider.gameObject.transform.parent.gameObject; } } else if (hit.collider.gameObject.name == "Size+Btn") { if (lastOverBtn != null) { lastOverBtn.GetComponent <Renderer>().material = blueMaterial; } lastOverBtn = hit.collider.gameObject; hit.collider.gameObject.GetComponent <Renderer>().material = grayMaterial; if (Input.GetMouseButtonDown(0)) { if (hit.collider.gameObject.transform.parent.tag == "Desktop" || hit.collider.gameObject.transform.parent.tag == "Phone") { hit.collider.gameObject.transform.parent.localScale += new Vector3(transform.localScale.x * 0.05f, transform.localScale.y * 0.05f, 0) * Time.deltaTime * 10; } else { hit.collider.gameObject.transform.parent.localScale += new Vector3(transform.localScale.x * 0.05f, 0, transform.localScale.z * 0.05f) * Time.deltaTime * 10; } DataController.Instance.UpdateWindowData(hit.collider.gameObject.transform.parent.gameObject); } } else if (hit.collider.gameObject.name == "Size-Btn") { if (lastOverBtn != null) { lastOverBtn.GetComponent <Renderer>().material = blueMaterial; } lastOverBtn = hit.collider.gameObject; hit.collider.gameObject.GetComponent <Renderer>().material = grayMaterial; if (Input.GetMouseButtonDown(0)) { if (hit.collider.gameObject.transform.parent.tag == "Desktop" || hit.collider.gameObject.transform.parent.tag == "Phone") { hit.collider.gameObject.transform.parent.localScale -= new Vector3(transform.localScale.x * 0.05f, transform.localScale.y * 0.05f, 0) * Time.deltaTime * 10; } else { hit.collider.gameObject.transform.parent.localScale -= new Vector3(transform.localScale.x * 0.05f, 0, transform.localScale.z * 0.05f) * Time.deltaTime * 10; } DataController.Instance.UpdateWindowData(hit.collider.gameObject.transform.parent.gameObject); } } else if (hit.collider.gameObject.name == "Background" && Input.GetMouseButtonDown(0)) { dragTarget = hit.collider.gameObject.transform.parent.gameObject; isMouseDrag = true; if (lastOverBtn != null) { lastOverBtn.GetComponent <Renderer>().material = blueMaterial; } } }