예제 #1
0
        public void ClientShoot(StateManager states, Vector3 dir, Vector3 origin)
        {
            Ray ray = new Ray(origin, dir);

            Debug.DrawLine(origin, dir);
            RaycastHit[] hits;

            hits = Physics.RaycastAll(origin, dir, 100);
            if (hits == null)
            {
                return;
            }
            if (hits.Length == 0)
            {
                return;
            }

            RaycastHit closestHit;

            closestHit = GetClosestHit(origin, hits, states.photonId);

            IHittable isHittable = closestHit.transform.GetComponentInParent <IHittable>();

            if (isHittable == null)
            {
                GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("Bullet_Impact_FX");
                Quaternion rot         = Quaternion.LookRotation(-dir);
                hitParticle.transform.position = closestHit.point;
                hitParticle.transform.rotation = rot;
            }
            else
            {
                isHittable.OnHit(states, states.inventory.currentWeapon, dir, closestHit.point);
            }
        }
        public void CreateRoom(RoomButton b)
        {
            if (isMultiplayer.value)
            {
                if (!isConnected.value)
                {
                    // Cannot connect to server but tried to acces multiplayer
                }
                else
                {
                    RoomOptions roomOptions = new RoomOptions();
                    roomOptions.MaxPlayers = 4;

                    ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable
                    {
                        { "scene", b.scene }
                    };

                    roomOptions.CustomRoomPropertiesForLobby = new string[] { "scene" };
                    roomOptions.CustomRoomProperties         = properties;

                    PhotonNetwork.CreateRoom(null, roomOptions, TypedLobby.Default);
                }
            }
            else
            {
                //This will be single player
                Room r = ScriptableObject.CreateInstance <Room>();
                r.sceneName = b.scene;
                GameManagers.GetResourcesManager().currentRoom.Set(r);
            }
        }
        public void OnHit(StateManager shooter, Weapon w, Vector3 dir, Vector3 pos)
        {
            if (shooter == this)
            {
                return;
            }

            Debug.Log("Player has been hit by: " + shooter.photonId);
            GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("BloodSplat_FX");
            Quaternion rot         = Quaternion.LookRotation(-dir);

            hitParticle.transform.position = pos;
            hitParticle.transform.rotation = rot;

            if (Photon.Pun.PhotonNetwork.IsMasterClient)
            {
                if (!isDead)
                {
                    stats.health -= w.ammoType.damageValue;
                    MultiplayerManager mm = MultiplayerManager.singleton;
                    mm.BroadcastPlayerHealth(photonId, stats.health, shooter.photonId);

                    if (stats.health <= 0)
                    {
                        Debug.Log("Player: " + this.photonId + " has been killed by: " + shooter.photonId);
                        isDead = true;
                    }
                }
            }
        }
        public void LoadCharacterModelFromProfile()
        {
            PlayerProfile profile = GameManagers.GetProfile();

            Debug.Log("LoadCharacterModelFromProfile called: " + profile.modelId);
            LoadCharacterModel(profile.modelId);
        }
        public void OnHit(StateManager shooter, Weapon w, Vector3 dir, Vector3 pos)
        {
            GameObject hitParticle = GameManagers.GetObjectPool().RequestObject(targetParticle);
            Quaternion rot         = Quaternion.LookRotation(-dir);

            hitParticle.transform.position = pos;
            hitParticle.transform.rotation = rot;
        }
        public void Init()
        {
            runtime = new RuntimeWeapon();
            runtime.modelInstance = Instantiate(modelPrefab) as GameObject;
            runtime.weaponHook    = runtime.modelInstance.GetComponent <WeaponHook>();
            runtime.weaponHook.Init();

            ammoType = GameManagers.GetAmmoPool().GetAmmo(ammoType.name);
        }
        public void LoadCurrentSceneActual(OnSceneLoaded callback = null)
        {
            Room r = GameManagers.GetResourcesManager().currentRoom.value;

            if (!isLoading)
            {
                isLoading = true;
                StartCoroutine(LoadScene(r.sceneName, callback));
            }
        }
        public void LoadCharacterModel(string modelId)
        {
            ClothItem c = GameManagers.GetResourcesManager().GetClothItem(modelId);

            if (characterHook == null)
            {
                InitReferences();
            }
            characterHook.Init(c);
        }
        private void InstantiateNetworkPrint()
        {
            PlayerProfile profile = GameManagers.GetProfile();

            //Size is based on player profile size
            object[] data = new object[2];
            //0 index used for profile as the first item is gun
            data[0] = profile.itemIds[0];
            data[1] = profile.modelId;
            Debug.Log("(2) MultiplayerManager: InstantiateNetworkPrint called");
            GameObject go = PhotonNetwork.Instantiate("NetworkPrint", Vector3.zero, Quaternion.identity, 0, data) as GameObject;
        }
        private void OnEnable()
        {
            camera.position = cameraPositions[0].position;
            camera.rotation = cameraPositions[0].rotation;
            currentCat      = CategorySelection.none;

            clothes = GameManagers.GetResourcesManager().GetAllClothItems();
            weapons = GameManagers.GetResourcesManager().GetAllWeapons();

            string modelId         = GameManagers.GetProfile().modelId;
            string primaryWeapon   = GameManagers.GetProfile().itemIds[0];
            string secondaryWeapon = GameManagers.GetProfile().itemIds[1];

            for (int i = 0; i < clothes.Count; i++)
            {
                if (string.Equals(clothes[i].name, modelId))
                {
                    clothIndex = i;
                    break;
                }
            }

            for (int i = 0; i < weapons.Count; i++)
            {
                if (string.Equals(weapons[i].name, primaryWeapon))
                {
                    primaryWeaponIndex = i;
                    break;
                }

                if (string.Equals(weapons[i].name, secondaryWeapon))
                {
                    secondaryWeaponIndex = i;
                    break;
                }
            }

            offlineState.LoadCharacterModel(clothes[clothIndex].name);

            if (primaryWeaponObject != null)
            {
                Destroy(primaryWeaponObject);
            }
            primaryWeaponObject = CreateWeapon(weapons[primaryWeaponIndex], primaryWeaponParent);

            if (secondaryWeaponObject != null)
            {
                Destroy(secondaryWeaponObject);
            }
            secondaryWeaponObject = CreateWeapon(weapons[secondaryWeaponIndex], secondaryWeaponParent);
        }
        public override void OnCreatedRoom()
        {
            Room   r = ScriptableObject.CreateInstance <Room>();
            object sceneName;

            PhotonNetwork.CurrentRoom.CustomProperties.TryGetValue("scene", out sceneName);
            r.sceneName = (string)sceneName;
            r.roomName  = PhotonNetwork.CurrentRoom.Name;
            Debug.Log("Roomname: " + r.roomName + " PhotonNetworkCurrentRoomName: " + PhotonNetwork.CurrentRoom.Name);
            Debug.Log("Scenename: " + r.sceneName);

            GameManagers.GetResourcesManager().currentRoom.value = r;
            Debug.Log("OnCreatedRoom");
        }
예제 #12
0
        public override void Execute(StateManager states, Weapon w)
        {
            Vector3 origin = w.runtime.modelInstance.transform.position;
            Vector3 dir    = states.movementValues.aimPosition - origin;


            Ray ray = new Ray(origin, dir);

            Debug.DrawLine(origin, dir);
            RaycastHit[] hits;

            hits = Physics.RaycastAll(origin, dir, 100);
            if (hits == null)
            {
                return;
            }
            if (hits.Length == 0)
            {
                return;
            }

            RaycastHit closestHit;

            closestHit = GetClosestHit(origin, hits, states.photonId);

            IHittable isHittable = closestHit.transform.GetComponentInParent <IHittable>();

            if (isHittable == null)
            {
                Debug.Log("isHittable was null");
                GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("Bullet_Impact_FX");
                Quaternion rot         = Quaternion.LookRotation(-dir);
                hitParticle.transform.position = closestHit.point;
                hitParticle.transform.rotation = rot;
            }
            else
            {
                Debug.Log("The object hit is: " + closestHit);
                isHittable.OnHit(states, w, dir, closestHit.point);
            }



            MultiplayerManager mm = MultiplayerManager.singleton;

            if (mm != null)
            {
                mm.BroadcastShootWeapon(states, dir, origin);
            }
        }
 //Gets called by an event
 public void LoadCurrentRoom()
 {
     Debug.Log("(7) Multiplayer Launcher: LoadCurrentRoom called");
     if (isConnected)
     {
         MultiplayerManager.singleton.BroadcastSceneChange();
     }
     else
     {
         Room r = GameManagers.GetResourcesManager().currentRoom.value;
         if (!isLoading)
         {
             isLoading = true;
             StartCoroutine(LoadScene(r.sceneName));
         }
     }
 }
예제 #14
0
        public override void Execute(StateManager states)
        {
            ResourcesManager resourcesManager = GameManagers.GetResourcesManager();

            Weapon targetWeapon = (Weapon)resourcesManager.GetItemInstance(states.inventory.weaponID);

            states.inventory.currentWeapon = targetWeapon;
            targetWeapon.Init();

            Transform rightHand = states.anim.GetBoneTransform(HumanBodyBones.RightHand);

            targetWeapon.runtime.modelInstance.transform.parent           = rightHand;
            targetWeapon.runtime.modelInstance.transform.localScale       = (Vector3.one * 100);
            targetWeapon.runtime.modelInstance.transform.localPosition    = Vector3.zero;
            targetWeapon.runtime.modelInstance.transform.localEulerAngles = Vector3.zero;


            states.animHook.LoadWeapon(targetWeapon);
        }
        public void PreviousOrNextItem(bool prev)
        {
            int modifier = (prev) ? -1 : 1;

            switch (currentCat)
            {
            case CategorySelection.none:
                break;

            case CategorySelection.clothes:
                clothIndex += modifier;
                if (clothIndex > clothes.Count - 1)
                {
                    clothIndex = 0;
                }
                if (clothIndex < 0)
                {
                    clothIndex = clothes.Count - 1;
                }
                GameManagers.GetProfile().modelId = clothes[clothIndex].name;
                offlineState.LoadCharacterModel(clothes[clothIndex].name);
                break;

            case CategorySelection.primaryWeapon:
                primaryWeaponIndex += modifier;
                if (primaryWeaponIndex > weapons.Count - 1)
                {
                    primaryWeaponIndex = 0;
                }
                if (primaryWeaponIndex < 0)
                {
                    primaryWeaponIndex = weapons.Count - 1;
                }
                GameManagers.GetProfile().itemIds[0] = weapons[primaryWeaponIndex].name;

                if (primaryWeaponObject != null)
                {
                    Destroy(primaryWeaponObject);
                }
                primaryWeaponObject = CreateWeapon(weapons[primaryWeaponIndex], primaryWeaponParent);

                break;

            case CategorySelection.secondaryWeapon:
                secondaryWeaponIndex += modifier;
                if (secondaryWeaponIndex > weapons.Count - 1)
                {
                    secondaryWeaponIndex = 0;
                }
                if (secondaryWeaponIndex < 0)
                {
                    secondaryWeaponIndex = weapons.Count - 1;
                }

                if (secondaryWeaponObject != null)
                {
                    Destroy(secondaryWeaponObject);
                }
                secondaryWeaponObject = CreateWeapon(weapons[secondaryWeaponIndex], secondaryWeaponParent);

                GameManagers.GetProfile().itemIds[1] = weapons[secondaryWeaponIndex].name;
                break;

            default:
                break;
            }
        }
 public void OnClick()
 {
     GameManagers.GetResourcesManager().currentRoom.SetRoomButton(this);
 }