public Animator(string name, string nodeName, bool loop, AnimationCollection animationCollection, string prefix = "\t") : base(name, prefix) { _name = name; _nodeName = nodeName; _loop = loop; _collection = animationCollection; }
public override void OnInspectorGUI() { DrawDefaultInspector(); AnimationCollection collection = (AnimationCollection)target; if (GUILayout.Button("Update Animator")) { Debug.Log("Update Animator"); AnimatorController animatorController = collection.AnimatorController; var stateMachine = animatorController.layers[1].stateMachine; //Clear animations stateMachine.states = new ChildAnimatorState[0]; var state = stateMachine.AddState("Null", new Vector3(250, 100)); //Add animations AnimationCollection.AnimationStruct abilityAnimation; for (int i = 0; i < collection.AbilityAnimations.Count; i++) { abilityAnimation = collection.AbilityAnimations[i]; state = stateMachine.AddState(abilityAnimation.AnimationName, new Vector3(30, 180 + 50 * i)); state.motion = abilityAnimation.Animation; } EditorUtility.SetDirty(stateMachine); collection.AnimatorController.layers[1].stateMachine = stateMachine; EditorUtility.SetDirty(animatorController); AssetDatabase.SaveAssets(); } }
private async void PlayBtn_Loaded(object sender, RoutedEventArgs e) { await Task.Delay(1000); var showAnimations = new AnimationCollection { new TranslationAnimation { Delay = TimeSpan.FromSeconds(0.3), SetInitialValueBeforeDelay = true, Duration = TimeSpan.FromSeconds(0.6), From = "0,-20,0", To = "0,0,0" }, new OpacityAnimation { Delay = TimeSpan.FromSeconds(0.3), SetInitialValueBeforeDelay = true, Duration = TimeSpan.FromSeconds(0.6), From = 0, To = 1 } }; Implicit.SetShowAnimations(PlayBtn, showAnimations); }
private void SetAnimationsForAppTiles() { int Counter = 1; foreach (AppTile Tile in AppGrid.Children.OfType <AppTile>()) { int Duration = Counter * 80; AnimationCollection Col = new AnimationCollection(); OpacityAnimation O = new OpacityAnimation { Duration = new TimeSpan(0, 0, 0, 0, Duration), From = 0, To = 1.0 }; TranslationAnimation T = new TranslationAnimation { Duration = new TimeSpan(0, 0, 0, 0, Duration), From = "0, 80, 0", To = "0" }; Col.Add(O); Col.Add(T); Implicit.SetShowAnimations(Tile, Col); Counter++; } }
/// <summary> /// Adds a SequencedAnimation as a child of this AnimationCollection, /// using the specified callback to configure the collection /// </summary> /// <param name="animationCollection">The target animation collection</param> /// <param name="configureFunction"></param> /// <returns>Returns this AnimationCollection to comply with fluent interface</returns> public static AnimationCollection Sequence(this AnimationCollection animationCollection, Action <SequencedAnimation> configureFunction) { var sequence = new SequencedAnimation(); animationCollection.Add(sequence); configureFunction(sequence); return(animationCollection); }
/// <summary> /// Adds a ParalleledAnimation as a child of this AnimationCollection, /// using the specified callback to configure the collection /// </summary> /// <param name="animationCollection">The target animation collection</param> /// <param name="configureFunction"></param> /// <returns>Returns this AnimationCollection to comply with fluent interface</returns> public static AnimationCollection Parallel(this AnimationCollection animationCollection, Action <ParalleledAnimation> configureFunction) { var parallel = new ParalleledAnimation(); animationCollection.Add(parallel); configureFunction(parallel); return(animationCollection); }
public CharacterBrain(AnimationCollection animationCollection, GameObject owner) : base(owner) { _transform = owner.Components.Get <Transform>() ?? throw new ComponentNotFoundException <Transform>(); _animationController = owner.Components.Get <AnimationController>() ?? throw new ComponentNotFoundException <AnimationController>(); }
public void Draw(AnimationCollection animationCollection, Vector2 position, Color color) { if (animationCollection.Length <= 0) { return; } Draw(animationCollection.GetCurrent(), position, color); }
public void Draw(AnimationCollection animationCollection, Rectangle destinationRectangle, Color color) { if (animationCollection.Length <= 0) { return; } Draw(animationCollection.GetCurrent(), destinationRectangle, color); }
private static void InitAnimationController(AnimationCollection animationCollection, GameObject warrior) { var animationController = new AnimationController(warrior); animationController.SetFloat("speed", 0f); animationController.SetBool("attacking", false); animationController.SetBool("jumping", false); warrior.Components.Add(animationController); var idle = new AnimationState(animationCollection.GetAnimation("Idle")); animationController.AddState(idle); var run = new AnimationState(animationCollection.GetAnimation("Run")); animationController.AddState(run); var jump = new AnimationState(animationCollection.GetAnimation("Jump")); animationController.AddState(jump); var attack = new AnimationState(animationCollection.GetAnimation("Attack1")); animationController.AddState(attack); idle.AddTransition(run, new Func <AnimationController, bool>[] { ctrl => ctrl.GetFloat("speed") > .1f }); idle.AddTransition(attack, new Func <AnimationController, bool>[] { ctrl => ctrl.GetBool("attacking") }); idle.AddTransition(jump, new Func <AnimationController, bool>[] { ctrl => ctrl.GetBool("jumping") }); run.AddTransition(idle, new Func <AnimationController, bool>[] { ctrl => ctrl.GetFloat("speed") < .1f }); run.AddTransition(attack, new Func <AnimationController, bool>[] { ctrl => ctrl.GetBool("attacking") }); attack.AddTransition(idle, new Func <AnimationController, bool>[] { ctrl => !ctrl.GetBool("attacking") }); jump.AddTransition(idle, new Func <AnimationController, bool>[] { ctrl => !ctrl.GetBool("jumping") }); }
public void Draw(AnimationCollection animationCollection, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { if (animationCollection.Length <= 0) { return; } Draw(animationCollection.GetCurrent(), position, color, rotation, origin, scale, effects, layerDepth); }
public void Draw(AnimationCollection animationCollection, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { if (animationCollection.Length <= 0) { return; } Draw(animationCollection.GetCurrent(), destinationRectangle, color, rotation, origin, effects, layerDepth); }
public static AnimationCollection GetTileAnimation(this TileSet tileSet, uint gid) { AnimationCollection animation; if (!tileSet.tileAnimations.TryGetValue(gid, out animation)) { animation = new AnimationCollection(); } return(animation); }
/// <summary> /// Run the application /// </summary> public void Go() { // Make the particle emitter. emit = new ParticleRectangleEmitter(particles); emit.Frequency = 50000; // 100000 every 1000 updates. emit.LifeFullMin = 20; emit.LifeFullMax = 50; emit.LifeMin = 10; emit.LifeMax = 30; emit.DirectionMin = -2; // shoot up in radians. emit.DirectionMax = -1; emit.ColorMin = Color.DarkBlue; emit.ColorMax = Color.LightBlue; emit.SpeedMin = 5; emit.SpeedMax = 20; emit.MaxSize = new SizeF(5, 5); emit.MinSize = new SizeF(1, 1); // Make the first particle (a pixel) ParticlePixel first = new ParticlePixel(Color.White, 100, 200, new Vector(0, 0, 0), -1); particles.Add(first); // Add it to the system if (File.Exists(Path.Combine(dataDirectory, "marble1.png"))) { filePath = ""; } // Make the second particle (an animated sprite) AnimationCollection anim = new AnimationCollection(); SurfaceCollection surfaces = new SurfaceCollection(); surfaces.Add(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png")), new Size(50, 50)); anim.Add(surfaces, 1); AnimatedSprite marble = new AnimatedSprite(anim); marble.Animate = true; ParticleSprite second = new ParticleSprite(marble, 200, 200, new Vector(-7, -9, 0), 500); second.Life = -1; particles.Add(second); // Add it to the system // Add some manipulators to the particle system. ParticleGravity grav = new ParticleGravity(0.5f); particles.Manipulators.Add(grav); // Gravity of 0.5f particles.Manipulators.Add(new ParticleFriction(0.1f)); // Slow down particles particles.Manipulators.Add(vort); // A particle vortex fixed on the mouse particles.Manipulators.Add(new ParticleBoundary(SdlDotNet.Graphics.Video.Screen.Size)); // fix particles on screen. Events.Run(); }
public AnimatedSprite(string name, AnimationCollection collection, IResourceCache resourceCache) { AnimationStates = new Dictionary<string, AnimationState>(); Name = name; LoadSprites(collection, resourceCache); if (AnimationStates.ContainsKey("idle")) SetAnimationState("idle"); SetLoop(true); SetCurrentSprite(); //IoCManager.Resolve<IResourceCache>(). }
private void ContainerItem_Loaded(object sender, RoutedEventArgs e) { var itemsPanel = (ItemsWrapGrid)_patternPickerGridView.ItemsPanelRoot; var itemContainer = (GridViewItem)sender; itemContainer.Loaded -= this.ContainerItem_Loaded; var button = itemContainer.FindDescendant <Button>(); if (button != null) { button.Click -= MoreInfoClicked; button.Click += MoreInfoClicked; } if (!_isCreatorsUpdateOrAbove) { return; } var itemIndex = _patternPickerGridView.IndexFromContainer(itemContainer); var referenceIndex = itemsPanel.FirstVisibleIndex; if (_patternPickerGridView.SelectedIndex >= 0) { referenceIndex = _patternPickerGridView.SelectedIndex; } var relativeIndex = Math.Abs(itemIndex - referenceIndex); if (itemContainer.Content != CurrentPattern && itemIndex >= 0 && itemIndex >= itemsPanel.FirstVisibleIndex && itemIndex <= itemsPanel.LastVisibleIndex) { var staggerDelay = TimeSpan.FromMilliseconds(relativeIndex * 30); var animationCollection = new AnimationCollection() { new OpacityAnimation() { From = 0, To = 1, Duration = TimeSpan.FromMilliseconds(400), Delay = staggerDelay, SetInitialValueBeforeDelay = true }, new ScaleAnimation() { From = "0.9", To = "1", Duration = TimeSpan.FromMilliseconds(400), Delay = staggerDelay } }; VisualEx.SetNormalizedCenterPoint(itemContainer, "0.5"); animationCollection.StartAnimation(itemContainer); } }
public AnimationCollection ToAsset() { var asset = new AnimationCollection(this.name); if (this.animations is not null) { foreach (var animDto in this.animations) { var elementRef = new ElementReference(Guid.NewGuid().ToString()); var anim = animDto.ToAsset(elementRef, asset); } } return(asset); }
public AnimatedTileLighting(BasicTile tile) { Position = tile.Position; Index = tile.Index; var array = tile.Animations.GetAnimations().Where(a => a.Name.EndsWith("shadow")).ToArray(); animations = new AnimationCollection(tile.Animations.StartAnimation + "shadow"); if (array.Length <= 0) { GameConsole.Warning("Warning: No shadow animations found."); return; } animations.AddAnimations(array); tile.Animations.AnimationChanged += AnimationChanged; }
public void SetAnimation(AnimationCollection animationCollection) { AnimationCollection = animationCollection; if (Animator == null) { delayed = true; return; } animationClipOverides["idle"] = animationCollection.Idle; animationClipOverides["walkup"] = animationCollection.WalkUp; animationClipOverides["walkdown"] = animationCollection.WalkDown; animationClipOverides["walkleft"] = animationCollection.WalkLeft; animationClipOverides["walkright"] = animationCollection.WalkRight; AnimatorOverrideController.ApplyOverrides(animationClipOverides); delayed = false; }
private void OnItemContainerLoaded(object sender, RoutedEventArgs e) { var itemsPanel = (ItemsWrapGrid)this.ItemsPanelRoot; var itemContainer = (GridViewItem)sender; itemContainer.Loaded -= this.OnItemContainerLoaded; if (!_isCreatorsUpdateOrAbove) { return; } var itemIndex = this.IndexFromContainer(itemContainer); var referenceIndex = itemsPanel.FirstVisibleIndex; if (this.SelectedIndex >= 0) { referenceIndex = this.SelectedIndex; } var relativeIndex = Math.Abs(itemIndex - referenceIndex); if (itemIndex >= 0 && itemIndex >= itemsPanel.FirstVisibleIndex && itemIndex <= itemsPanel.LastVisibleIndex) { var staggerDelay = TimeSpan.FromMilliseconds(relativeIndex * 30); var animationCollection = new AnimationCollection() { new OpacityAnimation() { From = 0, To = 1, Duration = TimeSpan.FromMilliseconds(400), Delay = staggerDelay, SetInitialValueBeforeDelay = true }, new ScaleAnimation() { From = "0.9", To = "1", Duration = TimeSpan.FromMilliseconds(400), Delay = staggerDelay } }; VisualEx.SetNormalizedCenterPoint(itemContainer, "0.5"); animationCollection.StartAnimation(itemContainer); } }
public static AnimatedSprite CreateColored(AnimatedSprite os, Color c) { if (os == null) { return(null); } AnimatedSprite nsprite = new AnimatedSprite(); foreach (KeyValuePair <string, AnimationCollection> kv in os.Animations) { string key = kv.Key; AnimationCollection anim = kv.Value; AnimationCollection nAnim = new AnimationCollection(); foreach (Surface s in anim) { Surface ns = CreateColored(s, c); nAnim.Add(ns); } nAnim.Loop = anim.Loop; nAnim.Delay = anim.Delay; nAnim.FrameIncrement = anim.FrameIncrement; nAnim.Alpha = anim.Alpha; nAnim.AlphaBlending = anim.AlphaBlending; nAnim.AnimateForward = anim.AnimateForward; //nAnim.AnimationTime = anim.AnimationTime; nAnim.Transparent = anim.Transparent; nAnim.TransparentColor = anim.TransparentColor; nsprite.Animations.Add(key, nAnim); } nsprite.AllowDrag = os.AllowDrag; nsprite.Alpha = os.Alpha; nsprite.AlphaBlending = os.AlphaBlending; nsprite.Animate = os.Animate; nsprite.AnimateForward = os.AnimateForward; nsprite.CurrentAnimation = os.CurrentAnimation; nsprite.Frame = os.Frame; nsprite.Transparent = os.Transparent; nsprite.TransparentColor = os.TransparentColor; nsprite.Visible = os.Visible; return(nsprite); }
/// <summary> /// Constructs the internal sprites needed for our demo. /// </summary> public DragMode() { // Create the fragment marbles int rows = 3; int cols = 3; int sx = (SpriteDemosMain.Size.Width - cols * 50) / 2; int sy = (SpriteDemosMain.Size.Height - rows * 50) / 2; SurfaceCollection m1 = LoadMarble("marble1"); SurfaceCollection m2 = LoadMarble("marble2"); AnimationCollection anim1 = new AnimationCollection(); anim1.Add(m1); AnimationCollection anim2 = new AnimationCollection(); anim2.Add(m2); AnimationDictionary frames = new AnimationDictionary(); frames.Add("marble1", anim1); frames.Add("marble2", anim2); DragSprite dragSprite; for (int i = 0; i < cols; i++) { Thread.Sleep(10); for (int j = 0; j < rows; j++) { dragSprite = new DragSprite(frames["marble1"], new Point(sx + i * 50, sy + j * 50) ); dragSprite.Animations.Add("marble1", anim1); dragSprite.Animations.Add("marble2", anim2); dragSprite.Animate = true; if (Randomizer.Next(2) == 1) { dragSprite.AnimateForward = false; } Thread.Sleep(10); Sprites.Add(dragSprite); } } }
public void SetAnimation(AnimationCollection animationCollection, Color?color = null) { if (AnimationLayers.ContainsKey(animationCollection.Layer)) { AnimationLayers[animationCollection.Layer].SetAnimation(animationCollection); return; } var newObj = Instantiate(AnimationLayerPrefab, transform); var layer = newObj.GetComponent <EntityAnimationLayer>(); layer.Layer = animationCollection.Layer; layer.name = animationCollection.Layer; AnimationLayers.Add(animationCollection.Layer, layer); layer.SetAnimation(animationCollection); if (color.HasValue) { layer.SetColor(color.Value); } }
static AnimationCollection CreateCollection(string path, string layer, string assetName) { var allAssets = AssetDatabase.LoadAllAssetsAtPath(path); var spri = allAssets.Where(x => x.GetType() == typeof(Sprite)).ToArray(); List <Sprite> sprites = new List <Sprite>(); foreach (var s in spri) { sprites.Add(s as Sprite); } var animationCollection = new AnimationCollection(); animationCollection.Name = assetName; animationCollection.Layer = layer; //idle var idle = sprites.Where(x => x.name.Contains("_hu_0")); animationCollection.Idle = CreateAnimation($"{layer}/{assetName}idle", idle.ToArray()); //walk up var walkup = sprites.Where(x => x.name.Contains("_wc_t_")); animationCollection.WalkUp = CreateAnimation($"{layer}/{assetName}walkup", walkup.ToArray()); //walk left var walkleft = sprites.Where(x => x.name.Contains("_wc_l_")); animationCollection.WalkLeft = CreateAnimation($"{layer}/{assetName}walkleft", walkleft.ToArray()); //walk right var walkright = sprites.Where(x => x.name.Contains("_wc_r_")); animationCollection.WalkRight = CreateAnimation($"{layer}/{assetName}walkright", walkright.ToArray()); //walk down var walkdown = sprites.Where(x => x.name.Contains("_wc_d_")); animationCollection.WalkDown = CreateAnimation($"{layer}/{assetName}walkdown", walkdown.ToArray()); return(animationCollection); }
//Todo encapsulate this further down as components -- AnimatedSpriteState, AnimatedSpriteStateDirection public void LoadSprites(AnimationCollection collection, IResourceManager resourceManager) { float x = 0, y = 0, h = 0, w = 0; int t = 0; foreach (var info in collection.Animations) { _sprites.Add(info.Name, new Dictionary <Direction, SFML.Graphics.Sprite[]>()); //Because we have a shitload of frames, we're going to store the average size as the AABB for each direction and each animation _averageAABBs.Add(info.Name, new Dictionary <Direction, FloatRect>()); var sprites = _sprites[info.Name]; var averageAABBs = _averageAABBs[info.Name]; AnimationStates.Add(info.Name, new AnimationState(info)); foreach (var dir in Enum.GetValues(typeof(Direction)).Cast <Direction>()) { sprites.Add(dir, new SFML.Graphics.Sprite[info.Frames]); var thisDirSprites = sprites[dir]; for (var i = 0; i < info.Frames; i++) { var spritename = collection.Name.ToLowerInvariant() + "_" + info.Name.ToLowerInvariant() + "_" + DirectionToUriComponent(dir) + "_" + i; thisDirSprites[i] = resourceManager.GetSprite(spritename); var bounds = thisDirSprites[i].GetLocalBounds(); x += bounds.Left; y += bounds.Top; w += bounds.Width; h += bounds.Height; t++; } averageAABBs.Add(dir, new FloatRect(x / t, y / t, w / t, h / t)); t = 0; x = 0; y = 0; w = 0; h = 0; } } }
internal CompositionScopedBatch StartAnimations(AnimationCollection target) { lock (Locker) { Compositor compositor = target?.FirstOrDefault()?.TargetVisual?.Compositor; if (compositor == null) { return(null); } CompositionScopedBatch resultBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); foreach (var animation in target) { animation.TargetVisual.StartAnimation(animation.TargetProperty.ToString(), animation.BuildCompositionAnimation()); } resultBatch.End(); return(resultBatch); } }
internal CompositionScopedBatch StartAnimations(AnimationCollection target) { lock (Locker) { Compositor compositor = target?.FirstOrDefault()?.TargetVisual?.Compositor; if (compositor == null) { return null; } CompositionScopedBatch resultBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); foreach (var animation in target) { animation.TargetVisual.StartAnimation(animation.TargetProperty.ToString(), animation.BuildCompositionAnimation()); } resultBatch.End(); return resultBatch; } }
public HeroExample() { // Start up the window Video.WindowIcon(); Video.WindowCaption = "SDL.NET - Hero Example"; Video.SetVideoMode(400, 300); string filePath = Path.Combine("..", ".."); string fileDirectory = "Data"; string fileName = "hero.png"; if (File.Exists(fileName)) { filePath = ""; fileDirectory = ""; } else if (File.Exists(Path.Combine(fileDirectory, fileName))) { filePath = ""; } string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName); // Load the image Surface image = new Surface(file); // Create the animation frames SurfaceCollection walkUp = new SurfaceCollection(); walkUp.Add(image, new Size(24, 32), 0); SurfaceCollection walkRight = new SurfaceCollection(); walkRight.Add(image, new Size(24, 32), 1); SurfaceCollection walkDown = new SurfaceCollection(); walkDown.Add(image, new Size(24, 32), 2); SurfaceCollection walkLeft = new SurfaceCollection(); walkLeft.Add(image, new Size(24, 32), 3); // Add the animations to the hero AnimationCollection animWalkUp = new AnimationCollection(); animWalkUp.Add(walkUp, 35); hero.Animations.Add("WalkUp", animWalkUp); AnimationCollection animWalkRight = new AnimationCollection(); animWalkRight.Add(walkRight, 35); hero.Animations.Add("WalkRight", animWalkRight); AnimationCollection animWalkDown = new AnimationCollection(); animWalkDown.Add(walkDown, 35); hero.Animations.Add("WalkDown", animWalkDown); AnimationCollection animWalkLeft = new AnimationCollection(); animWalkLeft.Add(walkLeft, 35); hero.Animations.Add("WalkLeft", animWalkLeft); // Change the transparent color of the sprite hero.TransparentColor = Color.Magenta; hero.Transparent = true; // Setup the startup animation and make him not walk hero.CurrentAnimation = "WalkDown"; hero.Animate = false; // Put him in the center of the screen hero.Center = new Point( Video.Screen.Width / 2, Video.Screen.Height / 2); }
public static async ValueTask <CharacterGame> Create(BECanvasComponent canvas, AnimationCollection animationCollection) { var warrior = new GameObject(); var animation = animationCollection.GetAnimation("Idle"); warrior.Components.Add(new Transform(warrior) { Position = Vector2.Zero, Direction = Vector2.One, Size = animation.FrameSize }); warrior.Components.Add(new AnimatedSpriteRenderComponent(warrior) { Animation = animation }); InitAnimationController(animationCollection, warrior); warrior.Components.Add(new CharacterBrain(animationCollection, warrior)); var game = new CharacterGame { _context = await canvas.CreateCanvas2DAsync(), _warrior = warrior }; return(game); }
public AnimatedSpriteUnit() { Animations = new AnimationCollection(); FramesPerRow = 1; FramesPerColumn = 1; }
public InteractiveTile(string name, Index2 index) : base(name, index) { durationOfInteraction = 1f; Animations = new AnimationCollection("idle"); }
/// <summary> /// 构建一个新的故事版。 /// </summary> public Storyboard() { Children = new AnimationCollection(); }
//Todo encapsulate this further down as components -- AnimatedSpriteState, AnimatedSpriteStateDirection public void LoadSprites(AnimationCollection collection, IResourceManager resourceManager) { float x=0, y=0, h=0, w=0; int t=0; foreach(var info in collection.Animations) { _sprites.Add(info.Name, new Dictionary<Direction, Sprite[]>()); //Because we have a shitload of frames, we're going to store the average size as the AABB for each direction and each animation _averageAABBs.Add(info.Name, new Dictionary<Direction, RectangleF>()); var sprites = _sprites[info.Name]; var averageAABBs = _averageAABBs[info.Name]; AnimationStates.Add(info.Name, new AnimationState(info)); foreach( var dir in Enum.GetValues(typeof(Direction)).Cast<Direction>()) { sprites.Add(dir, new Sprite[info.Frames]); var thisDirSprites = sprites[dir]; for (var i = 0; i < info.Frames; i++) { var spritename = collection.Name.ToLowerInvariant() + "_" + info.Name.ToLowerInvariant() + "_" + DirectionToUriComponent(dir) + "_" + i; thisDirSprites[i] = resourceManager.GetSprite(spritename); x += thisDirSprites[i].AABB.X; y += thisDirSprites[i].AABB.Y; w += thisDirSprites[i].AABB.Width; h += thisDirSprites[i].AABB.Height; t++; } averageAABBs.Add(dir, new RectangleF(x / t, y / t, w / t, h / t)); t = 0; x = 0; y = 0; w = 0; h = 0; } } }
/// <summary> /// <para>Loads all Resources from given Zip into the respective Resource Lists and Caches</para> /// </summary> public void LoadResourceZip(string path = null, string pw = null) { string zipPath = path ?? _configurationManager.GetResourcePath(); string password = pw ?? _configurationManager.GetResourcePassword(); if (Assembly.GetEntryAssembly().GetName().Name == "SS14.UnitTesting") { string debugPath = "..\\"; debugPath += zipPath; zipPath = debugPath; } if (!File.Exists(zipPath)) { throw new FileNotFoundException("Specified Zip does not exist: " + zipPath); } FileStream zipFileStream = File.OpenRead(zipPath); var zipFile = new ZipFile(zipFileStream); if (!string.IsNullOrWhiteSpace(password)) { zipFile.Password = password; } #region Sort Resource pack var directories = from ZipEntry a in zipFile where a.IsDirectory orderby a.Name.ToLowerInvariant() == "textures" descending select a; Dictionary <string, List <ZipEntry> > sorted = new Dictionary <string, List <ZipEntry> >(); foreach (ZipEntry dir in directories) { if (sorted.ContainsKey(dir.Name.ToLowerInvariant())) { continue; //Duplicate folder? shouldnt happen. } List <ZipEntry> folderContents = (from ZipEntry entry in zipFile where entry.Name.ToLowerInvariant().Contains(dir.Name.ToLowerInvariant()) where entry.IsFile select entry).ToList(); sorted.Add(dir.Name.ToLowerInvariant(), folderContents); } sorted = sorted.OrderByDescending(x => x.Key == "textures/").ToDictionary(x => x.Key, x => x.Value); //Textures first. #endregion #region Load Resources foreach (KeyValuePair <string, List <ZipEntry> > current in sorted) { switch (current.Key) { case ("textures/"): foreach (ZipEntry texture in current.Value) { if (supportedImageExtensions.Contains(Path.GetExtension(texture.Name).ToLowerInvariant())) { Texture loadedImg = LoadTextureFrom(zipFile, texture); if (loadedImg == null) { continue; } else { _textures.Add(Path.GetFileNameWithoutExtension(texture.Name), loadedImg); } } } break; case ("tai/"): // Tai? HANK HANK foreach (ZipEntry tai in current.Value) { if (Path.GetExtension(tai.Name).ToLowerInvariant() == ".tai") { IEnumerable <KeyValuePair <string, Sprite> > loadedSprites = LoadSpritesFrom(zipFile, tai); foreach (var currentSprite in loadedSprites.Where(currentSprite => !_sprites.ContainsKey(currentSprite.Key))) { _sprites.Add(currentSprite.Key, currentSprite.Value); } } } break; case ("fonts/"): foreach (ZipEntry font in current.Value) { if (Path.GetExtension(font.Name).ToLowerInvariant() == ".ttf") { Font loadedFont = LoadFontFrom(zipFile, font); if (loadedFont == null) { continue; } string ResourceName = Path.GetFileNameWithoutExtension(font.Name).ToLowerInvariant(); _fonts.Add(ResourceName, loadedFont); } } break; case ("particlesystems/"): foreach (ZipEntry particles in current.Value) { if (Path.GetExtension(particles.Name).ToLowerInvariant() == ".xml") { ParticleSettings particleSettings = LoadParticlesFrom(zipFile, particles); if (particleSettings == null) { continue; } else { _particles.Add(Path.GetFileNameWithoutExtension(particles.Name), particleSettings); } } } break; case ("shaders/"): { GLSLShader LoadedShader; TechniqueList List; foreach (ZipEntry shader in current.Value) { int FirstIndex = shader.Name.IndexOf('/'); int LastIndex = shader.Name.LastIndexOf('/'); if (FirstIndex != LastIndex) // if the shader pixel/fragment files are in folder/technique group, construct shader and add it to a technique list. { string FolderName = shader.Name.Substring(FirstIndex + 1, LastIndex - FirstIndex - 1); if (!_TechniqueList.Keys.Contains(FolderName)) { List = new TechniqueList(); List.Name = FolderName; _TechniqueList.Add(FolderName, List); } LoadedShader = LoadShaderFrom(zipFile, shader); if (LoadedShader == null) { continue; } else { _TechniqueList[FolderName].Add(LoadedShader); } } // if the shader is not in a folder/technique group, add it to the shader dictionary else if (Path.GetExtension(shader.Name).ToLowerInvariant() == ".vert" || Path.GetExtension(shader.Name).ToLowerInvariant() == ".frag") { LoadedShader = LoadShaderFrom(zipFile, shader); if (LoadedShader == null) { continue; } else { _shaders.Add(Path.GetFileNameWithoutExtension(shader.Name).ToLowerInvariant(), LoadedShader); } } } break; } case ("animations/"): foreach (ZipEntry animation in current.Value) { if (Path.GetExtension(animation.Name).ToLowerInvariant() == ".xml") { AnimationCollection animationCollection = LoadAnimationCollectionFrom(zipFile, animation); if (animationCollection == null) { continue; } else { _animationCollections.Add(animationCollection.Name, animationCollection); } } } break; } } #endregion sorted = null; zipFile.Close(); zipFileStream.Close(); zipFileStream.Dispose(); GC.Collect(); }
public static void SetAnimations (FrameworkElement d, AnimationCollection value) { d.SetValue(AnimationsProperty, value); }
public AnimatedSprite(string name, AnimationCollection collection, IResourceManager resourceManager) { AnimationStates = new Dictionary<string, AnimationState>(); Name = name; LoadSprites(collection, resourceManager); if (AnimationStates.ContainsKey("idle")) SetAnimationState("idle"); SetLoop(true); SetCurrentSprite(); //IoCManager.Resolve<IResourceManager>(). }