private void OnHotbarChange(object sender, UIHookHotbar.HotbarChangeEvent e)
    {
        UpdateViewModel();

        if (e.itemStack != null)
        {
            //  Relay the item name to the action bar
            if (previousItem != e.itemStack.GetItem())
            {
                UIMaster.SendText(UITextType.ACTION, e.itemStack.GetItem().GetDisplayName());
            }

            int viewCount = e.itemStack.GetAmount() / 8;
            if (viewCount < 1)
            {
                viewCount = 1;
            }
            Transform root = fpMainHandRoot.transform;

            float previousX = 0.0f;
            for (int i = 0; i < viewCount; i++)
            {
                GameObject obj = Instantiate(e.itemStack.GetItem().GetWorldModel(), Vector3.zero, Quaternion.identity, root);
                if (i == 0)
                {
                    root = obj.transform;
                }

                obj.transform.localPosition = e.itemStack.GetItem().GetViewModel().transform.localPosition;
                obj.transform.localRotation = e.itemStack.GetItem().GetViewModel().transform.localRotation;
                obj.transform.localScale    = e.itemStack.GetItem().GetViewModel().transform.localScale;

                if (viewCount > 1 && i > 0)
                {
                    obj.transform.localPosition = Vector3.zero;
                    obj.transform.localRotation = Quaternion.identity;
                    obj.transform.localScale    = Vector3.one;

                    obj.transform.localPosition += new Vector3(
                        previousX += (0.2f / viewCount * 2),
                        Random.value * 0.5f - 0.25f,
                        Random.value * 0.5f - 0.25f
                        );
                }
            }
        }

        previousItem = e.itemStack?.GetItem();
    }
Example #2
0
    public override void Tick()
    {
        base.Tick();

        movementDirection = Vector3.zero;
        isSprinting       = false;
        isWalking         = false;

        if (UIMaster.GetState() == UIState.FOCUSED)
        {
            return;                                         //  Don't allow interaction while the UI is focused
        }
        if (GameMaster.GetState() != GameState.PLAYING)
        {
            return;                                             //  Don't allow interaction while the gamestate isn't in play mode
        }
        if (Input.GetButton("Forward"))
        {
            movementDirection += Vector3.forward;
        }
        if (Input.GetButton("Backward"))
        {
            movementDirection += Vector3.back;
        }
        if (Input.GetButton("Left"))
        {
            movementDirection += Vector3.left;
        }
        if (Input.GetButton("Right"))
        {
            movementDirection += Vector3.right;
        }

        if (movementDirection != Vector3.zero && Input.GetButton("Sprint") && HasEndurance(Constants.END_COST_SPRINT))
        {
            isSprinting = true;
        }

        if (movementDirection != Vector3.zero && Input.GetButton("Walk"))
        {
            isWalking = true;
        }

        if (isGrounded == true)
        {
            if (Input.GetButton("Jump") && CostModifyEndurance(Constants.END_COST_JUMP))
            {
                velocity.y = jumpStrength;

                isJumping = true;
            }
        }

        if (Input.GetButton("Attack"))
        {
            Attack();
        }

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // Offset interact range based on camera distance. Offset is relative to character facing, so invert it
        float range = interactRange;

        if (cameraMotor.view == CameraMotor.CameraView.THIRD_PERSON)
        {
            range += -cameraMotor.thirdPersonOffset.z;
        }
        else if (cameraMotor.view == CameraMotor.CameraView.FIRST_PERSON)
        {
            range += -cameraMotor.fpOffset.z;
        }

        if (Physics.Raycast(ray, out hit, range, interactableMask) == true)
        {
            Interactable component = hit.collider.gameObject.GetComponent <Interactable>();

            if (component != null)
            {
                UIMaster.GetHook("look_display").Enable();
                UIMaster.SendText(UITextType.SUBTEXT, component.GetDisplayText());

                if (Input.GetButton("Interact"))
                {
                    component.Interact(this);
                }
            }
            else
            {
                UIMaster.GetHook("look_display").Disable();
            }
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            Swordfish.Terrain terrain = GameObject.Find("Terrain").GetComponent <Swordfish.Terrain>();

            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z, 1);
            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z + 1, 1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z + 1, 1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z, 1);
            terrain.ModifyTerrain((int)transform.position.x - 1, (int)transform.position.z + 1, 1);
            terrain.ModifyTerrain((int)transform.position.x - 1, (int)transform.position.z, 1);
            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z - 1, 1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z - 1, 1);

            transform.position += new Vector3(0, 2, 0);
        }
        else if (Input.GetKeyDown(KeyCode.Y))
        {
            Swordfish.Terrain terrain = GameObject.Find("Terrain").GetComponent <Swordfish.Terrain>();

            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z, -1);
            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z + 1, -1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z + 1, -1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z, -1);
        }
    }