protected bool StartLooper(Int32 TimesPerSec) { Log.Debug("Starting the repeating function"); StopLooper(); // stop it if its running SetRepeatTimesPerSecond(TimesPerSec); // set the new value return(StartLooper()); // start it and return the result }
/* * MonoBehavior "LifeCycle" * * [ Reset ] * v * [ Awake ] * v * [ OnEnable ] * v>---------v * v [ Start ] * v<---------< * [ FixedUpdate ]<----o * v | "Physics Loop" * [ y4FixedUpdate ] ----o * v * [ Update ] * v * [ y4null ] -AND- * [ y4ForSeconds ] -AND- * [ y4StartLooper] * v * [ LateUpdate ] * v * [ OnWillRenderObject ] * v * ... * v * [ OnPostRender ] * v * [ OnGUI ]<-----------o "GUI Loop" * v | 1. <Layout> and <Repaint> * v | 2. <Layout> and <Keyboard> and <Mouse> * v---------------o * [ y4waitEOF ] * v===========> ^[ FixedUpdate ] "Frame Loop" * v * [ OnDisable ] * v * [ OnDestroy ] * * * Some notes: * + These states are **individual** to each gameObject. You can not depend on * all objects having finished [Start] just because one object is in [FixedUpdate]. * + * + The "GUI Loop" be run [2..N] times. * + Adapted from: http://www.richardfine.co.uk/2012/10/unity3d-monobehaviour-lifecycle/ * + Ref: http://docs.unity3d.com/Manual/ExecutionOrder.html */ #region "Constructor" protected MBW() : base() { //do the assembly name add so we get different windowIDs for multiple plugins WindowID = UnityEngine.Random.Range(1000, 2000000) + Log._AssemblyName.GetHashCode(); _Visible = false; Log.Debug("WindowID:{0}", WindowID); //and look for any customattributes WindowInitialsAttribute[] attrs = (WindowInitialsAttribute[])Attribute.GetCustomAttributes(GetType(), typeof(WindowInitialsAttribute)); foreach (WindowInitialsAttribute attr in attrs) { Visible = attr.Visible; WindowCaption = attr.Caption; IsDragging = attr.IsDragging; DragEnabled = attr.DragEnabled; ClampEnabled = attr.ClampEnabled; TooltipsEnabled = attr.TooltipsEnabled; IsResizing = attr.IsResizing; ResizeEnabled = attr.ResizeEnabled; WindowRect_Min = attr.MinSize; WindowRect_Max = attr.MaxSize; } }
public static void AddStyle(GUIStyle NewStyle, string SkinId) { Log.Debug("in AddStyle(GUIStyle ns,string sid)"); if (SkinExists(SkinId)) { GUISkin skinTemp = knownSkins[SkinId]; AddStyle(NewStyle, ref skinTemp); } }
protected bool StopLooper() { try { Log.Debug("Cancelling the repeating function"); this.CancelInvoke("LooperWrapper"); _RepeatRunning = false; } catch (Exception) { Log.Now("Unable to cancel the repeating function"); } return(_RepeatRunning); }
internal static void RemoveStyle(string SkinID, string StyleID) { Log.Debug("in RemoveStyle(string SkinID,string StyleID)"); if (SkinExists(SkinID)) { GUISkin skinTemp = knownSkins[SkinID]; RemoveStyle(ref skinTemp, StyleID); } }
public static bool RemoveSkin(string SkinID) { switch (SkinID) { case "Unity": case "KSP": Log.Now("RemoveSkin({0}) failed: removing a built-in skin is prohibited.", SkinID); return(false); default: Log.Now("RemoveSkin({0})", SkinID); return(knownSkins.Remove(SkinID)); } }
protected bool StartLooper() { try { Log.Debug("Invoking the repeating function"); this.InvokeRepeating("LooperWrapper", _RepeatInitialWait, LooperRate); _RepeatRunning = true; } catch (Exception) { Log.Now("Unable to invoke the repeating function"); } return(_RepeatRunning); }
internal static void RemoveStyle(ref GUISkin SkinToAction, string StyleID) { Log.Debug("in RemoveStyle(GUISkin s2a, string StyleID)"); if (StyleExists(SkinToAction, StyleID)) { List <GUIStyle> lstTemp = SkinToAction.customStyles.ToList <GUIStyle>(); // convert to a list GUIStyle styleTemp = lstTemp.First(x => x.name == StyleID); // find and ... lstTemp.Remove(styleTemp); // ... remove the style SkinToAction.customStyles = lstTemp.ToArray <GUIStyle>(); // write back } }
internal static GUIStyle GetStyle(GUISkin SkinToAction, string StyleID) { Log.Debug("in GetStyle(GUISkin s2a, string StyleID)"); if (StyleExists(SkinToAction, StyleID)) { return(SkinToAction.customStyles.First(x => x.name == StyleID)); } else { return(null); } }
public static GUISkin CopySkin(string SkinID) { Log.Debug("in CopySkin(string SkinID)"); if (knownSkins.ContainsKey(SkinID)) { return((GUISkin)MBE.Instantiate(knownSkins[SkinID])); } else { Log.Now("CopySkin(): GUISkin {0} not found", SkinID); throw new SystemException(string.Format("CopySkin(): GUISkin {0} not found", SkinID)); } }
public bool Save(string fileFullName) { try { ConfigNode cnToSave = AsConfigNode; ConfigNode cnSaveWrapper = new ConfigNode(GetType().Name); cnSaveWrapper.AddNode(cnToSave); cnSaveWrapper.Save(fileFullName); return(true); } catch (Exception ex) { Log.Now("Failed to Save ConfigNode to file({0})-Error:{1}", fileFullName, ex.Message); return(false); } }
internal static bool StyleExists(GUISkin SkinToAction, string StyleID) { Log.Debug("in StyleExists(GUISkin s2a,)"); if (SkinToAction.customStyles.Any(x => x.name == StyleID)) { return(true); } else { //Log.log("Unable to find Style: {0} in Skin: {1}", StyleID, SkinToAction.name); return(false); } //return (SkinToAction.customStyles.Any(x => x.name == StyleID)); }
public static GUIStyle GenDefKSPTooltip() { Log.Debug("in GenDefKSPTooltip()"); GUIStyle retStyle = new GUIStyle(DefKSPSkin.label); // build a new style to return Texture2D texBack = new Texture2D(1, 1, TextureFormat.ARGB32, false); // background texture texBack.SetPixel(0, 0, new Color(0.5f, 0.5f, 0.5f, 0.95f)); // background color texBack.Apply(); retStyle.normal.background = texBack; // put bkg into style retStyle.normal.textColor = new Color32(224, 224, 224, 255); // set some text defaults retStyle.padding = new RectOffset(3, 3, 3, 3); // set padding defaults retStyle.alignment = TextAnchor.MiddleCenter; // set default center alignment return(retStyle); }
public static bool LoadImageFromFile(ref Texture2D tex, string name = "octicons.png", string path = "./GameData/KSPPP") { var location = string.Format("{0}/{1}", path, name); if (File.Exists(location)) { return(tex.LoadImage(File.ReadAllBytes(location))); } else { Log.Now("File.Exists() failed with location: {0}", location); } return(false); }
public static void dumpSkins(this GUISkin s) { string msg = ""; Object[] fonts = UnityEngine.Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Font)); foreach (Object f in fonts) { msg += "found a font: " + ((UnityEngine.Font)f).name + "\n"; } Log.Now("----------------------------------\n{0}", msg); foreach (KeyValuePair <string, GUISkin> e in SkinsLibrary.knownSkins) { string k = e.Key; int hash = e.GetHashCode(); GUISkin v = e.Value; GUIStyle[] cs = e.Value.customStyles; string prefix = "#[" + hash.ToString("X8") + "]" + " GUISkin "; GUIStyle_.knownStyles.Add(v.box.dumpStyle(prefix + k + ".box")); GUIStyle_.knownStyles.Add(v.button.dumpStyle(prefix + k + ".button")); GUIStyle_.knownStyles.Add(v.label.dumpStyle(prefix + k + ".label")); GUIStyle_.knownStyles.Add(v.scrollView.dumpStyle(prefix + k + ".scrollView")); GUIStyle_.knownStyles.Add(v.textArea.dumpStyle(prefix + k + ".textArea")); GUIStyle_.knownStyles.Add(v.textField.dumpStyle(prefix + k + ".textField")); GUIStyle_.knownStyles.Add(v.toggle.dumpStyle(prefix + k + ".toggle")); GUIStyle_.knownStyles.Add(v.horizontalSlider.dumpStyle(prefix + k + ".HSlider")); GUIStyle_.knownStyles.Add(v.horizontalSliderThumb.dumpStyle(prefix + k + ".HSliderThumb")); GUIStyle_.knownStyles.Add(v.horizontalScrollbar.dumpStyle(prefix + k + ".HScrollbar")); GUIStyle_.knownStyles.Add(v.horizontalScrollbarLeftButton.dumpStyle(prefix + k + ".HScrollbarLeftButton")); GUIStyle_.knownStyles.Add(v.horizontalScrollbarRightButton.dumpStyle(prefix + k + ".HScrollbarRightButton")); GUIStyle_.knownStyles.Add(v.horizontalScrollbarThumb.dumpStyle(prefix + k + ".HScrollbarThumb")); GUIStyle_.knownStyles.Add(v.verticalSlider.dumpStyle(prefix + k + ".VSlider")); GUIStyle_.knownStyles.Add(v.verticalSliderThumb.dumpStyle(prefix + k + ".VSliderThumb")); GUIStyle_.knownStyles.Add(v.verticalScrollbar.dumpStyle(prefix + k + ".VScrollbar")); GUIStyle_.knownStyles.Add(v.verticalScrollbarUpButton.dumpStyle(prefix + k + ".VScrollbarLeftButton")); GUIStyle_.knownStyles.Add(v.verticalScrollbarDownButton.dumpStyle(prefix + k + ".VScrollbarRightButton")); GUIStyle_.knownStyles.Add(v.verticalScrollbarThumb.dumpStyle(prefix + k + ".VScrollbarThumb")); int i = 0; Log.Now("GUISkin {0}.customStyles contains {1} custom styles:", k, cs.Length); foreach (GUIStyle sty in cs) { string csi = ".customStyles[" + i++ + "]"; GUIStyle_.knownStyles.Add(sty.dumpStyle(prefix + k + csi)); } } }
public static event TooltipChangedEvent OnTooltipChanged; //FIXME: unused internal static void InitSkinList() { Log.Debug("in InitSkinList()"); if (!_Initialized) { DefUnitySkin = GUI.skin; DefKSPSkin = HighLogic.Skin; knownSkins.Add("Unity", DefUnitySkin); knownSkins.Add("KSP", DefKSPSkin); DefUnitySkin.dumpSkins(); SetCurrent("KSP"); _Initialized = true; } }
public static GUIStyle dumpStyle(this GUIStyle s, string breadcrumbs) { var hash = s.GetHashCode(); if (knownStyles.Contains(s)) { Log.Now("{0} => #[{2:X8}] {1} skipped", breadcrumbs, s.ToString(), hash); return(s); } Log.Now("{0} => #[{2:X8}] {1}", breadcrumbs, s.ToString(), s.GetHashCode()); Log.Now(" ------------------------------------------------------------------------------------------------ "); Log.Now(" -> contentOffset => {0}", s.contentOffset); Log.Now(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); Log.Now(" -> border => {0}", s.border); Log.Now(" -> padding => {0}", s.border); Log.Now(" -> margin => {0}", s.border); Log.Now(" -> overflow => {0}", s.border); // print all of the non-trivialGUIStyleState components Log.Now(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); s.active.PPP(" -> active => "); s.onActive.PPP(" -> onActive => "); s.normal.PPP(" -> normal => "); s.onNormal.PPP(" -> onNormal => "); s.hover.PPP(" -> hover => "); s.onHover.PPP(" -> onHover => "); s.focused.PPP(" -> focused => "); s.onFocused.PPP(" -> onFocused => "); Log.Now(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); Log.Now(" -> alignment => {0}", s.alignment); Log.Now(" -> wordwrap => {0}", s.alignment); Log.Now(" -> clipping => {0}", s.clipping); Log.Now(" -> richText? => {0}", s.richText); Log.Now(" -> lineHeight=> {0}", s.lineHeight); Log.Now(" -> font => {0}", s.fontPP()); Log.Now(" -> fontSize => {0}", s.fontSize); Log.Now(" -> fontStyle => {0}", s.fontStyle); Log.Now(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); Log.Now(" -> fixedW, stretchW? => {0} ({1})", s.fixedWidth, s.stretchWidth); Log.Now(" -> fixedH, stretchH? => {0} ({1})", s.fixedHeight, s.stretchHeight); Log.Now(" -> isHdepW? => {0}", s.isHeightDependantOnWidth); Log.Now(" ------------------------------------------------------------------------------------------------ "); return(s); }
protected override void Awake() { WindowCaption = "Test Window"; Visible = true; WindowRect = new Rect(UnityEngine.Random.Range(100, 800), UnityEngine.Random.Range(100, 800), 300, 300); ClampEnabled = true; DragEnabled = true; TooltipsEnabled = true; ResizeEnabled = true; foreach (CelestialBody body in FlightGlobals.Bodies) { bodyNames.Add(body.bodyName); bodyNameDesc.Add(textWithTT(body.bodyName, body.bodyDescription)); Log.Now("adding body name: {0}", body.bodyName); } }
public static void AddSkin(string SkinID, GUISkin NewSkin, bool SetAsCurrent = false) { Log.Debug("in AddSkin"); NewSkin.name = SkinID; if (knownSkins.ContainsKey(SkinID)) { knownSkins[SkinID] = NewSkin; } else { knownSkins.Add(SkinID, NewSkin); } if (SetAsCurrent) { SetCurrent(SkinID); } }
public static void loadAssets() { Log.Now("trying to load textures"); try { var ret = Icon.LoadImageFromFile(ref octIcons); var ret2 = Icon.LoadImageFromFile(ref planetIcons, "planeticons.png"); if (!ret) { Log.Now("Failed to load octIcons"); } if (!ret2) { Log.Now("Failed to load planetIcons"); } } catch (Exception e) { Log.Now("Failed to load textures. File location error: {0} ", e); } }
internal static void AddStyle(GUIStyle NewStyle, ref GUISkin SkinToAction) { Log.Debug("in AddStyle(GUIStyle ns,ref GUISkin)"); if (string.IsNullOrEmpty(NewStyle.name)) { Log.Now("No Name Provided in the Style to add to {0}. Cannot add this.", SkinToAction.name); return; } List <GUIStyle> lstTemp = SkinToAction.customStyles.ToList <GUIStyle>(); // convert to a list if (lstTemp.Any(x => x.name == NewStyle.name)) // add or edit the customstyle { GUIStyle styleTemp = lstTemp.First(x => x.name == NewStyle.name); lstTemp.Remove(styleTemp); // if itexists then remove it first } lstTemp.Add(NewStyle); // add the new style SkinToAction.customStyles = lstTemp.ToArray <GUIStyle>(); // write the list back to the array }
public static void SetCurrent(string SkinID) { GUISkin OldSkin = _CurrentSkin; Log.Debug("Setting GUISkin(string SkinID) to {0}", SkinID); if (knownSkins.ContainsKey(SkinID)) { _CurrentSkin = knownSkins[SkinID]; } else { Log.Now("SetCurrent: GUISkin {0} not found", SkinID); } SetCurrentTooltip(); // Now set the tooltip style as well if (OldSkin != CurrentSkin && OnSkinChanged != null) { OnSkinChanged(); } }
public static void PPP(this GUIStyleState s, string breadcrumbs) { string bkg = "null"; string colorName = ""; if (s.textColor == black && s.background == null) { return; } if (s.background != null) { bkg = s.background.ToString(); } if (Color_.knownColors.TryGetValue(s.textColor, out colorName)) { Log.Now("{0} {{ GUIss: textColor: {1} bkg: {2} }}", breadcrumbs, colorName, bkg); } else { Log.Now("{0} {{ GUIss: textColor: {1} bkg: {2} }}", breadcrumbs, s.textColor.ToString(), bkg); } }
public bool Load(string fileFullName) { try { Log.Debug("Loading ConfigNode"); if (FileExists) { ConfigNode cnToLoad = ConfigNode.Load(fileFullName); ConfigNode cnUnwrapped = cnToLoad.GetNode(GetType().Name); ConfigNode.LoadObjectFromConfig(this, cnUnwrapped); return(true); } else { Log.Now("File could not be found to load({0})", fileFullName); return(false); } } catch (Exception ex) { Log.Now("Failed to Load ConfigNode from file ({0}) - Error:{1}", fileFullName, ex.Message); Log.Now("Storing old config - {0}", fileFullName + ".err-" + timeNow); System.IO.File.Copy(fileFullName, fileFullName + ".err-" + timeNow, true); return(false); } }
public static void SetCurrentTooltip() { //Use the custom skin if it exists Log.Debug("in SetCurrentTooltip()"); if (StyleExists(_CurrentSkin, "Tooltip")) { _CurrentTooltip = GetStyle(_CurrentSkin, "Tooltip"); } else //otherwise lets build a style for the defaults or take the label style otherwise { if (_CurrentSkin == DefUnitySkin) { _CurrentTooltip = new GUIStyle(DefUnitySkin.box); } else if (_CurrentSkin == DefKSPSkin) { _CurrentTooltip = GenDefKSPTooltip(); } else { _CurrentTooltip = _CurrentSkin.label; } } }
internal static void AddStyle(GUIStyle NewStyle, string SkinId, string StyleID) { Log.Debug("in AddStyle(GUIStyle ns,string skinID, string StyleID)"); NewStyle.name = StyleID; AddStyle(NewStyle, SkinId); }
protected override void Awake() { WindowCaption = "Icon Window"; Visible = true; WindowRect = new Rect(UnityEngine.Random.Range(100, 800), UnityEngine.Random.Range(100, 800), 300, 300); ClampEnabled = true; DragEnabled = true; TooltipsEnabled = true; ResizeEnabled = true; Icon.loadAssets(); foreach (Icons i in (Icons[])Enum.GetValues(typeof(Icons))) { var total = Enum.GetNames(typeof(Icons)).Count() - 1; Texture2D norm = new Texture2D(32, 32, TextureFormat.ARGB32, false); var pix = Icon.octIcons.GetPixels(0, 32 * (int)(total - i), 32, 32); norm.SetPixels(0, 0, 32, 32, pix); norm.Apply(false); // create smaller versions, too var newtex = Instantiate(norm); TextureScale.Bilinear((Texture2D)newtex, (int)norm.width / 2, (int)norm.height / 2); icons.Add(new GUIContent(norm, i.ToString())); small.Add(new GUIContent((Texture2D)newtex, i.ToString())); Log.Now("adding real texture for: {0}", i.ToString()); } foreach (PlanetIcons i in (PlanetIcons[])Enum.GetValues(typeof(PlanetIcons))) { var total = Enum.GetNames(typeof(PlanetIcons)).Count() - 1; var extra = Enum.GetNames(typeof(MoonIcons)).Count(); Texture2D icon = new Texture2D(26, 26, TextureFormat.ARGB32, false); var pix = Icon.planetIcons.GetPixels(0, 26 * (int)((total + extra) - i), 26, 26); icon.SetPixels(0, 0, 26, 26, pix); icon.Apply(false); planets.Add(new GUIContent(icon, i.ToString())); Log.Now("adding real texture for: {0}", i.ToString()); } foreach (MoonIcons i in (MoonIcons[])Enum.GetValues(typeof(MoonIcons))) { var total = Enum.GetNames(typeof(MoonIcons)).Count() - 1; var extra = Enum.GetNames(typeof(PlanetIcons)).Count(); Texture2D icon = new Texture2D(26, 26, TextureFormat.ARGB32, false); var pix = Icon.planetIcons.GetPixels(0, 26 * (int)((total) - i), 26, 26); icon.SetPixels(0, 0, 26, 26, pix); icon.Apply(false); moons.Add(new GUIContent(icon, i.ToString())); Log.Now("adding real texture for: {0}", i.ToString()); } }
protected override void Awake() { Log.Debug("New MBWindow Awakened"); }
internal static bool SkinExists(string SkinID) { Log.Debug("in SkinExists()"); return(knownSkins.ContainsKey(SkinID)); }
internal static void AddStyle(GUIStyle NewStyle, ref GUISkin SkinToAction, string StyleID) { Log.Debug("in AddStyle(GUIStyle ns,ref GUISkin, string StyleID)"); NewStyle.name = StyleID; // set the name AddStyle(NewStyle, ref SkinToAction); // and push to the next method }