Пример #1
0
        void SetSelectedSegment(SegmentBehavior segment)
        {
            if (selectedSegment != segment)
            {
                if (selectedSegment)
                {
                    selectedSegment.selected = false;
                }
            }
            selectedSegment = segment;
            GameController.Instance.DebugOutput($"Selection change from {selectedSegment} to {segment}");
            if (segment)
            {
                SetHoverSegment(null);
                segment.selected = true;

                temporaryMoveSegment = Instantiate(selectedSegment.gameObject, selectedSegment.transform.parent);
                foreach (Collider col in temporaryMoveSegment.GetComponentsInChildren <Collider>(true))
                {
                    col.enabled = false;
                }
                temporaryMoveSegment.name = "temporaryMoveSegment";
                UpdateTemporarySegmentPlacementIndication(null);
                segment.ShowClick();
            }
            else
            {
                if (temporaryMoveSegment)
                {
                    Destroy(temporaryMoveSegment);
                }
            }
            UpdateFileStatusHighlight();
        }
Пример #2
0
        void SetHoverSegment(SegmentBehavior segment)
        {
            if (hoverSegment != segment)
            {
                if (hoverSegment)
                {
                    hoverSegment.highlighted = false;
                }
                if (segment)
                {
                    segment.highlighted = true;
                }
                GameController.Instance.DebugOutput($"Hover change from {hoverSegment} to {segment}");
                hoverSegment = segment;

                UpdateFileStatusHighlight();
            }
        }
Пример #3
0
        void HandleGamePlayInput()
        {
            if (!segmentsContainer)
            {
                return;
            }

            Vector3         mousePosition = Input.mousePosition;
            Ray             ray           = mainCamera.ScreenPointToRay(mousePosition);
            RaycastHit      hit;
            SegmentBehavior segmentUnderMouse = null;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity, GameController.LayerMaskSegments))
            {
                Transform objectHit = hit.transform;
                segmentUnderMouse = objectHit.parent.GetComponentInParent <SegmentBehavior>();
            }
            // determine potential target
            Plane plane = new Plane(Vector3.forward, 0);
            float enter = 0.0f;

            int?    potentialTargetLocation = null;
            Vector3 localMousePosition      = Vector3.zero;

            if (plane.Raycast(ray, out enter))
            {
                //Get the point that is under the pointer
                Vector3 hitPoint = ray.GetPoint(enter);

                localMousePosition      = segmentsContainer.transform.InverseTransformPoint(hitPoint);
                potentialTargetLocation = LocationForPosition(localMousePosition);

                if (selectedSegment)
                {
                    if (potentialTargetLocation.HasValue)
                    {
                        int?suggestedLocation = null;
                        if (!level.CanCopySegmentToLocation(selectedSegment.segmentData, potentialTargetLocation.Value, out suggestedLocation))
                        {
                            potentialTargetLocation = suggestedLocation;
                        }
                    }
                }
            }

            // clear segment unter mouse if temporary segment is in the way
            if (temporaryMoveSegment && temporaryMoveSegment.activeSelf)
            {
                foreach (Collider col in temporaryMoveSegment.GetComponentsInChildren <Collider>(true))
                {
                    col.enabled = true;
                }
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, GameController.LayerMaskSegments))
                {
                    Transform objectHit     = hit.transform;
                    var       hitGameObject = objectHit.parent.GetComponentInParent <SegmentBehavior>().gameObject;
                    if (hitGameObject == temporaryMoveSegment)
                    {
                        segmentUnderMouse = null;
                    }
                }
                foreach (Collider col in temporaryMoveSegment.GetComponentsInChildren <Collider>(true))
                {
                    col.enabled = false;
                }
            }

            if (!selectedSegment)
            {
                SetHoverSegment(segmentUnderMouse);
            }
            else
            {
                if (temporaryMoveSegment && temporaryMoveSegment.activeSelf &&
                    (temporaryMoveSegment.transform.localPosition - localMousePosition).magnitude > 3.0 &&
                    !potentialTargetLocation.HasValue)
                {
                    UpdateTemporarySegmentPlacementIndication(null);
                }
                else
                {
                    if (potentialTargetLocation.HasValue)
                    {
                        //Move your segment to the point where you clicked
                        UpdateTemporarySegmentPlacementIndication(potentialTargetLocation.Value);
                    }
                }
            }

            if (Input.GetButtonDown("Fire1"))
            {
                if (hoverSegment)
                {
                    SetSelectedSegment(hoverSegment);
                    lastClickDownTime     = Time.realtimeSinceStartup;
                    lastClickDownLocation = localMousePosition;
                }
                else if (selectedSegment)
                {
                    if (temporaryMoveSegment.activeSelf)
                    {
                        PlaceTemporarySegment();
                    }
                    else
                    {
                        SetSelectedSegment(null);
                    }
                }
            }

            if (Input.GetButtonUp("Fire1"))
            {
                if (selectedSegment)
                {
                    bool allowDrag = (Time.realtimeSinceStartup - lastClickDownTime) > 1.0f / 5.0f ||
                                     (localMousePosition - lastClickDownLocation).magnitude > 0.75;

                    if (temporaryMoveSegment.activeSelf && allowDrag)
                    {
                        PlaceTemporarySegment();
                    }
                    else if (Time.realtimeSinceStartup - lastClickDownTime > 1.0f / 2.0f)
                    {
                        SetSelectedSegment(null);
                    }
                }
            }

            if (Input.GetButtonDown("Fire2"))
            {
                if (selectedSegment)
                {
                    SetSelectedSegment(null);
                }
            }
        }