コード例 #1
0
        public void PickUp(PlayerInteractionBehaviour interaction)
        {
            player      = interaction;
            player.item = this;
            var string_type = _I.GetType().ToString();

            player.CmdSetHolding(true, string_type);
            player.CmdSetItemBeingHeld(true, item_network_identity);

            player.CmdAssignItemAuthority(item_network_identity);
            Debug.Log("ATTEMPT TO ASSIGN AUTHORITY: EXPECTED = True, RESULT = " + item_network_identity.hasAuthority.ToString());

            rb.MovePosition(player.HoldingItemPosition.position);

            var colliders = GetComponents <Collider>().ToList();

            colliders.ForEach(collider =>
            {
                if (!collider.isTrigger)
                {
                    collider.enabled = false;
                }
                //collider.enabled = false;
            });
            rb.useGravity = false;
            rb.velocity   = Vector3.zero;
        }
コード例 #2
0
        private void OnTriggerExit(Collider other)
        {
            ItemCanvas.SetActive(false);

            if (!isBeingHeld)
            {
                player = null;
            }
        }
コード例 #3
0
        public void Drop()
        {
            player.CmdRemoveItemAuthority(item_network_identity);
            Debug.Log("ATTEMPT TO REMOVE AUTHORITY: EXPECTED = False, RESULT = " + item_network_identity.hasAuthority.ToString());

            player.CmdSetHolding(false, "");
            player.CmdSetItemBeingHeld(false, item_network_identity);
            isBeingHeld = false;
            player.item = null;

            var colliders    = GetComponents <Collider>().ToList();
            var trigger_size = Vector3.zero;

            colliders.ForEach(collider =>
            {
                if (!collider.isTrigger)
                {
                    collider.enabled = true;
                }
                else
                {
                    collider.enabled = true;
                    trigger_size     = collider.bounds.size;
                    collider.enabled = false;
                }
            });

            rb.isKinematic = false;
            rb.constraints = RigidbodyConstraints.None;
            rb.useGravity  = true;

            var drop_position = Vector3.zero;

            var isUsingItem = player.Ani.GetBool("UsingItem");

            if (isUsingItem)
            {
                //DROP ITEM INFRONT OF PLAYER
                var front_drop_position = trigger_size;
                front_drop_position.x = 0;
                front_drop_position.y = 0;
                front_drop_position.z = front_drop_position.z * DropItemOffset;

                drop_position = player.transform.TransformPoint(front_drop_position);
            }
            else
            {
                //DROP ITEM ON SIDE OF PLAYER
                var side_drop_position = trigger_size;
                side_drop_position.x = side_drop_position.x * DropItemOffset;
                side_drop_position.y = 0;
                side_drop_position.z = 0;

                drop_position = player.transform.TransformPoint(side_drop_position);
            }

            drop_position.y = transform.position.y;

            //var drop_position = player.HoldingItemPosition.position;
            //trigger_size.y = 0;
            //trigger_size.x = 0;
            //trigger_size.z = -trigger_size.z;

            //drop_position += trigger_size * DropItemOffset;

            RaycastHit hit;

            if (Physics.Raycast(transform.position, -Vector3.up, out hit))
            {
                //PUT THE ITEM ON THE GROUND
                drop_position.y -= hit.distance;
            }

            rb.transform.position = (drop_position);
            //rb.MovePosition(drop_position);
            rb.velocity = -Vector3.up * DropItemPower;

            //rb.MovePosition(drop_position);

            player = null; //REMOVE REFRENCE TO PLAYER
        }
コード例 #4
0
        private void OnTriggerStay(Collider other)
        {
            if (isServer)
            {
                return;
            }

            if (other.tag == "Player")
            {
                var player_identity = other.GetComponentInParent <NetworkIdentity>();
                if (player_identity.isLocalPlayer && !isBeingHeld)
                {
                    ItemCanvas.SetActive(true);
                    var player_behaviour = player_identity.GetComponent <PlayerBehaviour>();
                    //var camTransform = player_behaviour.VirtualCamera.GetComponent<Cinemachine.CinemachineFreeLook>().GetRig(1).transform;
                    var cinemachine_rig = player_behaviour.VirtualCamera.GetComponent <Cinemachine.CinemachineFreeLook>().LiveChildOrSelf;
                    var camTransform    = cinemachine_rig.VirtualCameraGameObject.transform;
                    ItemUILookat(camTransform);
                }

                var player_interaction = other.GetComponentInParent <PlayerInteractionBehaviour>();
                if (player_interaction != null)
                {
                    player = player_interaction;
                }
            }

            if (other.CompareTag("Hand"))
            {
                var player_interaction = other.GetComponentInParent <PlayerInteractionBehaviour>();
                if (player_interaction != null)
                {
                    if (!player_interaction.isHolding && !isBeingHeld)
                    {
                        PickUp(player_interaction);
                    }
                }
            }

            if (other.tag == "Vehicle")
            {
                Debug.Log("COLLISION WITH: " + other.gameObject.name);

                var vehicle_behaviour = other.GetComponentInParent <VehicleBehaviour>();
                var vehicle_identity  = other.GetComponentInParent <NetworkIdentity>();

                if (isBeingHeld && player.isLocalPlayer && !vehicle_behaviour.isDestroyed)
                {
                    var string_type = _I.GetType().ToString();          //GET THE TYPE OF ITEM
                    player.CmdAssignVehicleAuthority(vehicle_identity); //ASSIGN THE VEHICLE 'AUTHORITY'

                    if (vehicle_identity.hasAuthority)
                    {
                        player.UseItemOnVehicle(string_type, item_network_identity, vehicle_identity); //USE THE ITEM ON THE VEHICLE
                        player.playerBrain.CmdRemoveVehicleAuthority(vehicle_identity);                //REMOVE THE AUTHORITY FROM THE VEHICLE
                        player._DropItem();                                                            //REMOVE THE ITEM FROM THE PLAYER

                        var net_companion = FindObjectOfType <InGameNetworkBehaviour>();
                        net_companion.Server_Destroy(gameObject);
                    }
                }
            }
        }