Esempio n. 1
0
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.tag == PLAYER_TAG)
     {
         CommandKeeper.SetPlayerOnALadder(false);
     }
 }
        void LateUpdate()
        {
            RaycastHit hit = CommandKeeper.GetCameraRaycastHit();


            if (hit.collider != null)
            {
                BuildingBlockPassport pass = hit.collider.GetComponentInParent <BuildingBlockPassport>();

                if (pass != null)
                {
                    /////

                    Vector3 hitObjPosition = pass.transform.position;

                    Vector3Int hitObjPositionInt = new Vector3Int(
                        (int)Mathf.Floor(hitObjPosition.x),
                        (int)Mathf.Round(hitObjPosition.y),
                        (int)Mathf.Floor(hitObjPosition.z)
                        );

                    transform.position = hitObjPositionInt;
                    //Debug.Log("hit pos=" + transform.position);
                }
            }
        } // LateUpdate() ///
Esempio n. 3
0
        void Update()
        {
            float horizontalMouseAxis = Input.GetAxis("Mouse X");
            float verticalMouseAxis   = Input.GetAxis("Mouse Y");

            CommandKeeper.OnPlayerRotateCommand(horizontalMouseAxis, verticalMouseAxis);

            float horizontalAxis = Input.GetAxis("Horizontal");
            float verticalAxis   = Input.GetAxis("Vertical");

            CommandKeeper.OnPlayerMoveCommand(horizontalAxis, verticalAxis);

            if (Input.GetMouseButtonUp(0))
            {
                CommandKeeper.OnBuildCommand();
            }
            else if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.SMALL_PLATFORM);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.SMALL_PILLAR);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.WALL);
            }
            else if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.LADDER);
            }
            //else if (Input.GetKeyDown(KeyCode.Alpha5))
            //{
            //    CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.CORNER_WALL);
            //}
            //else if (Input.GetKeyDown(KeyCode.Alpha8))
            //{
            //    CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.PLATFORM);
            //}
            //else if (Input.GetKeyDown(KeyCode.Alpha9))
            //{
            //    CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.PILLAR);
            //}
            else if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                CommandKeeper.OnBuildingBlockChoose(Model.MapObjectType.AIR);
            }
            else if (Input.GetKeyUp(KeyCode.Escape))
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#else
                Application.Quit();
#endif
            }
        }
Esempio n. 4
0
        ///////////////////////////////////////////////////////////////////////////////

        void LateUpdate()
        {
            if (isCursorOn)
            {
                RaycastHit hit = CommandKeeper.GetCameraRaycastHit();

                if (hit.collider != null)
                {
                    BuildingBlockPassport pass = hit.collider.GetComponentInParent <BuildingBlockPassport>();
                    if (pass != null)
                    {
                        /////

                        Vector3 hitObjPosition = pass.transform.position;

                        Vector3Int hitObjPositionInt = new Vector3Int(
                            (int)Mathf.Floor(hitObjPosition.x),
                            (int)Mathf.Round(hitObjPosition.y),
                            (int)Mathf.Floor(hitObjPosition.z)
                            );


                        ////////

                        lastCursorRotationAngle = CalculateCursorRotation(CommandKeeper.GetPlayerRotationAngle());

                        canBuildOnLastCursorPosition = CanIBuildAndWhere(hitObjPositionInt, hit.point, out lastCursorPosition);

                        positiveCursor.position = lastCursorPosition;
                        negativeCursor.position = lastCursorPosition;

                        if (positiveRotator != null)
                        {
                            positiveRotator.SetHorizontalRotation(lastCursorRotationAngle);
                        }
                        if (negativeRotator != null)
                        {
                            negativeRotator.SetHorizontalRotation(lastCursorRotationAngle);
                        }

                        positiveCursor.gameObject.SetActive(canBuildOnLastCursorPosition);
                        negativeCursor.gameObject.SetActive(!canBuildOnLastCursorPosition);
                    } // if (pass != null) ///
                }
                else  // raycasted collider == null ///
                {
                    positiveCursor.gameObject.SetActive(false);
                    negativeCursor.gameObject.SetActive(false);
                }
            } // if isCurosrOn ///
        }     // LateUpdate() ////
Esempio n. 5
0
    }     // PlanesCreationCoroutine() //

    private void CreatePlane(string id)
    {
        BoundedPlane plane = planesCreationBuffer[id];

        GameObject go;

        go = Instantiate(m_PlanePrefab, planesRoot);

        // Make sure we can pick them later
        foreach (var collider in go.GetComponentsInChildren <Collider>())
        {
            collider.gameObject.layer = m_PlaneLayer;
        }

        m_Planes.Add(plane.id, go);
        go.SetActive(planesAreEnabled);

        CommandKeeper.WriteLineDebug("Plane added: " + plane.id);

        SetPlanePosition(go, plane);
    }
Esempio n. 6
0
    } // PlaneUpdatedHandler() //

    protected virtual void PlaneRemovedHandler(BoundedPlane plane)
    {
        lock (lockObject)
        {
            BoundedPlane bufferedPlane;

            if (planesCreationBuffer.TryGetValue(plane.id, out bufferedPlane))
            {
                planesRequestTime.Remove(plane.id);
                planesCreationBuffer.Remove(plane.id);
            }
            else
            {
                GameObject go;
                if (m_Planes.TryGetValue(plane.id, out go))
                {
                    Destroy(go);
                    m_Planes.Remove(plane.id);

                    CommandKeeper.WriteLineDebug("Plane deleted: " + plane.id);
                }
            }
        }
    } // PlaneRemovedHandler() //
Esempio n. 7
0
        void LateUpdate()
        {
            RaycastHit hit = CommandKeeper.GetCameraRaycastHit();

            transform.position = hit.point;
        }
Esempio n. 8
0
    void Update()
    {
        if (Input.touchCount > 0)
        {
            var touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began /*|| touch.phase == TouchPhase.Moved*/)
            {
                Vector2 touchPosition = touch.position;

                if (UITouched(touchPosition))
                {
                    //CommandKeeper.WriteLineDebug("UI Touched");
                }
                else
                {
                    // if touched not UI //

                    if (CommandKeeper.GetPointCloudOn())
                    {
                        // Searching nearest pointcloud point and set position near it //
                        Vector3 worldTouchPosition = mainCamera.ScreenToWorldPoint(touchPosition);



                        List <Vector3> points = CommandKeeper.GetPointCloudCoordsList();

                        if (points != null)
                        {
                            Vector3 screenTouchPosition = new Vector3(touchPosition.x, touchPosition.y, 0);//mainCamera.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, 0));

                            Vector3 nearestPoint             = points[0];
                            float   minimalScreenSqrDistance = (screenTouchPosition - mainCamera.WorldToScreenPoint(nearestPoint)).sqrMagnitude;

                            for (int i = 1; i < points.Count; i++)
                            {
                                float sqrDistance = (screenTouchPosition - mainCamera.WorldToScreenPoint(points[i])).sqrMagnitude;

                                if (sqrDistance < minimalScreenSqrDistance)
                                {
                                    minimalScreenSqrDistance = sqrDistance;
                                    nearestPoint             = points[i];
                                }
                            }

                            // Now we know nearest point in projection on screen //

                            Vector3 nearestPointVector = nearestPoint - worldTouchPosition;
                            //float nearestPointWorldDistance = Vector3.Distance(worldTouchPosition, nearestPoint);

                            Vector3 forward = mainCamera.transform.forward.normalized;

                            Vector3 targetPosition = mainCamera.ScreenPointToRay(screenTouchPosition).GetPoint(Vector3.Dot(forward, nearestPointVector));
                            //Vector3 targetPosition = worldTouchPosition + forward * (Vector3.Dot(forward, nearestPointVector));

                            CommandKeeper.UserPointedTo(targetPosition);
                        } // if points != null //
                    }
                    else if (CommandKeeper.GetPlanesOn())
                    {
                        // Raycasting for planes //

                        Vector3 viewPortPoint = mainCamera.ScreenToViewportPoint(touchPosition);

                        //CommandKeeper.WriteLineDebug("touchpos=" + position + "viewPPoint=" + viewPortPoint);

                        Ray ray = mainCamera.ViewportPointToRay(viewPortPoint);

                        RaycastHit hit;


                        //Transform cameraTransform = Camera.main.transform;
                        //Vector3 pos = cameraTransform.position;
                        //Vector3 fwd = cameraTransform.forward;
                        //if (Physics.Raycast(pos, fwd, out hit))
                        //{
                        //    CommandKeeper.WriteLineDebug("centerhit=" + hit.collider.name + " at " + hit.point);
                        //    cursor.transform.position = hit.point;
                        //}


                        if (Physics.Raycast(ray, out hit, maxDistance, raycastLayerMask))
                        {
                            Vector3 worldPosition = hit.point;
                            //CommandKeeper.WriteLineDebug("HitCollider=" + hit.collider.name);
                            //CommandKeeper.WriteLineDebug("worldPos=" + worldPosition);

                            CommandKeeper.UserPointedTo(worldPosition);

                            //cursor.transform.position = worldPosition;
                        }
                    } // if raycasting planes //
                }     // if touched not UI //
            }         // if touch.phase //
        }             // if touchCount //
    }     // Update() //
Esempio n. 9
0
    public void OnPlanesVisibilityChanged(bool on)
    {
        CommandKeeper.WriteLineDebug("Planes on = " + on);

        CommandKeeper.SetPlanesOn(on);
    }
Esempio n. 10
0
    public void OnPointsVisibilityChanged(bool on)
    {
        CommandKeeper.WriteLineDebug("Points on = " + on);

        CommandKeeper.SetPointCloudOn(on);
    }