Exemplo n.º 1
0
    private void ClearTargetsIfInCutsceneOrInteracting()
    {
        if (PlayerCore.Instance.GetIsInteracting() || DialogueSystem.isInCutscene || PlayerViewScript.paused || PlayerViewScript.GetIsWindowActive())
        {
            if (!PlayerViewScript.paused)
            {
                reticleScript.ClearSecondaryTargets();
                reticleScript.SetTarget(null);
            }

            SetClicking(false);
            return;
        }
    }
Exemplo n.º 2
0
    public void AddEntityInfo(Entity entity, ReticleScript reticle)
    {
        var secondary = Instantiate(secondaryTargetInfoPrefab, content);

        secondary.GetComponent <Button>().onClick.AddListener(new UnityEngine.Events.UnityAction
                                                                  (() =>
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                reticle.RemoveSecondaryTarget(entity);
            }
            else
            {
                var targSys = PlayerCore.Instance.GetTargetingSystem();
                if (targSys.GetTarget() && targSys.GetTarget().GetComponent <Entity>())
                {
                    reticle.AddSecondaryTarget(targSys.GetTarget().GetComponent <Entity>());
                }

                reticle.SetTarget(entity.transform);
                reticle.RemoveSecondaryTarget(entity);
            }
        }));

        if (!secondaryInfosByEntity.ContainsKey(entity))
        {
            secondaryInfosByEntity.Add(entity, secondary);
        }
        else
        {
            if (secondaryInfosByEntity[entity])
            {
                Destroy(secondaryInfosByEntity[entity].gameObject);
            }

            secondaryInfosByEntity[entity] = secondary;
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);                      // create a ray

        RaycastHit2D[] hits       = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity); // get an array of all hits
        bool           overTarget = false;

        foreach (var hit in hits)
        {
            var hitTransforn = hit.transform;
            var ent          = hitTransforn.GetComponent <Entity>();
            if ((hitTransforn.GetComponent <ITargetable>() != null && hitTransforn != PlayerCore.Instance.transform) ||
                (hitTransforn.GetComponent <Draggable>() && (!ent || ent.faction == PlayerCore.Instance.faction)))
            {
                Cursor.SetCursor(overTargetableCursor, new Vector2(-0.16F, 0.16F), CursorMode.Auto);
                overTarget = true;
                break;
            }
        }

        if (!overTarget)
        {
            Cursor.SetCursor(defaultCursor, new Vector2(-0.16F, 0.16F), CursorMode.Auto);
        }

        // Clear targets if in cutscene/interacting
        if (PlayerCore.Instance.GetIsInteracting() || DialogueSystem.isInCutscene || PlayerViewScript.paused || PlayerViewScript.GetIsWindowActive())
        {
            // Debug.Log(PlayerCore.Instance.GetIsInteracting() + " " + DialogueSystem.isInCutscene + " " + PlayerViewScript.paused + " " + PlayerViewScript.GetIsWindowActive());
            if (!PlayerViewScript.paused)
            {
                reticleScript.ClearSecondaryTargets();
                reticleScript.SetTarget(null);
            }
            image.enabled = false;
            clicking      = false;
            return;
        }

        var targSys = PlayerCore.Instance.GetTargetingSystem();

        // Tab cycles primary target
        if (Input.GetKeyDown(KeyCode.Tab) && targSys.GetSecondaryTargets().Count > 0)
        {
            if (targSys.GetTarget() && targSys.GetTarget().GetComponent <Entity>())
            {
                reticleScript.AddSecondaryTarget(targSys.GetTarget().GetComponent <Entity>());
            }

            var newTarget = targSys.GetSecondaryTargets()[0];
            reticleScript.SetTarget(newTarget.transform);
            reticleScript.RemoveSecondaryTarget(newTarget);
        }

        // Right click clears targets

        /*
         * if(Input.GetMouseButtonDown(1))
         * {
         *  if(Input.GetKey(KeyCode.LeftShift))
         *  {
         *      PlayerCore.Instance.GetTargetingSystem().SetTarget(null);
         *  }
         *  else
         *  {
         *      if(PlayerCore.Instance.GetTargetingSystem().GetSecondaryTargets().Count > 0)
         *          reticleScript.ClearSecondaryTargets();
         *      else PlayerCore.Instance.GetTargetingSystem().SetTarget(null);
         *  }
         * }
         */

        if (Input.GetMouseButtonDown(0) && !eventSystem.IsPointerOverGameObject())
        {
            dronesChecked = reticleScript.FindTarget();
            reticleScript.ClearSecondaryTargets();

            // Get reference point of selection box for drawing
            startPoint = Input.mousePosition;
            image.rectTransform.anchoredPosition = startPoint;

            clicking = true;
        }

        if (((Vector2)Input.mousePosition - startPoint).sqrMagnitude > 10) // Make sure the drag isn't interfering with clicks
        {
            if (Input.GetMouseButton(0) && clicking)
            {
                // Draw box
                image.enabled = true;
                sizeVec       = (Vector2)Input.mousePosition - startPoint;
                sizeVec.x     = Mathf.Abs(sizeVec.x);
                sizeVec.y     = Mathf.Abs(sizeVec.y);
                image.rectTransform.sizeDelta = sizeVec;

                // Change the pivot of the size delta when the mouse goes under/before the start point
                pivotVec   = new Vector2();
                pivotVec.x = Input.mousePosition.x < startPoint.x ? 1 : 0;
                pivotVec.y = Input.mousePosition.y < startPoint.y ? 1 : 0;
                image.rectTransform.pivot = pivotVec;
            }
            else if (Input.GetMouseButtonUp(0) && clicking)
            {
                // End selection, push entities in box into secondary targets
                clicking = false;
                // Grab the rect of the selection box
                Vector2 boxStart =
                    Camera.main.ScreenToWorldPoint(new Vector3(startPoint.x, startPoint.y, CameraScript.zLevel));
                Vector2 boxExtents =
                    Camera.main.ScreenToWorldPoint(
                        new Vector3((1 - 2 * pivotVec.x) * sizeVec.x + startPoint.x,
                                    (1 - 2 * pivotVec.y) * sizeVec.y + startPoint.y,
                                    CameraScript.zLevel));
                Rect finalBox = Rect.MinMaxRect(
                    Mathf.Min(boxStart.x, boxExtents.x),
                    Mathf.Min(boxStart.y, boxExtents.y),
                    Mathf.Max(boxStart.x, boxExtents.x),
                    Mathf.Max(boxStart.y, boxExtents.y)
                    );

                // Now scan for entities
                foreach (var ent in AIData.entities)
                {
                    if (ent != PlayerCore.Instance && ent.transform != PlayerCore.Instance.GetTargetingSystem().GetTarget() &&
                        finalBox.Contains(ent.transform.position))
                    {
                        reticleScript.AddSecondaryTarget(ent);
                    }
                }
                image.enabled = false;
            }
        }

        /*
         * // Drones being commanded has a higher priority than mouse movement, so it should prevent the player themselves from moving.
         * // This controls mouse movement, first it checks if the click was meant for mouse movement
         * else if(!dronesChecked && Input.GetMouseButtonUp(0)
         *  && !PlayerCore.Instance.GetIsDead() && !PlayerCore.Instance.GetTargetingSystem().GetTarget()
         *      && (Input.GetKey(KeyCode.LeftShift) || simpleMouseMovement) && !DialogueSystem.isInCutscene)
         * {
         *  var mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0,0,CameraScript.zLevel));
         *  var renderer = Instantiate(movementReticlePrefab, mouseWorldPos, Quaternion.identity).GetComponent<SpriteRenderer>();
         *  renderer.color = new Color32((byte)100, (byte)100, (byte)100, (byte)255);
         *
         *  var node = new PathData.Node();
         *  node.children = new List<int>();
         *  node.position = mouseWorldPos;
         *  node.ID = nodeID++;
         *
         *  if(currentPathData == null
         || (!Input.GetKey(KeyCode.LeftShift) && simpleMouseMovement))
         || {
         ||     BeginPathData(node, renderer);
         || }
         || else
         || {
         ||     ContinuePathData(node, renderer);
         || }
         ||} else if(Input.GetMouseButtonUp(0)) dronesChecked = false;
         */
    }