Пример #1
0
    bool MoveUnit()
    {
        HandleCameraMovement();
        HandleStandardInput();

        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit = RaycastToGround();

            dragStartPos = hit.point;

            foreach (SelectableComponent selectedObject in selectedObjects)
            {
                MoveComponent mc = selectedObject.GetComponent <MoveComponent>();
                if (mc != null)
                {
                    //mc.GetComponent<UnityEngine.AI.NavMeshAgent>().destination = hit.point;
                    mc.SetAgentDestination(hit.point);
                }
            }

            return(true);
        }

        return(false);
    }
Пример #2
0
    protected void HandleStandardInput()
    {
        if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            StartDrag();
        }
        if (Input.GetMouseButton(0))
        {
            dragTimer += Time.deltaTime;

            RaycastHit hit = RaycastToGround();

            dragEndPos = hit.point;

            Vector3 midPoint = (dragStartPos + dragEndPos) / 2;
            Vector3 extents  = new Vector3(Mathf.Abs((dragStartPos - midPoint).x), Mathf.Abs((dragStartPos - midPoint).y), Mathf.Abs((dragStartPos - midPoint).z)) * 2;

            selectionImage.transform.position = midPoint;
            selectionImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, extents.x);
            selectionImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, extents.z);
        }
        if (Input.GetMouseButtonUp(0))
        {
            //if (dragTimer < 0.1f) {
            //    selectionImage.enabled = false;

            //    foreach (SelectableComponent selectedObject in selectedObjects) {
            //        if (selectedObject != null) {
            //            //selectedObject.GetComponentInChildren<Renderer>().material.color = Color.white;
            //            selectedObject.Deselect();
            //        }
            //    }
            //    selectedObjects.Clear();
            //    dragTimer = 0;

            //    //ClickableComponent[] clickableComponents = RaycastForClickableComponents();
            //    //if (clickableComponents != null && clickableComponents.Length > 0)
            //    //    ClickableComponentManager.instance.UnclickAllClickableComponents();
            //    //foreach (ClickableComponent clickableComponent in clickableComponents) {
            //    //    clickableComponent.Click();
            //    //}

            //    return;
            //}
            dragTimer = 0;

            EndDrag();
        }
        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit = RaycastToGround();

            dragStartPos = hit.point;

            foreach (SelectableComponent selectedObject in selectedObjects)
            {
                MoveComponent mc = selectedObject.GetComponent <MoveComponent>();
                if (mc != null)
                {
                    //mc.GetComponent<UnityEngine.AI.NavMeshAgent>().destination = hit.point;
                    mc.SetAgentDestination(hit.point);
                }
            }
        }
    }