// Start is called before the first frame update void Start() { focusSquare = this.GetComponent <FocusSquare>(); if (IsBuildMode) { Icon_BuildBtn.sprite = Icon_Builder; } else { Icon_BuildBtn.sprite = Icon_Destoryer; } }
void Start() { //Set up references mapSession = GameObject.Find("MapSession").GetComponent <MapSession> (); focusSquare = GameObject.Find("FocusSquare").GetComponent <FocusSquare> (); //Mapsession initialization bool isMappingMode = PlayerPrefs.GetInt("IsMappingMode") == 1; string mapID = PlayerPrefs.GetString("MapID"); string userID = PlayerPrefs.GetString("UserID"); string developerKey = @"PUT DEV KEY HERE"; mapSession.Init(isMappingMode ? MapMode.MapModeMapping : MapMode.MapModeLocalization, userID, mapID, developerKey); //Set callback to handly MapStatus updates mapSession.StatusChangedEvent += mapStatus => { Debug.Log("status updated: " + mapStatus); }; //Set callback that confirms when assets are stored mapSession.AssetStoredEvent += stored => { Debug.Log("Assets stored: " + stored); Toast("Your bear's garden has been planted!", 2.0f); }; //Set Callback for when assets are reloaded mapSession.AssetLoadedEvent += mapAsset => { Vector3 position = new Vector3(mapAsset.X, mapAsset.Y, mapAsset.Z); Quaternion orientation = Quaternion.Euler(0, mapAsset.Orientation, 0); Debug.Log(mapAsset.AssetId + " found at: " + position.ToString()); Instantiate(GetPrefab(mapAsset.AssetId), position, orientation); Toast("Your bear's garden has been found!", 2.0f); }; //Set up the UI of the scene saveAssetButton.SetActive(false); placeAssetButtons.SetActive(false); if (mapSession.Mode == MapMode.MapModeLocalization) { placeAssetButtons.SetActive(false); } Toast("First scan around your area to start!", 10.0f); }
private void InitJido() { //Set up references mapSession = GameObject.Find("MapSession").GetComponent <MapSession>(); focusSquare = GameObject.Find("FocusSquare").GetComponent <FocusSquare>(); //Mapsession initialization bool isMappingMode = PlayerPrefs.GetInt("IsMappingMode") == 1; string mapID = PlayerPrefs.GetString("MapID"); string userID = PlayerPrefs.GetString("UserID"); mapSession.Init(isMappingMode ? MapMode.MapModeMapping : MapMode.MapModeLocalization, userID, mapID); //Set callback to handly MapStatus updates mapSession.StatusChangedEvent += mapStatus => { Debug.Log("status updated: " + mapStatus); }; //Set callback that confirms when assets are stored mapSession.AssetStoredEvent += stored => { Debug.Log("Assets stored: " + stored); }; //Set Callback for when assets are reloaded mapSession.AssetLoadedEvent += LoadAsset; mapSession.ObjectDetectedEvent += detectedObject => { Debug.Log("Detected " + detectedObject.Name); }; mapSession.ProgressIncrementedEvent += ProgressIncrement; //Set up the UI of the scene addButton.SetActive(false); if (mapSession.Mode == MapMode.MapModeLocalization) { addButton.SetActive(false); } Toast("Look around to start!", 5.0f); }
// Update is called once per frame void Update() { if (detecting) { IEnumerable <ARPlaneAnchorGameObject> planes = unityARAnchorManager.GetCurrentPlaneAnchors(); foreach (var plane in planes) { if (plane.planeAnchor.extent.x > 0.1f && plane.planeAnchor.extent.z > 0.1f) { var cell = gameObject[index]; cell.SetActive(true); cell.transform.position = UnityARMatrixOps.GetPosition(plane.planeAnchor.transform); cell.transform.rotation = UnityARMatrixOps.GetRotation(plane.planeAnchor.transform); detecting = false; GeneratePlane.GetComponent <FocusSquare>().enabled = false; FocusSquare.SetActive(false); break; } } } else { Debug.Log(gameObject[index].transform.position.ToString()); if (Input.touchCount == 1) { var touchPoint = Input.GetTouch(0); if (touchPoint.phase == TouchPhase.Began) { oldPoint = touchPoint.position; oldPosition = gameObject[index].transform.position; } else if (touchPoint.phase == TouchPhase.Moved) { gameObject[index].transform.position = oldPosition + (touchPoint.position.y - oldPoint.y) * new Vector3(0, 0.001f, 0); } } } }
void Update() { if (Input.GetMouseButtonDown(0) && CheckPanel.CheckPanel()) { Ray mRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit mHit; //射线检验 LayerMask mask = 1 << LayerMask.NameToLayer("Sphere");//只在Sphere层检测 if (Physics.Raycast(mRay, out mHit, 20f, mask.value) || CheckUIClick.OnClickUI()) { ; } else { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { Vector3 screenPos = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPos.x, y = screenPos.y }; List <ARHitTestResult> hitTestResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlane); if (flag == false && hitTestResults.Count > 0) { UnityARCameraManager.CloseDetection(); flag = true; GeneratePlane.GetComponent <FocusSquare>().enabled = false; FocusSquare.SetActive(false); HintController.ShowElement(3); } else if (flag && hitTestResults.Count > 0) { HintController.ShowElement(4); hintFinished = true; } /* == 第一次点击的时候关闭平面检测 */ if (currentObj[0].activeSelf == false) { //currentObj[0].transform.position = UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform) + Vector3.up * currentObj[0].transform.localScale.y*0.1f; //currentObj[0].transform.position = UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform); //currentObj[0].transform.rotation = UnityARMatrixOps.GetRotation(hitTestResults[hitTestResults.Count - 1].worldTransform); var player = ClientScene.localPlayers[0].gameObject.GetComponent <Player>(); player.CheckAuthority(GetComponent <NetworkIdentity>(), player.GetComponent <NetworkIdentity>()); CmdChangeTransform(0, UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform), UnityARMatrixOps.GetRotation(hitTestResults[hitTestResults.Count - 1].worldTransform)); //currentObj[0].GetComponent<Touch>().ActiveBall(); //if (currentObj[1].activeSelf == true) currentObj[0].transform.position = new Vector3(currentObj[0].transform.position.x, currentObj[1].transform.position.y, currentObj[0].transform.position.z); } else if (currentObj[1].activeSelf == false) { //currentObj[1].transform.position = UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform) + Vector3.up * currentObj[1].transform.localScale.y*0.1f; //currentObj[1].transform.position = UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform); //currentObj[1].transform.rotation = UnityARMatrixOps.GetRotation(hitTestResults[hitTestResults.Count - 1].worldTransform); var player = ClientScene.localPlayers[0].gameObject.GetComponent <Player>(); player.CheckAuthority(GetComponent <NetworkIdentity>(), player.GetComponent <NetworkIdentity>()); CmdChangeTransform(1, UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform), UnityARMatrixOps.GetRotation(hitTestResults[hitTestResults.Count - 1].worldTransform)); //currentObj[1].GetComponent<Touch>().ActiveBall(); //if (currentObj[0].activeSelf == true) currentObj[1].transform.position = new Vector3(currentObj[1].transform.position.x, currentObj[0].transform.position.y, currentObj[1].transform.position.z); } else { if (NoneUIClickEvent != null) { NoneUIClickEvent(); } } } } } if (hintFinished) { time += Time.deltaTime; if (time > thresholdTime) { HintController.HideElement(); hintFinished = false;// not really unfinished } } }
// Update is called once per frame void Update() { //CheckButton(); //Debug.Log("模型ActiveFalse"); if (Model.activeSelf == false) { if (Input.GetMouseButtonDown(0)) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { //Debug.Log("执行HitTest"); Vector3 screenPos = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPos.x, y = screenPos.y }; List <ARHitTestResult> hitTestResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlane); if (flag == false && hitTestResults.Count > 0) { UnityARCameraManager.CloseDetection(); flag = true; GeneratePlane.GetComponent <FocusSquare>().enabled = false; FocusSquare.SetActive(false); HintController.ShowElement(3); } /* == 第一次点击的时候关闭平面检测 */ //Debug.Log("放置模型"); /* UNET */ var player = ClientScene.localPlayers[0].gameObject.GetComponent <Player>(); player.CheckAuthority(GetComponent <NetworkIdentity>(), player.GetComponent <NetworkIdentity>()); CmdChangeTransform(UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform), UnityARMatrixOps.GetRotation(hitTestResults[hitTestResults.Count - 1].worldTransform)); CmdSetModelActive(); CmdSetConfirmButtonActive(); /* == UNET */ //Button.SetActive(true); } } } else if (adjustable) { if (Input.touchCount == 2) { var touch1 = Input.GetTouch(0); var touch2 = Input.GetTouch(1); if (touch1.phase == TouchPhase.Moved && touch2.phase == TouchPhase.Moved) { Vector3 screenPos = Camera.main.ScreenToViewportPoint((touch1.position + touch2.position) / 2); ARPoint point = new ARPoint { x = screenPos.x, y = screenPos.y }; List <ARHitTestResult> hitTestResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, ARHitTestResultType.ARHitTestResultTypeExistingPlane); //Model.transform.position = UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform); /* UNET */ var player = ClientScene.localPlayers[0].gameObject.GetComponent <Player>(); player.CheckAuthority(GetComponent <NetworkIdentity>(), player.GetComponent <NetworkIdentity>()); CmdChangeTransform(UnityARMatrixOps.GetPosition(hitTestResults[hitTestResults.Count - 1].worldTransform), Model.transform.rotation); /* == UNET */ } //保证重新开始双指触摸记录的初始位置不是松开手时的位置,而是初始触摸的位置 if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(1).phase == TouchPhase.Began) { //记录初始位置 oldPosition1 = Input.GetTouch(0).position; oldPosition2 = Input.GetTouch(1).position; } if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved) { //计算出当前两点触摸点的位置 var tempPosition1 = Input.GetTouch(0).position; var tempPosition2 = Input.GetTouch(1).position; float currentTouchDistance = Vector2.Distance(tempPosition1, tempPosition2); float lastTouchDistance = Vector2.Distance(oldPosition1, oldPosition2); //计算上次和这次双指触摸之间的距离差距 //然后去更改摄像机的距离 float distance = currentTouchDistance - lastTouchDistance; float scaleFactor = distance / 200f; Vector3 localScale = Model.transform.localScale; Vector3 scale = new Vector3(localScale.x + scaleFactor, localScale.y + scaleFactor, localScale.z + scaleFactor); //在什么情况下进行缩放 if (scale.x >= 0.2f && scale.y >= 0.2f && scale.z >= 0.2f) { //Model.transform.localScale = scale; var player = ClientScene.localPlayers[0].gameObject.GetComponent <Player>(); player.CheckAuthority(GetComponent <NetworkIdentity>(), player.GetComponent <NetworkIdentity>()); CmdChangeScale(scale); } //备份上一次触摸点的位置,用于对比 //也是松开手时的位置 oldPosition1 = tempPosition1; oldPosition2 = tempPosition2; } //if (Vector2.Dot(touch1.deltaPosition,touch2.deltaPosition)<=0 && touch1.position.y < touch2.position.y) //{ // Model.transform.Rotate(Vector3.down * touch1.deltaPosition.x * 0.75f, Space.World); //} //else if (Vector2.Dot(touch1.deltaPosition, touch2.deltaPosition) <= 0 && touch1.position.y > touch2.position.y) //{ // Model.transform.Rotate(Vector3.down * touch2.deltaPosition.x * 0.75f, Space.World); //} } else if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved) { Vector2 deltaPos = Input.GetTouch(0).deltaPosition; //Model.transform.Rotate(Vector3.down * deltaPos.x * 0.5f, Space.World); var player = ClientScene.localPlayers[0].gameObject.GetComponent <Player>(); player.CheckAuthority(GetComponent <NetworkIdentity>(), player.GetComponent <NetworkIdentity>()); CmdRotate(deltaPos); } } if (hintFinished) { time += Time.deltaTime; if (time > thresholdTime) { HintController.HideElement(); hintFinished = false;// not really unfinished } } }
void Start() { character.gameObject.SetActive(false); focusSquare = GetComponent <FocusSquare> (); }