private async void Show() { using (var releaser = await _AnimationGenerateLock.LockAsync()) { if (this.AssociatedObject == null) { return; } Debug.WriteLine($"{_CurrentAnimation?.State}"); _CurrentAnimation?.Dispose(); _CurrentAnimation = null; if (IsAnimationEnabled) { _CurrentAnimation = AssociatedObject.Fade(1.0f, Duration.TotalMilliseconds); _CurrentAnimation?.StartAsync().ConfigureAwait(false); if (IsAutoHideEnabled) { AutoHideSubject.OnNext(0); } Debug.WriteLine($"{nameof(VisiblityFadeChanger)}: 表示アニメーション開始 (自動非表示:{IsAutoHideEnabled})"); } else { AssociatedObject.Opacity = 1.0; Debug.WriteLine($"{nameof(VisiblityFadeChanger)}: 表示"); } } }
protected override void OnDetaching() { base.OnDetaching(); _FadeInAnimation?.Dispose(); _FadeOutAnimation?.Dispose(); this.AssociatedObject.Visibility = Visibility.Visible; }
async void ResetAnimation() { var container = GetTemplateChild("ContentContainer") as FrameworkElement; if (container == null) { return; } using (var releaser = await _AnimLock.LockAsync()) { if (_PrevFadeAnimation != null) { var prevAnimState = _PrevFadeAnimation.State; _PrevFadeAnimation?.Dispose(); if (prevAnimState == AnimationSetState.Running) { // 前アニメーションが実行中だった場合は終わるまで待機 // (ここでは横着して50ms止めるだけ) await Task.Delay(50); } } if (Content != null) { _PrevFadeAnimation = container .Fade(1.0f, 100); if (IsAutoHideEnabled) { _PrevFadeAnimation = _PrevFadeAnimation.Then() .Fade(0.0f, 100, delay: DisplayDuration.TotalMilliseconds); } } else { _PrevFadeAnimation = container .Fade(0.0f, 100); } _PrevFadeAnimation?.StartAsync().ConfigureAwait(false); } }
/// <summary>Create the mesh data</summary> public void Create(Device device, string name) { defaultMaterial.Diffuse = System.Drawing.Color.White; defaultMaterial.Ambient = System.Drawing.Color.White; shadowMaterial.Diffuse = System.Drawing.Color.Black; shadowMaterial.Ambient = System.Drawing.Color.Black; // Hook the device events System.Diagnostics.Debug.Assert(device != null, "Device should not be null."); this.device = device; device.DeviceLost += new EventHandler(OnLostDevice); device.DeviceReset += new EventHandler(OnResetDevice); device.Disposing += new EventHandler(OnDeviceDisposing); GraphicsStream adjacency; // Adjacency information ExtendedMaterial[] materials; // Mesh material information // First try to find the filename string path = string.Empty; try { path = Utility.FindMediaFile(name); } catch (MediaNotFoundException) { // The media was not found, maybe a full path was passed in? if (System.IO.File.Exists(name)) { path = name; } else { // No idea what this is trying to find throw new MediaNotFoundException(name); } } // Now load the mesh systemMemoryMesh = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out adjacency, out materials); using (adjacency) { // Optimize the mesh for performance systemMemoryMesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeCompact | MeshFlags.OptimizeAttributeSort, adjacency); // Find the folder of where the mesh file is located string folder = Utility.AppendDirectorySeparator(new System.IO.FileInfo(path).DirectoryName); // Create the materials CreateMaterials(folder, device, adjacency, materials); } // Finally call reset OnResetDevice(device, EventArgs.Empty); BonsaiAllocateHierarchy allocH = new BonsaiAllocateHierarchy(path); animationRoot = Mesh.LoadHierarchyFromFile(path, MeshFlags.Managed, device, allocH, null); animationController = animationRoot.AnimationController; AnimationSet set = animationController.GetAnimationSet(0); animationController.SetTrackAnimationSet(0, set); animationController.SetTrackEnable(0, true); animationController.SetTrackPosition(0, 0.0); animationController.SetTrackPriority(0, PriorityType.Low); animationController.SetTrackSpeed(0, 1.0f); animationController.SetTrackPriority(0, PriorityType.Low); animationController.PriorityBlend = 1.0f; set.Dispose(); // will this fix the very sporadic crashes? }
private void CancelAndRemoveAnimation(AnimationSet animationSet) { animationSet.Dispose(); animationSet.Completed -= FadeCompleted; _animations.Remove(animationSet); }