public static void PlayVoice(AudioClip clip, bool loop = false, System.Action onBeganCallback = null, System.Action onEndedCallback = null) { var audioMgr = AudioManager.Instance; audioMgr.CurrentVoiceName = "voice" + clip.GetHashCode(); if (!Settings.IsVoiceOn.Value) { return; } VoicePlayer.SetOnStartListener(musicUnit => { onBeganCallback.InvokeGracefully(); VoicePlayer.SetOnStartListener(null); }); VoicePlayer.SetAudioExt(AudioManager.Instance.gameObject, clip, audioMgr.CurrentVoiceName, loop); VoicePlayer.SetOnFinishListener(musicUnit => { onEndedCallback.InvokeGracefully(); VoicePlayer.SetOnFinishListener(null); }); }
public override void OnGUI() { if (Visible && GUILayout.Button(mText, mLayoutOptions.ToArray())) { mOnClickAction.InvokeGracefully(); } }
/// <summary> /// 播放背景音乐 /// </summary> /// <param name="musicName"></param> /// <param name="onBeganCallback"></param> /// <param name="onEndCallback"></param> /// <param name="loop"></param> /// <param name="allowMusicOff"></param> /// <param name="volume"></param> public static void PlayMusic(string musicName, bool loop = true, System.Action onBeganCallback = null, System.Action onEndCallback = null, bool allowMusicOff = true, float volume = -1f) { var audioMgr = AudioManager.Instance; audioMgr.CurrentMusicName = musicName; if (!Settings.IsMusicOn.Value && allowMusicOff) { onBeganCallback.InvokeGracefully(); onEndCallback.InvokeGracefully(); return; } Log.I(">>>>>> Start Play Music"); // TODO: 需要按照这个顺序去 之后查一下原因 // 需要先注册事件,然后再play MusicPlayer.SetOnStartListener(musicUnit => { onBeganCallback.InvokeGracefully(); if (volume < 0) { MusicPlayer.SetVolume(Settings.MusicVolume.Value); } else { MusicPlayer.SetVolume(volume); } // 调用完就置为null,否则应用层每注册一个而没有注销,都会调用 MusicPlayer.SetOnStartListener(null); }); MusicPlayer.SetAudio(audioMgr.gameObject, musicName, loop); MusicPlayer.SetOnFinishListener(musicUnit => { onEndCallback.InvokeGracefully(); // 调用完就置为null,否则应用层每注册一个而没有注销,都会调用 MusicPlayer.SetOnFinishListener(null); }); }
public static IEnumerator DoRegister(string username, string password, string email, System.Action succeed) { var loginPage = UnityWebRequest.Get(LOGIN_URL); Debug.Log(username + ":" + password + ":" + email); yield return(loginPage.Send()); #if UNITY_2017_1_OR_NEWER if (loginPage.isNetworkError) #else if (loginPage.isError) #endif { Debug.Log(loginPage.error); yield break; } // get the csrf cookie var SetCookie = loginPage.GetResponseHeader("set-cookie"); var rxCookie = new Regex("csrftoken=(?<csrf_token>.{64});"); var cookieMatches = rxCookie.Matches(SetCookie); var csrfCookie = cookieMatches[0].Groups["csrf_token"].Value; /* * Make a login request. */ var form = new WWWForm(); form.AddField("username", username); form.AddField("email", email); form.AddField("password1", password); form.AddField("password2", password); var doRegister = UnityWebRequest.Post(REGISTER_URL, form); doRegister.SetRequestHeader("cookie", "csrftoken=" + csrfCookie); doRegister.SetRequestHeader("X-CSRFToken", csrfCookie); yield return(doRegister.Send()); #if UNITY_2017_1_OR_NEWER if (doRegister.isNetworkError) #else if (doRegister.isError) #endif { Log.E(doRegister.error); } else { Log.I(doRegister.downloadHandler.text); succeed.InvokeGracefully(); } }
public static void PlayMusic(string musicName, bool loop = true, System.Action onBeganCallback = null, System.Action onEndCallback = null, bool allowMusicOff = true, float volume = 1.0f) { var self = Instance; self.mCurMusicName = musicName; if (!IsMusicOn && allowMusicOff) { onBeganCallback.InvokeGracefully(); onEndCallback.InvokeGracefully(); return; } Log.I(">>>>>> Start Play Music"); // TODO: 需要按照这个顺序去 之后查一下原因 //需要先注册事件,然后再play self.mMainUnit.SetOnStartListener(musicUnit => { onBeganCallback.InvokeGracefully(); self.mMainUnit.SetVolume(volume); //调用完就置为null,否则应用层每注册一个而没有注销,都会调用 self.mMainUnit.SetOnStartListener(null); }); self.mMainUnit.SetAudio(self.gameObject, musicName, loop); self.mMainUnit.SetOnFinishListener(musicUnit => { onEndCallback.InvokeGracefully(); //调用完就置为null,否则应用层每注册一个而没有注销,都会调用 self.mMainUnit.SetOnFinishListener(null); }); }
public static void Example() { // action System.Action action = () => Log.I("action called"); action.InvokeGracefully(); // if (action != null) action(); // func Func <int> func = () => 1; func.InvokeGracefully(); /* * public static T InvokeGracefully<T>(this Func<T> selfFunc) * { * return null != selfFunc ? selfFunc() : default(T); * } */ // delegate TestDelegate testDelegate = () => { }; testDelegate.InvokeGracefully(); }
/// <summary> /// finished /// </summary> protected override void OnExecute(float dt) { mOnExecuteEvent.InvokeGracefully(); Finished = true; }
private IEnumerator Runner() { bool isTimeup = false; DateTime timer = DateTime.Now; yield return(null); IEnumerator enumerator = mEnumerator; while (mIsRunning) { if (mTimer > 0) { System.TimeSpan tsc = DateTime.Now - timer; if (tsc.Seconds > mTimer) { isTimeup = true; break; } } if (mIsPaused) { yield return(null); } else { bool isFinish = false; try { isFinish = enumerator.MoveNext(); } catch (Exception e) { isFinish = false; mIsRunning = false; mLogger.LogError(string.Format("{0}: {1}", mName, e.Message)); mLogger.LogException(e); } if ((enumerator != null) && isFinish) { yield return(enumerator.Current); } else { mIsRunning = false; } } } if (!isTimeup) { mOnFinished.InvokeGracefully(mIsStopped); } else { mOnTimeup.InvokeGracefully(); } if (mMgr != null) { int index = mMgr.Container.IndexOf(this); if (index >= 0) { mMgr.Container.RemoveAt(index); } } }
public static void DoUpload(PackageVersion packageVersion, System.Action succeed) { EditorUtility.DisplayProgressBar("插件上传", "打包中...", 0.1f); var fileName = packageVersion.Name + "_" + packageVersion.Version + ".unitypackage"; var fullpath = PackageManagerView.ExportPaths(fileName, packageVersion.InstallPath); var file = File.ReadAllBytes(fullpath); var form = new WWWForm(); form.AddField("username", User.Username.Value); form.AddField("password", User.Password.Value); form.AddField("name", packageVersion.Name); form.AddField("version", packageVersion.Version); form.AddField("file_name", fileName); form.AddBinaryData("file", file); form.AddField("version", packageVersion.Version); // form.AddField("release_note", packageVersion.Readme.content); form.AddField("installPath", packageVersion.InstallPath); // form.AddField("access_right", packageVersion.AccessRight.ToString().ToLower()); form.AddField("docUrl", packageVersion.DocUrl); // if (packageVersion.Type == PackageType.FrameworkModule) // { // form.AddField("type", "fm"); // } // else if (packageVersion.Type == PackageType.Shader) // { // form.AddField("type", "s"); // } // else if (packageVersion.Type == PackageType.AppOrGameDemoOrTemplate) // { // form.AddField("type", "agt"); // } // else if (packageVersion.Type == PackageType.Plugin) // { // form.AddField("type", "p"); // } Debug.Log(fullpath); EditorUtility.DisplayProgressBar("插件上传", "上传中...", 0.2f); ObservableWWW.Post(UPLOAD_URL, form, new Dictionary <string, string> { { "Authorization", "Token " + User.Token.Value } }) .Subscribe(responseContent => { EditorUtility.ClearProgressBar(); Debug.Log(responseContent); succeed.InvokeGracefully(); File.Delete(fullpath); }, e => { EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("插件上传", "上传失败!{0}".FillFormat(e.Message), "确定"); File.Delete(fullpath); }); }