public override void Show(string assetName) { base.Show(assetName); EngineRef.SetViewsControlsEnabled(false, false, false, false, false); EngineRef.CameraEntity.GetComponent <Transform>().SetTransformations(new Vector3(0f, 0, -2f), Quaternion.RotationYawPitchRoll(MathUtil.Pi, 0, 0)); PreviewEntity.SetActive(true); EngineRef.ECSWorld.Refresh(); Texture2DAsset asset = AssetsManagerInstance.GetManager().LoadAsset <Texture2DAsset>(assetName); ratio = (float)asset.Data.Width / asset.Data.Height; Vector3 scale; if (ratio >= 1) { scale = (Vector3.Right + Vector3.Up / ratio) * 3.85f; } else { scale = (Vector3.Right + Vector3.Up * ratio) * 3.85f; } scale += Vector3.ForwardLH * 0.1f; PreviewEntity.GetComponent <Transform>().Scale = scale; TestMaterial.AlbedoMapAsset = assetName; }
public IAsset LoadAsset(StagedAsset stagedAsset) { IAsset asset = null; switch (stagedAsset.Type) { case (AssetType.AudioAsset): asset = new AudioAsset(stagedAsset.Id, new AudioFileReader(stagedAsset.FilePath)); break; case (AssetType.SpriteFontAsset): { SpriteFont sf; lock (stagedAsset.Content) sf = stagedAsset.Content.Load <SpriteFont>(stagedAsset.FilePath); asset = new SpriteFontAsset(stagedAsset.Id, sf); } break; case (AssetType.Texture2DAsset): { Texture2D td; lock (stagedAsset.Content) td = stagedAsset.Content.Load <Texture2D>(stagedAsset.FilePath); asset = new Texture2DAsset(stagedAsset.Id, td); } break; } return(asset); }
public Image(string id, Texture2DAsset texture2DAsset, Vector2 sourcePosition, Vector2 sourceDimensions, Color color, Vector2 positionOffset, Vector2 dimsensions, bool enabled = true, bool visible = true) : base(id) { _texture2DAsset = texture2DAsset; _sourceRectangle = new Rectangle(sourcePosition.ToPoint(), sourceDimensions.ToPoint()); _positionOffset = positionOffset; _dimensions = dimsensions; _color = color; _enabled = enabled; _visible = visible; }
public bool ImportAsset(string Path, string Name, bool Rewrite, out BaseAsset assetRes) { string[] arr = Path.Split('.'); string ext = arr[arr.Length - 1].ToLower(); assetRes = null; BaseAsset asset; if (shaderExts.Contains(ext)) { return(ImportShaderAsset(Path, Name, null, null, true, out assetRes)); } else if (meshExts.Contains(ext)) { asset = new MeshAsset() { Name = Name, }; } else if (textureExts.Contains(ext)) { asset = new Texture2DAsset() { Name = Name, // Hack for forcing srgb image with wrong meta-data ForceSRgb = Name.Contains("Albedo"), }; } else { Console.WriteLine("Unknown asset extension: {0}", ext); return(false); } if (!asset.ImportAsset(Path, ext)) { return(false); } assetRes = asset; return(FSWorker.CreateAssetFile(asset, Rewrite || asset.Type == AssetTypes.Shader)); }
public Sprite(string id, Texture2DAsset texture2DAsset, Vector2 sourcePosition, Vector2 sourceDimensions, Color color, Vector2 positionOffset, Vector2 dimensions, int rows, int columns, int frameTime = -1, bool looping = true, bool enabled = true, bool visible = true) : base(id, texture2DAsset, sourcePosition, sourceDimensions, color, positionOffset, dimensions, enabled, visible) { _sourcePosition = sourcePosition; _sourceDimensions = sourceDimensions; _rows = rows; _columns = columns; _looping = looping; _currentRow = 0; _currentColumn = 0; _elapsedTime = new TimeSpan(); if (frameTime > 0) { _frameTime = frameTime; } else { _frameTime = Graphics2DConfig.DefaultFrameTime; } }