public MyGameWorld( I2DRenderUtilities renderUtilities, IAssetManagerProvider assetManagerProvider, IEntityFactory entityFactory) { this.Entities = new List<IEntity>(); _renderUtilities = renderUtilities; _assetManager = assetManagerProvider.GetAssetManager(); _defaultFont = this._assetManager.Get<FontAsset>("font.Default"); // You can also save the entity factory in a field and use it, e.g. in the Update // loop or anywhere else in your game. var entityA = entityFactory.CreateExampleEntity("EntityA"); entityA.X = 100; entityA.Y = 50; var entityB = entityFactory.CreateExampleEntity("EntityB"); entityB.X = 120; entityB.Y = 100; // Don't forget to add your entities to the world! this.Entities.Add(entityA); this.Entities.Add(entityB); // This pulls in the texture asset via the asset manager. Note that // the folder seperator from "texture/Player" has been translated // into a single dot. _playerTexture = _assetManager.Get<TextureAsset>("texture.Player"); }
public MyGameWorld( I2DRenderUtilities renderUtilities, IAssetManagerProvider assetManagerProvider, IEntityFactory entityFactory) { this.Entities = new List <IEntity>(); _renderUtilities = renderUtilities; _assetManager = assetManagerProvider.GetAssetManager(); _defaultFont = this._assetManager.Get <FontAsset>("font.Default"); // You can also save the entity factory in a field and use it, e.g. in the Update // loop or anywhere else in your game. var entityA = entityFactory.CreateExampleEntity("EntityA"); entityA.X = 100; entityA.Y = 50; var entityB = entityFactory.CreateExampleEntity("EntityB"); entityB.X = 120; entityB.Y = 100; // Don't forget to add your entities to the world! this.Entities.Add(entityA); this.Entities.Add(entityB); // This pulls in the texture asset via the asset manager. Note that // the folder seperator from "texture/Player" has been translated // into a single dot. _playerTexture = _assetManager.Get <TextureAsset>("texture.Player"); }
public override void Allocate() { string uri = UriSource; if (String.IsNullOrEmpty(uri)) { if (_texture != null) { FreeData(); FireChanged(); } return; } TextureAsset texture = _texture; if (texture == null) { texture = _texture = ContentManager.Instance.GetTexture(uri, DecodePixelWidth, DecodePixelHeight, Thumbnail); } if (texture != null && !texture.IsAllocated) { if (Thumbnail) { texture.ThumbnailDimension = ThumbnailDimension; } texture.Allocate(); if (texture.IsAllocated) { _imageContext.Refresh(); FireChanged(); } } }
public PlayerEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, bool isRedColor, bool locallyOwned) { this.m_NetworkAPI = networkAPI; this.m_2DRenderUtilities = twodRenderUtilities; this.m_CubeRenderer = cubeRenderer; this.m_PlayerTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture." + (isRedColor ? "Red" : "Blue")); this.LocallyOwned = locallyOwned; this.Width = 0.5f; this.Depth = 0.5f; if (!this.LocallyOwned) { networkAPI.ListenForMessage( "player update", a => { var values = a.Split('|').Select(x => float.Parse(x)).ToArray(); this.X = values[0]; this.Y = values[1]; this.Z = values[2]; }); } }
protected override void FreeData() { _texture = null; _stream.Close(); _resourceAccessor.Dispose(); base.FreeData(); }
public GoalEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary <string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f + 0.4f; this.Z = y / 16f + 0.4f; this.CanPickup = false; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.Width = 0.2f; this.Depth = 0.2f; this.m_GoalTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.Goal"); this.m_GoalModel = assetManagerProvider.GetAssetManager().Get <ModelAsset>("model.Goal"); }
public void SyncLoadMatsTex(List <PrefabRenderHolder.RenderMatTexPair> rendersMatTexInfo, List <Asset> texResRefs) { if (rendersMatTexInfo == null) { return; } int len = rendersMatTexInfo.Count; for (int i = 0; i < len; i++) { if (rendersMatTexInfo[i].renderObj == null) { continue; } var renderMatInfos = rendersMatTexInfo[i].matAllInfos; if (renderMatInfos != null) { if (renderMatInfos.Length == 1) { var matTexInfos = renderMatInfos[0].matTexInfos; for (int m = 0; m < matTexInfos.Length; m++) { var mat = rendersMatTexInfo[i].renderObj.sharedMaterial; var attName = matTexInfos[m].attribute; TextureAsset res = (TextureAsset)TextureAssetManager.Singleton.Load(matTexInfos[m].tex2dName); var tex = res.GetMainAsset() as Texture; if (tex != null) { mat.SetTexture(attName, tex); res.AddRef(); //记录加载了哪些贴图 texResRefs.Add(res); } } } else { var mats = rendersMatTexInfo[i].renderObj.sharedMaterials; for (int j = 0; j < renderMatInfos.Length; j++) { if (mats.Length > renderMatInfos[j].matIndex && mats[j] != null) { var mtis = renderMatInfos[j].matTexInfos; for (int n = 0; n < mtis.Length; n++) { var mat = mats[renderMatInfos[j].matIndex]; var attName = mtis[n].attribute; TextureAsset res = (TextureAsset)TextureAssetManager.Singleton.Load(mtis[n].tex2dName); mat.SetTexture(attName, res.GetMainAsset() as Texture); res.AddRef(); //记录加载了哪些贴图 texResRefs.Add(res); } } } rendersMatTexInfo[i].renderObj.sharedMaterials = mats; } } } }
protected void UpdateTexture(string url) { lock (_imageSync) { var imageData = Utils.DownloadImage(url); _texture = ContentManager.Instance.GetTexture(imageData, _itemTitle); if (_texture == null) { return; } if (!_texture.IsAllocated) { _texture.Allocate(); } if (!_texture.IsAllocated) { return; } SurfaceDescription desc = _texture.Texture.GetLevelDescription(0); _textureMaxUv = new SizeF(_texture.Width / (float)desc.Width, _texture.Height / (float)desc.Height); // Reset animation _animator.Initialize(); _state = PlayerState.Active; } }
public void Load() { _tileMntTexture = Engine.AssetLoader.Get <TextureAsset>("Image/mnt.png"); _tileGrs1Texture = Engine.AssetLoader.Get <TextureAsset>("Image/grs1.png"); _tileGrs2Texture = Engine.AssetLoader.Get <TextureAsset>("Image/grs2.png"); // _ubuntuFontAsset = Engine.AssetLoader.Get<FontAsset>("font/UbuntuMono-R.ttf").GetAtlas(16f); GenHeightMap(); GetTileMap(); Rectangle boundsOfMap = Rectangle.BoundsFromPolygonPoints(new[] { tiles[0, 0].Vertex0, tiles[MAP_WIDTH - 1, 0].Vertex1, tiles[MAP_WIDTH - 1, MAP_HEIGHT - 1].Vertex2, tiles[0, MAP_HEIGHT - 1].Vertex3, }); quadTree = new QuadTree <TileQuadrilateral>(boundsOfMap, 100); foreach (var tile in tiles) { quadTree.Add(tile); } GLThread.ExecuteGLThread(() => { _frameBuffer = new FrameBuffer(new Texture(Engine.Renderer.DrawBuffer.Size)); }); }
/// <summary> /// The handle. /// </summary> /// <param name="assetManager"> /// The asset manager. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="IAsset"/>. /// </returns> public IAsset Handle(IAssetManager assetManager, string name, IRawAsset data) { if (data is CompiledAsset) { return(new TextureAsset(this.m_AssetContentManager, name, null, data.GetProperty <PlatformData>("PlatformData"), false)); } PlatformData platformData = null; if (data.GetProperty <PlatformData>("PlatformData") != null) { platformData = new PlatformData { Platform = data.GetProperty <PlatformData>("PlatformData").Platform, Data = data.GetProperty <PlatformData>("PlatformData").Data }; } var texture = new TextureAsset( this.m_AssetContentManager, name, ByteReader.ReadAsByteArray(data.GetProperty <object>("RawData")), platformData, data.GetProperty <bool>("SourcedFromRaw")); return(texture); }
private void LoadAsset() { if (!FileDialog.Open(out string path, filter: "All Image Files (*.bmp; *.jpg; *.jpeg; *.png; *.tif; *.tiff)\0*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff\0" + "PNG (*.png)\0*.png\0" + "JPG (*.jpg; *.jpeg)\0*.jpg;*.jpeg\0" + "BMP (*.bmp)\0*.bmp\0" + "GIF (*.gif)\0*.gif\0" + "TIFF (*.tif; *.tiff)\0*.tif;*.tiff\0" + "EXIF (*.exif)\0*.exif\0" + "All Files (*.*)\0*.*\0")) { return; } SelectedTextureAsset = new TextureAsset(path); SelectedTextureAsset.Load(); textureAssets.Add(SelectedTextureAsset); selectedIndex = textureAssets.GetAll().Count - 1; selectedIndex = Math.Clamp(selectedIndex, 0, Math.Max(textureAssets.GetAll().Count - 1, 0)); ResetView(); }
protected override void FreeData() { base.FreeData(); _lastTexture = null; _currentTexture = null; _lastImageContext.Clear(); }
public CrateEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary<string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f; this.Z = y / 16f; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.CanPush = true; this.Width = 0.8f; this.Depth = 0.8f; this.m_BlueCrateTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.BlueCrate"); this.m_RedCrateTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.RedCrate"); this.m_CrateModel = assetManagerProvider.GetAssetManager().Get<ModelAsset>("model.Crate"); }
public GoalEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary<string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f + 0.4f; this.Z = y / 16f + 0.4f; this.CanPickup = false; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.Width = 0.2f; this.Depth = 0.2f; this.m_GoalTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.Goal"); this.m_GoalModel = assetManagerProvider.GetAssetManager().Get<ModelAsset>("model.Goal"); }
protected void UpdateTexture(string url) { lock (_imageSync) { var imageData = Utils.DownloadImage(url); _texture = ContentManager.Instance.GetTexture(imageData, _itemTitle); if (_texture == null) { return; } if (!_texture.IsAllocated) { _texture.Allocate(); } if (!_texture.IsAllocated) { return; } //ImagePlayerSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<ImagePlayerSettings>() ?? new ImagePlayerSettings(); _animator = STILL_IMAGE_ANIMATION; //settings.UseKenBurns ? new KenBurnsAnimator() : STILL_IMAGE_ANIMATION; SurfaceDescription desc = _texture.Texture.GetLevelDescription(0); _textureMaxUv = new SizeF(_texture.Width / (float)desc.Width, _texture.Height / (float)desc.Height); // Reset animation _animator.Initialize(); _state = PlayerState.Active; } }
static void CreateSprite(string path, Sprite sprite) { TextureAsset obj = ScriptableObject.CreateInstance <TextureAsset>(); obj.sprite = sprite; AssetDatabase.CreateAsset(obj, path); }
protected void UpdateTexture(ImageItem item) { lock (imageSync) { itemTitle = item.ImageId; texture = ContentManager.Instance.GetTexture(item.ImageData, item.ImageId); if (texture == null) { return; } if (!texture.IsAllocated) { texture.Allocate(); } if (!texture.IsAllocated) { return; } //ImagePlayerSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<ImagePlayerSettings>() ?? new ImagePlayerSettings(); animator = STILL_IMAGE_ANIMATION; //settings.UseKenBurns ? new KenBurnsAnimator() : STILL_IMAGE_ANIMATION; SurfaceDescription desc = texture.Texture.GetLevelDescription(0); textureMaxUV = new SizeF(texture.Width / (float)desc.Width, texture.Height / (float)desc.Height); // Reset animation animator.Initialize(); state = PlayerState.Active; } }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SpriteSheetAsset asset, AssetCompilerResult result) { result.BuildSteps = new AssetBuildStep(AssetItem); // create the registry containing the sprite assets texture index association var imageToTextureIndex = new Dictionary <SpriteInfo, int>(); // create and add import texture commands if (asset.Sprites != null) { var gameSettingsAsset = context.GetGameSettingsAsset(); // sort sprites by referenced texture. var spriteByTextures = asset.Sprites.GroupBy(x => x.Source).ToArray(); for (int i = 0; i < spriteByTextures.Length; i++) { // skip the texture if the file is not valid. var textureFile = spriteByTextures[i].Key; if (!TextureFileIsValid(textureFile)) { continue; } var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { imageToTextureIndex[spriteAsset] = i; } // create an texture asset. var textureAsset = new TextureAsset { Id = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid) Alpha = asset.Alpha, Format = asset.Format, GenerateMipmaps = asset.GenerateMipmaps, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, }; // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( SpriteSheetAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), gameSettingsAsset.DefaultGraphicsProfile, gameSettingsAsset.TextureQuality))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } if (!result.HasErrors) { result.BuildSteps.Add(new SpriteSheetCommand(urlInStorage, new SpriteSheetParameters(asset, context.Platform), imageToTextureIndex)); } }
public CrateEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary <string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f; this.Z = y / 16f; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.CanPush = true; this.Width = 0.8f; this.Depth = 0.8f; this.m_BlueCrateTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.BlueCrate"); this.m_RedCrateTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.RedCrate"); this.m_CrateModel = assetManagerProvider.GetAssetManager().Get <ModelAsset>("model.Crate"); }
protected override void FreeData() { _possibleSources = null; _texture = null; _asyncStarted = false; base.FreeData(); }
public PlayerEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, bool isRedColor, bool locallyOwned) { this.m_NetworkAPI = networkAPI; this.m_2DRenderUtilities = twodRenderUtilities; this.m_CubeRenderer = cubeRenderer; this.m_PlayerTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture." + (isRedColor ? "Red" : "Blue")); this.LocallyOwned = locallyOwned; this.Width = 0.5f; this.Depth = 0.5f; if (!this.LocallyOwned) { networkAPI.ListenForMessage( "player update", a => { var values = a.Split('|').Select(x => float.Parse(x)).ToArray(); this.X = values[0]; this.Y = values[1]; this.Z = values[2]; }); } }
private void FinishAsync(int size) { if (!_transitionActive && (_nextTexture == null || _nextTexture.IsAllocated)) { CycleTextures(_nextTexture, Rotation); } _nextTexture = null; }
public TextureAssetControl(TextureAsset asset) { InitializeComponent(); Handler = new TextureAssetControlHandler(asset, this); Data.DataContext = asset; }
public MenuWorld(ISkin skin, IWorldFactory worldFactory, IAssetManagerProvider assetManagerProvider, I2DRenderUtilities twodRenderUtilities) { this.m_2DRenderUtilities = twodRenderUtilities; this.m_LogoTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.Logo"); this.m_WorldFactory = worldFactory; this.Entities = new List<IEntity>(); var startServer = new Button(); startServer.Text = "Start Server"; startServer.Click += (sender, e) => { this.m_LastGameContext.SwitchWorld<IWorldFactory>( x => x.CreateLobbyWorld(false, IPAddress.Any)); }; var ipAddressTextBox = new TextBox(); var joinGame = new Button(); joinGame.Text = "Join Game"; joinGame.Click += (sender, e) => { this.m_LastGameContext.SwitchWorld<IWorldFactory>( x => x.CreateLobbyWorld(true, IPAddress.Parse(ipAddressTextBox.Text))); }; var exitGame = new Button(); exitGame.Text = "Exit Game"; exitGame.Click += (sender, e) => { this.m_LastGameContext.Game.Exit(); }; var vertical = new VerticalContainer(); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(new Label { Text = "Perspective" }, "25"); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(startServer, "25"); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(new Label { Text = "Server IP address:" }, "20"); vertical.AddChild(ipAddressTextBox, "20"); vertical.AddChild(joinGame, "25"); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(exitGame, "25"); vertical.AddChild(new EmptyContainer(), "*"); var horizontal = new HorizontalContainer(); horizontal.AddChild(new EmptyContainer(), "*"); horizontal.AddChild(vertical, "250"); horizontal.AddChild(new EmptyContainer(), "*"); var canvas = new Canvas(); canvas.SetChild(horizontal); this.Entities.Add(new CanvasEntity(skin, canvas)); }
public override void Allocate() { TextureAsset nextTexture = null; if (_source) { _source = false; string uri = UriSource; if (String.IsNullOrEmpty(uri)) { if (_currentTexture != null) { CycleTextures(null, RightAngledRotation.Zero); } } else { nextTexture = ContentManager.Instance.GetTexture(uri, DecodePixelWidth, DecodePixelHeight, Thumbnail); nextTexture.ThumbnailDimension = ThumbnailDimension; } } // Check our previous texture is allocated. Synchronous. if (_lastTexture != null && !_lastTexture.IsAllocated) { _lastTexture.Allocate(); } // Check our current texture is allocated. Synchronous. if (_currentTexture != null && !_currentTexture.IsAllocated) { _currentTexture.Allocate(); } // Check our next texture is allocated. Asynchronous. if (nextTexture != null) { if (_nextTexture != null) { _nextTexture.AllocationChanged -= FinishAsync; } _nextTexture = nextTexture; // Load texture asynchronously and use eventhandler to cycle textures when finished. if (!nextTexture.LoadFailed) { nextTexture.AllocationChanged += FinishAsync; nextTexture.AllocateAsync(); } else { // Failed textures needs to be reset. _nextTexture = null; } if (nextTexture.IsAllocated || nextTexture.LoadFailed) { FinishAsync(nextTexture.AllocationSize); } } }
public void AddAsset(TextureAsset asset) { var exists = Assets.Any(t => t.GetAsset() == asset.GetAsset()); if (!exists) { Assets.Add(asset); } }
public void Draw(TextureAsset asset, Vector2f position, Color color) { Sprite sprite = new Sprite(asset.Resource); sprite.Position = position; sprite.Color = color; sprites.Add(sprite); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result) { result.BuildSteps = new ListBuildStep(); // Evaluate if we need to use a separate the alpha texture SeparateAlphaTexture = TextureCommandHelper.ShouldSeparateAlpha(asset.Alpha, asset.Format, context.Platform, context.GetGraphicsProfile()); // create the registry containing the sprite assets texture index association SpriteToTextureIndex = new Dictionary <TImageInfo, int>(); // create and add import texture commands if (asset.Images != null) { // return compilation error if one or more of the sprite does not have a valid texture var noSourceAsset = asset.Images.FirstOrDefault(x => !TextureFileIsValid(x.Source)); if (noSourceAsset != null) { result.Error("The texture of image '{0}' either does not exist or is invalid", noSourceAsset.Name); return; } // sort sprites by referenced texture. var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray(); for (int i = 0; i < spriteByTextures.Length; i++) { var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { SpriteToTextureIndex[spriteAsset] = i; } // create an texture asset. var textureAsset = new TextureAsset { Id = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid) Alpha = asset.Alpha, Format = asset.Format, GenerateMipmaps = asset.GenerateMipmaps, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, }; // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( ImageGroupAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } }
private void LoadAnimationController(XMLAsset<AnimationController> f) { if (f?.Content == null) return; AnimController = f.Content; _spriteSheetTexture = AnimController.AnimTex.TextureAsset; Animation = AnimController.AnimTex; _saveName = f.Name; AnimController.SetAnimation(AnimController.Animations.First().Key); }
public void DrawSprite(TextureAsset asset, Vector2f position, Color color, int frame) { Sprite sprite = new Sprite(asset.Resource); sprite.Position = position; sprite.Color = color; sprite.TextureRect = asset.GetSprite(frame); sprites.Add(sprite); }
protected override void AddNewAsset(Object o) { var texture = (Texture2D)o; EditorUtil.CheckTexture(texture); var t = new TextureAsset(texture); ((TileSet)CurrentSet).AddAsset(t); }
private void LoadSpriteSheetFile(TextureAsset f) { if (f?.Texture == null) return; _spriteSheetTexture?.Dispose(); _spriteSheetTexture = f; Animation = null; AnimController = null; _saveName = ""; }
private void LoadAnimatedTexture(XMLAsset<AnimatedTexture> f) { if (f?.Content == null) return; AnimatedTexture anim = f.Content; _spriteSheetTexture = anim.TextureAsset; Animation = anim; AnimController = null; _saveName = f.Name; }
public override void Allocate() { if (_tex == null && !string.IsNullOrEmpty(ImageSource)) { _tex = ContentManager.Instance.GetTexture(ImageSource, Thumbnail); } if (_tex != null && !_tex.IsAllocated) { _tex.Allocate(); } }
public Ship(IAssetManagerProvider assetManagerProvider, IFactory factory) { this.m_Factory = factory; this.Cells = new List<ShipCell>(); this.Rooms = new List<Room>(); this.m_CulledVertexBuffer = null; this.m_CulledIndexBuffer = null; this.m_BuffersNeedRecalculation = true; this.m_TextureAsset = assetManagerProvider.GetAssetManager().Get<TextureAsset>("ship"); }
/// <summary> /// マウスが重なっている場合、少し暗めに描画する /// </summary> public void MouseOverDraw() { if (!MouseOver()) { return; } DX.SetDrawBright(220, 220, 220); TextureAsset.DrawModi(TextureHandle, x1, y1, x2, y2, x3, y3, x4, y4, DX.TRUE); DrawText(); DX.SetDrawBright(255, 255, 255); }
public BackgroundCubeEntity( IAssetManagerProvider assetManagerProvider, bool atBottom) { this.m_Distance = m_Random.Next(1, 50); this.m_Rotation = m_Random.Next(0, 360); this.m_GrassAsset = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.Grass"); this.X = (float)(m_Random.NextDouble() - 0.5) * 25; this.Z = (float)(m_Random.NextDouble() - 0.5) * 25; if (atBottom) this.Y = 10; else this.Y = ((float)m_Random.NextDouble() * 60) - 50; }
public RoomEditorEntity( IKernel kernel, IMeshCollider meshCollider, I3DRenderUtilities threeRenderUtilities, IAssetManagerProvider assetManagerProvider, Room room) { this.m_Kernel = kernel; this.m_MeshCollider = meshCollider; this.m_3DRenderUtilities = threeRenderUtilities; this.m_Room = room; this.m_ShipTextureAsset = assetManagerProvider.GetAssetManager().Get<TextureAsset>("ship"); this.m_RoomEditorMode = RoomEditorMode.Hovering; }
// This is the player constructor. Both parameters are automatically dependency // injected when we call CreatePlayerEntity on the entity factory. public PlayerEntity( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider) { // Keep the 2D render utilities around for later. this.m_2DRenderUtilities = twodRenderUtilities; // Some implementations might assign the asset manager to a field, depending on // whether or not they need to look up assets during the update or render // loops. In this case we just need access to one texture, so we just keep // it in a local variable for easy access. var assetManager = assetManagerProvider.GetAssetManager(); // Retrieve the player texture. this.m_PlayerTexture = assetManager.Get<TextureAsset>("texture.Player"); }
public Room(IAssetManagerProvider assetManagerProvider) { this.FrontTextureIndex = 9; this.BackTextureIndex = 9; this.LeftTextureIndex = 9; this.RightTextureIndex = 9; this.AboveTextureIndex = 2; this.BelowTextureIndex = 1; this.Width = 80; this.Height = 60; this.Depth = 100; this.m_TextureAsset = assetManagerProvider.GetAssetManager().Get<TextureAsset>("ship"); this.m_RoomObjects = new List<RoomObject>(); this.m_RefreshBuffers = true; }
public void RenderLine(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Vector3 start, Vector3 end, TextureAsset texture, Vector2 startUV, Vector2 endUV) { if (!context.IsCurrentRenderPass<I3DRenderPass>()) { throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context."); } var vertexes = _renderCache.GetOrSet( "renderlinetex3dvb:" + start + ":" + end + ":" + startUV + ":" + endUV, () => { var vb = new VertexBuffer(context.GraphicsDevice, VertexPositionTexture.VertexDeclaration, 2, BufferUsage.WriteOnly); vb.SetData(new[] { new VertexPositionTexture(start, startUV), new VertexPositionTexture(end, endUV) }); return vb; }); var indicies = _renderCache.GetOrSet( "renderline3dib", () => { var ib = new IndexBuffer(context.GraphicsDevice, IndexElementSize.SixteenBits, 2, BufferUsage.WriteOnly); ib.SetData(new short[] { 0, 1 }); return ib; }); context.GraphicsDevice.SetVertexBuffer(vertexes); context.GraphicsDevice.Indices = indicies; var semantic = effectParameterSet.GetSemantic<ITextureEffectSemantic>(); if (semantic.Texture != texture.Texture) { semantic.Texture = texture.Texture; } effect.LoadParameterSet(context, effectParameterSet); foreach (var pass in effect.NativeEffect.CurrentTechnique.Passes) { pass.Apply(); context.GraphicsDevice.DrawPrimitives(PrimitiveType.LineList, 0, 1); } }
public Player( IPlatforming platforming, IAssetManager assetManager, I2DRenderUtilities renderUtilities, IAudioUtilities audioUtilities) { this.m_Platforming = platforming; this.m_AssetManager = assetManager; this.m_RenderUtilities = renderUtilities; this.m_AudioUtilities = audioUtilities; this.m_Texture = this.m_AssetManager.Get<TextureAsset>("texture.Player"); this.m_JumpSound = this.m_AssetManager.Get<AudioAsset>("audio.Jump"); this.m_JumpHandle = this.m_AudioUtilities.Play(this.m_JumpSound); this.Width = 32; this.Height = 32; }
public MenuWorld( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ISkin skin) { this.m_2DRenderUtilities = twodRenderUtilities; this.AssetManager = assetManagerProvider.GetAssetManager(); this.m_BackgroundCubeEntityFactory = backgroundCubeEntityFactory; this.m_TitleFont = this.AssetManager.Get<FontAsset>("font.Title"); this.m_PlayerModel = this.AssetManager.Get<ModelAsset>("model.Character"); this.m_PlayerModelTexture = this.AssetManager.Get<TextureAsset>("model.CharacterTex"); this.Entities = new List<IEntity>(); this.m_CanvasEntity = new CanvasEntity(skin) { Canvas = new Canvas() }; this.m_CanvasEntity.Canvas.SetChild(this.m_TitleMenu = new TitleMenu()); // Don't add the canvas to the entities list; that way we can explicitly // order it's depth. }
public LightEntity( LightRoomObject lightRoomObject, I3DRenderUtilities threedRenderUtilities, IAssetManagerProvider assetManagerProvider) { this.m_LightRoomObject = lightRoomObject; this.m_LightRoomObject.Deleted += this.OnDeleted; this.m_3DRenderUtilities = threedRenderUtilities; this.m_TextureAsset = assetManagerProvider.GetAssetManager().Get<TextureAsset>("ship"); var baseX = lightRoomObject.X + 0.5f; var baseY = lightRoomObject.Y + 0.5f; var baseZ = lightRoomObject.Z + 0.5f; // Set up rope physics. this.m_RopeComponents = new RigidBody[12]; this.m_PendingConstraints = new List<Constraint>(); for (var i = 0; i < 12; i++) { var shape = new BoxShape(0.5f, 0.5f, 0.5f); var rigidBody = new RigidBody(shape); rigidBody.Position = new JVector(baseX, baseY - (i * 0.6f), baseZ); this.m_RopeComponents[i] = rigidBody; if (i == 0) { rigidBody.IsStatic = true; } else { var constraint = new PointOnPoint( rigidBody, this.m_RopeComponents[i - 1], new JVector(baseX, baseY - (i * 0.6f) + 0.3f, baseZ)) { BiasFactor = 0.8f, Softness = 0.4f }; this.m_PendingConstraints.Add(constraint); } } }
protected void CycleTextures(RightAngledRotation rotation) { // Current -> Last _lastTexture = _currentTexture; _lastImageContext = _imageContext; // Next -> Current _currentTexture = _nextTexture; _imageContext = new ImageContext { FrameSize = _frameSize, ShaderEffect = Effect, Rotation = rotation }; // Clear next _nextTexture = null; if (_lastTexture != _currentTexture) { StartTransition(); FireChanged(); } }
protected override void FreeData() { _texture = null; base.FreeData(); }
public override void Allocate() { string uri = UriSource; if (String.IsNullOrEmpty(uri)) { if (_texture != null) { FreeData(); FireChanged(); } return; } TextureAsset texture = _texture; if (texture == null) texture = _texture = ContentManager.Instance.GetTexture(uri, DecodePixelWidth, DecodePixelHeight, Thumbnail); if (texture != null && !texture.IsAllocated) { if (Thumbnail) texture.ThumbnailDimension = ThumbnailDimension; texture.Allocate(); if (texture.IsAllocated) { _imageContext.Refresh(); FireChanged(); } } }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { Detach(); base.DeepCopy(source, copyManager); ImageBrush b = (ImageBrush) source; ImageSource = b.ImageSource; DownloadProgress = b.DownloadProgress; Thumbnail = b.Thumbnail; _tex = null; Attach(); }
/// <summary> /// The render texture. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="matrix"> /// The matrix. /// </param> /// <param name="texture"> /// The texture. /// </param> /// <param name="color"> /// The color. /// </param> /// <param name="flipHorizontally"> /// The flip horizontally. /// </param> /// <param name="flipVertically"> /// The flip vertically. /// </param> /// <param name="sourceArea"> /// The source area. /// </param> /// <exception cref="InvalidOperationException"> /// </exception> public void RenderTexture( IRenderContext context, Matrix matrix, TextureAsset texture, Color? color = null, bool flipHorizontally = false, bool flipVertically = false, Rectangle? sourceArea = null) { if (!context.Is3DContext) { throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context."); } this.RenderTexture(context, matrix, texture.Texture, color, flipHorizontally, flipVertically, sourceArea); }
protected override void FreeData() { base.FreeData(); _lastTexture = null; _currentTexture = null; _nextTexture = null; _lastImageContext.Clear(); }
public void RenderTexture( IRenderContext context, Vector2 position, TextureAsset texture, Vector2? size = null, Color? color = null, float rotation = 0, Vector2? rotationAnchor = null, bool flipHorizontally = false, bool flipVertically = false, Rectangle? sourceArea = null) { RenderTexture( context, position, texture.Texture, size, color, rotation, rotationAnchor, flipHorizontally, flipVertically, sourceArea); }
public override void Allocate() { _imageContext.Rotation = _rotation; TextureAsset texture = _texture; if (texture == null && _stream != null) texture = _texture = ContentManager.Instance.GetTexture(_stream, _key); if (texture != null && !texture.IsAllocated) texture.Allocate(); }
/// <summary> /// Renders a 3D line using texture UVs. /// </summary> /// <param name="context"> /// The rendering context. /// </param> /// <param name="start"> /// The start of the line. /// </param> /// <param name="end"> /// The end of the line. /// </param> /// <param name="texture"> /// The texture to use. /// </param> /// <param name="startUV"> /// The UV for the start of the line. /// </param> /// <param name="endUV"> /// The UV for the end of the line. /// </param> public void RenderLine( IRenderContext context, Vector3 start, Vector3 end, TextureAsset texture, Vector2 startUV, Vector2 endUV) { if (!context.Is3DContext) { throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context."); } context.EnableTextures(); context.SetActiveTexture(texture.Texture); var vertexes = new[] { new VertexPositionTexture(start, startUV), new VertexPositionTexture(end, endUV) }; var indicies = new short[] { 0, 1 }; foreach (var pass in context.Effect.CurrentTechnique.Passes) { pass.Apply(); context.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertexes, 0, 2, indicies, 0, 1); } }
public override void Deallocate() { base.Deallocate(); _texture = null; }
public void RenderPlane(IRenderContext context, Matrix transform, TextureAsset texture, Vector2 topLeftUV, Vector2 bottomRightUV) { if (!context.Is3DContext) { throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context."); } var vertexes = new[] { new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, topLeftUV.Y)), new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)), new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)), new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)), }; var indicies = new short[] { 0, 2, 1, 3, 1, 2, }; context.EnableTextures(); context.SetActiveTexture(texture.Texture); var world = context.World; context.World = transform; foreach (var pass in context.Effect.CurrentTechnique.Passes) { pass.Apply(); context.GraphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.TriangleList, vertexes, 0, vertexes.Length, indicies, 0, indicies.Length / 3); } context.World = world; }
public override void Allocate() { if (_source) { _source = false; string uri = UriSource; if (String.IsNullOrEmpty(uri)) { _nextTexture = null; if (_currentTexture != null) CycleTextures(RightAngledRotation.Zero); } else { _nextTexture = ContentManager.Instance.GetTexture(uri, DecodePixelWidth, DecodePixelHeight, Thumbnail); _nextTexture.ThumbnailDimension = ThumbnailDimension; } } // Check our previous texture is allocated. Synchronous. TextureAsset lastTexture = _lastTexture; TextureAsset currentTexture = _currentTexture; TextureAsset nextTexture = _nextTexture; if (lastTexture != null && !lastTexture.IsAllocated) lastTexture.Allocate(); // Check our current texture is allocated. Synchronous. if (currentTexture != null && !currentTexture.IsAllocated) currentTexture.Allocate(); // Check our next texture is allocated. Asynchronous. if (nextTexture != null) { if (!nextTexture.LoadFailed) nextTexture.AllocateAsync(); else { _nextTexture = null; CycleTextures(RightAngledRotation.Zero); // If new texture cannot be loaded, we allow switching to "empty" texture return; } if (!_transitionActive && nextTexture.IsAllocated) CycleTextures(RightAngledRotation.Zero); } }
public void Free() { _tex = null; }
public override void Allocate() { if (_tex == null && !string.IsNullOrEmpty(ImageSource)) _tex = ContentManager.Instance.GetTexture(ImageSource, Thumbnail); if (_tex != null && !_tex.IsAllocated) _tex.Allocate(); }
public static Texture CreateTexture(this Graphics graphics, TextureAsset textureAsset) { return graphics.CreateTexture (textureAsset.TextureFormat, textureAsset.Width, textureAsset.Height, textureAsset.Data); }