Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Photon.Pun;
- using Photon.Realtime;
- using Timer = UnityEngine.Time;
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- /// <summary>
- /// Plugin For PhotonPun 0.2
- /// </summary>
- public class Network
- {
- private static Network myClass;
- private float timer;
- /// <summary>
- /// Instance of Network class
- /// </summary>
- public static Network Get
- {
- get { return myClass ?? (myClass = new Network()); }
- }
- /// <summary>
- /// Destroy object in Network or offline mode
- /// </summary>
- /// <param name="Object"> GameObject requires PhotonView </param>
- /// <param name="Offline">Set this true, if code must run in offline</param>
- public static void Destroy(GameObject Object, bool Offline)
- {
- if (Object != null)
- {
- if (!IsOffline())
- {
- if (Object.GetPhotonView().IsMine)
- {
- PhotonNetwork.Destroy(Object);
- }
- else
- {
- Object.SetActive(false);
- }
- }
- else
- if (Offline)
- {
- {
- UnityEngine.Object.Destroy(Object);
- }
- }
- }
- }
- /// <summary>
- /// Destroy Timer Use StartCoroutine(Network.Get.Destroy());
- /// </summary>
- /// <param name="Object">GameObject requires PhotonView </param>
- /// <param name="Offline">Set this true, if code must run in offline</param>
- /// <param name="time"></param>
- /// <returns></returns>
- public IEnumerator Destroy(GameObject Object, bool Offline, float time)
- {
- yield return new WaitForSeconds(time);
- if (Object != null)
- {
- if (Object.activeInHierarchy)
- {
- Destroy(Object, Offline);
- }
- }
- }
- /// <summary>
- /// Instantiate in network or offline mode
- /// </summary>
- /// <param name="IsSceneObject">Set this to true if is not a Player and not spawned by Player</param>
- /// <param name="Object">The prefab must be in a folder called Resources. more information in doc photon pun</param>
- /// <param name="Position"></param>
- /// <param name="Rotation"></param>
- /// <returns></returns>
- public static GameObject Instantiate(bool IsSceneObject, GameObject Object, Vector3 Position, Quaternion Rotation)
- {
- if (!IsOffline())
- {
- if (IsSceneObject)
- {
- return PhotonNetwork.InstantiateSceneObject(Object.name, Position, Rotation);
- }
- else
- {
- return PhotonNetwork.Instantiate(Object.name, Position, Rotation);
- }
- }
- else
- {
- return UnityEngine.Object.Instantiate(Object, Position, Rotation);
- }
- }
- /// <summary>
- /// Instantiate in network or offline mode
- /// </summary>
- /// <param name="IsSceneObject">Set this to true if is not a Player and not spawned by Player</param>
- /// <param name="Object">The prefab must be in a folder called Resources. more information in doc photon pun</param>
- /// <param name="Position"></param>
- /// <param name="Rotation"></param>
- /// <param name="group"></param>
- /// <returns></returns>
- public static GameObject Instantiate(bool IsSceneObject, GameObject Object, Vector3 Position, Quaternion Rotation, byte group)
- {
- if (!IsOffline() && PhotonNetwork.InRoom)
- {
- if (IsSceneObject)
- {
- return PhotonNetwork.InstantiateSceneObject(Object.name, Position, Rotation, group);
- }
- else
- {
- return PhotonNetwork.Instantiate(Object.name, Position, Rotation, group);
- }
- }
- else
- {
- return UnityEngine.Object.Instantiate(Object, Position, Rotation);
- }
- }
- /// <summary>
- /// Instantiate in network or offline mode
- /// </summary>
- /// <param name="IsSceneObject">Set this to true if is not a Player and not spawned by Player</param>
- /// <param name="Object">The prefab must be in a folder called Resources. More information in doc photon pun</param>
- /// <param name="Position"></param>
- /// <param name="Rotation"></param>
- /// <param name="group"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public static GameObject Instantiate(bool IsSceneObject, GameObject Object, Vector3 Position, Quaternion Rotation, byte group, object[] data)
- {
- if (!IsOffline())
- {
- if (IsSceneObject)
- {
- return PhotonNetwork.InstantiateSceneObject(Object.name, Position, Rotation, group, data);
- }
- else
- {
- return PhotonNetwork.Instantiate(Object.name, Position, Rotation, group, data);
- }
- }
- else
- {
- return UnityEngine.Object.Instantiate(Object, Position, Rotation);
- }
- }
- /// <summary>
- /// return true if Is Connected,Ready and IsMine
- /// </summary>
- /// <param name="photonView"></param>
- /// <param name="Offline">Set this true, if code must run in offline</param>
- /// <returns></returns>
- public bool IsConnectedAndIsMine(PhotonView photonView, bool Offline)
- {
- if (!IsOffline())
- {
- if (photonView != null)
- {
- if (photonView.IsMine)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- Debug.LogWarning("PhotonView == null Return false");
- return false;
- }
- }
- else if (Offline)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool IsOffline()
- {
- return !PhotonNetwork.IsConnectedAndReady;
- }
- /// <summary>
- /// if is offlone return false
- /// </summary>
- public static bool IsMaster()
- {
- if (!IsOffline())
- {
- return PhotonNetwork.IsMasterClient;
- }
- else
- {
- return false;
- }
- }
- public void ChangeRegion(Region region)
- {
- if (region != Region.ind)
- {
- PhotonNetwork.ConnectToRegion(region.ToString());
- }
- else
- {
- PhotonNetwork.ConnectToRegion("in");
- }
- }
- public static readonly string[] RegionNames = new string[12]
- {
- //Region | Token
- "Asia",// asia
- "Australia",// au
- "Canada East",// cae
- "Europe",// eu
- "India",// ind
- "Japan",// jp
- "Russia",// ru
- "Russia East",// rue
- "South America",// sa
- "South Korea",// kr
- "USA East",// us
- "USA West"// usw
- };
- public enum Region
- {
- asia,
- au,
- cae,
- eu,
- ind,
- jp,
- ru,
- rue,
- sa,
- kr,
- us,
- usw,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement