private void HandleFlagRespondMessage(FlagRespondMessage flagRespondMessage) { ServerFlags[flagRespondMessage.FlagName] = flagRespondMessage.FlagInfo; var flagFile = CommonUtil.CombinePaths(FlagPath, flagRespondMessage.FlagName); var flagTexture = new Texture2D(4, 4); if (flagTexture.LoadImage(flagRespondMessage.FlagData)) { flagTexture.name = "LunaMultiPlayer/Flags/" + Path.GetFileNameWithoutExtension(flagRespondMessage.FlagName); File.WriteAllBytes(flagFile, flagRespondMessage.FlagData); var textureInfo = new GameDatabase.TextureInfo(null, flagTexture, false, true, false) { name = flagTexture.name }; var containsTexture = GameDatabase.Instance.databaseTexture.Any(t => t.name == textureInfo.name); if (!containsTexture) { GameDatabase.Instance.databaseTexture.Add(textureInfo); } else { GameDatabase.Instance.ReplaceTexture(textureInfo.name, textureInfo); } Debug.Log($"[LMP]: Loaded {flagTexture.name}"); } else { Debug.LogError($"[LMP]: Failed to load flag {flagRespondMessage.FlagName}"); } }
public void ApplyTexture(Material mat, string name) { GameDatabase.TextureInfo texture = null; if ((type & TextureTypeEnum.CubeMapMask) > 0) { CubemapWrapper cubeMap = CubemapWrapper.fetchCubeMap(this); if (cubeMap != null) { cubeMap.ApplyCubeMap(mat, name, index); } } else { texture = GameDatabase.Instance.GetTextureInfo(value); } if (texture != null) { texture.texture.wrapMode = isClamped ? TextureWrapMode.Clamp : TextureWrapMode.Repeat; mat.SetTexture(name, texture.texture); } if ((type & TextureTypeEnum.AlphaMapMask) > 0) { mat.EnableKeyword(alphaMask + "_" + index); mat.EnableKeyword("ALPHAMAP_" + index); Vector4 alphaMaskVector; alphaMaskVector.x = alphaMask == AlphaMaskEnum.ALPHAMAP_R ? 1 : 0; alphaMaskVector.y = alphaMask == AlphaMaskEnum.ALPHAMAP_G ? 1 : 0; alphaMaskVector.z = alphaMask == AlphaMaskEnum.ALPHAMAP_B ? 1 : 0; alphaMaskVector.w = alphaMask == AlphaMaskEnum.ALPHAMAP_A ? 1 : 0; mat.SetVector("alphaMask" + index, alphaMaskVector); } }
private void HandleFlagRespondMessage(FlagRespondMessage flagRespondMessage) { serverFlags[flagRespondMessage.flagName] = flagRespondMessage.flagInfo; string flagFile = Path.Combine(flagPath, flagRespondMessage.flagName); Texture2D flagTexture = new Texture2D(4, 4); if (flagTexture.LoadImage(flagRespondMessage.flagData)) { flagTexture.name = "DarkMultiPlayer/Flags/" + Path.GetFileNameWithoutExtension(flagRespondMessage.flagName); File.WriteAllBytes(flagFile, flagRespondMessage.flagData); GameDatabase.TextureInfo ti = new GameDatabase.TextureInfo(flagTexture, false, true, false); ti.name = flagTexture.name; bool containsTexture = false; foreach (GameDatabase.TextureInfo databaseTi in GameDatabase.Instance.databaseTexture) { if (databaseTi.name == ti.name) { containsTexture = true; } } if (!containsTexture) { GameDatabase.Instance.databaseTexture.Add(ti); } else { GameDatabase.Instance.ReplaceTexture(ti.name, ti); } DarkLog.Debug("Loaded " + flagTexture.name); } else { DarkLog.Debug("Failed to load flag " + flagRespondMessage.flagName); } }
/// <summary> /// Loads external config node data. /// </summary> void LoadConfiguration() { // Load all the celestial body configuration ConfigNode[] bodyConfig = GameDatabase.Instance.GetConfigNodes("WAYPOINT_MANAGER_BODIES"); foreach (ConfigNode configNode in bodyConfig) { try { string config = configNode.GetValue("name"); Debug.Log("WaypointManager: Loading " + config + " icons."); string url = configNode.GetValue("url"); if (url.Last() != '/') { url += '/'; } foreach (GameDatabase.TextureInfo icon in GameDatabase.Instance.GetAllTexturesInFolder(url)) { string name = icon.name.Substring(icon.name.LastIndexOf('/') + 1); bodyIcons[name] = icon.texture; Debug.Log("WaypointManager: Loaded icon for " + name + "."); } } catch (Exception e) { Debug.LogError("WaypointManager: Exception when attempting to load Celestial Body configuration:"); Debug.LogException(e); } } // Get all the directories for icons ConfigNode[] iconConfig = GameDatabase.Instance.GetConfigNodes("WAYPOINT_MANAGER_ICONS"); foreach (ConfigNode configNode in iconConfig) { string dir = configNode.GetValue("url"); Debug.Log("handling dir = " + dir); // The FinePrint logic is such that it will only look in Squad/Contracts/Icons for icons. // Cheat this by hacking the path in the game database. foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture.Where(t => t.name.StartsWith(dir))) { Debug.Log("handling text = " + texInfo.name); texInfo.name = "Squad/Contracts/Icons/" + texInfo.name; } } // Extra stuff! GameDatabase.TextureInfo nyan = GameDatabase.Instance.databaseTexture.Where(t => t.name.Contains("WaypointManager/icons/Special/nyan")).FirstOrDefault(); if (nyan != null && DateTime.Now.Month == 4 && DateTime.Now.Day == 1) { foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture.Where(t => t.name.StartsWith("Squad/Contracts/Icons/"))) { string name = texInfo.name.Replace("Squad/Contracts/Icons/", ""); if (!CustomWaypointGUI.forbiddenIcons.Contains(name)) { texInfo.texture = nyan.texture; } } } }
/// <summary> /// Adds the button to the toolbar. /// </summary> public void Add() { // _logger.Trace("Add"); if (!IsAvailable) { _logger.Info("Blizzy's toolbar not available."); return; } if (_button != null) { _logger.Info("Button already added."); return; } _button = ToolbarManager.Instance.add("ScienceChecklist", "button"); _button.ToolTip = "[x] Science!"; _button.Text = "[x] Science!"; const string texturePath = "ScienceChecklist/icons/icon-small.png"; if (!GameDatabase.Instance.ExistsTexture(texturePath)) { var icon = TextureHelper.FromResource("ScienceChecklist.icons.icon-small.png", 24, 24); var ti = new GameDatabase.TextureInfo(null, icon, false, true, true); ti.name = texturePath; GameDatabase.Instance.databaseTexture.Add(ti); } _button.TexturePath = texturePath; _button.Visibility = new GameScenesVisibility(GameScenes.SPACECENTER, GameScenes.EDITOR, GameScenes.FLIGHT, GameScenes.TRACKSTATION); _button.OnClick += OnClick; _button.Enabled = true; }
public static void Resize(GameDatabase.TextureInfo texture, int width, int height, bool mipmaps, bool convertToNormalFormat) { ActiveTextureManagement.DBGLog("Resizing..."); Texture2D tex = texture.texture; TextureFormat format = tex.format; if (texture.isNormalMap) { format = TextureFormat.ARGB32; } else if (format == TextureFormat.DXT1 || format == TextureFormat.RGB24) { format = TextureFormat.RGB24; } else { format = TextureFormat.RGBA32; } Color32[] pixels = tex.GetPixels32(); if (convertToNormalFormat) { ConvertToUnityNormalMap(pixels); } Color32[] newPixels = ResizePixels(pixels, tex.width, tex.height, width, height); tex.Resize(width, height, format, mipmaps); tex.SetPixels32(newPixels); tex.Apply(mipmaps); }
private GameDatabase.TextureInfo getTextureForState(string name) { NE_Helper.log("Experiment Name: " + name); switch (name) { case "empty": if (noExp == null) { noExp = getTexture(folder, noExpTexture); } return(noExp); case "MEE1": if (mee1 == null) { mee1 = getTexture(folder, mee1Texture); } return(mee1); case "MEE2": if (mee2 == null) { mee2 = getTexture(folder, mee2Texture); } return(mee2); default: return(null); } }
// Makes lod taking over control over an already loaded texture. public static void ForceManage(GameDatabase.TextureInfo info) { // this one is experimental for now. // it tries to resolve the source file by the textures name (yea, kinda stupid) // it unloads the currently laoded texture // it places an unloaded "dummy" // warning, this might not work with derived TextureInfos! Or think about this replacing TextureInfo in the first place if (iManagedTextures.ContainsKey(info)) { "Texture already managed!".Log(); return; } UrlDir.UrlFile file = Stuff.ResolveTextureInfo(info); // Todo: Resolve file... if (file == null) { throw new NotSupportedException("Could not find a source file for this texture. This kinda textures are not currently supported."); } if (info.texture != null) { UnityEngine.Resources.UnloadAsset(info.texture); } var data = new TextureData(info, file); if (!DelayLoading) { SetupNative(data); // Todo14: See above } "ForceManage, Adding texture".Log(); iManagedTextures.Add(data.Info, data); }
/// <summary> /// Adds the button to the toolbar. /// </summary> public void Add () { // _logger.Trace("Add"); if (!IsAvailable) { _logger.Info("Blizzy's toolbar not available."); return; } if (_button != null) { _logger.Info("Button already added."); return; } _button = ToolbarManager.Instance.add("ScienceChecklist", "button"); _button.ToolTip = "[x] Science!"; _button.Text = "[x] Science!"; const string texturePath = "ScienceChecklist/icons/icon-small.png"; if (!GameDatabase.Instance.ExistsTexture(texturePath)) { var icon = TextureHelper.FromResource("ScienceChecklist.icons.icon-small.png", 24, 24); var ti = new GameDatabase.TextureInfo( null, icon, false, true, true ); ti.name = texturePath; GameDatabase.Instance.databaseTexture.Add(ti); } _button.TexturePath = texturePath; _button.Visibility = new GameScenesVisibility(GameScenes.SPACECENTER, GameScenes.EDITOR, GameScenes.FLIGHT, GameScenes.TRACKSTATION); _button.OnClick += OnClick; _button.Enabled = true; }
/// <summary> /// Here we handle an unloaded flag and we load it into the game /// </summary> private void HandleFlag(ExtendedFlagInfo flagInfo) { //We have a flag with the same name! if (FlagExists(flagInfo.FlagName)) { return; } var flagTexture = new Texture2D(4, 4); if (flagTexture.LoadImage(flagInfo.FlagData)) { //Flags have names like: Squad/Flags/default flagTexture.name = flagInfo.FlagName; var textureInfo = new GameDatabase.TextureInfo(null, flagTexture, true, true, false) { name = flagInfo.FlagName }; GameDatabase.Instance.databaseTexture.Add(textureInfo); LunaLog.Log($"[LMP]: Loaded flag {flagTexture.name}"); } else { LunaLog.LogError($"[LMP]: Failed to load flag {flagInfo.FlagName}"); } }
public TextureData(GameDatabase.TextureInfo info, UrlDir.UrlFile file) { File = file; Info = info; Info.texture = CreateEmptyThumbnailTexture(); Info.texture.name = Info.name = file.url; }
public static Resources.IResource Get(GameDatabase.TextureInfo textureObject) { TextureData textureData; if (iManagedTextures.TryGetValue(textureObject, out textureData)) { if ((textureData.NativeId == -1) || (textureData.File == null)) { return(new Resources.ResourceDummy()); } TextureResource textureResource; if (textureData.LoadedTextureResource == null || !textureData.LoadedTextureResource.IsAlive) { textureResource = new TextureResource(textureData); textureData.LoadedTextureResource = new WeakReference(textureResource); } else { // Todo: Potential race condition. Hope we asap get .net 4 and thus WeakRef.TryGet... don't see another way to fix that if-else textureResource = (TextureResource)textureData.LoadedTextureResource.Target; } return(new TextureReference(textureResource)); } else { return(null); } }
public static bool Reload(GameDatabase.TextureInfo texture, bool inPlace, Vector2 size = default(Vector2), string cache = null, bool mipmaps = true) { Debug.Log("Getting readable tex from " + texture.file.url + "." + texture.file.fileExtension); if (texture.file.fileExtension == "jpg" || texture.file.fileExtension == "jpeg" || texture.file.fileExtension == "png" || texture.file.fileExtension == "truecolor") { IMGToTexture(texture, inPlace, size, cache, mipmaps); return(true); } else if (texture.file.fileExtension == "tga") { TGAToTexture(texture, inPlace, size, cache, mipmaps); return(true); } else if (texture.file.fileExtension == "mbm") { MBMToTexture(texture, inPlace, size, cache, mipmaps); return(true); } else if (texture.file.fileExtension == "dds") { DDSToTexture(texture, inPlace, size, cache, mipmaps); return(true); } return(false); }
private static void ReplaceIfNecessary(string name, bool normalMap, bool mipmaps, bool readable, bool compressed) { if (GameDatabase.Instance.ExistsTexture(name)) { GameDatabase.TextureInfo info = GameDatabase.Instance.GetTextureInfo(name); bool isReadable = false; try { info.texture.GetPixel(0, 0); isReadable = true; } catch { } bool hasMipmaps = info.texture.mipmapCount > 0; bool isCompressed = (info.texture.format == TextureFormat.DXT1 || info.texture.format == TextureFormat.DXT5); bool isNormalMap = info.isNormalMap; if (!isReadable || (isCompressed && !compressed) || (isNormalMap != normalMap)) { //Pretty ineficient to not check beforehand, but makes the logic much simpler by simply reloading the textures. info.isNormalMap = normalMap; info.isReadable = readable; info.isCompressed = compressed; TextureConverter.Reload(info, false, default(Vector2), null, mipmaps); info.texture.name = name; } else if (isReadable != readable || isCompressed != compressed || hasMipmaps != mipmaps) { if (compressed) { info.texture.Compress(true); } info.texture.Apply(mipmaps, !readable); } } }
/// <summary> /// Loads external config node data. /// </summary> void LoadConfiguration() { // Load all the celestial body configuration ConfigNode[] bodyConfig = GameDatabase.Instance.GetConfigNodes("WAYPOINT_MANAGER_BODIES"); foreach (ConfigNode configNode in bodyConfig) { try { string config = configNode.GetValue("name"); Log.Info("WaypointManager: Loading " + config + " icons."); string url = configNode.GetValue("url"); if (url.Last() != '/') { url += '/'; } if (Directory.Exists("GameData/" + url)) { foreach (var str in Directory.GetFiles("GameData/" + url)) { var icon = new Texture2D(2, 2); ToolbarControl.LoadImageFromFile(ref icon, str); //string name = icon.name.Substring(icon.name.LastIndexOf('/') + 1); string name = Path.GetFileNameWithoutExtension(str); bodyIcons[name] = icon; } } #if false foreach (GameDatabase.TextureInfo icon in GameDatabase.Instance.GetAllTexturesInFolder(url)) { string name = icon.name.Substring(icon.name.LastIndexOf('/') + 1); bodyIcons[name] = icon.texture; Log.Info("WaypointManager: Loaded icon for " + name + "."); } #endif } catch (Exception e) { Debug.LogError("WaypointManager: Exception when attempting to load Celestial Body configuration:"); Debug.LogException(e); } } // Extra stuff! GameDatabase.TextureInfo nyan = GameDatabase.Instance.databaseTexture.Where(t => t.name.Contains("WaypointManager/icons/Special/nyan")).FirstOrDefault(); if (nyan != null && DateTime.Now.Month == 4 && DateTime.Now.Day == 1) { foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture.Where(t => t.name.StartsWith("Squad/Contracts/Icons/"))) { string name = texInfo.name.Replace("Squad/Contracts/Icons/", ""); if (!CustomWaypointGUI.forbiddenIcons.Contains(name)) { texInfo.texture = nyan.texture; } } } }
private static List <TextureSetDefinition> LoadTextureSetsDefinitions(ConfigNode[] cfg = null) { if (cfg == null) { cfg = GameDatabase.Instance.GetConfigNodes("CRFPTextureDefinition"); } List <TextureSetDefinition> result = new List <TextureSetDefinition>(); foreach (var config in cfg) { foreach (var texDefNode in config.GetNodes("TextureDefinition")) { if (texDefNode != null) { var texDef = new TextureSetDefinition(); if (!texDefNode.TryGetValue("name", ref texDef.name) || !texDefNode.TryGetValue("directory", ref texDef.directory) || !texDefNode.TryGetValue("diffuse", ref texDef.diffuse) || !texDefNode.TryGetValue("normals", ref texDef.normals) || !texDefNode.TryGetValue("specular", ref texDef.specular) ) { Debug.LogError($"[CRFP] Can't load TextureDefinition {texDefNode.name}"); continue; } GameDatabase.TextureInfo tex = LoadTextureFromDatabase(texDef.directory, texDef.diffuse, asNormal: false); if (tex == null) { Debug.LogError($"[CRFP] Texture {texDef.diffuse} isn't load by the game"); continue; } texDef.diff = tex.texture; tex = LoadTextureFromDatabase(texDef.directory, texDef.normals, asNormal: true); if (tex == null) { Debug.LogError($"[CRFP] Texture {texDef.normals} isn't load by the game"); continue; } texDef.norm = tex.texture; tex = LoadTextureFromDatabase(texDef.directory, texDef.specular, asNormal: false); if (tex == null) { Debug.LogError($"[CRFP] Texture {texDef.specular} isn't load by the game"); continue; } texDef.spec = tex.texture; result.Add(texDef); } } } return(result); }
public IMaterialModifier Parse(ConfigNode node) { string propertyName = node.GetValue("name"); if (propertyName == null) { throw new FormatException("name not found, cannot create material modifier"); } else if (propertyName == string.Empty) { throw new FormatException("name is empty, cannot create material modifier"); } if (node.name == "FLOAT_PROPERTY") { float value = float.Parse(node.GetValue("value")); return(new FloatPropertyMaterialModifier(propertyName, value)); } else if (node.name == "COLOR_PROPERTY") { Color color = ConfigNode.ParseColor(node.GetValue("color")); return(new ColorPropertyMaterialModifier(propertyName, color)); } else if (node.name == "TEXTURE_PROPERTY") { string textureUrl = node.GetValue("textureUrl"); bool normalMapToggle = false; if (node.GetValue("isNormalMap") is string normalMapToggleString) { normalMapToggle = bool.Parse(normalMapToggleString); } GameDatabase.TextureInfo textureInfo = GameDatabase.Instance.GetTextureInfo(textureUrl); if (textureInfo == null) { throw new Exception($"Cannot find texture: '{textureUrl}'"); } Texture2D texture = normalMapToggle ? textureInfo.normalMap : textureInfo.texture; if (texture == null) { throw new Exception($"Cannot get texture from texture info '{textureUrl}' isNormalMap = {normalMapToggle}"); } return(new TexturePropertyMaterialModifier(propertyName, texture)); } else { throw new FormatException($"Can't create material modifier from node: '{node.name}'"); } }
public static Resources.IResource GetOrThrow(GameDatabase.TextureInfo textureObject) { var res = Get(textureObject); if (res == null) { throw new ArgumentOutOfRangeException("TextureManager does not manage this GameDatabase.TextureInfo[Name:" + textureObject.name.ToString() + "]"); } return(res); }
public TexRefCnt(GameDatabase.TextureInfo texInfo, string hash, bool unloaded) { this.texInfo = texInfo; if (texInfo == null) { Loader.Log("texInfo for " + texInfo.name + " is null!"); } textureDictionary[texInfo.texture.name] = this; this.unloaded = unloaded; this.hash = hash; }
// returns true iff it's a local load public static bool LoadTexture(string path, ref Texture2D map, bool compress, bool upload, bool unreadable) { map = null; print("RSS searching for texture " + path); // first try in GDB Texture2D[] textures = Resources.FindObjectsOfTypeAll(typeof(Texture2D)) as Texture2D[]; foreach (Texture2D tex in textures) { if (tex.name.Equals(path)) { map = tex; break; } } if ((object)map == null) { print("RSS Loading local texture " + path); path = KSPUtil.ApplicationRootPath + path; if (File.Exists(path)) { try { map = new Texture2D(4, 4, TextureFormat.RGB24, true); if (path.ToLower().Contains(".dds")) { GameDatabase.TextureInfo tInfo = DDSLoader.DatabaseLoaderTexture_DDS.LoadDDS(path, !unreadable, path.Contains("NRM"), -1, upload); map = tInfo.texture; } else { map.LoadImage(System.IO.File.ReadAllBytes(path)); if (compress) { map.Compress(true); } if (upload) { map.Apply(true, unreadable); } } return(true); } catch (Exception e) { Debug.Log("*RSS* *ERROR* failed to load " + path + " with exception " + e.Message); } } else { print("*RSS* *ERROR* texture does not exist! " + path); } } return(false); }
public static UrlDir.UrlFile ResolveTextureInfo(GameDatabase.TextureInfo texInfo) { /* * URL splittten * Dirs solange existent aus dingsda rausholen * Sobald nicht mehr existent manuell weitersuchen * Thats just great! */ throw new NotImplementedException(); throw new NotImplementedException(); }
private void setTexture(LabEquipment type) { GameDatabase.TextureInfo tex = texFac.getTextureForEquipment(type.getType()); if (tex != null) { changeTexture(tex); } else { NE_Helper.logError("Change Equipment Container Texure: Texture Null"); } }
private void setTexture(ExperimentData expData) { GameDatabase.TextureInfo tex = textureReg.getTextureForExperiment(expData); if (tex != null) { changeTexture(tex); } else { NE_Helper.logError("Change Experiment Container Texure: Texture Null"); } }
public static void GetReadable(TexInfo Texture, bool mipmaps) { String mbmPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".mbm"; String pngPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".png"; String pngPathTruecolor = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".truecolor"; String jpgPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".jpg"; String tgaPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".tga"; if (File.Exists(pngPath) || File.Exists(pngPathTruecolor) || File.Exists(jpgPath) || File.Exists(tgaPath) || File.Exists(mbmPath)) { Texture2D tex = new Texture2D(2, 2); String name; if (Texture.name.Length > 0) { name = Texture.name; } else { name = Texture.name; } GameDatabase.TextureInfo newTexture = new GameDatabase.TextureInfo(tex, Texture.isNormalMap, true, false); Texture.texture = newTexture; newTexture.name = Texture.name; if (File.Exists(pngPath)) { Texture.filename = pngPath; IMGToTexture(Texture, mipmaps, false); } else if (File.Exists(pngPathTruecolor)) { Texture.filename = pngPathTruecolor; IMGToTexture(Texture, mipmaps, false); } else if (File.Exists(jpgPath)) { Texture.filename = jpgPath; IMGToTexture(Texture, mipmaps, false); } else if (File.Exists(tgaPath)) { Texture.filename = tgaPath; TGAToTexture(Texture, mipmaps); } else if (File.Exists(mbmPath)) { Texture.filename = mbmPath; MBMToTexture(Texture, mipmaps); } tex.name = newTexture.name; } }
private void changeTexture(GameDatabase.TextureInfo newTexture) { Material mat = getContainerMaterial(); if (mat != null) { mat.mainTexture = newTexture.texture; } else { NE_Helper.logError("Transform NOT found: " + "Equipment Container"); } }
private void changeTexture(GameDatabase.TextureInfo newTexture) { Material mat = getScreenMaterial(); if (mat != null) { mat.mainTexture = newTexture.texture; } else { NE_Helper.logError("Transform NOT found: " + "MEP IVA Screen"); } }
public static void IMGToTexture(TexInfo Texture, bool mipmaps, bool isNormalFormat) { GameDatabase.TextureInfo texture = Texture.texture; TextureConverter.InitImageBuffer(); FileStream imgStream = new FileStream(Texture.filename, FileMode.Open, FileAccess.Read); imgStream.Position = 0; imgStream.Read(imageBuffer, 0, MAX_IMAGE_SIZE); imgStream.Close(); Texture2D tex = texture.texture; tex.LoadImage(imageBuffer); bool convertToNormalFormat = texture.isNormalMap && !isNormalFormat ? true : false; bool hasMipmaps = tex.mipmapCount == 1 ? false : true; if (Texture.loadOriginalFirst) { Texture.Resize(tex.width, tex.height); } TextureFormat format = tex.format; if (texture.isNormalMap) { format = TextureFormat.ARGB32; } if (Texture.needsResize) { TextureConverter.Resize(texture, Texture.resizeWidth, Texture.resizeHeight, mipmaps, convertToNormalFormat); } else if (convertToNormalFormat || hasMipmaps != mipmaps || format != tex.format) { Color32[] pixels = tex.GetPixels32(); if (convertToNormalFormat) { for (int i = 0; i < pixels.Length; i++) { pixels[i].a = pixels[i].r; pixels[i].r = pixels[i].g; pixels[i].b = pixels[i].g; } } if (tex.format != format || hasMipmaps != mipmaps) { tex.Resize(tex.width, tex.height, format, mipmaps); } tex.SetPixels32(pixels); tex.Apply(mipmaps); } }
private GameDatabase.TextureInfo getTexture(EquipmentRacks p) { KeyValuePair <string, string> textureName; if (textureNameReg.TryGetValue(p, out textureName)) { GameDatabase.TextureInfo newTex = GameDatabase.Instance.GetTextureInfoIn(textureName.Key, textureName.Value); if (newTex != null) { return(newTex); } } NE_Helper.logError("Could not load texture for Exp: " + p); return(null); }
private GameDatabase.TextureInfo getTexture(string p) { KeyValuePair <string, string> textureName; if (textureNameReg.TryGetValue(p, out textureName)) { NE_Helper.log("Looking for Texture:" + textureName.Value + " in : " + textureName.Key); GameDatabase.TextureInfo newTex = GameDatabase.Instance.GetTextureInfoIn(textureName.Key, textureName.Value); if (newTex != null) { return(newTex); } } NE_Helper.logError("Could not load texture for Exp: " + p); return(null); }
public TexRefCnt(Texture2D tex) { if (tex != null) { texInfo = GameDatabase.Instance.GetTextureInfo(tex.name); if (texInfo == null) { Loader.Log("texInfo for " + tex.name + " is null!"); } else { hash = GetMD5String(texInfo.file.fullPath); } textureDictionary[tex.name] = this; } }
private void tryCompress(GameDatabase.TextureInfo Texture) { Texture2D tex = Texture.texture; if (tex.format != TextureFormat.DXT1 && tex.format != TextureFormat.DXT5) { try { tex.GetPixel(0, 0); tex.Compress(true); Texture.isCompressed = true; Texture.isReadable = true; } catch { Texture.isReadable = false; } } }
private GameDatabase.TextureInfo getTextureForState(MEPLabStatus p) { switch (p) { case MEPLabStatus.NOT_READY: if (notReady == null) notReady = getTexture(folder, notReadyTexture); return notReady; case MEPLabStatus.READY: if (ready == null) ready = getTexture(folder, readyTexture); return ready; case MEPLabStatus.RUNNING: if (running == null) running = getTexture(folder, runningTexture); return running; case MEPLabStatus.ERROR_ON_START: case MEPLabStatus.ERROR_ON_STOP: if (error == null) error = getTexture(folder, errorTexture); return error; default: return null; } }
private void HandleFlagRespondMessage(FlagRespondMessage flagRespondMessage) { serverFlags[flagRespondMessage.flagName] = flagRespondMessage.flagInfo; string flagFile = Path.Combine(flagPath, flagRespondMessage.flagName); Texture2D flagTexture = new Texture2D(4, 4); if (flagTexture.LoadImage(flagRespondMessage.flagData)) { flagTexture.name = "DarkMultiPlayer/Flags/" + Path.GetFileNameWithoutExtension(flagRespondMessage.flagName); File.WriteAllBytes(flagFile, flagRespondMessage.flagData); GameDatabase.TextureInfo ti = new GameDatabase.TextureInfo(null, flagTexture, false, true, false); ti.name = flagTexture.name; bool containsTexture = false; foreach (GameDatabase.TextureInfo databaseTi in GameDatabase.Instance.databaseTexture) { if (databaseTi.name == ti.name) { containsTexture = true; } } if (!containsTexture) { GameDatabase.Instance.databaseTexture.Add(ti); } else { GameDatabase.Instance.ReplaceTexture(ti.name, ti); } DarkLog.Debug("Loaded " + flagTexture.name); } else { DarkLog.Debug("Failed to load flag " + flagRespondMessage.flagName); } }
private GameDatabase.TextureInfo getTextureForState(string name) { NE_Helper.log("Experiment Name: " + name); switch (name) { case "empty": if (noExp == null) noExp = getTexture(folder, noExpTexture); return noExp; case "MEE1": if (mee1 == null) mee1 = getTexture(folder, mee1Texture); return mee1; case "MEE2": if (mee2 == null) mee2 = getTexture(folder, mee2Texture); return mee2; default: return null; } }
private GameDatabase.TextureInfo getTextureForState(bool running) { if(running){ if (expRunning == null) expRunning = getTexture(folder, expRunningTexture); return expRunning; }else { if (noExp == null) noExp = getTexture(folder, noExpTexture); return noExp; } }