#if UNITY_5_3_OR_NEWER #define NOESIS #endif #if NOESIS using Noesis; using UnityEngine; #else using System; #endif namespace Noesis.Samples { /// /// Buttons sample view model /// public class ButtonsViewModel { private Button _startButton; public ButtonsViewModel(Button startButton) { _startButton = startButton; StartCommand = new DelegateCommand(this.Start); SettingsCommand = new DelegateCommand(this.Settings); ExitCommand = new DelegateCommand(this.Exit); } public DelegateCommand StartCommand { get; private set; } public DelegateCommand SettingsCommand { get; private set; } public DelegateCommand ExitCommand { get; private set; } private void Start(object parameter) { Test.PrepareTiltReturnStoryboard(_startButton); #if NOESIS Debug.Log("Start Game"); #endif } private void Settings(object parameter) { #if NOESIS Debug.Log("Change Settings"); #endif } private void Exit(object parameter) { #if NOESIS Debug.Log("Exit Game"); #endif } } public class Test { private static Storyboard story; public static void PrepareTiltReturnStoryboard(Button button) { if (story != null) { story.Stop(); // all OK story = null; } else { button.Projection = new PlaneProjection(); // setup animation Storyboard story = new Storyboard(); story.Completed += (sender, args) => { button.Content = "done"; }; DoubleAnimation anim = new DoubleAnimation(); Storyboard.SetTargetProperty(anim, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationZ)")); anim.To = 45; anim.Duration = System.TimeSpan.FromSeconds(2); story.Children.Add(anim); Storyboard.SetTarget(anim, button); story.Begin(button, true); if (story.IsPlaying()) // ERROR: this code will show "Target Not Found" crash in Unity log { story.Stop(); // ERROR: this code will show "Target not Found" too in case the if() is removed } } } } }