/// <summary> /// Waits for the Application Launcher before beginning initialization /// </summary> /// <returns></returns> System.Collections.IEnumerator WaitOnAppLauncher() { Log.Debug("Waiting on AppLauncher..."); while (!ApplicationLauncher.Ready) { yield return(null); } Log.Verbose("Retrieving animation sheet."); var sheet = ResourceUtil.GetEmbeddedTexture("ScienceAlert.Resources.sheet_app.png", false, false); if (sheet == null) { Log.Error("Failed to locate embedded app sheet texture!"); // well ... without it we're sunk. Something is better than // nothing. We can't let the stock behaviour fail Log.Warning("Creating dummy sprite texture"); sheet = new Texture2D(38, 38, TextureFormat.ARGB32, false); sheet.SetPixels32(Enumerable.Repeat((Color32)Color.clear, 38 * 38).ToArray()); sheet.Apply(); } Log.Verbose("Setting up sprite"); sprite = PackedSprite.Create("ScienceAlert.Button.Sprite", Vector3.zero); sprite.SetMaterial(new Material(Shader.Find("Sprite/Vertex Colored")) { mainTexture = sheet }); sprite.renderer.sharedMaterial.mainTexture.filterMode = FilterMode.Point; sprite.Setup(38f, 38f); sprite.SetFramerate(Settings.Instance.StarFlaskFrameRate); sprite.SetAnchor(SpriteRoot.ANCHOR_METHOD.UPPER_LEFT); sprite.gameObject.layer = LayerMask.NameToLayer("EzGUI_UI"); // normal state Log.Verbose("Setting up normal animation"); UVAnimation normal = new UVAnimation() { name = "Unlit", loopCycles = 0, framerate = Settings.Instance.StarFlaskFrameRate }; normal.BuildUVAnim(sprite.PixelCoordToUVCoord(9 * 38, 8 * 38), sprite.PixelSpaceToUVSpace(38, 38), 1, 1, 1); // animated state Log.Verbose("Setting up star flask animation"); UVAnimation anim = new UVAnimation() { name = "Spin", loopCycles = -1, framerate = Settings.Instance.StarFlaskFrameRate }; anim.BuildWrappedUVAnim(new Vector2(0, sprite.PixelCoordToUVCoord(0, 38).y), sprite.PixelSpaceToUVSpace(38, 38), 100); // add animations to button sprite.AddAnimation(normal); sprite.AddAnimation(anim); sprite.PlayAnim("Unlit"); Log.Verbose("Creating mod button..."); button = ApplicationLauncher.Instance.AddModApplication( OnToggle, OnToggle, () => { }, () => { }, () => { }, () => { }, ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW, sprite); GameEvents.onGUIApplicationLauncherUnreadifying.Add(AppLauncherUnreadifying); Log.Debug("AppLauncherInterface: Button transform = {0}", button.transform.position.ToString()); Log.Verbose("AppLauncherInterface ready"); }