protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); terrainSprite = Content.Load <Texture2D>(@"Terrain"); var appSprites = Content.Load <Texture2D>("DesertRatsSprites"); selectionSprite = CreateSelectorTexture(GraphicsDevice); var waterTextures = new WaterTextures(terrainSprite); var cityTexture = new TextureHolder(terrainSprite, new Rectangle(7 * Config.SpriteSize, 9 * Config.SpriteSize, Config.SpriteSize, Config.SpriteSize)); var groundTexture = new TextureHolder(terrainSprite, new Rectangle(0 * Config.SpriteSize, 0, Config.SpriteSize, Config.SpriteSize)); var landUnitTexture = new TextureHolder(appSprites, new Rectangle(1 + 0 * Config.SpriteSize, 1 + 0, Config.SpriteSize, Config.SpriteSize)); var spriteSize = new Rectangle(1, 1 + 1 + Config.SpriteSize, Config.SpriteSize, Config.SpriteSize); window = new Window( waterTextures, cityTexture, new DefaultStrategy(waterTextures.Sea), new CoastWithLandToTheNorthStrategy(waterTextures.CoastWithLandToTheNorth), new CoastWithLandToTheSouthStrategy(waterTextures.CoastWithLandToTheSouth), new GroundStrategy(groundTexture), new LandUnitStrategy(landUnitTexture), new CityStrategy(cityTexture) ); window.AddIsland(island); window.AddCity(new CityEntity(20, 20)); window.Include(new LandUnitEntity(21, 20)); }
IEnumerator Compare(TextureHolder textureHolder) { ///System.GC.Collect(); //Texture2D prueba = ScaleTexture((Texture2D)textureHolder.materialGameObject.mainTexture, 128, 128); //prueba.GetPixels(); // Obtenemos la textura de tiempo real textureHolder.runtimeTexture = ((RenderTexture)textureHolder.materialGameObject.mainTexture).ToTexture2D(); //textureHolder.runtimeTexture = ScaleTexture(textureHolder.runtimeTexture, 128, 128); Color32[] textura1 = textureHolder.runtimeTexture.GetPixels32();; Color32 tempColor1; int[] values = new int[colores.Length]; tempColor1 = textura1[0]; var a = new Rgb { R = 149, G = 13, B = 12 }; var b = new Rgb(); yield return(StartCoroutine(BucleFor(a, b, values, textura1, tempColor1, textureHolder.palabras, textureHolder))); // Debug.LogError(textureHolder.nameObject); }
public TextureHolder GenerateTextures(TexturesGenerationMode mode, int[] resolutions) { TextureHolder newTextureHolder = new TextureHolder(); Color mainColor = Utils.GenerateRandomColor(Color.white); Color secondColor = Utils.GenerateRandomColor(mainColor); newTextureHolder.mainColor = mainColor; newTextureHolder.secondColor = secondColor; switch (mode) { case TexturesGenerationMode.LinearRamp: { for (int i = 0; i < resolutions.Length; i++) { newTextureHolder.AddTexture(GetLinearRampTexture(resolutions[i], mainColor, secondColor)); } break; } case TexturesGenerationMode.CircularRamp: { for (int i = 0; i < resolutions.Length; i++) { newTextureHolder.AddTexture(GetCircularRampTexture(resolutions[i], mainColor, secondColor)); } break; } } return(newTextureHolder); }
/// <summary> /// Load textures from extended data that were stored with <see cref="Save"/>. /// </summary> public void Load(PluginData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } lock (_data) { foreach (var dataPair in data.data.Where(x => x.Key.StartsWith(DataMarker))) { var idStr = dataPair.Key.Substring(DataMarker.Length); if (!int.TryParse(idStr, out var id)) { KoikatuAPI.Logger.LogDebug($"Invalid ID {idStr} in key {dataPair.Key}"); continue; } var value = dataPair.Value as byte[]; if (value == null && dataPair.Value != null) { KoikatuAPI.Logger.LogDebug($"Invalid value of ID {id}. Should be of type byte[] but is {dataPair.Value.GetType()}"); continue; } _data[id] = new TextureHolder(value, _format); } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); TheCursor.Create(Content.Load <Texture2D>("ASCursor"), Content.Load <Texture2D>("CursorAim"), Content.Load <Texture2D>("CharacAim"), Color.White); // TODO: use this.Content to load your game content here List <String> TextureNames = FileServices.ReadFileLines(@"Files\TextureNames.txt"); foreach (string TexName in TextureNames) { TextureHolder temp = new TextureHolder(); temp.Texture = Content.Load <Texture2D>(TexName); temp.Filename = TexName; TheContentHolder.Textures.Add(temp); } Areas.Create(TheContentHolder, graphics, TheCamera); List <string> WeaponLines = FileServices.ReadFileLines(@"Files\Weapons.txt"); TheWeapons.Create(WeaponLines, TheContentHolder); //must make sure character spawns within normal camera boundaries TheMainCharacter.Create(150, 150, 0f, TheContentHolder.GetTexture("Man2"), TheContentHolder.GetTexture("Man_Aim2"), TheWeapons.WeaponList[0], TheCamera); }
private void RandomizeNightModeTextures() { // This is called if global texture randomization is disabled, but night-mode randomization is selected. // The main idea is to replace the SkyBox in levels that are now set at night, but this is treated as a // texture category so potentially any other textures could also be targeted. _textureOptions = new Dictionary <TextureCategory, bool>(); foreach (TR23ScriptedLevel lvl in Levels) { LoadLevelInstance(lvl); if (_levelInstance.IsNightMode) { TextureLevelMapping mapping = GetMapping(_levelInstance); using (TextureHolder holder = new TextureHolder(mapping, this)) { foreach (AbstractTextureSource source in holder.Variants.Keys) { if (source.IsInCategory(TextureCategory.NightMode)) { RedrawTargets(holder.Mapping, source, holder.Variants[source], _textureOptions); } } } SaveLevelInstance(); } if (!TriggerProgress()) { break; } } }
public RedLaser(Weapon newweapon, IMediator mediator) : base(mediator) { newweapon.LaserSight = new string("Red"); newweapon.LaserSprite = new Sprite(TextureHolder.GetInstance().Get(TextureIdentifier.RedLaser)); CheckGun(newweapon.Name, newweapon); //this.Origin = new Vector2f(SpriteUtils.GetSpriteCenter(this).X, 3f); }
protected override void ProcessImpl() { Dictionary <TextureCategory, bool> options = new Dictionary <TextureCategory, bool>(_outer._textureOptions); foreach (TR2CombinedLevel level in _holders.Keys) { options[TextureCategory.NightMode] = level.IsNightMode; options[TextureCategory.DayMode] = !options[TextureCategory.NightMode]; using (TextureHolder holder = _holders[level]) { foreach (AbstractTextureSource source in holder.Variants.Keys) { _outer.RedrawTargets(holder.Mapping, source, holder.Variants[source], options); } // Add landmarks, but only if there is room available for them if (holder.Mapping.LandmarkMapping.Count > 0) { _landmarkImporter.Import(level, holder.Mapping); } } if (!_outer.TriggerProgress()) { break; } _outer.SaveLevel(level); if (!_outer.TriggerProgress()) { break; } } }
/// <summary> /// Store a texture and get an ID representing it. The ID can be used to get the texture with <see cref="GetSharedTexture"/>. /// If you try to store a texture that was already stored before, the ID of the previous texture is returned so there are no multiple identical textures stored. /// </summary> /// <param name="tex">Raw PNG data of the texture. If you reuse a texture make sure you always use the same PNG data or deduplicating won't work.</param> public int StoreTexture(byte[] tex) { if (tex == null) { throw new ArgumentNullException(nameof(tex)); } lock (_data) { var existing = _data.FirstOrDefault(x => x.Value != null && x.Value.Data.SequenceEqual(tex)); if (existing.Value != null) { Console.WriteLine("StoreTexture - Texture already exists, reusing it"); return(existing.Key); } // Use random ID instaed of sequential to help catch code using IDs that no longer exist for (var i = Random.Range(1000, 9990); ; i++) { if (!_data.ContainsKey(i)) { _data[i] = new TextureHolder(tex, _format); return(i); } } } }
public static GetTexture() { if(instance==null) { instance = new TextureHolder(); } return instance; }
public TextureHolder(string name, int w, int h, N64TexFormat format, byte[] tex) : base(name) { Width = w; Height = h; Format = format; Tlut = null; SetData(tex); }
// キャッシュにテクスチャソースを保持する private void FilterTexture(Texture2D texture, FilterParam filter) { TextureHolder orgTex = originalTexCache.GetOrAdd(texture); orgTex.dirty = false; filter.ClearDirtyFlag(); FilterTexture(texture, orgTex.texture, filter); }
public void Setup(int _id, float _scale, float _speed, TextureHolder _bubbleTexture) { id = _id; speed = _speed; bubbleTexture = _bubbleTexture; transform.localScale = new Vector3(_scale, _scale, _scale); renderer.material.SetColor("_DiffuseColor", Color.white); int resolution = Mathf.FloorToInt((_scale * ConfigDictionary.Config.texturesResolutions.Length) / GameController.maxBubbleSize); resolution = Mathf.Clamp(resolution, 0, ConfigDictionary.Config.texturesResolutions.Length - 1); renderer.material.SetTexture("_Texture", bubbleTexture.GetTextureByResolution(ConfigDictionary.Config.texturesResolutions[resolution])); }
private void Awake() { if (instance != null) { Destroy(gameObject); return; } instance = this; DontDestroyOnLoad(this); }
public TextureHolder GetOrAdd(Texture2D tex) { TextureHolder holder; if (!cacheDic.TryGetValue(tex.name, out holder)) { holder = new TextureHolder(); holder.texture = UnityEngine.Object.Instantiate(tex) as Texture2D; cacheDic[tex.name] = holder; } return(holder); }
public Button() { normalTexture = TextureHolder.GetInstance().Get(TextureIdentifier.ButtonDefault); selectedTexture = TextureHolder.GetInstance().Get(TextureIdentifier.ButtonSelected); pressedTexture = TextureHolder.GetInstance().Get(TextureIdentifier.ButtonClicked); sprite = new Sprite(); text = new Text(string.Empty, ResourceHolderFacade.GetInstance().Fonts.Get(FontIdentifier.PixelatedSmall), 16); sprite.Texture = normalTexture; var bounds = sprite.GetLocalBounds(); text.Position = new Vector2f(bounds.Width / 2, bounds.Height / 2); }
public GameObject explosionGif; // displayed when switching singleplayer games void Awake() { keyboardPlayerMap = new int[4] { (int)PartyNames.Guigl, (int)PartyNames.Ubaldino, (int)PartyNames.Walusneaki, (int)PartyNames.Blooch }; swapper = GetComponent <TextureHolder>(); inputManager = GetComponent <KeyInput>(); allGames = new GameObject[4][]; allGames [0] = games1P; allGames [1] = games2P; allGames [2] = games3P; allGames [3] = games4P; allPosns = new Vector3[4][]; allPosns [0] = posns1P; allPosns [1] = posns2P; allPosns [2] = posns3P; allPosns [3] = posns4P; miniGames = new MiniGame[4]; names = new string[4] { "Guigl", "Ubaldino", "Walusneaki", "Blooch" }; gameCams = new GameObject[4]; for (int i = 0; i < 4; i++) { gameCams[i] = transform.FindChild("Q" + (i + 1) + "Cam").gameObject; } partyers = new Partyer[4]; for (int i = 0; i < 4; i++) { partyers [i] = new Partyer(names [i], sprites [i], Constants.lights [i], Constants.darks [i]); } scoreTemplate = transform.FindChild("scoreDisplayTemplate").gameObject; scoreBoards = new GameObject[4]; scoreBoardPosns = new Vector3[4] { new Vector3(-4.7f, 3f, 0f), new Vector3(4.7f, 3f, 0f), new Vector3(-4.7f, -3f, 0f), new Vector3(4.7f, -3f, 0f) }; jukeBox = transform.FindChild("JukeBox").GetComponent <JukeBox>(); }
public TextureHolder GetOrAdd(Texture2D tex) { TextureHolder holder; if (_cacheDic.TryGetValue(tex.name, out holder)) { return(holder); } holder = new TextureHolder { texture = UnityEngine.Object.Instantiate(tex) }; _cacheDic[tex.name] = holder; return(holder); }
public WaterTextures(Texture2D terrain) { var spriteSize = new Point(32, 32); var ss = Config.SpriteSize; CoastWithLandToTheNorth = new TextureHolder(terrain, new Rectangle(new Point(4 * ss, 0 * ss), spriteSize)); CoastWithLandToTheSouth = new TextureHolder(terrain, new Rectangle(new Point(10 * ss, 0 * ss), spriteSize)); CoastWithLandToTheWest = new TextureHolder(terrain, new Rectangle(new Point(6 * ss, 0 * ss), spriteSize)); CoastWithLandToTheEast = new TextureHolder(terrain, new Rectangle(new Point(18 * ss, 0 * ss), spriteSize)); CoastWithLandToTheNorthEast = new TextureHolder(terrain, new Rectangle(new Point(14 * ss, 0 * ss), spriteSize)); CoastWithLandToTheNorthWest = new TextureHolder(terrain, new Rectangle(new Point(6 * ss, 1 * ss), spriteSize)); CoastWithLandToTheSouthEast = new TextureHolder(terrain, new Rectangle(new Point(8 * ss, 0 * ss), spriteSize)); CoastWithLandToTheSouthWest = new TextureHolder(terrain, new Rectangle(new Point(0 * ss, 1 * ss), spriteSize)); Sea = new TextureHolder(terrain, new Rectangle(new Point(2 * ss, 0 * ss), spriteSize)); }
public AssaultRifle(IMediator mediator) : base(mediator) { this.Name = "AK-47"; this.MagazineSize = 45; this.Ammo = 45; this.Damage = 25; this.ProjectileSpeed = 2000; this.AttackSpeed = 90; this.ReloadDuration = 800; this.Projectiles = new List <Projectile>(); this.SpreadAmount = 50; this.CanShoot = true; this.ProjectileSprite = new Sprite(TextureHolder.GetInstance().Get(TextureIdentifier.Bullet)); this.Texture = TextureHolder.GetInstance().Get(TextureIdentifier.GunAk47); this.Origin = new Vector2f(SpriteUtils.GetSpriteCenter(this).X, 3f); }
public Flamethrower(IMediator mediator) : base(mediator) { this.Name = "FlameThrower"; this.MagazineSize = 200; this.Ammo = 200; this.Damage = 10; this.ProjectileSpeed = 500; this.AttackSpeed = 20; this.ReloadDuration = 2000; this.Projectiles = new List <Projectile>(); this.SpreadAmount = 50; this.CanShoot = true; this.ProjectileSprite = new Sprite(TextureHolder.GetInstance().Get(TextureIdentifier.Bullet)); this.Texture = TextureHolder.GetInstance().Get(TextureIdentifier.Flamethrower); this.Origin = new Vector2f(SpriteUtils.GetSpriteCenter(this).X, 3f); }
/// <summary> /// Loads in all textures for this state. /// </summary> private void LoadTextures() { TextureHolder.AddTexture("player", _game.Content.Load <Texture2D>("player")); TextureHolder.AddTexture("explosion", _game.Content.Load <Texture2D>("explosion1")); TextureHolder.AddTexture("bullet_light", _game.Content.Load <Texture2D>("bullet_light")); TextureHolder.AddTexture("bullet_medium", _game.Content.Load <Texture2D>("bullet_medium")); TextureHolder.AddTexture("bullet_heavy", _game.Content.Load <Texture2D>("bullet_heavy")); TextureHolder.AddTexture("meteor_tiny", _game.Content.Load <Texture2D>("meteor_tiny")); TextureHolder.AddTexture("meteor_small", _game.Content.Load <Texture2D>("meteor_small")); TextureHolder.AddTexture("meteor_medium", _game.Content.Load <Texture2D>("meteor_med")); TextureHolder.AddTexture("meteor_big", _game.Content.Load <Texture2D>("meteor_big")); TextureHolder.AddTexture("planet_blue", _game.Content.Load <Texture2D>("planet_blue")); TextureHolder.AddTexture("planet_brown", _game.Content.Load <Texture2D>("planet_brown")); TextureHolder.AddTexture("planet_red", _game.Content.Load <Texture2D>("planet_red")); TextureHolder.AddTexture("healthbar", _game.Content.Load <Texture2D>("healthbar")); }
public void Refresh(Texture2D[] maidTextures) { // 既に使われなくなったテクスチャを削除 var nonExistNames = new List <string>(); foreach (string name in cacheDic.Keys) { bool b = false; foreach (Texture2D t in maidTextures) { if (t.name == name) { b = true; break; } } if (!b) { nonExistNames.Add(name); } } foreach (string name in nonExistNames) { TextureHolder texHolder; if (cacheDic.TryGetValue(name, out texHolder)) { UnityEngine.Object.Destroy(texHolder.texture); } cacheDic.Remove(name); } // 知らないテクスチャを追加 foreach (Texture2D t in maidTextures) { if (!cacheDic.ContainsKey(t.name)) { var texHolder = new TextureHolder(); texHolder.texture = UnityEngine.Object.Instantiate(t) as Texture2D; texHolder.dirty = false; cacheDic[t.name] = texHolder; } } }
protected override void StartImpl() { // Load the level mapping and variants outwith the processor thread // to ensure the RNG selected for each level/texture remains consistent // between randomization sessions. List <TR2CombinedLevel> levels = new List <TR2CombinedLevel>(_holders.Keys); foreach (TR2CombinedLevel level in levels) { TextureLevelMapping mapping = _outer.GetMapping(level); if (mapping != null) { _holders[level] = new TextureHolder(mapping, _outer); } else { _holders.Remove(level); } } }
public void CheckGun(string text, Weapon newweapon) { //if (text == "Pistol") //{ // newweapon.Texture = TextureHolder.GetInstance().Get(TextureIdentifier.RedPistolLaser); // newweapon.LaserSprite.Origin = new Vector2f(SpriteUtils.GetSpriteCenter(this).X, 3f); //} if (text == "AK-47") { newweapon.Name = "AK-47R"; newweapon.Texture = TextureHolder.GetInstance().Get(TextureIdentifier.RedGunAk47Laser); newweapon.LaserSprite.Origin = new Vector2f(SpriteUtils.GetSpriteCenter(this).X, 8f); } else if (text == "Sniper") { newweapon.Name = "SniperR"; newweapon.Texture = TextureHolder.GetInstance().Get(TextureIdentifier.RedSniperLaser); newweapon.LaserSprite.Origin = new Vector2f(SpriteUtils.GetSpriteCenter(this).X, 10f); } }
public void Refresh(Texture2D[] maidTextures) { // 既に使われなくなったテクスチャを削除 var nonExistNames = new List <string>(); foreach (var key in _cacheDic.Keys) { var b = maidTextures.Any(t => t.name == key); if (!b) { nonExistNames.Add(key); } } foreach (var name in nonExistNames) { TextureHolder texHolder; if (_cacheDic.TryGetValue(name, out texHolder)) { UnityEngine.Object.Destroy(texHolder.texture); } _cacheDic.Remove(name); } // 知らないテクスチャを追加 foreach (var t in maidTextures) { if (_cacheDic.ContainsKey(t.name)) { continue; } var texHolder = new TextureHolder { texture = UnityEngine.Object.Instantiate(t), dirty = false }; _cacheDic[t.name] = texHolder; } }
public static Rect[] GenerateTextureAtlas(int maxWidth, Texture2D[] textures, ref Texture2D TextureAtlas) { List <Rect> rects = new List <Rect>(); List <TextureHolder> targetPanel = new List <TextureHolder>(); int highestThisRow = 0; int count = 0, total = 0, rowCount = 1; float totalHeight = 0f; int maxRowWidth = maxWidth; int highestLastRow = 0; foreach (var sprite in textures) { TextureHolder pb = new TextureHolder(); pb.Width = sprite.width; pb.Height = sprite.height; pb.Texture = sprite; if (targetPanel.Count > 0) { var lastControl = targetPanel[targetPanel.Count - 1]; var loc = lastControl.Location; var w = lastControl.Width; var h = lastControl.Height; var outOfBounds = ((w + loc.X + 1 + pb.Width) > maxRowWidth); if (outOfBounds) { count = 0; rowCount++; if (highestThisRow < h) { highestThisRow = (int)h; } pb.Location = new Point(0, loc.Y + highestThisRow + 1); totalHeight += highestThisRow + 1; highestLastRow = highestThisRow; highestThisRow = 0; } else { if (count == 0) { highestThisRow = highestLastRow; } if (highestThisRow < h) { highestThisRow = (int)h; } if (rowCount == 1) { totalHeight = highestThisRow + 1; } // var newY = loc.Y; // if (total > 10) newY = loc.Y + size.Height; pb.Location = new Point(loc.X + w + 1, loc.Y); } } targetPanel.Add(pb); count++; total++; } foreach (var pb in targetPanel) { // 0,1 1,1 // |-\ \-----| // | \ \ | // | \ \ | // | \ \ | // |-----\ \-| // 0,0 1,0 // // X: 400 // Y: 200 // // var uvX = pb.Location.X / (float)maxWidth; var uvY = (pb.Location.Y / (float)totalHeight); var uvX2 = ((pb.Width + pb.Location.X) / (float)maxWidth); var uvY2 = ((pb.Height + pb.Location.Y) / (float)totalHeight); // Debug.Log(); rects.Add(new Rect(uvX, uvY, uvX2, uvY2)); Debug.Log("UV: " + uvX + "," + uvY + "," + uvX2 + "," + uvY2); } TextureAtlas = new Texture2D(maxWidth, (int)totalHeight, TextureFormat.ARGB32, false); foreach (var t in targetPanel) { var pixels = t.Texture.GetPixels(); // Debug.Log("Set Pixels At: " + t.Location.X + "," + t.Location.Y); TextureAtlas.SetPixels((int)t.Location.X, (int)t.Location.Y, (int)t.Width, (int)t.Height, pixels); } //var reversed = TextureAtlas.GetPixels().Reverse(); //TextureAtlas.SetPixels(reversed.ToArray()); TextureAtlas.Apply(); //TextureAtlas = Rotate(TextureAtlas, RotateFlipType.RotateNoneFlipY); var data = TextureAtlas.EncodeToPNG(); File.WriteAllBytes(@"c:\textures2\texturepack.png", data); return(rects.ToArray()); }
public void Refresh(Texture2D[] maidTextures) { // 既に使われなくなったテクスチャを削除 var nonExistNames = new List<string>(); foreach (string name in cacheDic.Keys) { bool b = false; foreach (Texture2D t in maidTextures) { if (t.name == name) { b = true; break; } } if (!b) { nonExistNames.Add(name); } } foreach (string name in nonExistNames) { TextureHolder texHolder; if (cacheDic.TryGetValue(name, out texHolder)) { UnityEngine.Object.Destroy(texHolder.texture); } cacheDic.Remove(name); } // 知らないテクスチャを追加 foreach (Texture2D t in maidTextures) { if (!cacheDic.ContainsKey(t.name)) { var texHolder = new TextureHolder(); texHolder.texture = UnityEngine.Object.Instantiate(t) as Texture2D; texHolder.dirty = false; cacheDic[t.name] = texHolder; } } }
public void Start() { BasicStaticObjectStack.stackOfObjects.Push(this); notIgnoredInDerivedClass = new TextureHolder(); notIgnoredInDerivedClass.texture = new Texture2D(1024, 1024, TextureFormat.RGBA32, false); }
public Wall() { this.Texture = TextureHolder.GetInstance().Get(TextureIdentifier.Wall); }
public static void Draw(this SpriteBatch spriteBatch, Vector2 position, TextureHolder texture) { spriteBatch.Draw(texture.Texture2D, position, texture.Source, Color.White); }
public TextureHolder GetOrAdd(Texture2D tex) { TextureHolder holder; if (!cacheDic.TryGetValue(tex.name, out holder)) { holder = new TextureHolder(); holder.texture = UnityEngine.Object.Instantiate(tex) as Texture2D; cacheDic[tex.name] = holder; } return holder; }