/// <summary> /// Try to connect once to the setting server. /// </summary> /// <param name="hostname"> Internet Protocal </param> /// <param name="port"> Port Number </param> public void Connect(string hostname, int port) { try { // Close the socket if it is still open if (mSocket != null && mSocket.Connected) { mSocket.Shutdown(SocketShutdown.Both); System.Threading.Thread.Sleep(10); mSocket.Close(); } // Create the socket object mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Define the Server address and port IPEndPoint epServer = new IPEndPoint(IPAddress.Parse(hostname), port); // Connect to server non-Blocking method mSocket.Blocking = false; AsyncCallback onconnect = new AsyncCallback(OnConnect); mSocket.BeginConnect(epServer, onconnect, mSocket); // set receive callback SetupRecieveCallback(mSocket); } catch (Exception ex) { Debug.LogError("Server Connect failed: " + ex.Message); JCS_UtilityFunctions.PopIsConnectDialogue(); } }
/// <summary> /// Do ping pong packet action. /// </summary> /// <returns>true : connect, false: disconnect</returns> public void CheckConnectionWithTime() { // do the following script only when is online mode if (!JCS_NetworkSettings.instance.ONLINE_MODE) { return; } mConnectionCounter += Time.deltaTime; if (mConnectionCounter < JCS_NetworkConstant.CONNECT_TIME) { return; } else { if (SERVER_CLOSE) { Debug.Log("Server End!"); JCS_UtilityFunctions.PopIsConnectDialogue(); } else if (FIRST_LOGIN) { FIRST_LOGIN = false; JCS_PatchManager.instance.LoadNextLevel(); } mConnectionCounter = 0; } }
/* Functions */ private void Awake() { instance = this; switch (mSwitchSceneType) { case JCS_SwitchSceneType.BLACK_SCREEN: { JCS_UtilityFunctions.PopJCSBlackScreen(); } break; case JCS_SwitchSceneType.SLIDE_SCREEN: { JCS_UtilityFunctions.PopJCSBlackSlideScreen(); } break; } // Pop white screen depends on game needs. if (mPopWhiteScreen) { JCS_UtilityFunctions.PopJCSWhiteScreen(); } #if (UNITY_EDITOR) // add the tool in editor mode. this.gameObject.AddComponent <ReadSceneNames>(); #endif }
public override void JCS_OnClickCallback() { JCS_UtilityFunctions.ToOfficailWebpage(); JCS_UtilityFunctions.DestoryCurrentDialogue(JCS_DialogueType.SYSTEM_DIALOGUE); JCS_UtilityFunctions.QuitApplication(); }
/// <summary> /// Take a snapshot and store image to data path. /// </summary> public string TakeSnapshotWebcam() { // No device detected!! // cannot take snap shot without the device!! if (!mDetectDevice) { JCS_Debug.LogError("No webcam detected in the current devices"); return null; } var gs = JCS_GameSettings.instance; var prefix = gs.WEBCAM_FILENAME; var ext = gs.WEBCAM_EXTENSION; string savePath = SavePath(); JCS_IO.CreateDirectory(savePath); Texture2D snap = new Texture2D(mWebCamTexture.width, mWebCamTexture.height); snap.SetPixels(mWebCamTexture.GetPixels()); snap.Apply(); // get the last saved webcam image's index int last_saved_index = LastImageFileIndex() + 1; string fullPath = ImagePathByIndex(last_saved_index); File.WriteAllBytes(fullPath, snap.EncodeToPNG()); if (mSplash) { JCS_SceneManager sm = JCS_SceneManager.instance; if (sm.GetWhiteScreen() == null) JCS_UtilityFunctions.PopJCSWhiteScreen(); sm.GetWhiteScreen().FadeIn(); // do the snap shot effect mSplashEffectTrigger = true; } // Stop the camera mWebCamTexture.Pause(); // start the timer wait for resume mResumeTrigger = true; // play sound. { var soundm = JCS_SoundManager.instance; JCS_SoundPlayer sp = soundm.GetGlobalSoundPlayer(); sp.PlayOneShot(mTakePhotoSound); } return fullPath; }
/// <summary> /// /// </summary> public void TakeSnapshotWebcam() { // No device detected!! // cannot take snap shot without the device!! if (!mDetectDevice) { JCS_Debug.LogError("JCS_Webcam", "No webcam detected in the current devices."); return; } string fullPath = Application.dataPath + mSavePath; // if Directory does not exits, create it prevent error! if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } Texture2D snap = new Texture2D(mWebCamTexture.width, mWebCamTexture.height); snap.SetPixels(mWebCamTexture.GetPixels()); snap.Apply(); System.IO.File.WriteAllBytes(fullPath + mCaptureCounter.ToString() + ".png", snap.EncodeToPNG()); ++mCaptureCounter; if (mSplash) { JCS_SceneManager sm = JCS_SceneManager.instance; if (sm.GetJCSWhiteScreen() == null) { JCS_UtilityFunctions.PopJCSWhiteScreen(); } sm.GetJCSWhiteScreen().FadeIn(); // do the snap shot effect mSplashEffectTrigger = true; } // Stop the camera mWebCamTexture.Stop(); // start the timer wait for resume mResumeTrigger = true; // play sound. mSoundPlayer.PlayOneShot(mTakePhotoSound); }
private void Update() { #if (UNITY_EDITOR) Test(); #endif #if (UNITY_EDITOR || UNITY_STANDALONE) // Exit in game diagloue not in game UI!! // (Admin input) if (Input.GetKeyDown(KeyCode.Escape)) { JCS_UtilityFunctions.DestoryCurrentDialogue(JCS_DialogueType.PLAYER_DIALOGUE); } #endif }
public override void JCS_OnClickCallback() { JCS_UtilityFunctions.DestoryCurrentDialogue(JCS_DialogueType.PLAYER_DIALOGUE); }