Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .idea/.idea.ExpressElevator/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 134 additions & 12 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ RectTransform:
m_GameObject: {fileID: 133261010}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.65895814, y: 3.6083734, z: 2.0473042}
m_LocalScale: {x: 0.71134526, y: 3.8952389, z: 2.2100646}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 221982703}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 671.8, y: -124.7}
m_AnchoredPosition: {x: 675.4, y: -123.5}
m_SizeDelta: {x: 109.8411, y: 21.2261}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &133261012
Expand Down Expand Up @@ -239,6 +239,126 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 133261010}
m_CullTransparentMesh: 1
--- !u!1 &136626621
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 136626622}
- component: {fileID: 136626625}
- component: {fileID: 136626624}
- component: {fileID: 136626623}
m_Layer: 5
m_Name: Undo Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &136626622
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 136626621}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.51014125, y: 2.7934704, z: 1.5849478}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 221982703}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 675.4002, y: -475.4}
m_SizeDelta: {x: 109.8411, y: 21.2261}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &136626623
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 136626621}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: -1644469932529679544, guid: 2fbcf72e5debc9a4e9d7664a76b378ef, type: 3}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 136626624}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!114 &136626624
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 136626621}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 934592570805267804, guid: 8f41e9100ef952c468e6bde2c6bb48c9, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &136626625
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 136626621}
m_CullTransparentMesh: 1
--- !u!1 &221982702
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -270,14 +390,15 @@ RectTransform:
m_Children:
- {fileID: 732320779}
- {fileID: 2120192488}
- {fileID: 136626622}
- {fileID: 751619573}
- {fileID: 465397682}
- {fileID: 133261011}
m_Father: {fileID: 1552064758}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -960, y: 540}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &221982704
Expand All @@ -296,6 +417,7 @@ MonoBehaviour:
_firstButton: {fileID: 751619574}
_secondButton: {fileID: 465397683}
_thirdButton: {fileID: 133261012}
_undoButton: {fileID: 136626623}
--- !u!1001 &288834280
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -381,14 +503,14 @@ RectTransform:
m_GameObject: {fileID: 465397681}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.65895814, y: 3.6083734, z: 2.0473042}
m_LocalScale: {x: 0.71134526, y: 3.8952389, z: 2.2100646}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 221982703}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 671.8, y: -213.7}
m_AnchoredPosition: {x: 674, y: -213.7}
m_SizeDelta: {x: 109.8411, y: 21.2261}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &465397683
Expand Down Expand Up @@ -653,7 +775,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: -7358055287198136362, guid: 68632c519531ba842801917f64f8b609, type: 3}
m_Sprite: {fileID: -8367254710825533528, guid: 5a2e4ed0564466b4c94c62ad161b0406, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
Expand Down Expand Up @@ -699,14 +821,14 @@ RectTransform:
m_GameObject: {fileID: 751619572}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.65895814, y: 3.6083734, z: 2.0473042}
m_LocalScale: {x: 0.71134526, y: 3.8952389, z: 2.2100646}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 221982703}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 671.8, y: -301.3}
m_AnchoredPosition: {x: 674.9, y: -306.2}
m_SizeDelta: {x: 109.8411, y: 21.2261}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &751619574
Expand Down Expand Up @@ -2188,14 +2310,14 @@ RectTransform:
m_GameObject: {fileID: 2120192487}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.65895814, y: 3.6083734, z: 2.0473042}
m_LocalScale: {x: 0.71134526, y: 3.8952389, z: 2.2100646}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 221982703}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 671.8, y: -390.66687}
m_AnchoredPosition: {x: 676.8, y: -398.6}
m_SizeDelta: {x: 109.8411, y: 21.2261}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2120192489
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Command.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/Command/AbstractCommand.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Scripts/Command/AbstractCommand/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using ExpressElevator.Event;
using ExpressElevator.Passenger;
using UnityEngine;

namespace ExpressElevator.Command
{
public interface ICommand
{
void Execute(PassengerController passengerController,EventService eventService);
void Undo();
}
}
2 changes: 2 additions & 0 deletions Assets/Scripts/Command/AbstractCommand/ICommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions Assets/Scripts/Command/CommandInvoker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using ExpressElevator.Event;
using ExpressElevator.Passenger;
using UnityEngine;

namespace ExpressElevator.Command
{
public class CommandInvoker
{
private Dictionary<PassengerController,Stack<ICommand>> _commandHistory = new Dictionary<PassengerController,Stack<ICommand>>();

private EventService _eventService;

public void InjectDependencies(EventService eventService)
{
_eventService = eventService;
Events();
}

private void Events()
{
_eventService.AddPassenger.AddListener(PrcessCommands);
_eventService.Undo.AddListener(Undo);
}

private void PrcessCommands(PassengerController passengerController, ICommand command)
{
ExecuteCommand(passengerController, command);
RegisterCommand(passengerController, command);
}

private void ExecuteCommand(PassengerController passengerController, ICommand command) => command.Execute(passengerController,_eventService);

private void RegisterCommand(PassengerController passengerController, ICommand command)
{
if (!_commandHistory.ContainsKey(passengerController))
{
_commandHistory[passengerController] = new Stack<ICommand>();
}
_commandHistory[passengerController].Push(command);
}

private void Undo(PassengerController passengerController)
{
if (_commandHistory.ContainsKey(passengerController) && _commandHistory[passengerController].Count > 0)
{
_commandHistory[passengerController].Pop().Undo();
}
}
}
}
2 changes: 2 additions & 0 deletions Assets/Scripts/Command/CommandInvoker.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/Command/ConcreteCommand.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading