예제 #1
0
        public void On(FocusTarget newTarget)
        {
            if (Current != null)
            {
                Current.OnFocusLost();
                if (m_focusLossHandlers != null)
                {
                    m_focusLossHandlers(Current);
                }
            }

            Current = newTarget;
            if (newTarget != null)
            {
                Current.OnFocusGained();
                if (m_focusGainHandlers != null)
                {
                    m_focusGainHandlers(Current);
                }
            }
        }
예제 #2
0
 void OnFocusLost(FocusTarget target)
 {
     m_focusTarget = null;
 }
예제 #3
0
        void Update()
        {
            float horizontal  = CrossPlatformInputManager.GetAxis("Mouse X");
            float vertical    = CrossPlatformInputManager.GetAxis("Mouse Y");
            float scrollWheel = CrossPlatformInputManager.GetAxis("Mouse ScrollWheel");

            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;

                if (Physics.Raycast(ray, out hitInfo))
                {
                    if (hitInfo.collider != null)
                    {
                        FocusTarget focusTarget = hitInfo.collider.GetComponent <FocusTarget>();
                        WorldController.Instance.MainState.Focus.On(focusTarget);
                    }
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                //Create a ray from the Mouse click position
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                //Initialise the enter variable
                float enter = 0.0f;

                if (m_groundPlane.Raycast(ray, out enter))
                {
                    Vector3      hitPoint     = ray.GetPoint(enter);
                    TilePosition tilePosition = TilePosition.FromWorldPosition(hitPoint);
                    Tile         targetTile   = WorldController.Instance.MainState.TileMap.TileAt(tilePosition);
                    if (targetTile != null)
                    {
                        if (!targetTile.HasObject)
                        {
                            Worker selectedWorker = WorldController.Instance.MainState.Focus.Current as Worker;
                            if (selectedWorker != null)
                            {
                                selectedWorker.MoveTo(tilePosition);
                            }
                        }

                        /*if(!targetTile.HasObject)
                         * {
                         *  targetTile.Install(new WallTileObject());
                         * }
                         * else
                         * {
                         *  targetTile.UninstallObject();
                         * }*/
                    }
                }
            }

            if (Input.GetMouseButton(2))
            {
                Vector3 forward = transform.forward;
                forward.y = 0;
                forward.Normalize();
                Vector3 right = transform.right;
                right.y = 0;
                right.Normalize();

                Vector3 position = transform.position;
                position          += -right * horizontal * m_moveSpeedFactor;
                position          += -forward * vertical * m_moveSpeedFactor;
                transform.position = position;

                m_focusTarget = null;
            }

            if (CrossPlatformInputManager.GetButtonDown("Turn Camera Left"))
            {
                RotateBy(m_cameraTurnIncrement);
            }

            if (CrossPlatformInputManager.GetButtonDown("Turn Camera Right"))
            {
                RotateBy(-m_cameraTurnIncrement);
            }

            if (scrollWheel != 0 || m_lastDistance != m_distance)
            {
                m_distance = Mathf.Clamp(m_distance - scrollWheel * m_scrollSpeed * (1 + m_distance * m_scrollAccellerationFactor), m_minDistance, m_maxDistance);
                UpdateCameraPosition();
                m_lastDistance = m_distance;
            }

            if (m_yRotationProgress < 1.0F)
            {
                m_yRotationProgress += Time.deltaTime * m_rotationSpeedFactor;
                if (m_yRotationProgress > 1.0F)
                {
                    m_yRotationProgress = 1.0F;
                }
            }

            transform.rotation = Quaternion.Euler(0, CalculateCurrentYOrientation(), 0);

            if (m_focusTarget != null)
            {
                Vector3 difference = m_focusTarget.transform.position - transform.position;
                float   t          = Mathf.Min(Mathf.Pow(m_focusFollowSpeed, Time.deltaTime * 100), 1);
                transform.position += difference * (t);
            }
        }
예제 #4
0
 void OnFocusGained(FocusTarget target)
 {
     m_focusTarget = target;
 }