//initialize variables IEnumerator Start() { //on non-mobile devices hide joystick controls, except in editor #if !UNITY_EDITOR && (UNITY_STANDALONE || UNITY_WEBGL) ToggleControls(false); #endif //on mobile devices enable additional aiming indicator #if !UNITY_EDITOR && !UNITY_STANDALONE && !UNITY_WEBGL if (aimIndicator != null) { Transform indicator = Instantiate(aimIndicator).transform; indicator.SetParent(GameManager.GetInstance().localPlayer.shotPos); indicator.localPosition = new Vector3(0f, 0f, 3f); } #endif //play background music AudioManager.PlayMusic(1); //don't continue Everyplay initialization on non-supported devices if (!UnityEveryplayManager.IsRecordingSupported()) { yield break; } //set thumbnail used by Everyplay to our image reference, start recording and //immediately take a snapshot to be displayed as thumbnail after a short delay //this is because Unity Everyplay seems to need some time to initialize properly UnityEveryplayManager.InitializeThumbnail(thumbnailImage); UnityEveryplayManager.StartRecord(); yield return(new WaitForSeconds(0.5f)); UnityEveryplayManager.TakeThumbnail(); }
/// <summary> /// Tries to display a video ad. This could fail if an ad is not available or ready, /// the player requesting the ad is hosting the game - in which case showing an ad would /// pause the game for all clients - an ad was already shown or the percentage based /// chance has calculated to not show an ad for this attempt. All these checks can be /// skipped by setting the argument passed in to true, effectively forcing an ad to show. /// </summary> public static bool ShowAd(bool force = false) { if (force || !GameManager.isMaster() && !adShown && GetInstance().shouldShowAd()) { if (Advertisement.IsReady()) { //this attempt should show an ad: initialize ad and pass the result to //the HandleResult method. Stop recording gameplay video while showing an ad Advertisement.Show("", new ShowOptions { resultCallback = GetInstance().HandleResult }); UnityEveryplayManager.PauseRecord(); return(true); } } //at this point we were not able to show an ad yet. //if this ad attempt has not been forced, increase attempt counter //so the next attempt has a higher probability of showing an ad if (!force) { counter++; } return(false); }
//initialize variables IEnumerator Start() { if (PlayerPrefs.HasKey(PrefsKeys.cameradistance) || PlayerPrefs.HasKey(PrefsKeys.cameraheight)) { OnCameraHeightChanged(PlayerPrefs.GetFloat(PrefsKeys.cameraheight)); OnCameraDistanceChanged(PlayerPrefs.GetFloat(PrefsKeys.cameradistance)); } else { OnCameraHeightChanged(camera.height); OnCameraDistanceChanged(camera.distance); } //get music and effect musicToggle.isOn = bool.Parse(PlayerPrefs.GetString(PrefsKeys.playMusic)); volumeSlider.value = PlayerPrefs.GetFloat(PrefsKeys.appVolume); OnMusicChanged(musicToggle.isOn); OnVolumeChanged(volumeSlider.value); BotSpawner.ChangElement.AddListener(ChangElement); BotSpawner.OnupStatusplayer.AddListener(ButtonStatusOn); TimeWave_S.maxValue = botspawn.TimeWave; LevelWave_S.maxValue = 25; //on non-mobile devices hide joystick controls, except in editor #if !UNITY_EDITOR && (UNITY_STANDALONE || UNITY_WEBGL) ToggleControls(false); #endif //on mobile devices enable additional aiming indicator // #if !UNITY_EDITOR && !UNITY_STANDALONE && !UNITY_WEBGL****************************** // if (aimIndicator != null) // { // Transform indicator = Instantiate(aimIndicator).transform; // indicator.SetParent(GameManager.GetInstance().localPlayer.shotPos); // indicator.localPosition = new Vector3(0f, 0f, 3f); // } // #endif //play background music AudioManager.PlayMusic(1); //don't continue Everyplay initialization on non-supported devices if (!UnityEveryplayManager.IsRecordingSupported()) { yield break; } //set thumbnail used by Everyplay to our image reference, start recording and //immediately take a snapshot to be displayed as thumbnail after a short delay //this is because Unity Everyplay seems to need some time to initialize properly UnityEveryplayManager.InitializeThumbnail(thumbnailImage); UnityEveryplayManager.StartRecord(); yield return(new WaitForSeconds(0.5f)); UnityEveryplayManager.TakeThumbnail(); }
//how many times the shop has been opened //private int shopOpened = 0; //how many times the settings have been opened //private int settingsOpened = 0; //initialize player selection in Settings window //if this is the first time launching the game, set initial values void Start() { //set initial values for all settings if (!PlayerPrefs.HasKey(PrefsKeys.playerName)) { PlayerPrefs.SetString(PrefsKeys.playerName, "User" + System.String.Format("{0:0000}", Random.Range(1, 9999))); } if (!PlayerPrefs.HasKey(PrefsKeys.networkMode)) { PlayerPrefs.SetInt(PrefsKeys.networkMode, 0); } if (!PlayerPrefs.HasKey(PrefsKeys.serverAddress)) { PlayerPrefs.SetString(PrefsKeys.serverAddress, "127.0.0.1"); } if (!PlayerPrefs.HasKey(PrefsKeys.playMusic)) { PlayerPrefs.SetString(PrefsKeys.playMusic, "true"); } if (!PlayerPrefs.HasKey(PrefsKeys.appVolume)) { PlayerPrefs.SetFloat(PrefsKeys.appVolume, 1f); } if (!PlayerPrefs.HasKey(PrefsKeys.recordGame)) { PlayerPrefs.SetString(PrefsKeys.recordGame, "true"); } if (!PlayerPrefs.HasKey(PrefsKeys.activeTank)) { PlayerPrefs.SetString(PrefsKeys.activeTank, Encryptor.Encrypt("0")); } PlayerPrefs.Save(); //read the selections and set them in the corresponding UI elements nameField.text = PlayerPrefs.GetString(PrefsKeys.playerName); networkDrop.value = PlayerPrefs.GetInt(PrefsKeys.networkMode); serverField.text = PlayerPrefs.GetString(PrefsKeys.serverAddress); musicToggle.isOn = bool.Parse(PlayerPrefs.GetString(PrefsKeys.playMusic)); volumeSlider.value = PlayerPrefs.GetFloat(PrefsKeys.appVolume); recordToggle.isOn = bool.Parse(PlayerPrefs.GetString(PrefsKeys.recordGame)); //call the onValueChanged callbacks once with their saved values OnMusicChanged(musicToggle.isOn); OnVolumeChanged(volumeSlider.value); //listen to network connection and IAP billing errors NetworkManagerCustom.connectionFailedEvent += OnConnectionError; UnityIAPManager.purchaseFailedEvent += OnBillingError; //add Everyplay callback in case it changes later on, //but also call it immediately right when its initialization finishes UnityEveryplayManager.recordingSupportedEvent += OnEveryplaySupport; OnEveryplaySupport(UnityEveryplayManager.IsSupported()); }
protected virtual void RpcRespawn() { //toggle visibility for player gameobject (on/off) gameObject.SetActive(!gameObject.activeInHierarchy); bool isActive = gameObject.activeInHierarchy; //the player has been killed if (!isActive) { //detect whether the current user was responsible for the kill //yes, that's my kill: take thumbnail via EveryPlay if (killedBy == GameManager.GetInstance().localPlayer.gameObject) { UnityEveryplayManager.TakeThumbnail(); } if (explosionFX) { //spawn death particles locally using pooling and colorize them in the player's team color GameObject particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation); ParticleColor pColor = particle.GetComponent <ParticleColor>(); if (pColor) { pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color); } } //play sound clip on player death if (explosionClip) { AudioManager.Play3D(explosionClip, transform.position); } } //further changes only affect the local client if (!photonView.isMine) { return; } //local player got respawned so reset states if (isActive == true) { ResetPosition(); } else { //local player was killed, set camera to follow the killer camFollow.target = killedBy.transform; //hide input controls and other HUD elements camFollow.HideMask(true); //display respawn window (only for local player) GameManager.GetInstance().DisplayDeath(); } }
/// <summary> /// Displays the game's end screen. Called by GameManager after few seconds delay. /// Stops Everplay recording and tries to display a video ad, if not shown already. /// </summary> public void ShowGameOver() { UnityEveryplayManager.StopRecord(); //hide text but enable game over window gameOverText.gameObject.SetActive(false); gameOverMenu.SetActive(true); //check whether an ad was shown during the game //if no ad was shown during the whole round, we request one here // #if UNITY_ADS****************************** // if(!UnityAdsManager.didShowAd()) // UnityAdsManager.ShowAd(true); // #endif }
//called by Unity Ads on completed video views private void HandleResult(ShowResult result) { //if the result is finished or skipped, //the ad was actually shown during the game // switch(result)***************************** // { // case ShowResult.Finished: // case ShowResult.Skipped: // adShown = true; // break; // } //pass result to listeners // if(adResultEvent != null)************************* // adResultEvent(result); //resume gameplay recording after displaying ad UnityEveryplayManager.ResumeRecord(); }
/// <summary> /// Shares the recorded gameplay video using Everyplay's sharing dialog. /// </summary> public void Share() { UnityEveryplayManager.Share(); }
/// <summary> /// Displays the Everyplay community hub using our manager. /// </summary> public void ShowEveryplay() { UnityEveryplayManager.ShowMenu(); }