Skip to content

Commit cb8f29f

Browse files
committed
Use async/await instead of Coroutine.
Use Strategy Pattern refactor switch case. fix some bugs.
1 parent cbd4a37 commit cb8f29f

69 files changed

Lines changed: 872 additions & 616 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Performance;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
// ensure class initializer is called whenever scripts recompile
6+
namespace Editor
7+
{
8+
[InitializeOnLoad]
9+
public static class PlayModeStateChanged
10+
{
11+
// register an event handler when the class is initialized
12+
static PlayModeStateChanged()
13+
{
14+
EditorApplication.playModeStateChanged += LogPlayModeState;
15+
}
16+
17+
private static void LogPlayModeState( PlayModeStateChange state )
18+
{
19+
if ( state == PlayModeStateChange.ExitingPlayMode )
20+
{
21+
CubeController.runLevel = 0;
22+
Time.timeScale = 0;
23+
Debug.Log( "Quit Play Mode." );
24+
}
25+
}
26+
}
27+
}

Assets/Editor/PlayModeStateChanged.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scenes/MainScene.unity

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,7 @@ RectTransform:
37173717
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
37183718
m_AnchorMin: {x: 0.5, y: 0.5}
37193719
m_AnchorMax: {x: 0.5, y: 0.5}
3720-
m_AnchoredPosition: {x: 240, y: 0}
3720+
m_AnchoredPosition: {x: 280, y: 0}
37213721
m_SizeDelta: {x: 300, y: 50}
37223722
m_Pivot: {x: 0.5, y: 0.5}
37233723
--- !u!114 &868835302
@@ -4961,7 +4961,7 @@ RectTransform:
49614961
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
49624962
m_AnchorMin: {x: 0, y: 0.5}
49634963
m_AnchorMax: {x: 0, y: 0.5}
4964-
m_AnchoredPosition: {x: 600, y: -25}
4964+
m_AnchoredPosition: {x: 570, y: -25}
49654965
m_SizeDelta: {x: 350, y: 20}
49664966
m_Pivot: {x: 0.5, y: 0.5}
49674967
--- !u!114 &1192521223
@@ -6755,7 +6755,7 @@ RectTransform:
67556755
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
67566756
m_AnchorMin: {x: 0.5, y: 0.5}
67576757
m_AnchorMax: {x: 0.5, y: 0.5}
6758-
m_AnchoredPosition: {x: 240, y: 0}
6758+
m_AnchoredPosition: {x: 280, y: 0}
67596759
m_SizeDelta: {x: 300, y: 50}
67606760
m_Pivot: {x: 0.5, y: 0.5}
67616761
--- !u!114 &1699172604
@@ -7400,7 +7400,7 @@ RectTransform:
74007400
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
74017401
m_AnchorMin: {x: 0, y: 0.5}
74027402
m_AnchorMax: {x: 0, y: 0.5}
7403-
m_AnchoredPosition: {x: 600, y: 19.8}
7403+
m_AnchoredPosition: {x: 570, y: 19.8}
74047404
m_SizeDelta: {x: 350, y: 20}
74057405
m_Pivot: {x: 0.5, y: 0.5}
74067406
--- !u!114 &1811542393

Assets/Scripts/Performance/Actions.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2021 Dylan Cheng (https://github.com/newlooper). All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
using System;
6+
using Cysharp.Threading.Tasks;
7+
8+
namespace Performance.Actions
9+
{
10+
public class ChangeSelection : ICubeAction
11+
{
12+
public async UniTask Perform( Step step )
13+
{
14+
var index = step.Left;
15+
var cubes = GameManager.Cubes;
16+
var cubeSelected = step.Pace.SelectedMaterial;
17+
var cubeDefault = Config.DefaultCube;
18+
19+
CubeController.SetPillarMaterial( cubes[index], cubeSelected );
20+
if ( index - 1 > step.Right ) CubeController.SetPillarMaterial( cubes[index - 1], cubeDefault );
21+
22+
CodeDictionary.AddMarkLine( step.CodeLineKey );
23+
await UniTask.Delay( TimeSpan.FromSeconds( step.Lifetime / CubeController.speed.value ) );
24+
CodeDictionary.RemoveMarkLine( step.CodeLineKey );
25+
}
26+
}
27+
}

Assets/Scripts/Performance/Actions/ChangeSelection.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2021 Dylan Cheng (https://github.com/newlooper). All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
using System;
6+
using Cysharp.Threading.Tasks;
7+
8+
namespace Performance.Actions
9+
{
10+
public class CodeHighlight : ICubeAction
11+
{
12+
public async UniTask Perform( Step step )
13+
{
14+
CodeDictionary.AddMarkLine( step.CodeLineKey );
15+
await UniTask.Delay( TimeSpan.FromSeconds( step.Lifetime / CubeController.speed.value ) );
16+
CodeDictionary.RemoveMarkLine( step.CodeLineKey );
17+
}
18+
}
19+
}

Assets/Scripts/Performance/Actions/CodeHighlight.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2021 Dylan Cheng (https://github.com/newlooper). All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
using System.Collections.Generic;
6+
using Cysharp.Threading.Tasks;
7+
8+
namespace Performance.Actions
9+
{
10+
public static class Context
11+
{
12+
private static readonly Dictionary<PerformanceEffect, ICubeAction> StrategiesDictionary =
13+
new Dictionary<PerformanceEffect, ICubeAction>();
14+
15+
static Context()
16+
{
17+
StrategiesDictionary.Add( PerformanceEffect.SimpleSwap, new SimpleSwap() );
18+
StrategiesDictionary.Add( PerformanceEffect.SelectTwo, new HighlightTwo() );
19+
StrategiesDictionary.Add( PerformanceEffect.CodeLine, new CodeHighlight() );
20+
StrategiesDictionary.Add( PerformanceEffect.HeapSwap, new HeapSwap() );
21+
StrategiesDictionary.Add( PerformanceEffect.JumpOut, new JumpOut() );
22+
StrategiesDictionary.Add( PerformanceEffect.JumpIn, new JumpIn() );
23+
StrategiesDictionary.Add( PerformanceEffect.SelectOne, new HighlightOne() );
24+
StrategiesDictionary.Add( PerformanceEffect.RelaySwap, new RelaySwap() );
25+
StrategiesDictionary.Add( PerformanceEffect.MergePick, new SimpleMoveOut() );
26+
StrategiesDictionary.Add( PerformanceEffect.MergeBack, new SimpleMoveIn() );
27+
StrategiesDictionary.Add( PerformanceEffect.MergeHistory, new MergeHistory() );
28+
StrategiesDictionary.Add( PerformanceEffect.RadixPick, new MoveToDigitsBucket() );
29+
StrategiesDictionary.Add( PerformanceEffect.RadixBack, new RadixBack() );
30+
StrategiesDictionary.Add( PerformanceEffect.ChangeSelection, new ChangeSelection() );
31+
StrategiesDictionary.Add( PerformanceEffect.SelectNewMin, new HighlightChange() );
32+
}
33+
34+
public static UniTask Execute( Step step )
35+
{
36+
return StrategiesDictionary[step.PerformanceEffect].Perform( step );
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)