public override void CheckOverlap()
        {
            if (!m_arrCondition.PassAllCondition(eventConditionData))
            {
                return;
            }



            Vector2 vPos = m_hOverlapPosition != null ? m_hOverlapPosition.position : transform.position;
            float   fAngle;

            if (m_bUseLocalAngle)
            {
                fAngle = m_hOverlapPosition != null ? m_hOverlapPosition.localEulerAngles.z : transform.localEulerAngles.z;
            }
            else
            {
                fAngle = m_hOverlapPosition != null ? m_hOverlapPosition.eulerAngles.z : transform.eulerAngles.z;
            }


            int nHit = Physics2D.OverlapBoxNonAlloc(vPos, m_vSize, fAngle, hitColArray, m_eCheckLayer);

            if (nHit <= 0)
            {
                m_hNotHitEvent?.Invoke();
                return;
            }

            bool bHit       = false;
            int  nSendCount = 0;

            for (int i = 0; i < nHit; i++)
            {
                var hHitGO = m_arrHitCol[i].gameObject;
                if (CheckNotIgnoreTarget(hHitGO))
                {
                    if (!bHit)
                    {
                        m_hHitEvent?.Invoke();
                    }

                    bHit = true;

                    m_hHitEventGameObject?.Invoke(hHitGO);
                    nSendCount++;

                    if (nSendCount >= m_nMaxSendData)
                    {
                        break;
                    }
                }
            }

            if (!bHit)
            {
                m_hNotHitEvent?.Invoke();
            }
        }
    void Update()
    {
        if (_useDefaultCursor)
        {
            Cursor.SetCursor(pointer, new Vector2(16, 16), CursorMode.Auto);
            return;
        }

        // Raycast into scene
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 50, clickableLayer.value))
        {
            //override cursor
            Cursor.SetCursor(target, new Vector2(16, 16), CursorMode.Auto);

            bool door = false;
            if (hit.collider.gameObject.tag == "Doorway")
            {
                Cursor.SetCursor(doorway, new Vector2(16, 16), CursorMode.Auto);
                door = true;
            }

            bool chest = false;
            if (hit.collider.gameObject.tag == "Chest")
            {
                Cursor.SetCursor(pointer, new Vector2(16, 16), CursorMode.Auto);
                door = true;
            }

            bool isAttackable = hit.collider.GetComponent(typeof(IAttackable)) != null;
            if (isAttackable)
            {
                Cursor.SetCursor(sword, new Vector2(16, 16), CursorMode.Auto);
            }

            // if environment surface is clicked, invoke callbacks.
            if (Input.GetMouseButtonDown(0))
            {
                if (door)
                {
                    Transform doorway = hit.collider.gameObject.transform;
                    OnClickEnvironment.Invoke(doorway.position + doorway.forward * 10);
                }
                else if (isAttackable)
                {
                    GameObject attackable = hit.collider.gameObject;
                    OnClickAttackable.Invoke(attackable);
                }
                else if (!chest)
                {
                    OnClickEnvironment.Invoke(hit.point);
                }
            }
        }
        else
        {
            Cursor.SetCursor(pointer, Vector2.zero, CursorMode.Auto);
        }
    }
示例#3
0
 public void OnEventRaised(GameObject value)
 {
     LastFired = Time.time;
     SetTriggered();
     OnEvent(value);
     Response.Invoke(value);
 }
        public override void CheckOverlap()
        {
            if (!m_arrCondition.PassAllCondition(eventConditionData))
            {
                return;
            }



            Vector3    vPos = m_hOverlapPosition != null ? m_hOverlapPosition.position : transform.position;
            Quaternion qRot;

            if (m_bUseLocalRotation)
            {
                qRot = m_hOverlapPosition != null ? m_hOverlapPosition.localRotation : transform.localRotation;
            }
            else
            {
                qRot = m_hOverlapPosition != null ? m_hOverlapPosition.rotation : transform.rotation;
            }

            int nHit = Physics.OverlapBoxNonAlloc(vPos, m_vSize * 0.5f, hitColArray, qRot, m_eCheckLayer);

            if (nHit <= 0)
            {
                m_hNotHitEvent?.Invoke();
                return;
            }

            bool bHit       = false;
            int  nSendCount = 0;

            for (int i = 0; i < nHit; i++)
            {
                var hHitGO = m_arrHitCol[i].gameObject;
                if (CheckNotIgnoreTarget(hHitGO))
                {
                    if (!bHit)
                    {
                        m_hHitEvent?.Invoke();
                    }

                    bHit = true;

                    m_hHitEventGameObject?.Invoke(hHitGO);
                    nSendCount++;

                    if (nSendCount >= m_nMaxSendData)
                    {
                        break;
                    }
                }
            }

            if (!bHit)
            {
                m_hNotHitEvent?.Invoke();
            }
        }
        protected virtual void OnTriggerExit2D(Collider2D collision)
        {
            if (!IsPassCondition())
            {
                return;
            }

            m_hExitEvent?.Invoke();
            m_hExitEventGameObject?.Invoke(collision.gameObject);
        }
        protected virtual void OnCollisionExit(Collision collision)
        {
            if (!IsPassCondition())
            {
                return;
            }

            m_hExitEvent?.Invoke();
            m_hExitEventGameObject?.Invoke(collision.gameObject);
        }
示例#7
0
        protected virtual void OnTriggerExit(Collider other)
        {
            if (!IsPassCondition())
            {
                return;
            }

            m_hExitEvent?.Invoke();
            m_hExitEventGameObject?.Invoke(other.gameObject);
        }
        protected virtual void OnCollisionStay2D(Collision2D collision)
        {
            if (!IsPassCondition())
            {
                return;
            }

            m_hStayEvent?.Invoke();
            m_hStayEventGameObject?.Invoke(collision.gameObject);
        }
        public override void CheckRaycast()
        {
            if (!m_arrCondition.PassAllCondition(eventConditionData))
            {
                return;
            }

            Vector3 vPos = m_hOriginPosition != null ? m_hOriginPosition.position : transform.position;
            int     nHit = Physics.RaycastNonAlloc(vPos, m_vDirection, rayHitArray, m_fDistance, m_eTargetLayer);

            if (nHit <= 0)
            {
                m_hNotHitEvent?.Invoke();
                return;
            }

            bool bHit       = false;
            int  nSendCount = 0;

            for (int i = 0; i < nHit; i++)
            {
                var hHitGO = m_arrRayHit[i].collider.gameObject;
                if (CheckNotIgnoreTarget(hHitGO))
                {
                    if (m_arrTargetTag.HasData() && !hHitGO.CompareTag(m_arrTargetTag))
                    {
                        continue;
                    }

                    if (!bHit)
                    {
                        m_hHitEvent?.Invoke();
                    }

                    bHit = true;

                    m_hHitEventGameObject?.Invoke(hHitGO);
                    nSendCount++;

                    if (nSendCount >= m_nMaxSendData)
                    {
                        break;
                    }
                }
            }

            if (!bHit)
            {
                m_hNotHitEvent?.Invoke();
            }
        }
示例#10
0
        public override void CheckOverlap()
        {
            if (!m_arrCondition.PassAllCondition(eventConditionData))
            {
                return;
            }

            Vector3 vPos = m_hOverlapPosition != null ? m_hOverlapPosition.position : transform.position;
            int     nHit = Physics.OverlapSphereNonAlloc(vPos, m_fRadius, hitColArray, m_eTargetLayer);

            if (nHit <= 0)
            {
                m_hNotHitEvent?.Invoke();
                return;
            }

            bool bHit       = false;
            int  nSendCount = 0;

            for (int i = 0; i < nHit; i++)
            {
                var hHitGo = m_arrHitCol[i].gameObject;
                if (CheckNotIgnoreTarget(hHitGo))
                {
                    if (m_arrTargetTag.HasData() && !hHitGo.CompareTag(m_arrTargetTag))
                    {
                        continue;
                    }

                    if (!bHit)
                    {
                        m_hHitEvent?.Invoke();
                    }

                    bHit = true;

                    m_hHitEventGameObject?.Invoke(hHitGo);
                    nSendCount++;

                    if (nSendCount >= m_nMaxSendData)
                    {
                        break;
                    }
                }
            }

            if (!bHit)
            {
                m_hNotHitEvent?.Invoke();
            }
        }
        protected virtual void OnTriggerStay2D(Collider2D collision)
        {
            if (m_arrTargetTag.HasData() && !collision.CompareTag(m_arrTargetTag))
            {
                return;
            }

            if (!IsPassCondition())
            {
                return;
            }

            m_hStayEvent?.Invoke();
            m_hStayEventGameObject?.Invoke(collision.gameObject);
        }
        public virtual void CheckLinecast()
        {
            if (!m_arrCondition.PassAllCondition(eventConditionData))
            {
                return;
            }

            Vector3 vPos         = m_hOriginPosition != null ? m_hOriginPosition.position : transform.position;
            Vector3 vDestination = m_hDestinationPosition != null ? m_hDestinationPosition.position : transform.position;

            if (Physics.Linecast(vPos, vDestination, out RaycastHit hHit, m_eCheckLayer))
            {
                m_hHitEvent?.Invoke();
                m_hHitEventGameObject?.Invoke(hHit.transform.gameObject);
            }
        protected virtual void OnTriggerExit(Collider other)
        {
            if (m_arrTargetTag.HasData() && !other.CompareTag(m_arrTargetTag))
            {
                return;
            }

            if (!IsPassCondition())
            {
                return;
            }

            m_hExitEvent?.Invoke();
            m_hExitEventGameObject?.Invoke(other.gameObject);
        }
示例#14
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray origin = _camera.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(origin, out RaycastHit raycastHit))
         {
             _controllable = raycastHit.collider.GetComponent <IControllable>();
             if (_controllable != null)
             {
                 AtPlayerClicked.Invoke(raycastHit.collider.gameObject);
             }
             else
             {
                 OnGroundClicked.Invoke(raycastHit.point);
             }
         }
     }
 }
示例#15
0
        public void SpawnGameObject(GameObject hGameObject)
        {
            if (hGameObject == null)
            {
                Debug.LogWarning("Don't have any GameObject to spawn.");
                return;
            }
            Vector3 vPos = transform.position;

            if (m_lstSpawnPosition != null && m_lstSpawnPosition.Count > 0)
            {
                if (m_lstTempSpawnPosition == null)
                {
                    m_lstTempSpawnPosition = new List <GameObject>();
                }
                else
                {
                    m_lstTempSpawnPosition.Clear();
                }

                m_lstTempSpawnPosition.AddRange(m_lstSpawnPosition);

                do
                {
                    int nRan = Random.Range(0, m_lstTempSpawnPosition.Count);

                    var hSpawnPos = m_lstTempSpawnPosition[nRan];
                    if (hSpawnPos != null)
                    {
                        vPos = hSpawnPos.transform.position;

                        break;
                    }

                    m_lstTempSpawnPosition.RemoveAt(nRan);
                } while (m_lstTempSpawnPosition.Count > 0);
            }


            GameObject hGO = Instantiate(hGameObject, vPos, Quaternion.identity);

            m_hSpawnEvent?.Invoke(hGO);
        }
示例#16
0
        public virtual void CheckLinecast()
        {
            if (!m_arrCondition.PassAllCondition(eventConditionData))
            {
                return;
            }

            Vector2 vPos         = m_hOriginPosition != null ? m_hOriginPosition.position : transform.position;
            Vector2 vDestination = m_hDestinationPosition != null ? m_hDestinationPosition.position : transform.position;

            var hHit = Physics2D.Linecast(vPos, vDestination, m_eCheckLayer);

            if (hHit.collider != null)
            {
                m_hHitEvent?.Invoke();
                m_hHitEventGameObject?.Invoke(hHit.transform.gameObject);
            }
            else
            {
                m_hNotHitEvent?.Invoke();
            }
        }
示例#17
0
 public void OnEventsRaised(GameObject go)
 {
     ResponseWithObject.Invoke(go);
 }
示例#18
0
    public EventGameObject onClickAttackable;  // Событие для атаки врага.

#pragma warning restore 649

    void Update()
    {
        // Если это начало игры или смерть, то данный функционал не требуется
        if (GameManager.Instance.CurrentState == GameState.Pregame || GameManager.Instance.CurrentState == GameState.Death)
        {
            return;
        }

        // ---------------------
        #region Нажатие кнопок мыши

        // Стреляем лучами по сцене :)
        RaycastHit hit;
        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 70, clickableLayer.value) && !EventSystem.current.IsPointerOverGameObject())
        {
            // Если объект содержит интерфейс IEnemy - значит это враг, которого можно атаковать
            if (hit.collider.GetComponent(typeof(AbstractEnemy)) != null /*|| hit.collider.CompareTag("Enemy")*/)
            {
                Cursor.SetCursor(sword, new Vector2(16, 16), CursorMode.Auto);

                if (Input.GetMouseButtonDown(0))
                {
                    onClickAttackable?.Invoke(hit.collider.gameObject);
                }
            }
            else
            {
                Cursor.SetCursor(target, new Vector2(16, 16), CursorMode.Auto);
                if (Input.GetMouseButton(1))
                {
                    OnClickEnviroment?.Invoke(hit.point);
                }
            }
        }
        else
        {
            Cursor.SetCursor(pointer, Vector2.zero, CursorMode.Auto);
        }

        #endregion
        // ---------------------

        // ---------------------
        #region Вращение колесика мышки

        // Вращение колесика мышки - Приближение/Отдаление камеры
        if (Input.GetAxis("Mouse ScrollWheel") < 0 && SmoothFollowTarget.Instance.Offset.magnitude < 30)
        {
            SmoothFollowTarget.Instance.Offset += SmoothFollowTarget.Instance.Offset * Time.deltaTime * _scrollSens;
        }
        else if (Input.GetAxis("Mouse ScrollWheel") > 0 && SmoothFollowTarget.Instance.Offset.magnitude > 10)
        {
            SmoothFollowTarget.Instance.Offset -= SmoothFollowTarget.Instance.Offset * Time.deltaTime * _scrollSens;
        }

        #endregion
        // ---------------------

        // ---------------------
        #region Нажатия клавиш

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            CanvasManager.Instance.PauseHandler();
        }
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            SkillsManager.Instance.FirstSkill();
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            SkillsManager.Instance.SecondSkill();
        }

        #endregion
        // ---------------------
    }
示例#19
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("muis");
            RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition).origin, direction: Vector2.up);
            if (EventSystem.current.IsPointerOverGameObject())    // is the touch on the GUI
            {
                // GUI Action
                Debug.Log("hIT");
                return;
            }
            else if (hitInfo.transform != null)
            {
                Debug.Log("Hit");
                Clickable clickeble = hitInfo.transform.GetComponent <Clickable>();
                if (clickeble != null)
                {
                    print("It's working");
                    switch (active)
                    {
                    case InvokeType.Clickmanager:
                        OnClick.Invoke(clickeble.gameObject);
                        break;

                    case InvokeType.clickable:
                        clickeble.OnClick.Invoke();
                        break;

                    case InvokeType.both:
                        OnClick.Invoke(clickeble.gameObject);
                        clickeble.OnClick.Invoke();
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    Debug.Log("clickeble");
                }
            }
        }

        /*if (Input.touchCount == 1)
         * {
         *  Debug.Log("touch");
         *  RaycastHit hitInfo = new RaycastHit();
         *  if (Physics2D.Raycast(Camera.main.ScreenPointToRay(Input.GetTouch(0).position), out hitInfo) && Input.GetTouch(0).phase == TouchPhase.Began)
         *  {
         *      Debug.Log("Hit");
         *      Clickeble clickeble = hitInfo.transform.GetComponent<Clickeble>();
         *      if (clickeble != null)
         *      {
         *          print("It's working");
         *          OnClick.Invoke(clickeble.gameObject);
         *          clickeble.OnClick.Invoke();
         *      }
         *      else
         *      {
         *          Debug.Log("clickeble");
         *      }
         *  }
         * }*/
    }
示例#20
0
 public void RunEventImmediate()
 {
     m_hEvent?.Invoke(m_hSendGameObject);
 }
示例#21
0
 public void RunEvent()
 {
     m_hEvent?.Invoke(m_hSendGameObject);
 }
示例#22
0
    /*
     * private void Awake()
     * {
     *  if (null != GameManager.Instance)
     *      GameManager.Instance.OnGameStateChanged.AddListener(HandleGameStateChanged);
     * }
     *
     * void HandleGameStateChanged(GameManager.GameState currentState, GameManager.GameState previousState)
     * {
     *  _useDefaultCursor = (currentState != GameManager.GameState.RUNNING);
     * }
     */

    void Update()
    {
        if (_useDefaultCursor)
        {
            return;
        }

        // Raycast into scene
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),
                            out hit, 50, clickableLayer.value))
        {
            bool door = false;
            if (hit.collider.gameObject.tag == "Doorway")
            {
                Cursor.SetCursor(doorway, new Vector2(16, 16), CursorMode.Auto);
                door = true;
            }
            else
            {
                Cursor.SetCursor(target, new Vector2(16, 16), CursorMode.Auto);
            }

            //Check if collision is attackable
            bool isAttackable = hit.collider.GetComponent(typeof(IAttackable)) != null;
            if (isAttackable)
            {
                Cursor.SetCursor(sword, new Vector2(0, 0), CursorMode.Auto);
            }
            //Check if collision is harvestable
            bool isHarvestable = hit.collider.tag == "Harvestable";
            if (isHarvestable)
            {
                Cursor.SetCursor(pointer, new Vector2(0, 0), CursorMode.Auto);
            }

            /*
             * //Check if collision is harvestable
             * bool isHarvestable = (hit.collider.tag == "Harvestable");
             * if (isHarvestable)
             * {
             *      Cursor.SetCursor(shovel, new Vector2(0, 0), CursorMode.Auto);
             * }
             */
            // If environment surface is clicked, invoke callbacks.
            if (Input.GetMouseButtonDown(0))
            {
                if (isAttackable)
                {
                    GameObject attackable = hit.collider.gameObject;
                    OnClickAttackable.Invoke(attackable);
                    return;
                }
                if (isHarvestable)
                {
                    GameObject harvestable = hit.collider.gameObject;
                    OnClickHarvestable.Invoke(harvestable);
                    return;
                }

                /*
                 * if (isHarvestable) {
                 *      GameObject harvestable = hit.collider.gameObject;
                 *      OnClickHarvestable.Invoke(harvestable);
                 *      return;
                 * }
                 */
                if (door)
                {
                    Transform doorway = hit.collider.gameObject.transform;
                    OnClickEnvironment.Invoke(doorway.position + doorway.forward * 10);
                }
                else
                {
                    OnClickEnvironment.Invoke(hit.point);
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                OnRightClickEnvironment.Invoke(hit.point);
            }
        }
        else
        {
            Cursor.SetCursor(pointer, Vector2.zero, CursorMode.Auto);
        }
    }
示例#23
0
 public void OnEventRaised(GameObject go)
 {
     response.Invoke(go);
 }