/// <summary> /// 透明Mask,用于禁止用户点击的 /// </summary> /// <param name="closeTime">关闭时间</param> /// <param name="closeCallBack">关闭回调</param> /// <returns></returns> public static GameObject OpenUIMask(float closeTime, System.Action closeCallBack = null) { Transform parentCanvas = GameObject.Find("Canvas").transform; GameObject maskObj = new GameObject("UIMask"); Image maskImg = maskObj.AddComponent <Image>(); maskObj.transform.SetParent(parentCanvas); maskObj.transform.SetAsLastSibling(); //赋值 maskImg.color = Color.clear; maskImg.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0); maskImg.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0); maskImg.rectTransform.anchorMin = Vector2.zero; maskImg.rectTransform.anchorMax = Vector2.one; TimerTool.OpenOnce(closeTime, () => { if (maskObj != null) { Destroy(maskObj); } if (closeCallBack != null) { closeCallBack(); } }); return(maskObj); }
private void Screen1() { Task.Factory.StartNew(() => { TimerTool tt = new TimerTool(); Bitmap b = null; while (true) { tt.Begin(); Graphics pictureG = pictureBox1.CreateGraphics(); b = ScreenCapture.Capture(); Graphics cursorG = Graphics.FromImage(b); ScreenCapture.DrawCursorImageToScreenImage(ref cursorG); pictureG.DrawImage(b, 0, 0, pictureBox1.Width, pictureBox1.Height); b?.Dispose(); BeginInvoke(new Action(() => { label1.Text = string.Format("{0} × {1} time: {2} ms", pictureBox1.Width, pictureBox1.Height, tt.ms); })); cursorG.Dispose(); pictureG.Dispose(); Thread.Sleep(10); } }); }
/// <summary> /// 创建计时器 /// </summary> /// <param name="gobjName">计时器名称</param> /// <returns>Timer</returns> public static TimerTool CreateTimer(string gobjName = "Timer") { GameObject g = new GameObject(gobjName); TimerTool timer = g.AddComponent <TimerTool>(); return(timer); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
void Update() { switch (gameState) { case GameState.Idle: // upgrade allies! break; case GameState.Attack: //if (attackTimer.isFinished(Time.time)) //{ // OnAttackTimerFinished(); //} //else //{ // if (shootTimer.isFinished(Time.time)) // { // shootTimer = new TimerTool(Time.time, shootTime); // StartCoroutine(state.AlliesAttack()); // } // if (Input.GetMouseButtonDown(0)) // { // StartCoroutine(state.AlliesAttack()); // } //} if (enemyAttackTimer.isFinished(Time.time)) { enemyAttackTimer = new TimerTool(Time.time, enemiesAttackTime); StartCoroutine(state.EnemiesAttack()); } if (alliesAttackTimer.isFinished(Time.time)) { alliesAttackTimer = new TimerTool(Time.time, alliesAttackTime); StartCoroutine(state.AlliesAttack()); } if (Input.GetMouseButtonDown(0)) { StartCoroutine(state.AlliesAttack()); } //if (Input.GetKey(KeyCode.F)) // StartCoroutine(state.EnemiesAttack()); break; default: break; } }
public void OnStateChangeBtnClick() { if (gameState == GameState.Idle) { gameState = GameState.Attack; SetState(new AttackState(this)); alliesAttackTimer = new TimerTool(Time.time, alliesAttackTime); enemyAttackTimer = new TimerTool(Time.time, enemiesAttackTime); StartCoroutine(state.AlliesAttack()); } else if (gameState == GameState.Attack) { gameState = GameState.Idle; SetState(new IdleState(this)); } }
/// <summary> /// 计时器开启一次 /// </summary> /// <param name="key">下标</param> /// <param name="time">时间</param> /// <param name="func">回调</param> public void TimerOpenOnce(int key, float time, System.Action func) { if (key < 0) { return; } if (key < TimerList.Length && TimerList[key] == null) { TimerTool timer = TimerTool.OpenOnce(time, func); TimerList[key] = timer; } else { TimerList[key].StatusOpenOnce(time, func); } }
/// <summary> /// 实现黑幕/白幕渐变的 /// </summary> /// <param name="delay">延迟播放</param> /// <param name="closeTimeDelta">变黑时间间隔</param> /// <param name="openTimeDelta">变亮时间间隔</param> /// <returns></returns> public static GameObject OpenGradualChangeMask(float delay = 0, float closeTimeDelta = 1, float openTimeDelta = 1f, bool isWhite = false, System.Action callBack = null) { Transform parentCanvas = GameObject.Find("Canvas").transform; GameObject maskObj = new GameObject("BlackMask"); Image maskImg = maskObj.AddComponent <Image>(); CanvasGroup ConnectLevelMask = maskObj.AddComponent <CanvasGroup>(); maskObj.transform.SetParent(parentCanvas); maskObj.transform.SetAsLastSibling(); //赋值 if (isWhite) { maskImg.color = Color.white; } else { maskImg.color = Color.black; } maskImg.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0); maskImg.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0); maskImg.rectTransform.anchorMin = Vector2.zero; maskImg.rectTransform.anchorMax = Vector2.one; maskImg.transform.localScale = Vector3.one; //屏幕效果 ConnectLevelMask.alpha = 0; TimerTool.OpenOnce(delay, () => { Sequence sequenceTw = DOTween.Sequence(); sequenceTw.Append(ConnectLevelMask.DOFade(1, closeTimeDelta)); sequenceTw.Append(ConnectLevelMask.DOFade(0, openTimeDelta)).OnComplete(() => { if (maskObj != null) { Destroy(maskObj); } if (callBack != null) { callBack(); } }); }); return(maskObj); }
private static Transform TimerRoot; //计时器挂载位置 /// <summary> /// 开启计时器 /// </summary> /// <param name="mark">标识</param> /// <param name="time">时间</param> /// <param name="isLoop">是否循环</param> /// <param name="loopCount">循环次数</param> /// <param name="func">调用方法</param> /// <returns></returns> private static TimerTool Open(float time, bool isLoop, int loopCount, System.Action func, System.Action loopFinishFun = null) { if (TimerRoot == null) { TimerRoot = new GameObject("TimerRoot").transform; } GameObject buf; //通常方法 buf = new GameObject("timer"); buf.transform.parent = TimerRoot; //初始化 TimerTool timer = buf.AddComponent <TimerTool>(); timer.TimerInit(time, isLoop, loopCount, func, loopFinishFun); return(timer); }
/// <summary> /// 计时器循环开启 /// </summary> /// <param name="key">下标</param> /// <param name="time">时间间隔</param> /// <param name="loopCount">循环次数</param> /// <param name="func">回调</param> public void TimerOpenLoop(int key, float time, int loopCount, System.Action func) { if (key < 0) { return; } if (key < TimerList.Length && TimerList[key] == null) { TimerTool timer = TimerTool.OpenLoop(time, loopCount, func); TimerList[key] = timer; } else { if (TimerList[key].IsOpen) { return; } TimerList[key].StatusOpenLoop(time, loopCount, func); } }
public override void Init() { base.Init(); cbPackQue = new Queue <TaskCbPack>(); timerTool = new TimerTool(20); timerTool.SetLog((string str) => { Console.WriteLine(str); }); timerTool.SetHandleCb((Action <int> cb, int id) => { if (cb != null) { lock (lock_que) { cbPackQue.Enqueue(new TaskCbPack(id, cb)); } } }); }
private void OnEnable() { t = TimerTool.CreateTimer(); t.StartTiming(wc.watchTime, StartTimer, EndTimer, MarkCircle); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //reset working directory Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //set culture Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); var autoMapper = new SimpleAutoMapper(); var dataIO = new DataIO(); var messageBox = new MessageBoxService(); var mouseHook = new MouseHook(); var timerTool = new TimerTool(); var autoUpdater = new AutoUpdater(messageBox); var clipboard = new ViewModelClipboard(); var recent = new RecentFileManager(); var mtpManager = new MTPManager(); var DependencyDict = new Dictionary <Type, object>() { { typeof(SimpleAutoMapper), autoMapper }, { typeof(MessageBoxService), messageBox }, { typeof(ViewModelClipboard), clipboard }, }; var viewModelFactory = new ViewModelFactory(DependencyDict); (new ScriptGenerateBootstrap()).SetUp(out IActionToScriptFactory actionToScriptFactory, out IEmulatorToScriptFactory emulatorToScriptFactory); var settingVM = new SettingViewModel(Settings.Default(), autoMapper, mtpManager); var macroManagerVM = new MacroManagerViewModel(dataIO, messageBox, viewModelFactory, recent); var scriptApplyFactory = new ScriptApplyBootStrap(messageBox, mtpManager).GetScriptApplyFactory(); var scriptGenerator = new ScriptGenerator(scriptApplyFactory, settingVM, messageBox, emulatorToScriptFactory, actionToScriptFactory); var scriptGeneratorVM = new ScriptGeneratorViewModel(macroManagerVM, scriptGenerator, messageBox); var customActionManager = new CustomActionManager(macroManagerVM, viewModelFactory, dataIO, messageBox); var timerToolVM = new TimerToolViewModel(mouseHook, timerTool); var resulutionTool = new ResolutionConverterTool(viewModelFactory); var resolutionToolVM = new ResolutionConverterToolViewModel(resulutionTool, macroManagerVM, messageBox); var autoLocationVM = new AutoLocationViewModel(new MouseHook(), new AutoLocation(), macroManagerVM); var mainWindowViewModel = new MainWindowViewModel(macroManagerVM, settingVM, autoUpdater, timerToolVM, resolutionToolVM, scriptGeneratorVM, customActionManager, autoLocationVM); MainWindow = new MainWindow { DataContext = mainWindowViewModel }; //Handle arguments var agrs = Environment.GetCommandLineArgs(); if (agrs.Length > 1) { var filepath = agrs.Where(s => s.Contains(".emm")).First(); macroManagerVM.SetCurrentMacro(filepath, agrs.Any(s => s.Equals(StaticVariables.NO_SAVE_AGRS))); } // Select the text in a TextBox when it receives focus. EventManager.RegisterClassHandler(typeof(TextBox), TextBox.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(SelectivelyIgnoreMouseButton)); EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent, new RoutedEventHandler(SelectAllText)); EventManager.RegisterClassHandler(typeof(TextBox), TextBox.MouseDoubleClickEvent, new RoutedEventHandler(SelectAllText)); MainWindow.Show(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //reset working directory Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var autoMapper = new SimpleAutoMapper(); var dataIO = new DataIO(); var messageBox = new MessageBoxService(); var mouseHook = new MouseHook(); var timerTool = new TimerTool(); var autoUpdater = new AutoUpdater(messageBox); var DependencyDict = new Dictionary <Type, object>() { { typeof(SimpleAutoMapper), autoMapper }, { typeof(MessageBoxService), messageBox } }; var scriptApplyDict = new Dictionary <Emulator, IApplyScriptToFolder>() { { Emulator.Nox, new NoxScriptApply(messageBox) }, { Emulator.Memu, new MemuScriptApply(messageBox) } }; var viewModelFactory = new ViewModelFactory(DependencyDict); var settingVM = new SettingViewModel(Settings.Default(), autoMapper); var macroManagerVM = new MacroManagerViewModel(dataIO, messageBox, viewModelFactory); var scriptApplyFactory = new ScriptApplyFactory(messageBox, scriptApplyDict); var scriptGenerator = new ScriptGenerator(scriptApplyFactory, settingVM, messageBox); var scriptGeneratorVM = new ScriptGeneratorViewModel(macroManagerVM, scriptGenerator, messageBox); var customActionManager = new CustomActionManager(macroManagerVM, viewModelFactory, dataIO, messageBox); var timerToolVM = new TimerToolViewModel(mouseHook, timerTool); var resulutionTool = new ResolutionConverterTool(viewModelFactory); var resolutionToolVM = new ResolutionConverterToolViewModel(resulutionTool, macroManagerVM, messageBox); var autoLocationVM = new AutoLocationViewModel(new MouseHook(), new AutoLocation(), macroManagerVM); var mainWindowViewModel = new MainWindowViewModel(macroManagerVM, settingVM, autoUpdater, timerToolVM, resolutionToolVM, scriptGeneratorVM, customActionManager, autoLocationVM); MainWindow = new MainWindow { DataContext = mainWindowViewModel }; //Handle arguments var agrs = Environment.GetCommandLineArgs(); if (agrs.Length > 1) { var filepath = agrs.Where(s => s.Contains(".emm")).First(); macroManagerVM.SetCurrentMacro(filepath); } // Select the text in a TextBox when it receives focus. EventManager.RegisterClassHandler(typeof(TextBox), TextBox.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(SelectivelyIgnoreMouseButton)); EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent, new RoutedEventHandler(SelectAllText)); EventManager.RegisterClassHandler(typeof(TextBox), TextBox.MouseDoubleClickEvent, new RoutedEventHandler(SelectAllText)); MainWindow.Show(); }