Skip to content

Commit 974bd9c

Browse files
committed
Scripts Update 3
1 parent 9d3219a commit 974bd9c

File tree

5 files changed

+444
-0
lines changed

5 files changed

+444
-0
lines changed

CameraShake.cs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Cinemachine;
5+
using UnityEngine.Rendering;
6+
7+
public class CameraShake : MonoBehaviour
8+
{
9+
CinemachineVirtualCamera cam;
10+
public Volume vignette;
11+
public Animation pulsating;
12+
float shakeTimer;
13+
void Start()
14+
{
15+
cam = GetComponent<CinemachineVirtualCamera>();
16+
}
17+
18+
19+
public void IntCS(float intensity, float timer)
20+
{
21+
CinemachineBasicMultiChannelPerlin CBMP =
22+
cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
23+
CBMP.m_AmplitudeGain = intensity;
24+
shakeTimer = timer;
25+
}
26+
27+
public void VignetteActivation(bool trigger)
28+
{
29+
if(trigger)
30+
{
31+
vignette.enabled = true;
32+
pulsating.Play();
33+
}
34+
else
35+
{
36+
vignette.enabled = false;
37+
pulsating.Stop();
38+
}
39+
}
40+
41+
42+
43+
private void Update()
44+
{
45+
if(shakeTimer > 0)
46+
{
47+
shakeTimer -= Time.deltaTime;
48+
}
49+
else if (shakeTimer <= 0)
50+
{
51+
CinemachineBasicMultiChannelPerlin CBMP =
52+
cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
53+
CBMP.m_AmplitudeGain = 0;
54+
this.transform.localRotation = Quaternion.Euler(0, 0, 0);
55+
}
56+
}
57+
}
+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Photon.Pun;
5+
using Photon.Realtime;
6+
using System.IO;
7+
8+
public class NetwookPooling :MonoBehaviourPun, IPunObservable
9+
{
10+
public static NetwookPooling Instance;
11+
12+
PhotonView PV;
13+
14+
[System.Serializable]
15+
public class Pool
16+
{
17+
public string tag;
18+
public string prefabName;
19+
public int size;
20+
}
21+
public List<Pool> pools;
22+
23+
public Dictionary<string, Queue<GameObject>> poolDictionary;
24+
25+
26+
27+
// Start is called before the first frame update
28+
void Start()
29+
{
30+
PV = GetComponent<PhotonView>();
31+
32+
33+
if (PV.IsMine)
34+
{
35+
if (PhotonNetwork.IsMasterClient)
36+
{
37+
poolDictionary = new Dictionary<string, Queue<GameObject>>();
38+
39+
foreach (Pool pool in pools)
40+
{
41+
Queue<GameObject> objectpool = new Queue<GameObject>();
42+
43+
for (int i = 0; i < pool.size; i++)
44+
{
45+
GameObject obj = PhotonNetwork.InstantiateRoomObject(Path.Combine("PhotonPrefabs", pool.prefabName), transform.position,
46+
transform.rotation, 0);
47+
obj.SetActive(false);
48+
objectpool.Enqueue(obj);
49+
}
50+
51+
poolDictionary.Add(pool.tag, objectpool);
52+
53+
}
54+
55+
}
56+
57+
}
58+
59+
}
60+
61+
[PunRPC]
62+
public void CreatePools()
63+
{
64+
65+
poolDictionary = new Dictionary<string, Queue<GameObject>>();
66+
67+
foreach (Pool pool in pools)
68+
{
69+
Queue<GameObject> objectpool = new Queue<GameObject>();
70+
if (PhotonNetwork.IsMasterClient)
71+
{
72+
for (int i = 0; i < pool.size; i++)
73+
{
74+
GameObject obj = PhotonNetwork.InstantiateRoomObject(Path.Combine("PhotonPrefabs", pool.prefabName), transform.position,
75+
transform.rotation, 0);
76+
obj.SetActive(false);
77+
objectpool.Enqueue(obj);
78+
}
79+
80+
81+
82+
}
83+
poolDictionary.Add(pool.tag, objectpool);
84+
}
85+
86+
}
87+
public void InstantiateFromPool(string tag, Vector3 Position, Quaternion rotation, bool activate, Transform spawner, float force)
88+
{
89+
if (!poolDictionary.ContainsKey(tag))
90+
{
91+
Debug.Log("Pool with tag" + tag + " doesn't excist.");
92+
return;
93+
}
94+
95+
96+
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
97+
98+
objectToSpawn.SetActive(true);
99+
objectToSpawn.transform.position = Position;
100+
objectToSpawn.transform.rotation = rotation;
101+
if(activate)
102+
{
103+
Rigidbody2D rb = objectToSpawn.GetComponent<Rigidbody2D>();
104+
rb.AddForce(spawner.up * force, ForceMode2D.Impulse);
105+
}
106+
107+
//poolDictionary[tag].Enqueue(objectToSpawn);
108+
}
109+
110+
public void DestroyToPool(string tag, GameObject objToDestroy)
111+
{
112+
if (!poolDictionary.ContainsKey(tag))
113+
{
114+
Debug.Log("Pool with tag" + tag + " doesn't excist.");
115+
return;
116+
}
117+
118+
119+
poolDictionary[tag].Enqueue(objToDestroy);
120+
121+
objToDestroy.SetActive(false);
122+
Rigidbody2D rb = objToDestroy.GetComponent<Rigidbody2D>();
123+
rb.Sleep();
124+
// objectToSpawn.transform.position = Position;
125+
// objectToSpawn.transform.rotation = rotation;
126+
127+
}
128+
129+
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
130+
{
131+
if(stream.IsWriting)
132+
{
133+
//stream.SendNext(poolDictionary);
134+
}
135+
else
136+
{
137+
// poolDictionary = (Dictionary<string, Queue<GameObject>>)stream.ReceiveNext();
138+
}
139+
}
140+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Photon.Pun;
5+
using Photon.Realtime;
6+
7+
8+
public class NeworkObservable : MonoBehaviourPun, IPunObservable
9+
{
10+
public NetworkWeaponManager NWM;
11+
public NetworkShooting[] NS;
12+
WeaponState state;
13+
14+
private void Start()
15+
{
16+
NWM = GetComponent<NetworkWeaponManager>();
17+
state = NWM.state;
18+
}
19+
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
20+
{
21+
if(stream.IsWriting)
22+
{
23+
stream.SendNext(NWM.state);
24+
}
25+
else
26+
{
27+
state = (WeaponState)stream.ReceiveNext();
28+
NWM.state = state;
29+
}
30+
}
31+
32+
33+
}
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Photon.Pun;
5+
using Photon.Realtime;
6+
using UnityEngine.UI;
7+
8+
public class PhotonLobby : MonoBehaviourPunCallbacks
9+
{
10+
public static PhotonLobby lobby;
11+
12+
public Text status;
13+
public GameObject battleButtom;
14+
public GameObject cancleButton;
15+
16+
private void Awake()
17+
{
18+
lobby = this;
19+
}
20+
// Start is called before the first frame update
21+
void Start()
22+
{
23+
PhotonNetwork.ConnectUsingSettings();//connects to master photon server
24+
}
25+
26+
public override void OnConnectedToMaster()
27+
{
28+
status.text = "Connected";
29+
status.color = Color.green;
30+
31+
32+
PhotonNetwork.JoinLobby();
33+
battleButtom.SetActive(true);
34+
}
35+
36+
public override void OnJoinedLobby()
37+
{
38+
status.text = "Lobby joined";
39+
PhotonNetwork.AutomaticallySyncScene = true;
40+
}
41+
42+
public void OnBattleButtonClick()
43+
{
44+
PhotonNetwork.JoinRandomRoom();
45+
status.text = "Searching for Room";
46+
battleButtom.SetActive(false);
47+
cancleButton.SetActive(true);
48+
}
49+
50+
public override void OnJoinRandomFailed(short returnCode, string message)
51+
{
52+
status.text = "Tried to join Room but failed";
53+
CreateRoom();
54+
55+
}
56+
57+
void CreateRoom()
58+
{
59+
status.text = "Room Created";
60+
int randomRoomNumber = Random.Range(1, 10000);
61+
RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)MultiplayerSettings.multiplayerSettings.maxPlayers };
62+
PhotonNetwork.CreateRoom("Room" + randomRoomNumber, roomOps);
63+
}
64+
65+
public override void OnCreateRoomFailed(short returnCode, string message)
66+
{
67+
status.text = "Tried Creating Room but failed";
68+
CreateRoom();
69+
}
70+
public void OnCancledButtonClicked()
71+
{
72+
battleButtom.SetActive(true);
73+
cancleButton.SetActive(false);
74+
PhotonNetwork.LeaveRoom();
75+
76+
}
77+
78+
79+
}

0 commit comments

Comments
 (0)