public override bool Convert(ConvertOperation convert) { List<object> results = new List<object>(); List<Material> availData = convert.Perform<Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) continue; DrawTechnique tech = mat.Technique.Res; LightingTechnique lightTech = tech as LightingTechnique; if (tech == null) continue; bool isDynamicLighting = lightTech != null || tech.PreferredVertexFormat == VertexC1P3T2A4.Declaration || tech.PreferredVertexFormat == VertexC1P3T4A4A1.Declaration; if (!isDynamicLighting) continue; Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0) { LightingSpriteRenderer sprite = convert.Result.OfType<LightingSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<LightingSpriteRenderer>(); if (sprite == null) sprite = new LightingSpriteRenderer(); sprite.SharedMaterial = mat; if (mainTex != null) sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { LightingAnimSpriteRenderer sprite = convert.Result.OfType<LightingAnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<LightingAnimSpriteRenderer>(); if (sprite == null) sprite = new LightingAnimSpriteRenderer(); sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2, (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = basePixmap.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return false; }
public override bool Convert(ConvertOperation convert) { // If we already have a renderer in the result set, consider generating // another one to be not the right course of action. if (convert.Result.OfType<ICmpRenderer>().Any()) return false; List<object> results = new List<object>(); List<Material> availData = convert.Perform<Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) continue; Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0) { SpriteRenderer sprite = convert.Result.OfType<SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<SpriteRenderer>(); if (sprite == null) sprite = new SpriteRenderer(); sprite.SharedMaterial = mat; if (mainTex != null) sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { AnimSpriteRenderer sprite = convert.Result.OfType<AnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<AnimSpriteRenderer>(); if (sprite == null) sprite = new AnimSpriteRenderer(); sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2, (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = basePixmap.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return false; }
public override bool Convert(ConvertOperation convert) { List<object> results = new List<object>(); List<Font> availData = convert.Perform<Font>().ToList(); // Generate objects foreach (Font font in availData) { if (convert.IsObjectHandled(font)) continue; GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); TextRenderer renderer = convert.Result.OfType<TextRenderer>().FirstOrDefault(); if (renderer == null && gameobj != null) renderer = gameobj.GetComponent<TextRenderer>(); if (renderer == null) renderer = new TextRenderer(); convert.SuggestResultName(renderer, font.Name); if (!renderer.Text.Fonts.Contains(font)) { var fonts = renderer.Text.Fonts.ToList(); if (fonts[0] == Font.GenericMonospace10) fonts.RemoveAt(0); fonts.Add(font); renderer.Text.Fonts = fonts.ToArray(); renderer.Text.ApplySource(); } results.Add(renderer); convert.MarkObjectHandled(font); } convert.AddResult(results); return false; }
public override bool Convert(ConvertOperation convert) { // If we already have a renderer in the result set, consider generating // a tilemap to be not the right course of action. if (convert.Result.OfType<ICmpRenderer>().Any()) return false; List<object> results = new List<object>(); List<Tileset> availData = convert.Perform<Tileset>().ToList(); // Generate objects foreach (Tileset tileset in availData) { if (convert.IsObjectHandled(tileset)) continue; // Retrieve previously generated GameObjects and Tilemaps for re-use GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); Tilemap tilemap = convert.Result.OfType<Tilemap>().FirstOrDefault(); TilemapRenderer tilemapRenderer = convert.Result.OfType<TilemapRenderer>().FirstOrDefault(); if (tilemap == null && gameobj != null) tilemap = gameobj.GetComponent<Tilemap>(); // Create a new Tilemap (and TilemapRenderer) if none did exist before if (tilemap == null) { tilemap = new Tilemap(); TilemapsSetupUtility.SetupTilemap(tilemap, tileset); // Add a renderer for this Tilemap to the result list, if there was none before if (tilemapRenderer == null) { results.Add(new TilemapRenderer()); } } // Configure the Tilemap according to the Tileset we're converting tilemap.Tileset = tileset; // Add the Tilemap to our result set results.Add(tilemap); convert.SuggestResultName(tilemap, tileset.Name); convert.MarkObjectHandled(tileset); } convert.AddResult(results); return false; }
public override bool Convert(ConvertOperation convert) { List<Sound> availData = convert.Perform<Sound>().ToList(); // Generate objects foreach (Sound snd in availData) { if (convert.IsObjectHandled(snd)) continue; GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); SoundEmitter emitter = convert.Result.OfType<SoundEmitter>().FirstOrDefault(); if (emitter == null && gameobj != null) emitter = gameobj.GetComponent<SoundEmitter>(); if (emitter == null) emitter = new SoundEmitter(); convert.SuggestResultName(emitter, snd.Name); SoundEmitter.Source source = new SoundEmitter.Source(snd); emitter.Sources.Add(source); convert.AddResult(emitter); convert.MarkObjectHandled(snd); } return false; }
public override bool Convert(ConvertOperation convert) { List<object> results = new List<object>(); List<Material> availData = convert.Perform<Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) continue; Texture mainTex = mat.MainTexture.Res; GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); if (mainTex == null || mainTex.AnimFrames == 0) { SpriteRenderer sprite = convert.Result.OfType<SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<SpriteRenderer>(); if (sprite == null) sprite = new SpriteRenderer(); sprite.SharedMaterial = mat; if (mainTex != null) sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { AnimSpriteRenderer sprite = convert.Result.OfType<AnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) sprite = gameobj.GetComponent<AnimSpriteRenderer>(); if (sprite == null) sprite = new AnimSpriteRenderer(); sprite.SharedMaterial = mat; sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth / mainTex.AnimCols, mainTex.PixelHeight / mainTex.AnimRows); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = mainTex.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return false; }
public override bool Convert(ConvertOperation convert) { List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0) { SpriteRenderer sprite = convert.Result.OfType <SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <SpriteRenderer>(); } if (sprite == null) { sprite = new SpriteRenderer(); } sprite.SharedMaterial = mat; if (mainTex != null) { sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); } convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { AnimSpriteRenderer sprite = convert.Result.OfType <AnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <AnimSpriteRenderer>(); } if (sprite == null) { sprite = new AnimSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.AlignCenter( 0.0f, 0.0f, (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2, (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = basePixmap.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
public override bool Convert(ConvertOperation convert) { // If we already have a renderer in the result set, consider generating // another one to be not the right course of action. if (convert.Result.OfType <ICmpRenderer>().Any()) { return(false); } List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); bool hasAnimation = (mainTex != null && basePixmap != null && basePixmap.Atlas != null && basePixmap.Atlas.Count > 0); // Determine the size of the displayed sprite Vector2 spriteSize; if (hasAnimation) { Rect atlasRect = basePixmap.LookupAtlas(0); spriteSize = atlasRect.Size; } else if (mainTex != null) { spriteSize = mainTex.ContentSize; // If we're dealing with default content, clamp sprite size to // something easily visible in order to avoid 1x1 sprites for // default White / Black or similar fallback textures. if (mainTex.IsDefaultContent) { spriteSize = Vector2.Max(spriteSize, new Vector2(32.0f, 32.0f)); } } else { spriteSize = Pixmap.Checkerboard.Res.Size; } // Create a sprite Component in any case SpriteRenderer sprite = convert.Result.OfType <SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <SpriteRenderer>(); } if (sprite == null) { sprite = new SpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, spriteSize.X, spriteSize.Y); results.Add(sprite); // If we have animation data, create an animator component as well if (hasAnimation) { SpriteAnimator animator = convert.Result.OfType <SpriteAnimator>().FirstOrDefault(); if (animator == null && gameobj != null) { animator = gameobj.GetComponent <SpriteAnimator>(); } if (animator == null) { animator = new SpriteAnimator(); } animator.AnimDuration = 5.0f; animator.FrameCount = basePixmap.Atlas.Count; results.Add(animator); } convert.SuggestResultName(sprite, mat.Name); convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
public override bool Convert(ConvertOperation convert) { List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } DrawTechnique tech = mat.Technique.Res; LightingTechnique lightTech = tech as LightingTechnique; if (tech == null) { continue; } bool isDynamicLighting = lightTech != null || tech.PreferredVertexFormat == VertexC1P3T2A4.VertexTypeIndex || tech.PreferredVertexFormat == VertexC1P3T4A4A1.VertexTypeIndex; if (!isDynamicLighting) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0) { LightingSpriteRenderer sprite = convert.Result.OfType <LightingSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingSpriteRenderer>(); } if (sprite == null) { sprite = new LightingSpriteRenderer(); } sprite.SharedMaterial = mat; if (mainTex != null) { sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); } convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { LightingAnimSpriteRenderer sprite = convert.Result.OfType <LightingAnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingAnimSpriteRenderer>(); } if (sprite == null) { sprite = new LightingAnimSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.AlignCenter( 0.0f, 0.0f, (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2, (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = basePixmap.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
public override bool Convert(ConvertOperation convert) { // If we already have a renderer in the result set, consider generating // another one to be not the right course of action. if (convert.Result.OfType <ICmpRenderer>().Any()) { return(false); } List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } DrawTechnique tech = mat.Technique.Res; if (tech == null) { continue; } bool isDynamicLighting = tech is LightingTechnique || tech.PreferredVertexFormat == VertexDynamicLighting.Declaration; if (!isDynamicLighting) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); bool hasAnimation = (mainTex != null && basePixmap != null && basePixmap.Atlas != null && basePixmap.Atlas.Count > 0); // Determine the size of the displayed sprite Vector2 spriteSize; if (hasAnimation) { Rect atlasRect = basePixmap.LookupAtlas(0); spriteSize = atlasRect.Size; } else if (mainTex != null) { spriteSize = mainTex.ContentSize; } else { spriteSize = Pixmap.Checkerboard.Res.Size; } // Create a sprite Component in any case LightingSpriteRenderer sprite = convert.Result.OfType <LightingSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingSpriteRenderer>(); } if (sprite == null) { sprite = new LightingSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, spriteSize.X, spriteSize.Y); results.Add(sprite); // If we have animation data, create an animator component as well if (hasAnimation) { SpriteAnimator animator = convert.Result.OfType <SpriteAnimator>().FirstOrDefault(); if (animator == null && gameobj != null) { animator = gameobj.GetComponent <SpriteAnimator>(); } if (animator == null) { animator = new SpriteAnimator(); } animator.AnimDuration = 5.0f; animator.FrameCount = basePixmap.Atlas.Count; results.Add(animator); } convert.SuggestResultName(sprite, mat.Name); convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }