// ------------------------------------------- /* * NetworkWorldObject * * @params _assignedName: It's the identification name of the variable * @params _indexPrefabObject: Position in the array * @params _initialPosition: Initial position of the object * @params _initialRotation: Initial rotation of the object * @params _initialScale: Initial scale of the object * @params _allowServerChange: We allow the server to change the variable * @params _allowClientChange: We allow the client to change the variable * @params _createInServer: We create the variable on the server or locally */ public NetworkWorldObject(string _assignedName, string _namePrefabObject, Vector3 _initialPosition, Vector3 _initialForward, Vector3 _initialScale, object _initialData, bool _allowServerChange, bool _allowClientChange, bool _createInServer) { m_assignedName = _assignedName; m_initialPosition = _initialPosition; m_initialForward = _initialForward; m_initialScale = _initialScale; m_initialData = _initialData; m_namePrefabObject = _namePrefabObject; m_allowServerChange = _allowServerChange; m_allowClientChange = _allowClientChange; NetworkEventController.Instance.NetworkEvent += new NetworkEventHandler(OnNetworkTypeEvent); if (CommunicationsController.Instance.IsServer) { // IS SERVER: CREATE THE OBJECT Debug.Log("**********NETWORK VARIABLE[" + m_assignedName + "," + m_namePrefabObject + "] REQUESTED BY SERVER"); NetworkEventController.Instance.DispatchLocalEvent(NetworkEventController.EVENT_COMMUNICATIONSCONTROLLER_REQUEST_TO_CREATE_NETWORK_OBJECT, NetworkEventController.CLASS_WORLDOBJECTCONTROLLER_NAME, NetworkEventController.REGISTER_PREFABS_OBJECTS, m_namePrefabObject, Vector3.zero, m_assignedName, m_allowServerChange, m_allowClientChange); } else { // IS CLIENT: THEN ASK THE SERVER TO CREATE THE OBJECT Debug.Log("++++++++++++++NETWORK CUBE REQUESTED BY CLIENT"); if (_createInServer == false) { Debug.Log("++++CREATE LOCALLY"); NetworkEventController.Instance.DispatchLocalEvent(NetworkEventController.EVENT_COMMUNICATIONSCONTROLLER_REQUEST_TO_CREATE_NETWORK_OBJECT, NetworkEventController.CLASS_WORLDOBJECTCONTROLLER_NAME, NetworkEventController.REGISTER_PREFABS_OBJECTS, m_namePrefabObject, Vector3.zero, m_assignedName, m_allowServerChange, m_allowClientChange); } else { Debug.Log("++++CREATE REMOTELLY"); string message = CommunicationsController.MessageCreateObject(CommunicationsController.Instance.NetworkID, NetworkEventController.CLASS_WORLDOBJECTCONTROLLER_NAME, NetworkEventController.REGISTER_PREFABS_OBJECTS, m_namePrefabObject, Vector3.zero, m_assignedName, m_allowServerChange, m_allowClientChange); NetworkEventController.Instance.DispatchLocalEvent(NetworkEventController.EVENT_COMMUNICATIONSCONTROLLER_SEND_MESSAGE_CLIENT_TO_SERVER, message); } } RegisterNewNetworkVariable(); }
// ------------------------------------------- /* * A client has been disconnected */ public void ClientDisconnected(int _idConnection) { if (RemoveConnection(_idConnection)) { string eventDisconnected = CommunicationsController.CreateJSONMessage(_idConnection, CommunicationsController.MESSAGE_TYPE_DISCONNECTION); Debug.Log(eventDisconnected); UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMAINCOMMANDCENTER_LIST_USERS, m_playersConnections); UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMAINCOMMANDCENTER_REGISTER_LOG, eventDisconnected); NetworkEventController.Instance.DispatchLocalEvent(NetworkEventController.EVENT_PLAYERCONNECTIONDATA_USER_DISCONNECTED, _idConnection); } }
// ------------------------------------------- /* * Destroy all references */ public void Destroy() { if (_instance != null) { if (m_clientInstalledApps != null) { m_clientInstalledApps.Destroy(); } NetworkEventController.Instance.NetworkEvent -= OnNetworkEvent; UIEventController.Instance.UIEvent -= OnUIEvent; Destroy(_instance.gameObject); _instance = null; } }
// ------------------------------------------- /* * New client has been connected */ public bool ClientNewConnection(int _idConnection) { PlayerConnectionData newPlayerConnection = new PlayerConnectionData(_idConnection, null); if (!m_playersConnections.Contains(newPlayerConnection)) { m_playersConnections.Add(newPlayerConnection); string eventConnected = CommunicationsController.CreateJSONMessage(_idConnection, CommunicationsController.MESSAGE_TYPE_NEW_CONNECTION); Debug.Log(eventConnected); UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMAINCOMMANDCENTER_LIST_USERS, m_playersConnections); UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMAINCOMMANDCENTER_REGISTER_LOG, eventConnected); return(true); } else { return(false); } }