Exemplo n.º 1
0
    void Shoot_CurrentItem()
    {
        if (inventory.prefab == null)
        {
            return;
        }

        switch (inventory.inv.ci.itemType)
        {
        case Item.PlayerItem.ItemType.Bullet:
        case Item.PlayerItem.ItemType.Knife:
        {
            RaycastHit hit;
            if (Physics.Raycast(inventory.prefab.firePoint.position, MouseOrbitImproved.instance.transform.forward, out hit, inventory.inv.ci.range, ~hitMask))
            {
                if (isLocalPlayer)
                {
                    if (inventory.inv.ci.itemType == Item.PlayerItem.ItemType.Bullet)
                    {
                        SNet_Network.instance.Send_Spawn("bulletImpact", hit.point, Quaternion.LookRotation(-inventory.prefab.firePoint.forward), Vector3.zero, 0);
                    }

                    if (hit.collider.CompareTag("Explosive"))
                    {
                        hit.collider.GetComponent <Explosive>().Explode_Request();
                        return;
                    }

                    /*
                     * ONLY LOCAL PLAYER CAN MAKE HIT.
                     * Bone damage multipliers are the parts of the user.
                     * If you are making a third person shooter game you can use the ragdoll bones for this.
                     * Add bone damage multipliers to the bones have colliders.
                     *
                     * For example if you are making a car fight game (non-humanoid) drop the bone damage multiplier to the car has collider.
                     * */
                    SNet_Identity id = hit.collider.transform.root.GetComponent <SNet_Identity>();

                    if (id != null)
                    {
                        BoneDamageMultiplier bone = hit.collider.GetComponent <BoneDamageMultiplier>();
                        if (bone != null)
                        {         // Hit an agent
                            UserHit userHit = new UserHit(id.identity);
                            userHit.v = Mathf.RoundToInt(inventory.inv.ci.damage * bone.damageModifier);
                            userHit.h = transform.position;
                            SNet_Network.instance.Send_Message(userHit);

                            /*
                             * IMPACT TO BONE
                             * */
                            SNet_Network.instance.Send_Message(new RagdollHelper.Impact(identity.identity, bone.name, inventory.prefab.firePoint.forward, inventory.inv.ci.damage / 100f));
                        }
                        else
                        {
                            if (id.vehicle != null)
                            {
                                /*
                                 * VEHICLE HEALTH IS HOST CONTROLLED
                                 * */
                                if (SNet_Network.instance.isHost())
                                {
                                    id.vehicle.health = new SNet_Vehicle.VH(id.identity, Mathf.RoundToInt(id.vehicle.health.v - inventory.inv.ci.damage / id.vehicle.armor));
                                    SNet_Network.instance.Send_Message(id.vehicle.health);
                                }

                                /*
                                 * */
                            }

                            if (id.rbody != null)
                            {
                                id.rbody.rBody.AddForce(inventory.prefab.firePoint.forward * inventory.inv.ci.damage, ForceMode.Force);
                                id.rbody.nextUpdate = 0;         // Update now
                            }
                        }
                    }
                }
            }
        }
        break;

        case Item.PlayerItem.ItemType.Throwable:
            if (isLocalPlayer)
            {
                Quaternion high = new Quaternion();
                high.eulerAngles = inventory.inv.ci.throwableRotation;
                SNet_Network.instance.SpawnRequest(inventory.inv.ci.ThrowPrefab, inventory.prefab.firePoint.position, MouseOrbitImproved.instance.transform.rotation * high, Vector3.zero, inventory.inv.ci.ThrowForce);
            }
            break;
        }

        if (inventory.inv.ci.countable)
        {
            inventory.inv.ci.ammo--;

            if (isLocalPlayer)
            { // Update ammo
                inventory.UpdateCurrentAmmo();
                InventorySelector.current.UI_UpdateCurrentAmmo();
            }
        }
    }
    void OnGUI()
    {
        GUILayout.Label("SNet Player Adder", EditorStyles.boldLabel);
        GUILayout.Label("This tool helps you to create a new character with a new 3d humanoid model.", EditorStyles.label);
        GUILayout.Label("You must ragdoll the player first. Please follow the tutorials at the web site www.easymoba.com", EditorStyles.label);

        GUILayout.Space(20);
        source = (GameObject)EditorGUILayout.ObjectField(source, typeof(GameObject), true);
        GUILayout.Space(20);
        if (source != null)
        {
            Animator anim = source.GetComponent <Animator>();
            if (anim == null)
            {
                GUILayout.Label("The target gameobject has not Animator component. Be sure it has a humanoid skeleton.", EditorStyles.boldLabel);
                return;
            }

            Rigidbody rb = anim.GetBoneTransform(HumanBodyBones.Hips).GetComponent <Rigidbody>();
            if (rb == null)
            {
                GUILayout.Label("The hips of target skeleton has not rigidbody component. The target gameobject may have not been ragdolled properly. You must initialize the ragdoll first.", EditorStyles.boldLabel);
                return;
            }

            if (source.GetComponent <SNet_Identity>())
            {
                GUILayout.Label("The target gameobject has an SNet_Identity component. Please create the gameobject from the main model file, not from the prefab.", EditorStyles.boldLabel);
                return;
            }

            if (GUILayout.Button("Generate"))
            {
                /* INITIALIZE */

                GameObject go           = new GameObject("CameraHolder");
                Transform  cameraHolder = Instantiate(go.transform, source.transform);
                cameraHolder.name             = "CameraHolder";
                cameraHolder.localPosition    = new Vector3(0.22f, 2.11f, -1.5f);
                cameraHolder.localEulerAngles = new Vector3(15, 0, 0);

                Transform focusHolder = Instantiate(go.transform, source.transform);
                focusHolder.name             = "FocusHolder";
                focusHolder.localPosition    = new Vector3(0.22f, 1.961f, -0.909f);
                focusHolder.localEulerAngles = new Vector3(15, 0, 0);

                DestroyImmediate(go);

                anim.runtimeAnimatorController = (RuntimeAnimatorController)AssetDatabase.LoadAssetAtPath("Assets/PlayerAnimator.controller", typeof(RuntimeAnimatorController));
                anim.applyRootMotion           = true;
                source.AddComponent <SNet_Animator>();
                source.AddComponent <SNet_Rigidbody>();
                source.AddComponent <SNet_Transform>();
                source.AddComponent <IKFixer>();
                source.AddComponent <UserFallDamage>();
                source.AddComponent <RagdollHelper>();
                source.AddComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
                source.AddComponent <CapsuleCollider>();
                source.AddComponent <AnimEventReceiver>();
                source.layer = 8;

                /*ADD BONE DAMAGE MULTIPLIER*/
                Collider[] cldrs = source.transform.GetComponentsInChildren <Collider>(true);
                foreach (Collider c in cldrs)
                {
                    if (c.gameObject == source)
                    {
                        continue;
                    }

                    BoneDamageMultiplier bone = c.gameObject.AddComponent <BoneDamageMultiplier>();

                    if (anim.GetBoneTransform(HumanBodyBones.Head) == c.transform || anim.GetBoneTransform(HumanBodyBones.Neck) == c.transform)
                    {
                        bone.damageModifier = 2f; // For head shots
                    }
                }
            }
        }
    }