/// <summary> /// Starts building process. /// Building is supposed to be placed. /// </summary> public void StartBuilding(DAT_Building buildingData) { // prepare position (middle of a screen) and instantiate Vector3 pos = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.nearClipPlane)); pos.y = M_MapManager.SGetHighYDepthValue(pos.z); // set appropriate depth value. (Building has to be above every other obj) // Instantiate new building in the TEMP group. m_tempBuildingObj = buildingData.InstantiateBuilding(pos, M_GameHelper.Group.TEMP); m_tempBuildingComp = m_tempBuildingObj.GetComponent <IBuilding>(); // Get build button and activate it. m_tempBuildingComp.GetBuildButton().GetComponent <Button>().onClick.AddListener(OnBuildingBuildIconClick); m_tempBuildingComp.GetBuildButton().SetActive(true); M_MiscManager.RemoveListenersCancelButton(); M_MiscManager.AddListenerCancelButton(QuitBuilding); M_MiscManager.ShowCancelButton(true); }
public void Update() { switch (SystemInfo.deviceType) { case DeviceType.Desktop: m_currentTrackedModel = M_GameHelper.SGetObjectAtScreenPoint(Input.mousePosition); break; case DeviceType.Handheld: if (Input.touchCount > 0) { m_currentTrackedModel = M_GameHelper.SGetObjectAtScreenPoint(Input.GetTouch(0).position); } break; } if (m_processing) { m_freezeTimeElapsed += Time.deltaTime; } if (m_freezeTimeElapsed > CLICK_TIME) { switch (SystemInfo.deviceType) { case DeviceType.Desktop: if (m_leftButtonDown) { m_leftButtDownTimeElapsed += Time.deltaTime; } if (Input.GetMouseButtonDown(0)) // On Start { m_leftButtDownTimeElapsed = 0f; m_leftButtonDown = true; m_draggingCandidate = m_currentTrackedModel; // Examine if object should be clicked. if not then skip to dragging examination. if (m_currentTrackedModel != null) { ClickableObject clickable = m_currentTrackedModel.GetComponent <ClickableObject>(); DraggableObject draggable = m_currentTrackedModel.GetComponent <DraggableObject>(); if (clickable != null && clickable.disabled && draggable != null && draggable.draggingEnabled) { m_leftButtDownTimeElapsed = CLICK_TIME * 2; CameraController.SSetOverallMovement(false); m_currentDraggedObject = m_currentTrackedModel.gameObject.transform.parent.gameObject; } } // } else if (Input.GetMouseButtonUp(0) && m_leftButtDownTimeElapsed < CLICK_TIME) // OnClick { if (m_currentTrackedModel != null) { ClickableObject comp = m_currentTrackedModel.transform.parent.gameObject.GetComponent <ClickableObject>(); if (comp != null) { comp.OnClick(); } } m_leftButtonDown = false; m_leftButtDownTimeElapsed = 0f; m_currentTrackedModel = null; m_draggingCandidate = null; } else if (Input.GetMouseButtonUp(0) && m_leftButtDownTimeElapsed > CLICK_TIME) // End of dragging { m_leftButtonDown = false; m_leftButtDownTimeElapsed = 0f; m_currentDraggedObject = null; } // Examine for dragging if (m_currentDraggedObject == null && m_leftButtDownTimeElapsed > CLICK_TIME) { // get a parent object if (m_draggingCandidate != null) { m_currentDraggedObject = m_draggingCandidate.transform.parent.gameObject; m_currentDraggedObjectComp = m_currentDraggedObject.GetComponent <DraggableObject>(); if (!(m_currentDraggedObjectComp != null && m_currentDraggedObjectComp.draggingEnabled)) { m_currentDraggedObject = null; } m_draggingCandidate = null; } } else if (m_currentDraggedObject != null) // Dragging { Vector3 temp = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (m_currentDraggedObjectComp.keepHighYDepthValue) { temp.y = M_MapManager.SGetHighYDepthValue(temp.z); } else { temp.y = M_MapManager.SGetYDepthValue(temp.z); } m_currentDraggedObject.transform.position = temp; } break; // ------- Handheld -------- case DeviceType.Handheld: StringBuilder stringBuilder = new StringBuilder(); if (m_leftButtonDown) { m_leftButtDownTimeElapsed += Time.deltaTime; } // Examine for dragging if (m_currentDraggedObject == null && m_leftButtDownTimeElapsed > CLICK_TIME) { // get a parent object if (m_draggingCandidate != null) { m_currentDraggedObject = m_draggingCandidate.transform.parent.gameObject; m_currentDraggedObjectComp = m_currentDraggedObject.GetComponent <DraggableObject>(); if (!(m_currentDraggedObjectComp != null && m_currentDraggedObjectComp.draggingEnabled)) { m_currentDraggedObject = null; } else { CameraController.SSetOverallMovement(false); } m_draggingCandidate = null; } } if (m_processing) { m_freezeTimeElapsed += Time.deltaTime; } if (m_freezeTimeElapsed > CLICK_TIME) { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); switch (touch.phase) { case TouchPhase.Began: stringBuilder.AppendLine("Began: " + touch.position); m_leftButtDownTimeElapsed = 0f; m_leftButtonDown = true; m_draggingCandidate = m_currentTrackedModel; // Examine if object should be clicked. if not then skip to dragging examination. if (m_currentTrackedModel != null) { ClickableObject clickable = m_currentTrackedModel.GetComponent <ClickableObject>(); DraggableObject draggable = m_currentTrackedModel.GetComponent <DraggableObject>(); if (clickable != null && clickable.disabled && draggable != null && draggable.draggingEnabled) { m_leftButtDownTimeElapsed = CLICK_TIME * 2; CameraController.SSetOverallMovement(false); m_currentDraggedObject = m_currentTrackedModel.gameObject.transform.parent.gameObject; } } // break; case TouchPhase.Moved: stringBuilder.AppendLine("Moved: " + touch.position); if (m_currentDraggedObject != null) // Dragging { Vector3 temp = Camera.main.ScreenToWorldPoint(touch.position); if (m_currentDraggedObjectComp.keepHighYDepthValue) { temp.y = M_MapManager.SGetHighYDepthValue(temp.z); } else { temp.y = M_MapManager.SGetYDepthValue(temp.z); } m_currentDraggedObject.transform.position = temp; } break; case TouchPhase.Ended: stringBuilder.AppendLine("Ended: " + touch.position); if (m_leftButtDownTimeElapsed < CLICK_TIME) // OnClick { if (m_currentTrackedModel != null) { ClickableObject comp = m_currentTrackedModel.transform.parent.gameObject.GetComponent <ClickableObject>(); if (comp != null) { comp.OnClick(); } } m_leftButtonDown = false; m_leftButtDownTimeElapsed = 0f; m_currentTrackedModel = null; m_draggingCandidate = null; } else // End of dragging { m_leftButtonDown = false; m_leftButtDownTimeElapsed = 0f; m_currentDraggedObject = null; CameraController.SSetOverallMovement(true); } break; } } else { stringBuilder.AppendLine("No touch"); } } stringBuilder.AppendLine("CurrentDraggedObject: " + (m_currentDraggedObject == null ? "NULL" : m_currentDraggedObject.name)); stringBuilder.AppendLine("CurrentTrackedModel: " + (m_currentTrackedModel == null ? "NULL" : m_currentTrackedModel.name)); stringBuilder.AppendLine("DraggingCandidate " + (m_draggingCandidate == null ? "NULL" : m_draggingCandidate.name)); M_GameHelper.debugText = stringBuilder.ToString(); break; } } }