コード例 #1
0
    private void Update()
    {
        for (int i = 0; i < 2; i++)
        {
            DomacinInputManager.Actions p = i == 0 ?
                                            DomacinInputManager.e.p1 :
                                            DomacinInputManager.e.p2;

            //moveInput = moveLeftAction.ReadValue<Vector2>();
            interactInput = p.interactAction.triggered;

            float x = p.moveLeftAction.ReadValue <float>() == 1 ? -1 : p.moveRightAction.ReadValue <float>() == 1 ? 1 : 0;
            float y = p.moveDownAction.ReadValue <float>() == 1 ? -1 : p.moveUpAction.ReadValue <float>() == 1 ? 1 : 0;
            moveInput = new Vector2(x, y);

            //if (interactInput)
            //Debug.Log("Interacted");
        }

        /*
         * if (Input.GetKeyDown(KeyCode.Escape))
         * {
         *  StartRebindDirection(0, 0);
         * }*/

        if (inputPreview)
        {
            inputPreview.position = new Vector3(moveInput.x, moveInput.y);
        }
    }
コード例 #2
0
    public void StartRebindDirection(int player, int dir)
    {
        DomacinInputManager.Actions p = player == 0 ?
                                        DomacinInputManager.e.p1 :
                                        DomacinInputManager.e.p2;

        if (!bindingInProgress)
        {
            var action =
                dir == 0 ? p.moveLeftAction :
                dir == 1 ? p.moveRightAction :
                dir == 2 ? p.moveUpAction :
                dir == 3 ? p.moveDownAction :
                p.interactAction;

            Debug.Log("Started rebinding " + action.name);

            action.Disable();

            action.PerformInteractiveRebinding()
            .WithControlsExcluding("Mouse")
            .WithCancelingThrough("<Keyboard>/escape")
            .OnMatchWaitForAnother(0.1f)
            .OnApplyBinding((op, keyPath) =>
            {
                Debug.Log("End binding");
                action.ApplyBindingOverride(0, keyPath);
                Debug.Log("Bindings " + op.action.bindings[0]);
            })
            .OnComplete(op =>
            {
                op.Dispose();
                Debug.Log("Binding complete");
                action.Enable();
                bindingInProgress = false;
                OnBindingComplete?.Invoke();
            })
            .OnCancel((op) =>
            {
                op.Dispose();
                Debug.Log("Canceled binding");
                bindingInProgress = false;
                action.Enable();

                OnBindingComplete?.Invoke();
            })
            .Start();

            bindingInProgress = true;
        }
    }
コード例 #3
0
ファイル: Hands.cs プロジェクト: SavaMinic/VeteraniIndustrije
    private void Update()
    {
        if (!Application.isPlaying || GameController.I.IsPaused)
        {
            return;
        }

        Vector3 myPos = transform.position;

        slotsToSearch.Clear();

        if (heldItem)
        {
            for (int i = 0; i < Slot.all.Length; i++)
            {
                Slot slot = Slot.all[i];

                // skip if slot is occupied
                if (slot.itemInSlot)
                {
                    continue;
                }
                // skip if slot only interacts with an item and this item is not held
                if (slot.onlyInteractsWith && slot.onlyInteractsWith != heldItem)
                {
                    continue;
                }
                // skip if slot uses interaction control and held item does not correspond
                if (slot.useInteractionControl && !InteractionControl.I.CanInteract(heldItem.gameObject, slot.gameObject))
                {
                    continue;
                }
                // special metla slot
                if (heldItem is Metla && slot.name != "MetlaSlot")
                {
                    continue;
                }

                slotsToSearch.Add(Slot.all[i]);
            }
        }

        Slot closestSlot = Util.FindClosest(slotsToSearch, myPos, interactRange, useViewSpaceDistance);


        interactablesToSearch.Clear();
        for (int i = 0; i < Interactable.all.Count; i++)
        {
            Interactable interactable = Interactable.all[i];
            // skip held item
            if (interactable == heldItem)
            {
                continue;
            }
            // don't interact with other player's item
            if (interactable.isHeld)
            {
                continue;
            }
            // prevent coffee interacting with dzezva if dzezva is empty
            if (interactable is Dzezva && heldItem is Coffee && interactable.GetComponent <Container>().amount == 0)
            {
                continue;
            }
            // don't interact with guests if nothing in hands
            if (!heldItem && interactable is Consumer)
            {
                continue;
            }
            // skip flekas if nothing is held or not a metla is held
            if (interactable is Fleka && (!heldItem || (heldItem && !(heldItem is Metla))))
            {
                continue;
            }
            // with metla interact only with doors and flekas
            if (heldItem && heldItem is Metla && !(interactable is Fleka || interactable is Door))
            {
                continue;
            }
            if (!(interactable is Door || interactable is Fleka))
            {
                if (heldItem && !InteractionControl.I.CanInteract(heldItem.gameObject, interactable.gameObject))
                {
                    continue;
                }
            }
            interactablesToSearch.Add(interactable);
        }

        Interactable closestItem = Util.FindClosest(interactablesToSearch, myPos, interactRange, useViewSpaceDistance);

        // Give priority to slot or item depending what's closer
        if (closestSlot && closestItem)
        {
            if (closestItem.IsCloserThan((IProximityFindable)closestSlot, myPos, true))
            {
                closestSlot = null;
            }
            else
            {
                closestItem = null;
            }
        }

        if (closestItem)
        {
            Debug.DrawLine(myPos, closestItem.ProximityPosition, Color.green);

            closestItem.Highlight(true);
        }
        else if (closestSlot)
        {
            Debug.DrawLine(transform.position, closestSlot.ProximityPosition, Color.red);

            closestSlot.Highlight(true);
        }

        if (closestItem != lastClosestItem && lastClosestItem)
        {
            lastClosestItem.Highlight(false);
        }

        if (closestSlot != lastClosestSlot && lastClosestSlot)
        {
            lastClosestSlot.Highlight(false);
        }

        lastClosestItem = closestItem;
        lastClosestSlot = closestSlot;

        DomacinInputManager.Actions p = player == 1 ?
                                        DomacinInputManager.e.p1 :
                                        DomacinInputManager.e.p2;

        bool btn_down = p.interactAction.triggered;
        bool btn_held = p.interactAction.ReadValue <float>() == 1;

        if (closestItem is Gajba && heldItem is Pivo && btn_down)
        {
            Pivo pivo = heldItem as Pivo;
            pivo.Remove();
            (closestItem as Gajba).putClip.Play2D(0.5f);
            Debug.Log("Pivo removed!");
        }
        else if (closestItem is Gajba && !heldItem && btn_down)
        {
            Interactable pivo = Database.e.CreatePivo();
            (closestItem as Gajba).pickupClip.Play2D(0.5f);
            heldItem = pivo.Take(this);
        }
        // Sibice
        else if (heldItem is Matches && closestItem is Candle candle && btn_down)
        {
            if (!candle.isBurning)
            {
                candle.Ignite();
            }
        }
コード例 #4
0
    void FixedUpdate()
    {
        if (!Application.isPlaying || GameController.I.IsPaused)
        {
            return;
        }

        DomacinInputManager.Actions p = player == 1 ?
                                        DomacinInputManager.e.p1 :
                                        DomacinInputManager.e.p2;

        float deadzone = 0.1f;

        float left  = p.moveLeftAction.ReadValue <float>();
        float right = p.moveRightAction.ReadValue <float>();
        float down  = p.moveDownAction.ReadValue <float>();
        float up    = p.moveUpAction.ReadValue <float>();

        float h =
            left > deadzone ? -left :
            right > deadzone ? right : 0;

        float v =
            down > deadzone ? -down :
            up > deadzone ? up : 0;

        //float h = Input.GetAxis(HorizontalAxis);
        //float v = Input.GetAxis(VerticalAxis);

        Vector3 diffPos = lastPos - transform.position;
        float   diff    = diffPos.magnitude;

        bool walkingInput = Mathf.Abs(h) > 0 || Mathf.Abs(v) > 0;
        bool speedThres   = diff > 0.05f;

        if (Mathf.Abs(h) > 0)
        {
            spriteRenderer.flipX = h > 0f;
        }
        animator.SetBool("walking", walkingInput && speedThres);

        // Move player relative to camera, but projected to ground
        Vector3   inputV       = Vector3.ClampMagnitude(new Vector3(h, v), 1);
        Transform camT         = Camera.main.transform;
        Vector3   camRelativeV = camT.right * inputV.x + camT.up * inputV.y;

        Vector3 targetPosition = transform.position + camRelativeV;

        targetPosition.y = 0;

        Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
        Ray   ray         = new Ray(camRelativeV, camT.forward);

        float enter;

        groundPlane.Raycast(ray, out enter);
        Vector3 forceV = ray.GetPoint(enter) * speed;

        rb.AddForce(forceV);

        lastPos = transform.position;
    }