示例#1
0
    private void Update()
    {
        if (player == null)
        {
            return;
        }

        if (targets == null || targets.Count == 0)
        {
            return;
        }

        for (int idx = 0; idx < targets.Count; idx++)
        {
            PointerTarget target       = targets[idx];
            Vector3       toPosition   = target.transform.position;
            Vector3       fromPosition = player.position;

            Vector3 dir = (toPosition - fromPosition).normalized;
            Vector3 targetPositionScreenPoint = uiCamera.WorldToScreenPoint(toPosition);

            if (targetPositionScreenPoint.z < 0)
            {
                targetPositionScreenPoint.x = Screen.width - targetPositionScreenPoint.x;
                targetPositionScreenPoint.y = Screen.height - targetPositionScreenPoint.y;
            }

            bool isOffScreen = targetPositionScreenPoint.x <= 0 || targetPositionScreenPoint.x >= Screen.width || targetPositionScreenPoint.y <= 0 || targetPositionScreenPoint.y >= Screen.height;

            if (isOffScreen)
            {
                target.pointer.gameObject.SetActive(true);

                Vector3 cappedTargetScreenPosition = targetPositionScreenPoint;
                if (cappedTargetScreenPosition.x <= 20)
                {
                    cappedTargetScreenPosition.x = 20f;
                }
                if (cappedTargetScreenPosition.x >= Screen.width - 20)
                {
                    cappedTargetScreenPosition.x = Screen.width - 20;
                }
                if (cappedTargetScreenPosition.y <= 20)
                {
                    cappedTargetScreenPosition.y = 20f;
                }
                if (cappedTargetScreenPosition.y >= Screen.height - 20)
                {
                    cappedTargetScreenPosition.y = Screen.height - 20;
                }

                target.pointer.position      = cappedTargetScreenPosition;
                target.pointer.localPosition = new Vector3(target.pointer.localPosition.x, target.pointer.localPosition.y, 0f);
            }
            else
            {
                target.pointer.gameObject.SetActive(false);
            }
        }
    }
示例#2
0
    void Update()
    {
        //SetCameraDrag();

        if (PlayerSM.state == 1)   //User is trying to select an object.
        {
            AddGridElement();
            PlayerSM.state = 2;
        }
        else if (PlayerSM.state == 2)     //User is dragging the selected object.
        {
            PointerTarget newTarget = GetTarget();
            DragElementToAdd(newTarget);
            pointerTarget = newTarget;
        }
        else if (PlayerSM.state == 4)     //User is trying to place the object.
        {
            SetGridElement(GetTarget());
            PlayerSM.state = 0;
        }


        if (Input.GetMouseButtonDown(1))  //Missing logic to erase object within rotation menu.
        {
            RemoveGridElement();
        }
    }
示例#3
0
    // Method to dinamically place element on grid depending on type selected

    public void SetGridElement(PointerTarget target)
    {
        //Sometimes the input won't enter the DragElement method.
        elementToAdd.GetComponent <Collider>().enabled = true;
        elementToAdd.SetActive(true);
        if (target.TargetCollider != null)
        {
            if (target.TargetCollider.CompareTag("Grid") && elementToAdd != null || InvManager.instance.Type == Element.Hamster)
            {
                if (!InvManager.instance.PlacedStructure())
                {
                    return;
                }
                elementToAdd.transform.position = target.TargetPosition;
                elementToAdd.GetComponent <Collider>().enabled = true;
            }
            else
            {
                Destroy(elementToAdd);
            }
            // Delete status color
            pointerTarget.TargetCollider.transform.Find("Fade").GetComponent <Renderer>().material = statusMaterial[2];
        }
        else
        {
            Destroy(elementToAdd);
        }
        elementToAdd = null;
    }
示例#4
0
 void Start()
 {
     mainCamera      = Camera.main;
     cameraContainer = GameObject.Find("Camera Container");
     scroller        = GameObject.Find("Scroll View").GetComponent <ScrollView>();
     elementToAdd    = null;
     pointerTarget   = new PointerTarget(new Vector3(), null);
     prevMaterial    = statusMaterial[2];
 }
示例#5
0
 // Method to change color of target position
 private void SetTargetColor(PointerTarget newTarget)
 {
     // Set color of next target
     if (newTarget.TargetCollider != null)
     {
         int index = newTarget.TargetCollider.CompareTag("Grid") ? 1 : 0;
         newTarget.TargetCollider.transform.Find("Fade").GetComponent <Renderer>().material = statusMaterial[index];
     }
     // Reset color of previous target
     if (pointerTarget.TargetCollider != null)
     {
         if (!pointerTarget.TargetPosition.Equals(newTarget.TargetPosition))
         {
             pointerTarget.TargetCollider.transform.Find("Fade").GetComponent <Renderer>().material = statusMaterial[2];
         }
     }
 }
示例#6
0
    private void UpdateLine()
    {
        RaycastHit hit;
        var        ray = new Ray(transform.position, transform.forward);

        Physics.Raycast(ray, out hit, MaxLength);

        if (hit.collider != null)
        {
            var pointerTarget = hit.transform.GetComponent <PointerTarget>();

            if (pointerTarget == null)
            {
                Dot.SetActive(false);
                lineRenderer.enabled = false;
                return;
            }
            Dot.SetActive(true);
            lineRenderer.enabled   = true;
            Dot.transform.position = hit.point;
            lineRenderer.SetPosition(0, transform.position);
            lineRenderer.SetPosition(1, Dot.transform.position);

            if (pointerTarget != CurrentPointerTarget)
            {
                if (CurrentPointerTarget != null)
                {
                    CurrentPointerTarget.OnHoverEnd?.Invoke();
                }
                pointerTarget.OnHoverStart?.Invoke();
                CurrentPointerTarget = pointerTarget;
            }
        }
        else
        {
            Dot.SetActive(false);
            lineRenderer.enabled = false;

            if (CurrentPointerTarget != null)
            {
                CurrentPointerTarget.OnHoverEnd?.Invoke();
                //Dot.gameObject.SetActive(false);
            }
            CurrentPointerTarget = null;
        }
    }
示例#7
0
        public override void GetFuzzBlockDescriptions(ref HashSet <FuzzBlock> blocks, int chunkSize)
        {
            if (this.Fuzz)
            {
                // Add this data argument as a fuzz
                var block = new FuzzBlockRegister(process.ProcessDotNet, Register, NamePrefix + Name + " + REGISTER " + Register, chunkSize);
                if (!blocks.Contains(block))
                {
                    blocks.Add(block);
                }
            }

            if (this.PointerTarget != null)
            {
                // Forward this to the pointed to arguments description
                PointerTarget.GetFuzzBlockDescriptions(ref blocks, chunkSize);
            }
        }
示例#8
0
    public void SetTargets(List <PointerTarget> targets)
    {
        this.targets = targets;
        if (this.targets == null || this.targets.Count == 0)
        {
            return;
        }
        var idx = 0;

        while (idx < this.targets.Count)
        {
            PointerTarget target  = this.targets[idx];
            GameObject    pointer = new GameObject();
            pointer.name = "Pointer";
            Image pointerImage = pointer.AddComponent <Image>();
            pointerImage.sprite = target.sprite;
            pointerImage.transform.localScale = Vector3.one * 0.2f;
            pointer.GetComponent <RectTransform>().SetParent(transform);
            target.pointer = pointer.GetComponent <RectTransform>();

            idx++;
        }
    }
示例#9
0
        /// <summary>Handles everything realted to the pointer.</summary>
        public static void UpdateHoverDetect()
        {
            if (isRunning)
            {
                //Cast ray
                Ray ray         = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition);
                var colliderHit = Physics.Raycast(
                    ray, out hit, maxDistance: 500,
                    layerMask: (int)(KspLayerMask.Part | KspLayerMask.Kerbal | KspLayerMask.SurfaceCollider),
                    queryTriggerInteraction: QueryTriggerInteraction.Ignore);
                if (!colliderHit)
                {
                    pointerTarget = PointerTarget.Nothing;
                    ResetMouseOver();
                    return;
                }

                // Check target type
                var        tgtPart       = Mouse.HoveredPart;
                KerbalEVA  tgtKerbalEva  = null;
                AttachNode tgtAttachNode = null;

                if (!tgtPart)
                {
                    // check linked part
                    KIS_LinkedPart linkedObject = hit.collider.gameObject.GetComponent <KIS_LinkedPart>();
                    if (linkedObject)
                    {
                        tgtPart = linkedObject.part;
                    }
                }
                if (tgtPart)
                {
                    tgtKerbalEva = tgtPart.GetComponent <KerbalEVA>();
                }

                // If rigidbody
                if (hit.rigidbody && !tgtPart && !tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.StaticRb;
                }

                // If kerbal
                if (tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.KerbalEva;
                }

                // If part
                if (tgtPart && !tgtKerbalEva)
                {
                    float currentDist = Mathf.Infinity;
                    foreach (AttachNode an in tgtPart.attachNodes)
                    {
                        if (an.icon)
                        {
                            float dist;
                            var   cameraToMouseRay =
                                FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition);
                            var iconRenderer = an.icon.GetComponent <Renderer>();
                            if (iconRenderer.bounds.IntersectRay(cameraToMouseRay, out dist))
                            {
                                if (dist < currentDist)
                                {
                                    tgtAttachNode = an;
                                    currentDist   = dist;
                                }
                            }
                        }
                    }
                    if (tgtAttachNode != null)
                    {
                        if (tgtAttachNode.icon.name == "KISMount")
                        {
                            pointerTarget = PointerTarget.PartMount;
                        }
                        else
                        {
                            pointerTarget = PointerTarget.PartNode;
                        }
                    }
                    else
                    {
                        pointerTarget = PointerTarget.Part;
                    }
                }

                //if nothing
                if (!hit.rigidbody && !tgtPart && !tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.Static;
                }

                if (tgtPart)
                {
                    if (tgtAttachNode != null)
                    {
                        // OnMouseEnter node
                        if (tgtAttachNode != hoveredNode)
                        {
                            if (hoveredNode != null)
                            {
                                OnMouseExitNode(hoveredNode);
                            }
                            OnMouseEnterNode(tgtAttachNode);
                            hoveredNode = tgtAttachNode;
                        }
                    }
                    else
                    {
                        // OnMouseExit node
                        if (tgtAttachNode != hoveredNode)
                        {
                            OnMouseExitNode(hoveredNode);
                            hoveredNode = null;
                        }
                    }

                    // OnMouseEnter part
                    if (tgtPart != hoveredPart)
                    {
                        if (hoveredPart)
                        {
                            OnMouseExitPart(hoveredPart);
                        }
                        OnMouseEnterPart(tgtPart);
                        hoveredPart = tgtPart;
                    }
                }
                else
                {
                    // OnMouseExit part
                    if (tgtPart != hoveredPart)
                    {
                        OnMouseExitPart(hoveredPart);
                        hoveredPart = null;
                    }
                }
            }
        }
示例#10
0
 private void DragElementToAdd(PointerTarget pointerTarget)
 {
     elementToAdd.SetActive(!scroller.PointerOnInventory);
     elementToAdd.transform.position = pointerTarget.TargetPosition;
     SetTargetColor(pointerTarget);
 }
示例#11
0
        public void UpdateHoverDetect()
        {
            if (isRunning)
            {
                //Cast ray
                Ray ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition);
                if (!Physics.Raycast(ray, out hit, 500, 557059))
                {
                    pointerTarget = PointerTarget.Nothing;
                    ResetMouseOver();
                    return;
                }

                // Check target type
                Part tgtPart = null;
                KerbalEVA tgtKerbalEva = null;
                AttachNode tgtAttachNode = null;

                tgtPart = KIS_Shared.GetPartUnderCursor();
                if (!tgtPart)
                {
                    // check linked part
                    KIS_LinkedPart linkedObject = hit.collider.gameObject.GetComponent<KIS_LinkedPart>();
                    if (linkedObject)
                    {
                        tgtPart = linkedObject.part;
                    }
                }
                if (tgtPart)
                {
                    tgtKerbalEva = tgtPart.GetComponent<KerbalEVA>();
                }

                // If rigidbody
                if (hit.rigidbody && !tgtPart && !tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.StaticRb;
                }

                // If kerbal
                if (tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.KerbalEva;
                }

                // If part
                if (tgtPart && !tgtKerbalEva)
                {
                    float currentDist = Mathf.Infinity;
                    foreach (AttachNode an in tgtPart.attachNodes)
                    {
                        if (an.icon)
                        {
                            float dist;
                            if (an.icon.renderer.bounds.IntersectRay(FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition), out dist))
                            {
                                if (dist < currentDist)
                                {
                                    tgtAttachNode = an;
                                    currentDist = dist;
                                }
                            }
                        }
                    }
                    if (tgtAttachNode != null)
                    {
                        if (tgtAttachNode.icon.name == "KISMount")
                        {
                            pointerTarget = PointerTarget.PartMount;
                        }
                        else
                        {
                            pointerTarget = PointerTarget.PartNode;
                        }
                    }
                    else
                    {
                        pointerTarget = PointerTarget.Part;
                    }
                }

                //if nothing
                if (!hit.rigidbody && !tgtPart && !tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.Static;
                }

                if (tgtPart)
                {
                    if (tgtAttachNode != null)
                    {
                        // OnMouseEnter node
                        if (tgtAttachNode != hoveredNode)
                        {
                            if (hoveredNode != null)
                            {
                                OnMouseExitNode(hoveredNode);
                            }
                            OnMouseEnterNode(tgtAttachNode);
                            hoveredNode = tgtAttachNode;
                        }
                    }
                    else
                    {
                        // OnMouseExit node
                        if (tgtAttachNode != hoveredNode)
                        {
                            OnMouseExitNode(hoveredNode);
                            hoveredNode = null;
                        }
                    }

                    // OnMouseEnter part
                    if (tgtPart != hoveredPart)
                    {
                        if (hoveredPart)
                        {
                            OnMouseExitPart(hoveredPart);
                        }
                        OnMouseEnterPart(tgtPart);
                        hoveredPart = tgtPart;
                    }
                }
                else
                {
                    // OnMouseExit part
                    if (tgtPart != hoveredPart)
                    {
                        OnMouseExitPart(hoveredPart);
                        hoveredPart = null;
                    }
                }

            }
        }
示例#12
0
        public void UpdateHoverDetect()
        {
            if (isRunning)
            {
                //Cast ray
                Ray ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition);
                if (!Physics.Raycast(ray, out hit, 500, 557059))
                {
                    pointerTarget = PointerTarget.Nothing;
                    ResetMouseOver();
                    return;
                }

                // Check target type
                Part       tgtPart       = null;
                KerbalEVA  tgtKerbalEva  = null;
                AttachNode tgtAttachNode = null;
                if (hit.rigidbody)
                {
                    tgtPart = hit.rigidbody.GetComponent <Part>();
                }
                if (!tgtPart)
                {
                    tgtPart = (Part)UIPartActionController.GetComponentUpwards("Part", hit.collider.gameObject);
                }
                if (!tgtPart)
                {
                    // check linked part
                    KIS_LinkedPart linkedObject = hit.collider.gameObject.GetComponent <KIS_LinkedPart>();
                    if (linkedObject)
                    {
                        tgtPart = linkedObject.part;
                    }
                }
                if (tgtPart)
                {
                    tgtKerbalEva = tgtPart.GetComponent <KerbalEVA>();
                }

                // If rigidbody
                if (hit.rigidbody && !tgtPart && !tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.StaticRb;
                }

                // If kerbal
                if (tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.KerbalEva;
                }

                // If part
                if (tgtPart && !tgtKerbalEva)
                {
                    float currentDist = Mathf.Infinity;
                    foreach (AttachNode an in tgtPart.attachNodes)
                    {
                        if (an.icon)
                        {
                            float dist;
                            if (an.icon.renderer.bounds.IntersectRay(FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition), out dist))
                            {
                                if (dist < currentDist)
                                {
                                    tgtAttachNode = an;
                                    currentDist   = dist;
                                }
                            }
                        }
                    }
                    if (tgtAttachNode != null)
                    {
                        if (tgtAttachNode.icon.name == "KISMount")
                        {
                            pointerTarget = PointerTarget.PartMount;
                        }
                        else
                        {
                            pointerTarget = PointerTarget.PartNode;
                        }
                    }
                    else
                    {
                        pointerTarget = PointerTarget.Part;
                    }
                }

                //if nothing
                if (!hit.rigidbody && !tgtPart && !tgtKerbalEva)
                {
                    pointerTarget = PointerTarget.Static;
                }

                if (tgtPart)
                {
                    if (tgtAttachNode != null)
                    {
                        // OnMouseEnter node
                        if (tgtAttachNode != hoveredNode)
                        {
                            if (hoveredNode != null)
                            {
                                OnMouseExitNode(hoveredNode);
                            }
                            OnMouseEnterNode(tgtAttachNode);
                            hoveredNode = tgtAttachNode;
                        }
                    }
                    else
                    {
                        // OnMouseExit node
                        if (tgtAttachNode != hoveredNode)
                        {
                            OnMouseExitNode(hoveredNode);
                            hoveredNode = null;
                        }
                    }

                    // OnMouseEnter part
                    if (tgtPart != hoveredPart)
                    {
                        if (hoveredPart)
                        {
                            OnMouseExitPart(hoveredPart);
                        }
                        OnMouseEnterPart(tgtPart);
                        hoveredPart = tgtPart;
                    }
                }
                else
                {
                    // OnMouseExit part
                    if (tgtPart != hoveredPart)
                    {
                        OnMouseExitPart(hoveredPart);
                        hoveredPart = null;
                    }
                }
            }
        }