├── .gitignore
├── README.md
└── UnityDesignPatternsExampleProject
├── Assembly-CSharp-vs.csproj
├── Assembly-CSharp.csproj
├── Assets
├── _PATTERNS.meta
└── _PATTERNS
│ ├── ALL PATTERNS.unity
│ ├── ALL PATTERNS.unity.meta
│ ├── Behavioral Patterns.meta
│ ├── Behavioral Patterns
│ ├── Chain Of Responsibility Design Pattern.meta
│ ├── Chain Of Responsibility Design Pattern
│ │ ├── ChainOfResponsibilityPattern.cs
│ │ └── ChainOfResponsibilityPattern.cs.meta
│ ├── Command Design Pattern.meta
│ ├── Command Design Pattern
│ │ ├── CommandDesignPattern.cs
│ │ └── CommandDesignPattern.cs.meta
│ ├── Interpreter Design Pattern.meta
│ ├── Interpreter Design Pattern
│ │ ├── InterpreterDesignPattern.cs
│ │ └── InterpreterDesignPattern.cs.meta
│ ├── Iterator Design Pattern.meta
│ ├── Iterator Design Pattern
│ │ ├── IteratorDesignPattern.cs
│ │ └── IteratorDesignPattern.cs.meta
│ ├── Mediator Design Pattern.meta
│ ├── Mediator Design Pattern
│ │ ├── MediatorDesignPattern.cs
│ │ └── MediatorDesignPattern.cs.meta
│ ├── Memento Design Pattern.meta
│ ├── Memento Design Pattern
│ │ ├── MementoDesignPattern.cs
│ │ └── MementoDesignPattern.cs.meta
│ ├── Observer Design Pattern.meta
│ ├── Observer Design Pattern
│ │ ├── ObserverDesignPattern.cs
│ │ └── ObserverDesignPattern.cs.meta
│ ├── State Design Pattern.meta
│ ├── State Design Pattern
│ │ ├── StateDesignPattern.cs
│ │ └── StateDesignPattern.cs.meta
│ ├── Strategy Design Pattern.meta
│ ├── Strategy Design Pattern
│ │ ├── BadCodeExample.cs
│ │ ├── BadCodeExample.cs.meta
│ │ ├── StrategyDesignPattern.cs
│ │ └── StrategyDesignPattern.cs.meta
│ ├── Template Method Design Pattern.meta
│ ├── Template Method Design Pattern
│ │ ├── TemplateMethodDesignPattern.cs
│ │ └── TemplateMethodDesignPattern.cs.meta
│ ├── Visitor Design Pattern.meta
│ └── Visitor Design Pattern
│ │ ├── VisitorDesignPattern.cs
│ │ └── VisitorDesignPattern.cs.meta
│ ├── Creational Patterns.meta
│ ├── Creational Patterns
│ ├── Abstract Factory Design Pattern.meta
│ ├── Abstract Factory Design Pattern
│ │ ├── AbstractFactoryPattern.cs
│ │ └── AbstractFactoryPattern.cs.meta
│ ├── Builder Design Pattern.meta
│ ├── Builder Design Pattern
│ │ ├── BuilderDesignPattern.cs
│ │ └── BuilderDesignPattern.cs.meta
│ ├── Factory Design Pattern.meta
│ ├── Factory Design Pattern
│ │ ├── FactoryDesignPattern.cs
│ │ └── FactoryDesignPattern.cs.meta
│ ├── Prototype Design Pattern.meta
│ └── Prototype Design Pattern
│ │ ├── PrototypeDesignPattern.cs
│ │ └── PrototypeDesignPattern.cs.meta
│ ├── Credits.cs
│ ├── Credits.cs.meta
│ ├── Structural Design Patterns.meta
│ └── Structural Design Patterns
│ ├── Adapter Design Pattern.meta
│ ├── Adapter Design Pattern
│ ├── AdapterDesignPattern.cs
│ └── AdapterDesignPattern.cs.meta
│ ├── Bridge Design Pattern.meta
│ ├── Bridge Design Pattern
│ ├── BridgeDesignPattern.cs
│ └── BridgeDesignPattern.cs.meta
│ ├── Composite Design Pattern.meta
│ ├── Composite Design Pattern
│ ├── CompositeDesignPattern.cs
│ └── CompositeDesignPattern.cs.meta
│ ├── Decorator Design Pattern.meta
│ ├── Decorator Design Pattern
│ ├── DecoratorDesignPattern.cs
│ └── DecoratorDesignPattern.cs.meta
│ ├── Facade Design Pattern.meta
│ ├── Facade Design Pattern
│ ├── FacadeDesignPattern.cs
│ └── FacadeDesignPattern.cs.meta
│ ├── Flyweight Design Pattern.meta
│ ├── Flyweight Design Pattern
│ ├── FlyWeightDesignPattern.cs
│ └── FlyWeightDesignPattern.cs.meta
│ ├── Proxy Design Pattern.meta
│ └── Proxy Design Pattern
│ ├── ProxyDesignPattern.cs
│ └── ProxyDesignPattern.cs.meta
├── ProjectSettings
├── AudioManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshLayers.asset
├── NetworkManager.asset
├── Physics2DSettings.asset
├── ProjectSettings.asset
├── QualitySettings.asset
├── TagManager.asset
└── TimeManager.asset
├── UnityDesignPatternsExampleProject-csharp.sln
├── UnityDesignPatternsExampleProject-csharp.v12.suo
├── UnityDesignPatternsExampleProject.sln
└── UnityDesignPatternsExampleProject.userprefs
/.gitignore:
--------------------------------------------------------------------------------
1 | # =============== #
2 | # Unity generated #
3 | # =============== #
4 | [Tt]emp/
5 | [Oo]bj/
6 | [Bb]uild
7 | [Ll]ibrary/
8 | sysinfo.txt
9 | # ===================================== #
10 | # Visual Studio / MonoDevelop generated #
11 | # ===================================== #
12 | [Ee]xported[Oo]bj/
13 | /*.userprefs
14 | /*.csproj
15 | /*.pidb
16 | /*.suo
17 | /*.sln*
18 | /*.user
19 | /*.unityproj
20 | /*.booproj
21 | # ============ #
22 | # OS generated #
23 | # ============ #
24 | .DS_Store*
25 | ._*
26 | .Spotlight-V100
27 | .Trashes
28 | Icon?
29 | ehthumbs.db
30 | [Tt]humbs.db
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # README #
2 |
3 | This is the great video tutorial series on Design Patterns by Derek Banas translated into C# and put into a simple Unity Project for learning and playing purposes !
4 |
5 | The whole Series is available here: https://www.youtube.com/playlist?list=PLF206E906175C7E07
6 |
7 | The Project covers:
8 |
9 |
10 | #### Behavioral Patterns:
11 | * Chain Of Responsibility Design Pattern
12 | * Command Design Pattern
13 | * Interpreter Design Pattern
14 | * Iterator Design Pattern
15 | * Mediator Design Pattern
16 | * Memento Design Pattern
17 | * Observer Design Pattern (to be implemented)
18 | * State Design Pattern
19 | * Strategy Design Pattern
20 | * Template Method Design Pattern
21 | * Visitor Design Pattern
22 |
23 | #### Creational Patterns:
24 | * Abstract Factory Design Pattern
25 | * Builder Design Pattern
26 | * Factory Design Pattern
27 | * Prototype Design Pattern
28 |
29 | #### Structural Design Patterns:
30 | * Adapter Design Pattern
31 | * Bridge Design Pattern
32 | * Composite Design Pattern
33 | * Decorator Design Pattern
34 | * Facade Design Pattern
35 | * Flyweight Design Pattern (To be implemented)
36 | * Proxy Design Pattern
37 |
38 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assembly-CSharp-vs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}
9 | Library
10 | Properties
11 |
12 | Assembly-CSharp
13 | v3.5
14 | 512
15 | Assets
16 |
17 |
18 | true
19 | full
20 | false
21 | Temp\bin\Debug\
22 | DEBUG;TRACE;UNITY_4_6_4;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_IL2CPP;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;UNITY5_SCRIPTING_IN_UNITY4;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_MONO;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE
23 | prompt
24 | 4
25 | 0169
26 |
27 |
28 | pdbonly
29 | true
30 | Temp\bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | 0169
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | D:/Software/Editor/Data/Managed/UnityEngine.dll
43 |
44 |
45 | D:/Software/Editor/Data/Managed/UnityEditor.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | D:/Software/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.4/UnityEngine.UI.dll
75 |
76 |
77 |
78 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assembly-CSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}
9 | Library
10 | Properties
11 |
12 | Assembly-CSharp
13 | v3.5
14 | 512
15 | Assets
16 |
17 |
18 | true
19 | full
20 | false
21 | Temp\bin\Debug\
22 | DEBUG;TRACE;UNITY_4_6_4;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_IL2CPP;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;UNITY5_SCRIPTING_IN_UNITY4;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_MONO;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE
23 | prompt
24 | 4
25 | 0169
26 |
27 |
28 | pdbonly
29 | true
30 | Temp\bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | 0169
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | D:/Software/Editor/Data/Managed/UnityEngine.dll
43 |
44 |
45 | D:/Software/Editor/Data/Managed/UnityEditor.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | D:/Software/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.4/UnityEngine.UI.dll
75 |
76 |
77 |
78 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ed96898b4862f0d4abe214a192725911
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/ALL PATTERNS.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/Assets/_PATTERNS/ALL PATTERNS.unity
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/ALL PATTERNS.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 98b3dc781572d7d4fbc16731a77e0c9e
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3044373dca1a55040a2778f210976001
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Chain Of Responsibility Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 54c54048c781f8449aee155690c3e63d
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Chain Of Responsibility Design Pattern/ChainOfResponsibilityPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | /*
5 | * This pattern sends data to an object and if that object can't use it, it sends it to any number of other objects that may be able to use it
6 | *
7 | * * Create 4 objects that can either add, substract, mulitply or divide
8 | * * Send 2 numbers and a command and allow these 4 objects to decide which can handle the requested calculation
9 | *
10 | *
11 | * */
12 |
13 | namespace ChainOfResponsibilityDesignPattern
14 | {
15 | public class ChainOfResponsibilityPattern : MonoBehaviour
16 | {
17 | void OnEnable ()
18 | {
19 | Debug.Log ("------------------");
20 | Debug.Log ("CHAIN OF RESPONSIBILITY DESIGN PATTERN");
21 |
22 | // create calculation objects that get chained to each other in a sec
23 | Chain calc1 = new AddNumbers();
24 | Chain calc2 = new SubstractNumbers();
25 | Chain calc3 = new DivideNumbers();
26 | Chain calc4 = new MultiplyNumbers();
27 |
28 | // now chain them to each other
29 | calc1.SetNextChain(calc2);
30 | calc2.SetNextChain(calc3);
31 | calc3.SetNextChain(calc4);
32 |
33 | // this is the request that will be passed to a chain object to let them figure out which calculation objects it the right for the request
34 | // the request is here the CalculationType enum we add. so we want this pair of numbers to be added
35 | Numbers myNumbers = new Numbers(3, 5, CalculationType.Add);
36 | calc1.Calculate(myNumbers);
37 |
38 | // another example:
39 | Numbers myOtherNumbers = new Numbers(6, 2, CalculationType.Multiply);
40 | calc1.Calculate(myOtherNumbers);
41 |
42 | // or pass it to some chain object inbetween which will not work in this case:
43 | Numbers myLastNumbers = new Numbers(12, 3, CalculationType.Substract);
44 | calc3.Calculate(myLastNumbers);
45 | }
46 | }
47 |
48 |
49 | // just defining some types of calculation we want to implement
50 | // it is better than passing string values as requests because you don't risk any typos that way :)
51 | public enum CalculationType
52 | {
53 | Add,
54 | Substract,
55 | Divide,
56 | Multiply
57 | };
58 |
59 |
60 |
61 |
62 | // We use this object as an example object to be passed to the calculation chain ;-)
63 | // to figure out what we want to do with it (which is stored in CalculationType/calculationWanted)
64 | public class Numbers
65 | {
66 | // some numbers:
67 | public int number1 { get; protected set; }
68 | public int number2 { get; protected set; }
69 |
70 | // here we store in this object what we want to do with it to let the chain figure out who is responsible for it ;-)
71 | public CalculationType calculationWanted { get; protected set; }
72 |
73 | // constructor:
74 | public Numbers(int num1, int num2, CalculationType calcWanted)
75 | {
76 | this.number1 = num1;
77 | this.number2 = num2;
78 | this.calculationWanted = calcWanted;
79 | }
80 | }
81 |
82 |
83 |
84 |
85 |
86 | // doesn't need to be called chain of course ;-)
87 | public interface Chain
88 | {
89 | void SetNextChain(Chain nextChain); // to be called when calulcation fails
90 | void Calculate(Numbers numbers); // try to calculate
91 | }
92 |
93 |
94 |
95 |
96 | public class AddNumbers : Chain
97 | {
98 | // each chain object stored a private nextInChain object, that gets called when the method calculate fails
99 | protected Chain nextInChain;
100 |
101 | public void SetNextChain(Chain nextChain)
102 | {
103 | this.nextInChain = nextChain;
104 | }
105 |
106 | public void Calculate(Numbers request)
107 | {
108 | if(request.calculationWanted == CalculationType.Add)
109 | {
110 | Debug.Log("Adding: " + request.number1 + " + " + request.number2 + " = " + (request.number1 + request.number2).ToString());
111 | }
112 | else if(nextInChain != null)
113 | nextInChain.Calculate(request);
114 | else
115 | Debug.Log ("Handling of request failed: " + request.calculationWanted);
116 | }
117 | }
118 |
119 | public class SubstractNumbers : Chain
120 | {
121 | protected Chain nextInChain;
122 |
123 | public void SetNextChain(Chain nextChain)
124 | {
125 | this.nextInChain = nextChain;
126 | }
127 |
128 | public void Calculate(Numbers request)
129 | {
130 | if(request.calculationWanted == CalculationType.Substract)
131 | {
132 | Debug.Log("Substracting: " + request.number1 + " - " + request.number2 + " = " + (request.number1 - request.number2).ToString());
133 | }
134 | else if(nextInChain != null)
135 | nextInChain.Calculate(request);
136 | else
137 | Debug.Log ("Handling of request failed: " + request.calculationWanted);
138 | }
139 | }
140 |
141 | public class DivideNumbers : Chain
142 | {
143 | protected Chain nextInChain;
144 |
145 | public void SetNextChain(Chain nextChain)
146 | {
147 | this.nextInChain = nextChain;
148 | }
149 |
150 | public void Calculate(Numbers request)
151 | {
152 | if(request.calculationWanted == CalculationType.Divide)
153 | {
154 | Debug.Log("Dividing: " + request.number1 + " / " + request.number2 + " = " + (request.number1 / request.number2).ToString());
155 | }
156 | else if(nextInChain != null)
157 | nextInChain.Calculate(request);
158 | else
159 | Debug.Log ("Handling of request failed: " + request.calculationWanted);
160 | }
161 | }
162 |
163 | public class MultiplyNumbers : Chain
164 | {
165 | protected Chain nextInChain;
166 |
167 | public void SetNextChain(Chain nextChain)
168 | {
169 | this.nextInChain = nextChain;
170 | }
171 |
172 | public void Calculate(Numbers request)
173 | {
174 | if(request.calculationWanted == CalculationType.Multiply)
175 | {
176 | Debug.Log("Multiplying: " + request.number1 + " * " + request.number2 + " = " + (request.number1 * request.number2).ToString());
177 | }
178 | else if(nextInChain != null)
179 | nextInChain.Calculate(request);
180 | else
181 | Debug.Log ("Handling of request failed: " + request.calculationWanted);
182 | }
183 | }
184 |
185 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Chain Of Responsibility Design Pattern/ChainOfResponsibilityPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4b541dc700f19bf4ebd425079a51fed5
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Command Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 578b4a94d5d045f4dac816b64bf6c6e0
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Command Design Pattern/CommandDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | // the command pattern is a behavioural design pattern in which an object is used to represent and encapsulate
6 | // all the information needed to call a method for a later time
7 |
8 | // this information includes the method name, the object that owns the method and values for the method parameters
9 |
10 | // allows store lists of code that is executed at a later time or many times
11 | // client says i want a specific command to run when execute() is called on 1 of these encapsulated (hidden) objects
12 | // ability to undo commands
13 |
14 | // an object called the invoker transfers this command to another object called a receiver to execute the right code
15 | // TurnTVOn - DeviceButton - TurnTVOn - Television.TurnTVOn()
16 |
17 |
18 | /* Benefits:
19 | *
20 | * allows to set aside a list of commands for later use
21 | *
22 | * a class is a great place to store procedures you want to be executed
23 | *
24 | * you can store multiple commands in a class to use over and over
25 | *
26 | * you can implement undo procedures for past commands
27 | *
28 | * negative: you create many small classes that store lists of commands
29 | *
30 | * */
31 |
32 | namespace CommandDesign
33 | {
34 | public class CommandDesignPattern : MonoBehaviour
35 | {
36 | void OnEnable ()
37 | {
38 | Debug.Log ("------------------");
39 | Debug.Log ("COMMAND DESIGN PATTERN");
40 | IElectronicDevice device = TVRemove.GetDevice();
41 |
42 | TurnTVOn onCommand = new TurnTVOn(device);
43 | DeviceButton onPressed = new DeviceButton(onCommand);
44 | onPressed.Press();
45 |
46 | // -----------------------
47 |
48 | TurnTVOff offCommand = new TurnTVOff(device);
49 | onPressed = new DeviceButton(offCommand);
50 | onPressed.Press();
51 |
52 | TurnVolumeUp volUpCommand = new TurnVolumeUp(device);
53 | onPressed = new DeviceButton(volUpCommand);
54 | onPressed.Press();
55 | onPressed.Press();
56 | onPressed.Press();
57 |
58 | TurnVolumeDown volDownCommand = new TurnVolumeDown(device);
59 | onPressed = new DeviceButton(volDownCommand);
60 | onPressed.Press();
61 |
62 | // -----------------------
63 | Television tv = new Television();
64 | Radio radio = new Radio();
65 |
66 | List allDevices = new List();
67 | allDevices.Add(tv);
68 | allDevices.Add (radio);
69 |
70 | TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);
71 | DeviceButton turnThemOff = new DeviceButton(turnOffDevices);
72 | turnThemOff.Press();
73 |
74 | // -----------------------
75 | turnThemOff.PressUndo();
76 |
77 |
78 | // Homework for better Undo:
79 | // saving all commands in linked lists
80 | // on undo go through commands in list for undoing and do the opposite
81 | }
82 | }
83 |
84 |
85 |
86 |
87 |
88 | // interface for electronic devices (or receivers)
89 | public interface IElectronicDevice
90 | {
91 | void On();
92 | void Off();
93 | void VolumeUp();
94 | void VolumeDown();
95 | }
96 |
97 |
98 | public class Television : IElectronicDevice
99 | {
100 | protected int volume = 0;
101 |
102 | public void On()
103 | {
104 | Debug.Log ("TV is On");
105 | }
106 |
107 | public void Off()
108 | {
109 | Debug.Log ("TV is Off");
110 | }
111 |
112 | public void VolumeUp()
113 | {
114 | ++volume;
115 | Debug.Log ("TV Turned Volume Up to " + volume);
116 | }
117 |
118 | public void VolumeDown()
119 | {
120 | if(volume > 0)
121 | --volume;
122 | Debug.Log ("TV Turned Volume Down to " + volume);
123 | }
124 | }
125 |
126 |
127 | // commands:
128 | // command interface:
129 | public interface ICommand
130 | {
131 | void Execute();
132 | void Undo();
133 | }
134 |
135 | public class TurnTVOn : ICommand
136 | {
137 | IElectronicDevice device;
138 |
139 | public TurnTVOn(IElectronicDevice device)
140 | {
141 | this.device = device;
142 | }
143 |
144 | public void Execute()
145 | {
146 | this.device.On ();
147 | }
148 |
149 | public void Undo()
150 | {
151 | this.device.Off();
152 | }
153 | }
154 |
155 | public class TurnTVOff : ICommand
156 | {
157 | IElectronicDevice device;
158 |
159 | public TurnTVOff(IElectronicDevice device)
160 | {
161 | this.device = device;
162 | }
163 |
164 | public void Execute()
165 | {
166 | this.device.Off ();
167 | }
168 |
169 | public void Undo()
170 | {
171 | this.device.On();
172 | }
173 | }
174 |
175 | public class TurnVolumeUp : ICommand
176 | {
177 | IElectronicDevice device;
178 |
179 | public TurnVolumeUp(IElectronicDevice device)
180 | {
181 | this.device = device;
182 | }
183 |
184 | public void Execute()
185 | {
186 | this.device.VolumeUp ();
187 | }
188 |
189 | public void Undo()
190 | {
191 | this.device.VolumeDown();
192 | }
193 | }
194 |
195 | public class TurnVolumeDown : ICommand
196 | {
197 | IElectronicDevice device;
198 |
199 | public TurnVolumeDown(IElectronicDevice device)
200 | {
201 | this.device = device;
202 | }
203 |
204 | public void Execute()
205 | {
206 | this.device.VolumeDown ();
207 | }
208 |
209 | public void Undo()
210 | {
211 | this.device.VolumeUp();
212 | }
213 | }
214 |
215 |
216 |
217 | public class DeviceButton
218 | {
219 | ICommand cmd;
220 |
221 | public DeviceButton(ICommand cmd)
222 | {
223 | this.cmd = cmd;
224 | }
225 |
226 | public void Press()
227 | {
228 | this.cmd.Execute(); // actually the invoker (device button) has no idea what it does
229 | }
230 |
231 | public void PressUndo()
232 | {
233 | this.cmd.Undo();
234 | }
235 | }
236 |
237 |
238 |
239 |
240 |
241 | public class TVRemove
242 | {
243 | public static IElectronicDevice GetDevice()
244 | {
245 | return new Television();
246 | }
247 | }
248 |
249 |
250 |
251 |
252 | public class Radio : IElectronicDevice
253 | {
254 | protected int volume = 0;
255 |
256 | public void On()
257 | {
258 | Debug.Log ("Radio is On");
259 | }
260 |
261 | public void Off()
262 | {
263 | Debug.Log ("Radio is Off");
264 | }
265 |
266 | public void VolumeUp()
267 | {
268 | ++volume;
269 | Debug.Log ("Radio Turned Volume Up to " + volume);
270 | }
271 |
272 | public void VolumeDown()
273 | {
274 | if(volume > 0)
275 | --volume;
276 | Debug.Log ("Radio Turned Volume Down to " + volume);
277 | }
278 | }
279 |
280 |
281 | public class TurnItAllOff : ICommand
282 | {
283 | List devices;
284 |
285 | public TurnItAllOff(List devices)
286 | {
287 | this.devices = devices;
288 | }
289 |
290 | public void Execute()
291 | {
292 | foreach(IElectronicDevice device in devices)
293 | {
294 | device.Off();
295 | }
296 | }
297 |
298 | public void Undo()
299 | {
300 | foreach(IElectronicDevice device in devices)
301 | {
302 | device.On();
303 | }
304 | }
305 | }
306 |
307 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Command Design Pattern/CommandDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6f74e4958a94bb24881925bcaef26738
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Interpreter Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cf4bce6fd57279448b7f352f48422485
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Interpreter Design Pattern/InterpreterDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System;
4 | using System.Globalization;
5 | using System.Reflection;
6 |
7 | /*
8 | * "The interpreter pattern is normally ignored" < great way to start :)
9 | * "This pattern is almost never used" < also good
10 | *
11 | * Derek Barnas: "I find it to be extremely useful if combined with Java Reflection techniques"
12 | * Derek Barnas: "I was able to put together the zork videogame adventure with those two that night"
13 | *
14 | * ====================================
15 | * It is used to convert one representation of data into another
16 | *
17 | * The context contains the information that will be interpreted
18 | * The Expression is an abstract class that defines all the methods needed to perform the different converions
19 | * The Terminal or Concrete Expressions provide specific conversions on different types of data
20 | *
21 | * ====================================
22 | *
23 | * Video: https://www.youtube.com/watch?v=6CVymSJQuJE&list=PLF206E906175C7E07&index=23
24 | *
25 | * */
26 |
27 | namespace InterpreterPattern
28 | {
29 | public class InterpreterDesignPattern : MonoBehaviour
30 | {
31 | void OnEnable ()
32 | {
33 | Debug.Log ("------------------");
34 | Debug.Log ("INTERPRETER DESIGN PATTERN");
35 |
36 | string question1 = "2 Gallons to pints";
37 | AskQuestion(question1);
38 |
39 | string question2 = "4 Gallons to tablespoons";
40 | AskQuestion(question2);
41 | }
42 |
43 | protected void AskQuestion(string question)
44 | {
45 | ConversionContext context = new ConversionContext (question);
46 |
47 | string fromConversion = context.fromConversion; // in this example fromConversion is always the second word
48 | string toConversion = context.toConversion;
49 | double quantity = context.quantity;
50 |
51 | // Trying to get a matching class for the word "fromConversion"
52 | try
53 | {
54 | // Getting the type, we also have to define the namespace (in this case InterpreterPattern as defined above)
55 | // and fromConversion should hold the class name (in this case Gallons)
56 | Type type = Type.GetType ("InterpreterPattern." + fromConversion);
57 | object instance = Activator.CreateInstance (type);
58 | Expression expression = instance as Expression;
59 |
60 | // Get the matching method: e.g. (toConversion = pints)
61 | MethodInfo method = type.GetMethod (toConversion);
62 | string result = (string) method.Invoke(instance, new object[]{quantity});
63 |
64 | Debug.Log ("Output: " + quantity.ToString () + " " + fromConversion + " are " + result + " " + toConversion);
65 | }
66 | catch (Exception e)
67 | {
68 | Debug.Log (e.Message);
69 | }
70 | }
71 | }
72 |
73 |
74 |
75 |
76 | // Context object that does try to make sense of an input string:
77 | public class ConversionContext
78 | {
79 | public string conversionQues { get; protected set; }
80 |
81 | public string fromConversion { get; protected set; }
82 |
83 | public string toConversion { get; protected set; }
84 |
85 | public double quantity { get; protected set; }
86 |
87 | protected string[] partsOfQues;
88 |
89 |
90 |
91 | // here happens the sensemaking
92 | public ConversionContext (string input)
93 | {
94 | Debug.Log ("Input: " + input);
95 | this.conversionQues = input;
96 | this.partsOfQues = input.Split (new string[]{" "}, System.StringSplitOptions.RemoveEmptyEntries);
97 |
98 | if (partsOfQues.Length >= 4)
99 | {
100 |
101 | fromConversion = GetCapitalized (partsOfQues [1]);
102 | // 1 gallon to pints
103 | toConversion = GetLowerCase (partsOfQues [3]);
104 |
105 | // get quantitiy:
106 | double quant;
107 | double.TryParse (partsOfQues [0], out quant);
108 | this.quantity = quant;
109 | }
110 | }
111 |
112 | // Some helper methods:
113 | protected string GetCapitalized (string word)
114 | {
115 | word = word.ToLower ();
116 | word = CultureInfo.CurrentCulture.TextInfo.ToTitleCase (word);
117 |
118 | // make sure a 's' is appended
119 | if (word.EndsWith ("s") == false)
120 | {
121 | word += "s";
122 | }
123 |
124 | return word;
125 | }
126 |
127 | protected string GetLowerCase (string word)
128 | {
129 | return word.ToLower ();
130 | }
131 | }
132 |
133 |
134 |
135 |
136 | // Definition of all the things the concrete expression
137 | // shall be able to convert into
138 | public abstract class Expression
139 | {
140 | public abstract string gallons (double quantity);
141 |
142 | public abstract string quarts (double quantity);
143 |
144 | public abstract string pints (double quantity);
145 |
146 | public abstract string cups (double quantity);
147 |
148 | public abstract string tablespoons (double quantity);
149 | }
150 |
151 |
152 | // concrete class
153 | public class Gallons : Expression
154 | {
155 | #region implemented abstract members of Expression
156 |
157 | public override string gallons (double quantity)
158 | {
159 | return quantity.ToString ();
160 | }
161 |
162 | public override string quarts (double quantity)
163 | {
164 | return (quantity * 4).ToString ();
165 | }
166 |
167 | public override string pints (double quantity)
168 | {
169 | return (quantity * 8).ToString ();
170 | }
171 |
172 | public override string cups (double quantity)
173 | {
174 | return (quantity * 16).ToString ();
175 | }
176 |
177 | public override string tablespoons (double quantity)
178 | {
179 | return (quantity * 256).ToString ();
180 | }
181 |
182 | #endregion
183 | }
184 |
185 |
186 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Interpreter Design Pattern/InterpreterDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 010428c38c9350b428fc20ef39349291
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Iterator Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 659e5bb732dd55943abb22e49628053a
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Iterator Design Pattern/IteratorDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | /* Iterator provides uniform way to access different collections of objects
6 | * If you get an Array, ArrayList, Hashtable of objects, you pop out an iterator for each and treat them the same
7 | *
8 | * This provides a uniform way to cycle through different collections
9 | *
10 | * You can also write polymorphic code because you can refer to each collection of objects
11 | * because they'll implement the same interface
12 | *
13 | *
14 | *
15 | * */
16 |
17 |
18 | namespace IteratorPattern
19 | {
20 | public class IteratorDesignPattern : MonoBehaviour
21 | {
22 | void OnEnable ()
23 | {
24 | Debug.Log ("------------------");
25 | Debug.Log ("ITERATOR DESIGN PATTERN");
26 |
27 | // creating the collections and adding some songs:
28 | SongsOfThe70s song70s = new SongsOfThe70s ();
29 | song70s.AddSong ("song title", "song artist", 1974);
30 | song70s.AddSong ("song title2", "song artist2", 1978);
31 |
32 | SongsOfThe80s song80s = new SongsOfThe80s ();
33 | song80s.AddSong ("song title 80s", "song artist 80s", 1985);
34 | song80s.AddSong ("song title2 80s", "song artist2 80s", 1989);
35 |
36 | // because of the iterator pattern we can loop through both types
37 | // of collections the same simple way and don't have to bother
38 | // with what type of collection the object stores:
39 |
40 | IEnumerator songsOfThe70sIterator = song70s.GetIterator();
41 | while(songsOfThe70sIterator.MoveNext())
42 | {
43 | SongInfo info = (SongInfo)songsOfThe70sIterator.Current;
44 | Debug.Log ("Song 70s: " + info.ToString());
45 | }
46 |
47 | IEnumerator songsOfThe80sIterator = song80s.GetIterator();
48 | while(songsOfThe80sIterator.MoveNext())
49 | {
50 | SongInfo info = (SongInfo)songsOfThe80sIterator.Current;
51 | Debug.Log ("Song 80s: " + info.ToString());
52 | }
53 | }
54 | }
55 |
56 |
57 |
58 | // just a sample object to hold some arbitrary information for demonstration
59 | public class SongInfo
60 | {
61 | public string songName { get; protected set; }
62 |
63 | public string bandName { get; protected set; }
64 |
65 | public int yearReleased { get; protected set; }
66 |
67 | public SongInfo (string songName, string bandName, int yearReleased)
68 | {
69 | this.songName = songName;
70 | this.bandName = bandName;
71 | this.yearReleased = yearReleased;
72 | }
73 |
74 | public string ToString ()
75 | {
76 | return this.songName + " - " + this.bandName + " : " + this.yearReleased.ToString();
77 | }
78 | }
79 |
80 |
81 |
82 | // Iterator Interface
83 | public interface SongIterator
84 | {
85 | IEnumerator GetIterator();
86 | }
87 |
88 |
89 |
90 | // These two classes implement the iterator
91 | public class SongsOfThe70s : SongIterator
92 | {
93 | // here it is a list
94 | protected List bestSongs;
95 |
96 | public SongsOfThe70s ()
97 | {
98 | bestSongs = new List ();
99 | }
100 |
101 | public void AddSong (string name, string artist, int year)
102 | {
103 | SongInfo song = new SongInfo (name, artist, year);
104 | bestSongs.Add (song);
105 | }
106 |
107 | // heart
108 | public IEnumerator GetIterator ()
109 | {
110 | foreach(SongInfo song in bestSongs)
111 | yield return song;
112 | yield break;
113 | }
114 | }
115 |
116 | public class SongsOfThe80s : SongIterator
117 | {
118 | // here we have an array
119 | protected SongInfo[] bestSongs;
120 |
121 | public SongsOfThe80s ()
122 | {
123 | bestSongs = new SongInfo[0];
124 | }
125 |
126 | public void AddSong (string name, string artist, int year)
127 | {
128 | SongInfo song = new SongInfo (name, artist, year);
129 | // just for the sake of easyness of appending something we will convert the array to a list
130 | List newSongs = new List(bestSongs);
131 | // add a new element
132 | newSongs.Add(song);
133 | // and convert it back to an array
134 | bestSongs = newSongs.ToArray();
135 | }
136 |
137 | // heart
138 | public IEnumerator GetIterator ()
139 | {
140 | foreach(SongInfo song in bestSongs)
141 | yield return song;
142 | yield break;
143 | }
144 | }
145 |
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Iterator Design Pattern/IteratorDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 17db77e5b1b3f0f43a94902df2568296
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Mediator Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2de3bc72dac95fe49beb071e2f6e4bcd
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Mediator Design Pattern/MediatorDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | /* Videolink: https://www.youtube.com/watch?v=8DxIpdKd41A&list=PLF206E906175C7E07&index=24
6 | *
7 | *
8 | * It is used to handle communication between related objects (Colleagues)
9 | *
10 | * All communication is handled by the mediator
11 | * the colleagues don't need to know anything about each other
12 | *
13 | * GOF: Allows loose coupling by encapsulating the way disparate sets of objects
14 | * interact and communicate with each other. Allows for the actions
15 | * of each object set to vary independently of one another
16 | *
17 | *
18 | * */
19 |
20 |
21 | namespace MediatorPattern
22 | {
23 | public class MediatorDesignPattern : MonoBehaviour
24 | {
25 | void OnEnable ()
26 | {
27 | Debug.Log ("------------------");
28 | Debug.Log ("MEDIATOR DESIGN PATTERN");
29 |
30 | StockMediator nyse = new StockMediator();
31 |
32 | // important here is:
33 | // in this example they both might be doing nothing different, but
34 | // they could be totally different objects and calculate stuff different or so
35 | // but still be able to talk to the mediator the same easy way
36 | // that's why we have different objects here:
37 | GormanSlacks broker = new GormanSlacks(nyse);
38 | JTPoorman broker2 = new JTPoorman(nyse);
39 |
40 | nyse.AddColleague(broker);
41 | nyse.AddColleague(broker2);
42 |
43 | // because they call methods on the same mediator object they talk to the same mediator
44 | // who handles all the stock exanche and keeps track of that. so the brokers by themselves
45 | // don't know anything about each other. which is a good thing :-)
46 | broker.SaleOffer(Stock.MSFT, 100);
47 | broker.SaleOffer(Stock.GOOG, 50);
48 |
49 | broker2.BuyOffer(Stock.MSFT, 100);
50 | broker2.SaleOffer(Stock.NRG, 10);
51 |
52 | broker.BuyOffer(Stock.NRG, 10);
53 | broker.BuyOffer(Stock.NRG, 50);
54 |
55 | nyse.PrintStockOfferings();
56 | }
57 | }
58 |
59 |
60 | // I like using enums more than using strings
61 | // because it prevents typos and I don't need to remember strings ;)
62 | public enum Stock
63 | {
64 | MSFT,
65 | GOOG,
66 | NRG
67 | };
68 |
69 |
70 | public class StockOffer
71 | {
72 | public int stockShares { get; private set; }
73 | public Stock stock { get; private set; }
74 | public int colleagueCode { get; private set; }
75 |
76 | public StockOffer(int numOfShares, Stock stock, int collCode)
77 | {
78 | this.stockShares = numOfShares;
79 | this.stock = stock;
80 | this.colleagueCode = collCode;
81 | }
82 | }
83 |
84 |
85 | public abstract class Colleague
86 | {
87 | private Mediator mediator;
88 | private int colleagueCode;
89 |
90 | public Colleague(Mediator mediator)
91 | {
92 | this.mediator = mediator;
93 | }
94 |
95 | public void SetCode(int code)
96 | {
97 | colleagueCode = code;
98 | }
99 |
100 | public void SaleOffer(Stock stock, int shares)
101 | {
102 | mediator.SaleOffer(stock, shares, this.colleagueCode);
103 | }
104 |
105 | public void BuyOffer(Stock stock, int shares)
106 | {
107 | mediator.BuyOffer(stock, shares, this.colleagueCode);
108 | }
109 | }
110 |
111 |
112 | public class GormanSlacks : Colleague
113 | {
114 | // using : base() like here calls the constructor of the base class with the arguments passed in
115 | // here it calls "Colleague(Mediator mediator)"
116 | public GormanSlacks(Mediator mediator) : base (mediator)
117 | {
118 | Debug.Log ("Gorman Slacks signed up with the stockexange");
119 | }
120 | }
121 |
122 | public class JTPoorman : Colleague
123 | {
124 | public JTPoorman(Mediator mediator) : base (mediator)
125 | {
126 | Debug.Log ("JT Poorman signed up with the stockexange");
127 | }
128 | }
129 |
130 |
131 |
132 |
133 |
134 |
135 | public interface Mediator
136 | {
137 | void AddColleague(Colleague colleague);
138 | void SaleOffer(Stock stock, int shares, int code);
139 | void BuyOffer(Stock stock, int shares, int code);
140 | }
141 |
142 |
143 | public class StockMediator : Mediator
144 | {
145 | private List colleagues;
146 | private List buyOffers;
147 | private List sellOffers;
148 |
149 | private int colleagueCodes = 0;
150 |
151 | public StockMediator()
152 | {
153 | colleagues = new List();
154 | buyOffers = new List();
155 | sellOffers = new List();
156 | }
157 |
158 | #region Mediator implementation
159 | public void AddColleague (Colleague colleague)
160 | {
161 | this.colleagues.Add (colleague);
162 | colleagueCodes += 1;
163 | colleague.SetCode(colleagueCodes);
164 | }
165 |
166 | public void SaleOffer (Stock stock, int shares, int code)
167 | {
168 | bool stockSold = false;
169 |
170 | // see if someone is willing to buy:
171 | for(int i = 0; i < buyOffers.Count; i++)
172 | {
173 | StockOffer offer = buyOffers[i];
174 | // check if the stock is the same:
175 | if(offer.stock == stock && offer.stockShares == shares)
176 | {
177 | Debug.Log (shares + " shares of " + stock + " stocks sold to colleague with code " + code);
178 |
179 | buyOffers.Remove(offer);
180 | stockSold = true;
181 | }
182 |
183 | if(stockSold) break;
184 | }
185 |
186 | if(!stockSold)
187 | {
188 | Debug.Log (shares + " shares of " + stock + " stocks added to inventory");
189 | StockOffer offer = new StockOffer(shares, stock, code);
190 | sellOffers.Add (offer);
191 | }
192 | }
193 |
194 | public void BuyOffer (Stock stock, int shares, int code)
195 | {
196 | bool stockBought = false;
197 |
198 | // see if someone is willing to buy:
199 | for(int i = 0; i < sellOffers.Count; i++)
200 | {
201 | StockOffer offer = sellOffers[i];
202 | // check if the stock is the same:
203 | if(offer.stock == stock && offer.stockShares == shares)
204 | {
205 | Debug.Log (shares + " shares of " + stock + " stocks bought by colleague with code " + code);
206 |
207 | sellOffers.Remove(offer);
208 | stockBought = true;
209 | }
210 |
211 | if(stockBought) break;
212 | }
213 |
214 | if(!stockBought)
215 | {
216 | Debug.Log (shares + " shares of " + stock + " stocks added to inventory");
217 | StockOffer offer = new StockOffer(shares, stock, code);
218 | buyOffers.Add (offer);
219 | }
220 | }
221 | #endregion
222 |
223 |
224 | public void PrintStockOfferings()
225 | {
226 | Debug.Log ("For Sale: " + sellOffers.Count);
227 | foreach(StockOffer offer in sellOffers)
228 | {
229 | Debug.Log (offer.stock + " - " + offer.stockShares + " - " + offer.colleagueCode);
230 | }
231 |
232 |
233 | Debug.Log("For Buy: " + buyOffers.Count);
234 | foreach(StockOffer offer in buyOffers)
235 | {
236 | Debug.Log (offer.stock + " - " + offer.stockShares + " - " + offer.colleagueCode);
237 | }
238 | }
239 | }
240 |
241 |
242 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Mediator Design Pattern/MediatorDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9baf2fc8d6c9cf24c8a69196687bb389
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Memento Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ea8785495042ba84782e7695396ff7b6
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Memento Design Pattern/MementoDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | /* Videolink: https://www.youtube.com/watch?v=jOnxYT8Iaoo&list=PLF206E906175C7E07&index=25
6 | *
7 | * provides a way to store previous states of an object easily
8 | *
9 | * memento: the basic object that is stored in different states
10 | *
11 | * originator: sets and gets values from the currently targeted memento. Creates new memenots and assigns current values to them
12 | *
13 | * caretaker: holds an list that contains all previous versions of the memento. it can store and retrieve stored mementos
14 | *
15 | *
16 | * */
17 |
18 |
19 |
20 | namespace MementoPattern
21 | {
22 | public class MementoDesignPattern : MonoBehaviour
23 | {
24 | Caretaker caretaker = new Caretaker();
25 |
26 | Originator originator = new Originator();
27 |
28 | int savedFiles = 0, currentArticle = 0;
29 |
30 | void OnEnable ()
31 | {
32 | Debug.Log ("------------------");
33 | Debug.Log ("MEMENTO DESIGN PATTERN");
34 |
35 | // here we do some virtual typing and saving texts:
36 | Save ("Tex1: Hello World, this is text example 1");
37 | Save ("Text2: Ok here comes example number 2.");
38 | Save ("Text3: And example number 3. Just testing.");
39 | Save ("Text4: ....");
40 |
41 | // Here we do some virtual button pressing
42 | Debug.Log("Pressing Undo");
43 | Undo ();
44 | Debug.Log("Pressing Undo");
45 | Undo ();
46 | Debug.Log("Pressing Undo");
47 | Undo ();
48 | Debug.Log("Pressing Redo");
49 | Redo ();
50 | }
51 |
52 | // these methods below might get called when someone is pressing a button
53 | // you could easily implement it with unitys new ui system :)
54 | public void Save(string text)
55 | {
56 | originator.Set(text);
57 | caretaker.Add(originator.StoreInMemento());
58 | savedFiles = caretaker.GetCountOfSavedArticles();
59 | currentArticle = savedFiles;
60 | }
61 |
62 | public string Undo()
63 | {
64 | if(currentArticle > 0)
65 | currentArticle -= 1;
66 |
67 | Memento prev = caretaker.Get(currentArticle);
68 | string prevArticle = originator.RestoreFromMemento(prev);
69 | return prevArticle;
70 | }
71 |
72 | public string Redo()
73 | {
74 | if(currentArticle < savedFiles)
75 | currentArticle += 1;
76 |
77 | Memento next = caretaker.Get(currentArticle);
78 | string nextArticle = originator.RestoreFromMemento(next);
79 | return nextArticle;
80 | }
81 |
82 | }
83 |
84 |
85 |
86 |
87 | ///
88 | /// the basic object that is stored in different states
89 | ///
90 | public class Memento
91 | {
92 | public string article { get; protected set; }
93 |
94 | // Base Memento class that in this case just stores article strings!:)
95 | public Memento (string article)
96 | {
97 | this.article = article;
98 | }
99 | }
100 |
101 |
102 | ///
103 | /// sets and gets values from the currently targeted memento. Creates new memenots and assigns current values to them.
104 | ///
105 | public class Originator
106 | {
107 | public string article { get; protected set; }
108 |
109 | public void Set (string article)
110 | {
111 | Debug.Log ("From Originator: Current Version of article is: [\"" + article + "\"]");
112 | this.article = article;
113 | }
114 |
115 | public Memento StoreInMemento ()
116 | {
117 | Debug.Log ("From Originator: Saving in Memento: [\"" + this.article + "\"]");
118 | return new Memento (this.article);
119 | }
120 |
121 | public string RestoreFromMemento (Memento memento)
122 | {
123 | article = memento.article;
124 | Debug.Log ("From Originator: Previous Article saved in Memento: [\"" + article + "\"]");
125 | return article;
126 | }
127 | }
128 |
129 |
130 | ///
131 | /// holds an list that contains all previous versions of the memento. it can store and retrieve stored mementos
132 | ///
133 | public class Caretaker
134 | {
135 | List savedArticles = new List ();
136 |
137 | public void Add (Memento m)
138 | {
139 | savedArticles.Add (m);
140 | }
141 |
142 | public Memento Get(int i)
143 | {
144 | return savedArticles[i];
145 | }
146 |
147 | public int GetCountOfSavedArticles()
148 | {
149 | return savedArticles.Count;
150 | }
151 | }
152 |
153 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Memento Design Pattern/MementoDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b6d321ceb23e10d42ba320bed2aa02e4
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Observer Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: abd250bf8e1aa4c47b09d628de6910d9
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Observer Design Pattern/ObserverDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | // when you need many objects that receive an update when another object changes
5 |
6 | // benefit: loose coupling, publisher doesn't know anything about the subscribers
7 | // negative: publisher may send updates that don't matter to the subscriber
8 |
9 | public class ObserverDesignPattern : MonoBehaviour
10 | {
11 | void Start ()
12 | {
13 | // mmh events ?
14 | Debug.Log ("------------------");
15 | Debug.Log ("OBSERVER DESIGN PATTERN");
16 | Debug.Log ("Not implemented yet");
17 | // do I need to???
18 | // mmh
19 | }
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Observer Design Pattern/ObserverDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f8e95f5e8e946b84982742d00fef8ec6
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/State Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fb842ea418238524da0d98b8f4923136
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/State Design Pattern/StateDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | /*
5 | * Allows object to alter behaviour when its internal state changes, the object will appear to change its class
6 | *
7 | * Context (Account): Maintains an instance of a ConcreteState sublcass that defines the current state
8 | *
9 | * State: Defines an interface for encapsulating the behaviour associated with a particular state of the context
10 | *
11 | * Concrete State: each subclass implements a behaviour associated with a state of a context
12 | *
13 | * */
14 |
15 | // using the proxy pattern here for an interface we need in the proxy pattern :)
16 | // don't worry it has nothing to do with the state design pattern
17 | using ProxyPattern;
18 |
19 | namespace StatePattern
20 | {
21 | public class StateDesignPattern : MonoBehaviour
22 | {
23 |
24 | void OnEnable ()
25 | {
26 | Debug.Log ("------------------");
27 | Debug.Log ("STATE DESIGN PATTERN");
28 |
29 | ATMMachine atm = new ATMMachine();
30 | atm.InsertCard();
31 | atm.EjectCard();
32 | atm.InsertCard();
33 | atm.InsertPin(1234);
34 | atm.RequestCash(2000);
35 | atm.InsertCard();
36 | atm.InsertPin(1234);
37 | }
38 | }
39 |
40 |
41 | // State Interface
42 | public interface ATMState
43 | {
44 | void InsertCard();
45 | void EjectCard();
46 | void InsertPin(int pinEntered);
47 | void RequestCash(int cash);
48 | }
49 |
50 |
51 | public class ATMMachine : GetATMData // this interface comes from the proxy design pattern and has nothing to do with the state design pattern
52 | {
53 | public ATMState hasCard { get; protected set; }
54 | public ATMState noCard { get; protected set; }
55 | public ATMState hasCorrectPin { get; protected set; }
56 | public ATMState atmOutOfMoney { get; protected set; }
57 |
58 | public ATMState atmState { get; protected set; }
59 |
60 | public int cashInMachine = 2000;
61 | public bool correctPinEntered = false;
62 |
63 | public ATMMachine()
64 | {
65 | hasCard = new HasCard(this);
66 | noCard = new NoCard(this);
67 | hasCorrectPin = new HasPin(this);
68 | atmOutOfMoney = new NoCash(this);
69 |
70 | atmState = noCard;
71 |
72 | if(cashInMachine < 0)
73 | {
74 | atmState = atmOutOfMoney;
75 | }
76 | }
77 |
78 | public void SetATMState(ATMState state)
79 | {
80 | atmState = state;
81 | }
82 |
83 | public void SetCashInMachine(int newCash)
84 | {
85 | cashInMachine = newCash;
86 | }
87 |
88 | public void InsertCard()
89 | {
90 | atmState.InsertCard();
91 | }
92 |
93 | public void EjectCard()
94 | {
95 | atmState.EjectCard();
96 | }
97 |
98 | public void RequestCash(int cash)
99 | {
100 | atmState.RequestCash(cash);
101 | }
102 |
103 | public void InsertPin(int pin)
104 | {
105 | atmState.InsertPin(pin);
106 | }
107 |
108 | //===================================================================================
109 | // Here come the Methods we need to implement from the Proxy Design Pattern to make the interface work
110 | // but remember: the following methods for ATMMachine don't have anything to do with the state machine pattern
111 | //===================================================================================
112 |
113 | public ATMState GetCurrentState()
114 | {
115 | return atmState;
116 | }
117 |
118 | public int GetCashInMachine()
119 | {
120 | return cashInMachine;
121 | }
122 |
123 | }
124 |
125 |
126 |
127 |
128 | public class HasCard : ATMState
129 | {
130 | protected ATMMachine atm;
131 |
132 | public HasCard(ATMMachine atm)
133 | {
134 | this.atm = atm;
135 | }
136 |
137 | public void InsertCard()
138 | {
139 | Debug.Log ("You can't enter one than more card");
140 | }
141 |
142 | public void EjectCard()
143 | {
144 | Debug.Log ("Card ejected.");
145 | atm.SetATMState(atm.noCard);
146 | }
147 |
148 | public void InsertPin(int pinEntered)
149 | {
150 | if(pinEntered == 1234)
151 | {
152 | Debug.Log ("Correct pin entered.");
153 | atm.correctPinEntered = true;
154 | atm.SetATMState(atm.hasCorrectPin);
155 | }
156 | else
157 | {
158 | Debug.Log ("False pin entered.");
159 | atm.correctPinEntered = false;
160 | Debug.Log ("Card ejected.");
161 | atm.SetATMState(atm.noCard);
162 | }
163 | }
164 |
165 | public void RequestCash(int cash)
166 | {
167 | Debug.Log ("Enter pin first.");
168 | }
169 | }
170 |
171 |
172 |
173 | public class NoCard : ATMState
174 | {
175 | protected ATMMachine atm;
176 |
177 | public NoCard(ATMMachine atm)
178 | {
179 | this.atm = atm;
180 | }
181 |
182 | public void InsertCard()
183 | {
184 | Debug.Log ("Card inserted");
185 | atm.SetATMState(atm.hasCard);
186 | }
187 |
188 | public void EjectCard()
189 | {
190 | Debug.Log ("Enter a card first.");
191 | }
192 |
193 | public void InsertPin(int pinEntered)
194 | {
195 | Debug.Log ("Enter a card first.");
196 | }
197 |
198 | public void RequestCash(int cash)
199 | {
200 | Debug.Log ("Enter a card first.");
201 | }
202 | }
203 |
204 |
205 |
206 | public class HasPin : ATMState
207 | {
208 | protected ATMMachine atm;
209 |
210 | public HasPin(ATMMachine atm)
211 | {
212 | this.atm = atm;
213 | }
214 |
215 | public void InsertCard()
216 | {
217 | Debug.Log ("You can't enter one than more card");
218 | }
219 |
220 | public void EjectCard()
221 | {
222 | Debug.Log ("Card ejected.");
223 | atm.SetATMState(atm.noCard);
224 | }
225 |
226 | public void InsertPin(int pinEntered)
227 | {
228 | Debug.Log ("Pin already entered.");
229 | }
230 |
231 | public void RequestCash(int cash)
232 | {
233 | if(cash <= atm.cashInMachine)
234 | {
235 | Debug.Log (cash + " provided by machine");
236 | atm.cashInMachine -= cash;
237 | atm.SetATMState(atm.noCard);
238 |
239 | if(atm.cashInMachine <= 0)
240 | {
241 | atm.SetATMState(atm.atmOutOfMoney);
242 | }
243 |
244 | Debug.Log ("Card ejected.");
245 | }
246 | else
247 | {
248 | Debug.Log ("Don't have enough cash");
249 | atm.SetATMState(atm.noCard);
250 | Debug.Log ("Card ejected.");
251 | }
252 | }
253 | }
254 |
255 |
256 |
257 | public class NoCash : ATMState
258 | {
259 | protected ATMMachine atm;
260 |
261 | public NoCash(ATMMachine atm)
262 | {
263 | this.atm = atm;
264 | }
265 |
266 | public void InsertCard()
267 | {
268 | Debug.Log ("We don't have no money");
269 | }
270 |
271 | public void EjectCard()
272 | {
273 | Debug.Log ("We don't have no money, you didn't enter a card");
274 | }
275 |
276 | public void InsertPin(int pinEntered)
277 | {
278 | Debug.Log ("We don't have no money");
279 | }
280 |
281 | public void RequestCash(int cash)
282 | {
283 | Debug.Log ("We don't have no money");
284 | }
285 | }
286 |
287 | }
288 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/State Design Pattern/StateDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3c94cb1d24081494ba9fe8758e2add05
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Strategy Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2927363e74e649940896167b2c65823c
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Strategy Design Pattern/BadCodeExample.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | public class Animal_BadExample
5 | {
6 | // bad code:
7 | public virtual void Fly()
8 | {
9 | Debug.Log ("Can Fly");
10 | }
11 | }
12 |
13 | public class Dog_BadExample : Animal_BadExample
14 | {
15 | // bad code:
16 | public override void Fly()
17 | {
18 | // override
19 | }
20 | }
21 |
22 | public class Cat_BadExample : Animal_BadExample
23 | {
24 | // bad code:
25 | public override void Fly()
26 | {
27 | // override
28 | }
29 | }
30 |
31 | public class Bird_BadExample : Animal_BadExample
32 | {
33 | public override void Fly()
34 | {
35 | }
36 | }
37 |
38 | // Rembember:
39 | // ALWAYS
40 | // eliminate duplicate code
41 | // eliminate technices that allow one class to affect others
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Strategy Design Pattern/BadCodeExample.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1f65787b797e8ac45bb0e749f0d90b96
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Strategy Design Pattern/StrategyDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | // USE when:
5 | // you need one of several behaviours dynamically
6 | // when you have long lists of conditionals
7 | // avoid duplicate code
8 | // can hide complicated / secret code
9 | // negative: increasing amount of classes
10 |
11 |
12 | // short implementation of Derek Barnas' Strategy Design Pattern
13 | namespace StrategyDesign
14 | {
15 | public class StrategyDesignPattern : MonoBehaviour
16 | {
17 | void OnEnable ()
18 | {
19 | Debug.Log ("------------------");
20 | Debug.Log ("STRATEGY DESIGN PATTERN");
21 | // create dog and bird example objects
22 | Animal sparky = new Dog ();
23 | Animal tweety = new Bird ();
24 |
25 | Debug.Log ("Dog: " + sparky.TryToFly ());
26 | Debug.Log ("Bird: " + tweety.TryToFly ());
27 |
28 | // change behaviour of dog
29 | sparky.SetFlyingAbility (new ItFlys ());
30 |
31 | Debug.Log ("Dog: " + sparky.TryToFly ());
32 | Debug.Log ("Bird: " + tweety.TryToFly ());
33 | }
34 | }
35 |
36 |
37 | // Using Interfaces for decoupling
38 | // putting behaviour that varies in different classes
39 | public interface IFly
40 | {
41 | string Fly ();
42 | }
43 |
44 | // Class that holds behaviour for objects that can fly
45 | class ItFlys : IFly
46 | {
47 | public string Fly ()
48 | {
49 | return "Flying high";
50 | }
51 | }
52 |
53 | // Class that holds behaviour for objects that can not fly
54 | class CantFly : IFly
55 | {
56 | public string Fly ()
57 | {
58 | return "I can't fly";
59 | }
60 | }
61 |
62 | class FlyingSuperFast : IFly
63 | {
64 | public string Fly ()
65 | {
66 | return "Fly super fast";
67 | }
68 | }
69 |
70 |
71 | // Classes that hold an instance of the behaviours above:
72 | public class Animal
73 | {
74 | // hereby adding the behaviour
75 | // it also can change that way
76 | public IFly flyingType;
77 |
78 | public string TryToFly ()
79 | {
80 | return flyingType.Fly ();
81 | }
82 |
83 | public void SetFlyingAbility (IFly newFlyingType)
84 | {
85 | this.flyingType = newFlyingType;
86 | }
87 | }
88 |
89 | // derived objects that vary from the base Animal:
90 | public class Dog : Animal
91 | {
92 | public Dog ()
93 | {
94 | flyingType = new CantFly ();
95 | }
96 | }
97 |
98 | public class Bird : Animal
99 | {
100 | public Bird ()
101 | {
102 | flyingType = new ItFlys ();
103 | }
104 | }
105 | }
106 |
107 | // Rembember:
108 | // ALWAYS
109 | // eliminate duplicate code
110 | // eliminate technices that allow one class to affect others
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Strategy Design Pattern/StrategyDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0bc48435d94877b4e8c33292bd5b03f1
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Template Method Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f93c0ececc643a1448f30c494c3274a5
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Template Method Design Pattern/TemplateMethodDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | /* Used to create a group of sublcasses that have to execute a similar group of methods
5 | *
6 | * You create an abstract class that contains a method called the Template Method
7 | *
8 | * The Template method contains a series of method calls that every sublcass object will call
9 | *
10 | * The subclass objects can override some of the method calls
11 | *
12 | * */
13 |
14 | namespace TemplateMethodPattern
15 | {
16 | public class TemplateMethodDesignPattern : MonoBehaviour
17 | {
18 | void OnEnable ()
19 | {
20 | Debug.Log ("------------------");
21 | Debug.Log ("TEMPLATE METHOD DESIGN PATTERN");
22 |
23 | Hoagie cust12Hoagie = new ItalienHoagie();
24 | cust12Hoagie.MakeSandwich();
25 |
26 | Hoagie cust13Hoagie = new VeggieHoagie();
27 | cust13Hoagie.MakeSandwich();
28 | }
29 | }
30 |
31 |
32 |
33 | public abstract class Hoagie
34 | {
35 | public void MakeSandwich()
36 | {
37 | Debug.Log ("Making new Sandwich");
38 |
39 | CutBun();
40 |
41 | if(CustomerWantsMeat())
42 | {
43 | AddMeat();
44 | }
45 |
46 | if(CustomerWantsCheese())
47 | {
48 | AddCheese();
49 | }
50 |
51 | if(CustomerWantsVegetables())
52 | {
53 | AddVegetables();
54 | }
55 |
56 | if(CustomerWantsCondiments())
57 | {
58 | AddCondiments();
59 | }
60 |
61 | WrapTheHoagie();
62 | }
63 | protected abstract void AddMeat();
64 | protected abstract void AddCheese();
65 | protected abstract void AddVegetables();
66 | protected abstract void AddCondiments();
67 |
68 | protected virtual bool CustomerWantsMeat() { return true; } // << called Hook
69 | protected virtual bool CustomerWantsCheese() { return true; }
70 | protected virtual bool CustomerWantsVegetables() { return true; }
71 | protected virtual bool CustomerWantsCondiments() { return true; }
72 |
73 | protected void CutBun()
74 | {
75 | Debug.Log ("Bun is Cut");
76 | }
77 |
78 | protected void WrapTheHoagie()
79 | {
80 | Debug.Log ("Hoagie is wrapped.");
81 | }
82 | }
83 |
84 |
85 | public class ItalienHoagie : Hoagie
86 | {
87 | protected override void AddMeat()
88 | {
89 | Debug.Log ("Adding the Meat: Salami");
90 | }
91 |
92 | protected override void AddCheese()
93 | {
94 | Debug.Log ("Adding the Cheese: Provolone");
95 | }
96 |
97 | protected override void AddVegetables()
98 | {
99 | Debug.Log ("Adding the Vegetables: Tomatoes");
100 | }
101 |
102 | protected override void AddCondiments()
103 | {
104 | Debug.Log ("Adding the Condiments: Vinegar");
105 | }
106 | }
107 |
108 |
109 |
110 | public class VeggieHoagie : Hoagie
111 | {
112 | protected override void AddMeat()
113 | {
114 | }
115 |
116 | protected override void AddCheese()
117 | {
118 | }
119 |
120 | protected override void AddVegetables()
121 | {
122 | Debug.Log ("Adding the Vegetables: Tomatoes");
123 | }
124 |
125 | protected override void AddCondiments()
126 | {
127 | Debug.Log ("Adding the Condiments: Vinegar");
128 | }
129 |
130 | protected override bool CustomerWantsMeat() { return false; }
131 | protected override bool CustomerWantsCheese() { return false; }
132 |
133 | }
134 |
135 |
136 |
137 |
138 |
139 | namespace BadExample
140 | {
141 | // this way you would have to rewrite a lot of code
142 | // especially if something changes or another class differs and does e.g. not AddMeat()
143 | public class ItalienHoagie
144 | {
145 | public void MakeSandwich ()
146 | {
147 | CutBun ();
148 | AddMeat ();
149 | AddCheese ();
150 | AddVegtables ();
151 | AddCondiments ();
152 | WrapHoagie ();
153 | }
154 |
155 | public void CutBun ()
156 | {
157 | Debug.Log ("Hoagie is Cut");
158 | }
159 |
160 | public void AddMeat ()
161 | {
162 | Debug.Log ("Added Meat");
163 | }
164 |
165 | public void AddCheese ()
166 | {
167 | Debug.Log ("Added Cheese");
168 | }
169 |
170 | public void AddVegtables()
171 | {
172 | Debug.Log ("Added Vegies");
173 | }
174 |
175 | public void AddCondiments()
176 | {
177 | Debug.Log ("Added Condiments");
178 | }
179 |
180 | public void WrapHoagie()
181 | {
182 | Debug.Log ("Wrapped Hoagie");
183 | }
184 | }
185 | }
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Template Method Design Pattern/TemplateMethodDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1b322890dc2f925408c2deda5d9444a2
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Visitor Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b4d6517bef598b746aadaa0c3be75b20
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Visitor Design Pattern/VisitorDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | /* video: https://www.youtube.com/watch?v=pL4mOUDi54o&list=PLF206E906175C7E07&index=26
5 | *
6 | *
7 | * allows you to add methods to classes of different types without much altering to those classes
8 | *
9 | * allows to make completely different methods depending on the class used
10 | *
11 | * allows you to define external classes that can be extend other classes without majorly editing them
12 | *
13 | *
14 | * */
15 |
16 | namespace VisitorPattern
17 | {
18 | public class VisitorDesignPattern : MonoBehaviour
19 | {
20 | void OnEnable ()
21 | {
22 | Debug.Log ("------------------");
23 | Debug.Log ("VISITOR DESIGN PATTERN");
24 |
25 | // testing the pattern:
26 |
27 | TaxVisitor taxCalc = new TaxVisitor();
28 | TaxHolidayVisitor taxHolidayCalc = new TaxHolidayVisitor();
29 |
30 | Necessity milk = new Necessity(3.25);
31 | Liquor vodka = new Liquor(11.99);
32 | Tobacco cigars = new Tobacco(19.99);
33 |
34 | double milkPrice = milk.Accept(taxCalc);
35 | double milkPriceHoliday = milk.Accept(taxHolidayCalc);
36 | Debug.Log ("Milk costs: " + milkPrice.ToString() + ", Holiday Price: " + milkPriceHoliday.ToString());
37 |
38 | double vodkaPrice = vodka.Accept(taxCalc);
39 | double vodkaHolidayPrice = vodka.Accept(taxHolidayCalc);
40 | Debug.Log ("Vodka costs: " + vodkaPrice.ToString() + ", Holiday Price: " + vodkaHolidayPrice.ToString());
41 |
42 | double cigarsPrice = cigars.Accept(taxCalc);
43 | double cigarsPriceHoliday = cigars.Accept(taxHolidayCalc);
44 | Debug.Log ("Cigars cost: " + cigarsPrice.ToString() + ", Holiday Price: " + cigarsPriceHoliday.ToString());
45 | }
46 | }
47 |
48 |
49 | // Visitor, Visitable, Accept and Visit are common jargon names for parts of the visitor pattern
50 | public interface Visitor
51 | {
52 | double visit(Liquor item);
53 | double visit(Tobacco item);
54 | double visit(Necessity item);
55 | }
56 |
57 | // concrete implementation
58 | public class TaxVisitor : Visitor
59 | {
60 | #region Visitor implementation
61 | public double visit (Liquor item)
62 | {
63 | Debug.Log ("Liquor item: Price with Tax");
64 | return item.price * 1.18f;
65 | }
66 | public double visit (Tobacco item)
67 | {
68 | Debug.Log ("Tobacco item: Price with Tax");
69 | return item.price * 1.32f;
70 | }
71 | public double visit (Necessity item)
72 | {
73 | Debug.Log ("Necessity item: Price with Tax");
74 | return item.price;
75 | }
76 | #endregion
77 | }
78 |
79 |
80 |
81 | // Interfaces and abstract classes
82 |
83 | // this belongs to the visitor pattern :)
84 | public interface Visitable
85 | {
86 | double Accept(Visitor visitor);
87 | }
88 |
89 | // this is just for not having to type this for every item
90 | public abstract class Item
91 | {
92 | public double price { get; protected set; }
93 |
94 | public Item(double price)
95 | {
96 | this.price = price;
97 | }
98 | }
99 |
100 |
101 | // some items:
102 |
103 | // concrete implementation
104 | public class Liquor : Item, Visitable
105 | {
106 | public Liquor(double price) : base(price) {}
107 |
108 | #region Visitable implementation
109 |
110 | public double Accept (Visitor visitor)
111 | {
112 | return visitor.visit(this);
113 | }
114 |
115 | #endregion
116 | }
117 |
118 | // concrete implementation
119 | public class Tobacco : Item, Visitable
120 | {
121 | public Tobacco(double price) : base(price) {}
122 |
123 | #region Visitable implementation
124 |
125 | public double Accept (Visitor visitor)
126 | {
127 | return visitor.visit(this);
128 | }
129 |
130 | #endregion
131 | }
132 |
133 | // concrete implementation
134 | public class Necessity : Item, Visitable
135 | {
136 | public Necessity(double price) : base(price) {}
137 |
138 | #region Visitable implementation
139 |
140 | public double Accept (Visitor visitor)
141 | {
142 | return visitor.visit(this);
143 | }
144 |
145 | #endregion
146 | }
147 |
148 |
149 |
150 |
151 | // if out of the sudden you need some other implementation or tax handling for holidays it is
152 | // a matter of copy paste edit to implement that :-)
153 | // see below:
154 |
155 | public class TaxHolidayVisitor : Visitor
156 | {
157 | #region Visitor implementation
158 | public double visit (Liquor item)
159 | {
160 | Debug.Log ("Liquor item: Price with Tax");
161 | return item.price * 1.10f;
162 | }
163 | public double visit (Tobacco item)
164 | {
165 | Debug.Log ("Tobacco item: Price with Tax");
166 | return item.price * 1.20f;
167 | }
168 | public double visit (Necessity item)
169 | {
170 | Debug.Log ("Necessity item: Price with Tax");
171 | return item.price;
172 | }
173 | #endregion
174 | }
175 |
176 |
177 |
178 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Behavioral Patterns/Visitor Design Pattern/VisitorDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ff82122a40b42004993fb1ec3fd5916e
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c7ca7fe8b1f7745429c5385c0b2bd055
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Abstract Factory Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1849534afd1d86e40bc4cc1c4f3ca560
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Abstract Factory Design Pattern/AbstractFactoryPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | // allows a family of related objects without specifying the concrete class
5 | // when there are many objects that can be added or changed dynamically
6 | // you can model everything you can image and have those objects interact through common interfaces
7 |
8 | // negative: can get very complicated
9 |
10 | namespace AbstractFactory
11 | {
12 | public class AbstractFactoryPattern : MonoBehaviour
13 | {
14 |
15 | void OnEnable ()
16 | {
17 | Debug.Log ("------------------");
18 | Debug.Log ("ABSTRACT FACTORY DESIGN PATTERN");
19 | // Test here:
20 | EnemyShipBuilding ufoBuilder = new UFOEnemyShipBuilding();
21 | ufoBuilder.orderShip(ShipType.UFO);
22 | }
23 | }
24 |
25 |
26 |
27 |
28 |
29 | public enum ShipType
30 | {
31 | UFO
32 | }
33 |
34 |
35 |
36 |
37 | public abstract class EnemyShipBuilding
38 | {
39 | // abstract order form:
40 | protected abstract EnemyShip MakeEnemyShip(ShipType type);
41 |
42 | public EnemyShip orderShip(ShipType type)
43 | {
44 | EnemyShip ship = MakeEnemyShip(type);
45 |
46 | ship.MakeShip();
47 | ship.DisplayShip();
48 | ship.FollowHeroShip();
49 | ship.Shoot();
50 |
51 | return ship;
52 | }
53 | }
54 |
55 | public class UFOEnemyShipBuilding : EnemyShipBuilding
56 | {
57 | // Make Ship varies per ship type...
58 | protected override EnemyShip MakeEnemyShip(ShipType type)
59 | {
60 | EnemyShip ship = null;
61 |
62 | if(type == ShipType.UFO)
63 | {
64 | IEnemyShipFactory factory = new UFOEnemyShipFactory();
65 | ship = new UFOEnemyShip(factory);
66 | ship.name = "UFO";
67 | }
68 |
69 | return ship;
70 | }
71 | }
72 |
73 |
74 |
75 |
76 |
77 | public interface IEnemyShipFactory
78 | {
79 | IESWeapon AddESGun();
80 | IESEngine AddESEngine();
81 | }
82 |
83 | public class UFOEnemyShipFactory : IEnemyShipFactory
84 | {
85 | // each factory can add different weapons and stuff
86 | public IESWeapon AddESGun()
87 | {
88 | return new ESUFOGun();
89 | }
90 |
91 | public IESEngine AddESEngine()
92 | {
93 | return new ESUFOEngine();
94 | }
95 | }
96 |
97 |
98 |
99 |
100 |
101 | public abstract class EnemyShip
102 | {
103 | public string name;
104 | protected IESEngine engine;
105 | protected IESWeapon weapon;
106 |
107 | public abstract void MakeShip();
108 |
109 | public void DisplayShip()
110 | {
111 | Debug.Log (name + " is on the screen.");
112 | }
113 |
114 | public void FollowHeroShip()
115 | {
116 | Debug.Log (name + " follows hero ship with " + engine.ToString());
117 | }
118 |
119 | public void Shoot()
120 | {
121 | Debug.Log (name + " shoots and does " + weapon.ToString());
122 | }
123 |
124 | public string ToString()
125 | {
126 | return "The " + name + " has a speed of " + engine.ToString() + " a firepower of " + weapon.ToString();
127 | }
128 | }
129 |
130 | public class UFOEnemyShip : EnemyShip
131 | {
132 | IEnemyShipFactory factory;
133 |
134 | public UFOEnemyShip(IEnemyShipFactory factory)
135 | {
136 | this.factory = factory;
137 | }
138 |
139 | public override void MakeShip()
140 | {
141 | Debug.Log ("Making enemy ship " + name);
142 | weapon = factory.AddESGun();
143 | engine = factory.AddESEngine();
144 | }
145 | }
146 |
147 |
148 |
149 | // possible Weapons to swap in and out
150 | public interface IESWeapon
151 | {
152 | string ToString();
153 | }
154 |
155 | public interface IESEngine
156 | {
157 | string ToString();
158 | }
159 |
160 | public class ESUFOGun : IESWeapon
161 | {
162 | public string ToString()
163 | {
164 | return "20 damage";
165 | }
166 | }
167 | public class ESUFOEngine : IESEngine
168 | {
169 | public string ToString()
170 | {
171 | return "1000 mph";
172 | }
173 | }
174 |
175 | }
176 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Abstract Factory Design Pattern/AbstractFactoryPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 33552744b979aa544a1db1c899d94436
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Builder Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 906cdc79c6bc78e4080a05c66db2722c
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Builder Design Pattern/BuilderDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | // When to make objects made from a bunch of other objects
5 | // when creation of these parts shall be independent
6 | // when the creation of these parts shall be hidden from the client
7 | // the builder knows the specific and no one else
8 |
9 | namespace BuilderPattern
10 | {
11 | public class BuilderDesignPattern : MonoBehaviour
12 | {
13 | void OnEnable()
14 | {
15 | Debug.Log ("------------------");
16 | Debug.Log ("BUILDER DESIGN PATTERN");
17 | IRobotBuilder oldRobot = new OldRobotBuilder();
18 | RobotEngineer engineer = new RobotEngineer(oldRobot);
19 | engineer.MakeRobot();
20 |
21 | Robot firstRobot = engineer.GetRobot();
22 | Debug.Log ("First Robot built");
23 | Debug.Log (firstRobot.ToString());
24 | }
25 | }
26 |
27 |
28 |
29 |
30 | public interface IRobotPlan
31 | {
32 | void SetRobotHead (string head);
33 |
34 | void SetRobotTorso (string torso);
35 |
36 | void SetRobotArms (string arms);
37 |
38 | void SetRobotLegs (string legs);
39 | }
40 |
41 | public class Robot : IRobotPlan
42 | {
43 | public string head { get; protected set; }
44 | public string torso { get; protected set; }
45 | public string arms { get; protected set; }
46 | public string legs { get; protected set; }
47 |
48 | public void SetRobotHead (string head)
49 | {
50 | this.head = head;
51 | }
52 |
53 | public void SetRobotTorso(string torso)
54 | {
55 | this.torso = torso;
56 | }
57 |
58 | public void SetRobotArms(string arms)
59 | {
60 | this.arms = arms;
61 | }
62 |
63 | public void SetRobotLegs(string legs)
64 | {
65 | this.legs = legs;
66 | }
67 |
68 | public string ToString()
69 | {
70 | return "Head: " + this.head + ", torso: " + this.torso + ", Arms: " + arms + ", legs: " + legs;
71 | }
72 | }
73 |
74 |
75 |
76 |
77 | // they're kinda like a blueprint these RobotBuilder classes:
78 | public interface IRobotBuilder
79 | {
80 | Robot GetRobot();
81 | void BuildRobotHead();
82 | void BuildRobotTorso();
83 | void BuildRobotArms();
84 | void BuildRobotLegs();
85 | }
86 |
87 | // for each new robot that you might want to have just create a new RobotBuilder Object
88 | public class OldRobotBuilder : IRobotBuilder
89 | {
90 | protected Robot robot { get; set; }
91 |
92 | public OldRobotBuilder()
93 | {
94 | this.robot = new Robot();
95 | }
96 |
97 | public Robot GetRobot()
98 | {
99 | return robot;
100 | }
101 |
102 | public void BuildRobotHead()
103 | {
104 | this.robot.SetRobotHead("Old Head");
105 | }
106 |
107 | public void BuildRobotTorso()
108 | {
109 | this.robot.SetRobotTorso("Old Torso");
110 | }
111 |
112 | public void BuildRobotArms()
113 | {
114 | this.robot.SetRobotArms("Old Arms");
115 | }
116 |
117 | public void BuildRobotLegs()
118 | {
119 | this.robot.SetRobotLegs("Roller Skates");
120 | }
121 | }
122 |
123 |
124 |
125 | // he just calls the method in the Robot Objects (which are defined by the interface, just think of blueprints)
126 | public class RobotEngineer
127 | {
128 | public IRobotBuilder robotBuilder { get; protected set; }
129 |
130 | public RobotEngineer(IRobotBuilder builder)
131 | {
132 | this.robotBuilder = builder;
133 | }
134 |
135 | public Robot GetRobot()
136 | {
137 | return this.robotBuilder.GetRobot();
138 | }
139 |
140 | public void MakeRobot()
141 | {
142 | this.robotBuilder.BuildRobotHead();
143 | this.robotBuilder.BuildRobotTorso();
144 | this.robotBuilder.BuildRobotArms();
145 | this.robotBuilder.BuildRobotLegs();
146 | }
147 | }
148 |
149 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Builder Design Pattern/BuilderDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fa4c816d676d97744987dcf13236be9b
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Factory Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 659de86e8dc62d54bb2c7f6371158ec6
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Factory Design Pattern/FactoryDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | // when you want a method to return one of several possible classes that share a common superclass
5 | // when you don't know ahead of time which class you might need
6 | // when you want to centralize class selection code
7 | // when you don't want the user to have to know every potential subclass
8 | // to encapsulate object creation
9 |
10 | // example in a game: put a random enemy to the screen, the enemy class can be chosen at runtime
11 |
12 | namespace FactoryDesign
13 | {
14 | // move that desicion making into another class:
15 | public class EnemyShipFactory
16 | {
17 | public enum ShipType
18 | {
19 | UFO,
20 | Rocket,
21 | Endboss }
22 | ;
23 |
24 | public EnemyShip MakeEnemyShip (ShipType shipType)
25 | {
26 | if (shipType == ShipType.UFO)
27 | return new UFOEnemyShip ();
28 | else if (shipType == ShipType.Rocket)
29 | return new RocketEnemyShip ();
30 | else if (shipType == ShipType.Endboss)
31 | return new BigEnemyShip ();
32 | else
33 | return null;
34 | }
35 | }
36 |
37 | public class FactoryDesignPattern : MonoBehaviour
38 | {
39 | EnemyShipFactory factory;
40 |
41 | void OnEnable ()
42 | {
43 | Debug.Log ("------------------");
44 | Debug.Log ("FACTORY DESIGN PATTERN");
45 | Debug.Log ("Use Keys U R and B in Scene)");
46 | factory = new EnemyShipFactory ();
47 | }
48 |
49 | void Update ()
50 | {
51 | if (Input.GetKeyDown (KeyCode.U))
52 | {
53 | EnemyShip ship = factory.MakeEnemyShip (EnemyShipFactory.ShipType.UFO);
54 | DoStuffEnemy (ship);
55 | }
56 | else if (Input.GetKeyDown (KeyCode.R))
57 | {
58 | EnemyShip ship = factory.MakeEnemyShip (EnemyShipFactory.ShipType.Rocket);
59 | DoStuffEnemy (ship);
60 | }
61 | else if (Input.GetKeyDown (KeyCode.B))
62 | {
63 | EnemyShip ship = factory.MakeEnemyShip (EnemyShipFactory.ShipType.Endboss);
64 | DoStuffEnemy (ship);
65 | }
66 | }
67 |
68 | void DoStuffEnemy (EnemyShip enemyShip)
69 | {
70 | enemyShip.displayEnemyShip ();
71 | enemyShip.followHeroShip ();
72 | enemyShip.enemyShipShoots ();
73 | }
74 | }
75 |
76 | public class BadCodeExample : MonoBehaviour
77 | {
78 | void Start ()
79 | {
80 | EnemyShip ufo = new UFOEnemyShip ();
81 | Debug.Log ("What kind of ship do you want? (R / U)");
82 | }
83 |
84 | // yes its dynamic but it is also modifyable
85 | // you don't want this sort of stuff going on inside of your actual program
86 | // lots of if and else statements and logic
87 | void Update ()
88 | {
89 | return; // < "deactivating"
90 |
91 |
92 | if (Input.GetKeyDown (KeyCode.U))
93 | {
94 | EnemyShip ship = new UFOEnemyShip ();
95 | DoStuffEnemy (ship);
96 | }
97 | else if (Input.GetKeyDown (KeyCode.R))
98 | {
99 | EnemyShip ship = new RocketEnemyShip ();
100 | DoStuffEnemy (ship);
101 | }
102 | }
103 |
104 | void DoStuffEnemy (EnemyShip enemyShip)
105 | {
106 | enemyShip.displayEnemyShip ();
107 | enemyShip.followHeroShip ();
108 | enemyShip.enemyShipShoots ();
109 | }
110 | }
111 |
112 | public abstract class EnemyShip
113 | {
114 | public string name;
115 | public double damage;
116 |
117 | public void followHeroShip ()
118 | {
119 | Debug.Log (name + " is following the hero.");
120 | }
121 |
122 | public void displayEnemyShip ()
123 | {
124 | Debug.Log (name + " is on the screen.");
125 | }
126 |
127 | public void enemyShipShoots ()
128 | {
129 | Debug.Log (name + " attacks and does " + damage + " damage");
130 | }
131 | }
132 |
133 | public class UFOEnemyShip : EnemyShip
134 | {
135 | public UFOEnemyShip ()
136 | {
137 | name = "UFOEnemyShip";
138 | damage = 20;
139 | }
140 | }
141 |
142 | public class RocketEnemyShip : EnemyShip
143 | {
144 | public RocketEnemyShip ()
145 | {
146 | name = "RocketEnemyShip";
147 | damage = 10;
148 | }
149 | }
150 |
151 | public class BigEnemyShip : UFOEnemyShip
152 | {
153 | public BigEnemyShip ()
154 | {
155 | name = "BigEnemyShip";
156 | damage = 40;
157 | }
158 | }
159 | }
160 |
161 |
162 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Factory Design Pattern/FactoryDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f4310ba8d68d8e5469ab0aa0f84e1b9c
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Prototype Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1f83f72c02b4c2647b069279e661b3da
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Prototype Design Pattern/PrototypeDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System;// needed for cloneable interface
4 | using System.Runtime.CompilerServices;
5 |
6 | // creating objects by cloning other objects
7 | // adding any subclass to a known superclass at runtime
8 | // when there are potential classes that you only want at runtime
9 | // reducing the need of creating subclasses
10 |
11 | namespace PrototypePattern
12 | {
13 | public class PrototypeDesignPattern : MonoBehaviour
14 | {
15 | void OnEnable ()
16 | {
17 | Debug.Log ("------------------");
18 | Debug.Log ("PROTOTYPE DESIGN PATTERN");
19 | CloneFactory factory = new CloneFactory();
20 |
21 | Sheep sally = new Sheep();
22 |
23 | Sheep clonedSheep = (Sheep) factory.GetClone(sally);
24 |
25 | Debug.Log ("Sally: " + sally.ToString());
26 | Debug.Log ("Clone of Sally: " + clonedSheep.ToString());
27 | Debug.Log ("Sally Hash: " + sally.GetHashCode() + " - Cloned Sheep Hash: " + clonedSheep.GetHashCode());
28 | }
29 | }
30 |
31 | public class CloneFactory
32 | {
33 | public IAnimal GetClone (IAnimal animalSample)
34 | {
35 | return (IAnimal) animalSample.Clone ();
36 | }
37 | }
38 |
39 | public interface IAnimal : ICloneable
40 | {
41 | object Clone ();
42 | }
43 |
44 | public class Sheep : IAnimal
45 | {
46 | public Sheep ()
47 | {
48 | Debug.Log ("Made Sheep");
49 | }
50 |
51 | public object Clone ()
52 | {
53 | Sheep sheep = null;
54 |
55 | try
56 | {
57 | sheep = (Sheep)base.MemberwiseClone ();
58 | } catch (Exception e)
59 | {
60 | Debug.LogError ("Error cloning Sheep");
61 | }
62 |
63 | return sheep;
64 | }
65 |
66 | public string ToString ()
67 | {
68 | return "Hello I'm a Sheep";
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Creational Patterns/Prototype Design Pattern/PrototypeDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ee5ba1dd0371a5145b2b23b9b2faefc5
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Credits.cs:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * ALL CREDIT belongs to Derek Banas
4 | *
5 | * I just followed his video tutorial series and tried to translate everything to C# in Unity
6 | * You can find his great series on Design Patterns here: https://www.youtube.com/playlist?list=PLF206E906175C7E07
7 | *
8 | *
9 | * */
10 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Credits.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 957a639c02351004a8ed335d8823741d
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fdfadc30c776f85469a7003222552ef6
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Adapter Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 62db3ce3c1e80164c8d759dfb5504215
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Adapter Design Pattern/AdapterDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | // allows 2 incompatible interfaces to work together
6 |
7 | // used when the client expects a (target) interface
8 |
9 | // the adapter class allows the use of the available interface and the target interface
10 | // think of adapters for cables
11 |
12 | // any class can work as long as the adapter solves the issue that
13 | // all classes must implement every method definied by the shared interface
14 |
15 |
16 |
17 | namespace AdapterPattern
18 | {
19 | public class AdapterDesignPattern : MonoBehaviour
20 | {
21 | void OnEnable ()
22 | {
23 | Debug.Log ("------------------");
24 | Debug.Log ("ADAPTER DESIGN PATTERN");
25 |
26 | IEnemyAttacker tank = new EnemyTank();
27 |
28 | EnemyRobot fredTheRobot = new EnemyRobot();
29 | IEnemyAttacker adapter = new EnemyRobotAdaper(fredTheRobot);
30 |
31 | fredTheRobot.ReactToHuman("Hans");
32 | fredTheRobot.WalkForward();
33 |
34 | tank.AssignDriver("Frank");
35 | tank.DriveForward();
36 | tank.FireWeapon();
37 |
38 | adapter.AssignDriver("Mark");
39 | adapter.DriveForward();
40 | adapter.FireWeapon();
41 | }
42 | }
43 |
44 |
45 |
46 |
47 | public interface IEnemyAttacker
48 | {
49 | void FireWeapon();
50 | void DriveForward();
51 | void AssignDriver(string driver);
52 | }
53 |
54 |
55 | public class EnemyTank : IEnemyAttacker
56 | {
57 | public void FireWeapon()
58 | {
59 | int attackDamage = Random.Range(1,10);
60 | Debug.Log ("Enemy Tank does " + attackDamage + " damage");
61 | }
62 |
63 | public void DriveForward()
64 | {
65 | int movement = Random.Range(1,5);
66 | Debug.Log ("Enemy Tank moves " + movement + " spaces");
67 | }
68 |
69 | public void AssignDriver(string driver)
70 | {
71 | Debug.Log (driver + " is driving the tank");
72 | }
73 | }
74 |
75 |
76 |
77 |
78 | // Adaptee:
79 | public class EnemyRobot
80 | {
81 | public void SmashWithHands()
82 | {
83 | int attackDamage = Random.Range (1,10);
84 | Debug.Log ("Robot causes " + attackDamage + " damage with it hands");
85 | }
86 |
87 | public void WalkForward()
88 | {
89 | int movement = Random.Range (1,3);
90 | Debug.Log ("Robot walks " + movement + " spaces");
91 | }
92 |
93 | public void ReactToHuman(string driverName)
94 | {
95 | Debug.Log ("Robot tramps on " + driverName);
96 | }
97 | }
98 |
99 |
100 |
101 | public class EnemyRobotAdaper : IEnemyAttacker
102 | {
103 | EnemyRobot robot;
104 |
105 | public EnemyRobotAdaper(EnemyRobot robot)
106 | {
107 | this.robot = robot;
108 | }
109 |
110 | public void FireWeapon()
111 | {
112 | robot.SmashWithHands();
113 | }
114 |
115 | public void DriveForward()
116 | {
117 | robot.WalkForward();
118 | }
119 |
120 | public void AssignDriver(string driver)
121 | {
122 | robot.ReactToHuman(driver);
123 | }
124 | }
125 |
126 |
127 |
128 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Adapter Design Pattern/AdapterDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 03979108f95fbac4990f290227fcb113
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Bridge Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bce4ccec0ebc2b44faf21cf9a5f1bad0
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Bridge Design Pattern/BridgeDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | /* Decouple an abstraction from its implementation so that the two can vary independently
5 | *
6 | * Progressingly adding functionality while separating out major differences using abstract classes
7 | * (think of remote controls with the same buttons but difference functionality among the buttons for different tvs)
8 | *
9 | * Use when you want to be able rto change both the abstractions (abstract classes) and concrete classes independently
10 | *
11 | * When you want the first abstract class to define rules (Abstract TV)
12 | *
13 | * The concrete class adds additional rules (Concrete TV)
14 | *
15 | * An abstract class has a reference to the device and it defines abstract methods that will be defined (Abstract Remote)
16 | *
17 | * The concrete Remote defines the abstract methods required
18 | *
19 | * */
20 |
21 |
22 |
23 | namespace BridgeDesign
24 | {
25 | public class BridgeDesignPattern : MonoBehaviour
26 | {
27 | void OnEnable ()
28 | {
29 | RemoteButton tv = new TVRemoteMute(new TVDevice(1,200));
30 | RemoteButton tv2 = new TVRemotePause(new TVDevice(1,200));
31 | //RemoteButton dvd = new DVDRemove(new DVDDevice(1,14));
32 |
33 | Debug.Log ("Test TV with Mute");
34 | tv.ButtonFivePressed();
35 | tv.ButtonSixPressed();
36 | tv.ButtonNinePressed(); // < this one differs on each tv
37 |
38 | Debug.Log ("Test TV with Pause");
39 | tv2.ButtonFivePressed();
40 | tv2.ButtonSixPressed();
41 | tv2.ButtonNinePressed(); // < this one differs on each tv
42 | }
43 | }
44 |
45 | public abstract class EntertainmentDevice
46 | {
47 | public int deviceState;
48 | public int maxSetting;
49 | public int volumeLevel = 0;
50 |
51 | public abstract void ButtonFivePressed ();
52 |
53 | public abstract void ButtonSixPressed ();
54 |
55 | public void DeviceFeedback ()
56 | {
57 | if (deviceState > maxSetting || deviceState < 0)
58 | deviceState = 0;
59 |
60 | Debug.Log ("On " + deviceState);
61 | }
62 |
63 | public void ButtonSevenPressed ()
64 | {
65 | volumeLevel ++;
66 | Debug.Log ("Volume at: " + volumeLevel);
67 | }
68 |
69 | public void ButtonEightPressed ()
70 | {
71 | volumeLevel --;
72 | Debug.Log ("Volume at: " + volumeLevel);
73 | }
74 | }
75 |
76 | public class TVDevice : EntertainmentDevice
77 | {
78 | public TVDevice (int newDeviceState, int newMaxSetting)
79 | {
80 | this.deviceState = newDeviceState;
81 | this.maxSetting = newMaxSetting;
82 | }
83 |
84 | public override void ButtonFivePressed ()
85 | {
86 | Debug.Log ("Channel up");
87 | deviceState ++;
88 | }
89 |
90 | public override void ButtonSixPressed ()
91 | {
92 | Debug.Log ("Channel down");
93 | deviceState --;
94 | }
95 | }
96 |
97 | // abstraction layer
98 | public abstract class RemoteButton
99 | {
100 | private EntertainmentDevice device;
101 |
102 | public RemoteButton (EntertainmentDevice device)
103 | {
104 | this.device = device;
105 | }
106 |
107 | public void ButtonFivePressed ()
108 | {
109 | device.ButtonFivePressed ();
110 | }
111 |
112 | public void ButtonSixPressed ()
113 | {
114 | device.ButtonSixPressed ();
115 | }
116 |
117 | public void DeviceFeedback ()
118 | {
119 | device.DeviceFeedback ();
120 | }
121 |
122 | public abstract void ButtonNinePressed ();
123 | }
124 |
125 |
126 | // refined abstraction:
127 | public class TVRemoteMute : RemoteButton
128 | {
129 | public TVRemoteMute(EntertainmentDevice device) : base(device)
130 | {
131 | }
132 |
133 | public override void ButtonNinePressed()
134 | {
135 | Debug.Log ("TV was muted.");
136 | }
137 | }
138 |
139 | public class TVRemotePause : RemoteButton
140 | {
141 | public TVRemotePause(EntertainmentDevice device) : base(device)
142 | {
143 | }
144 |
145 | public override void ButtonNinePressed()
146 | {
147 | Debug.Log ("TV was paused.");
148 | }
149 | }
150 |
151 |
152 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Bridge Design Pattern/BridgeDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: edb0adc2c8b1bfd4c96d542710dcefb1
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Composite Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c6c9998eb76b5a04188aec3568c6b35d
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Composite Design Pattern/CompositeDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | /*
6 | * Allows to treat individual objects and compositions of of objects unifrmly
7 | *
8 | * They allow you to represent part-whole hierarchies: it is when components can further be divided into smaller and smaller components
9 | *
10 | * Allows to structure date or represent the inner working of every part of a whole object individually
11 | *
12 | *
13 | * Example Objects:
14 | *
15 | * SongGroup <= Composite
16 | * Song <= Leaf
17 | *
18 | * then a SongGroup can contain Songs but also other SongGroups
19 | *
20 | *
21 | * Maybe think of it as folders containing files but also more folders
22 | *
23 | * */
24 |
25 | namespace CompositePattern
26 | {
27 | public class CompositeDesignPattern : MonoBehaviour
28 | {
29 |
30 | void OnEnable ()
31 | {
32 | Debug.Log ("------------------");
33 | Debug.Log ("COMPOSITE DESIGN PATTERN");
34 |
35 | SongComponent industrialMusic = new SongGroup("Industrial Music", "Industrial music is a genre of experimental music that draws on transgressive and provocative themes. The term was coined in the mid-1970s with the founding of Industrial Records by Genesis P-Orridge of Throbbing Gristle and Monte Cazazza; on Throbbing Gristle's debut album The Second Annual Report, they coined the slogan \"industrial music for industrial people\".");
36 | SongComponent heavyMetalMusic = new SongGroup("Heavy Metal Music", "Heavy metal is a genre of rock music[1] that developed in the late 1960s and early 1970s, largely in the United States and the United Kingdom.[2] With roots in blues rock and psychedelic rock,[3] the bands that created heavy metal developed a thick, massive sound, characterized by highly amplified distortion, extended guitar solos, emphatic beats, and overall loudness. Heavy metal lyrics and performance styles are often associated with masculinity, aggression, and machismo.[3]");
37 | SongComponent dubstepMusic = new SongGroup("Dubstep Music", "Dubstep /ˈdʌbstɛp/ is a genre of electronic dance music that originated in South London, England. It emerged in the late 1990s as a development within a lineage of related styles such as 2-step garage, broken beat, drum and bass, jungle, dub and reggae.[2] In the UK the origins of the genre can be traced back to the growth of the Jamaican sound system party scene in the early 1980s.[2][3] The music generally features syncopated drum and percussion patterns with bass lines that contain prominent sub bass frequencies.");
38 |
39 | SongComponent everySong = new SongGroup("Song List", "Every Song available");
40 | everySong.Add(industrialMusic);
41 | industrialMusic.Add(new Song("Head Like a Hole", "NIN", 1990));
42 | industrialMusic.Add(new Song("headhunter", "front 242", 1988));
43 | // see: here we are adding a group into a group and build up the hierarchy!!!!
44 | industrialMusic.Add(dubstepMusic);
45 | dubstepMusic.Add(new Song("Centipede", "Knife Party", 2012));
46 | dubstepMusic.Add (new Song("Tetris", "doctor P", 2011));
47 |
48 | everySong.Add (heavyMetalMusic);
49 | heavyMetalMusic.Add (new Song("War Pigs", "Black Sabath", 1970));
50 | heavyMetalMusic.Add (new Song("Ace of spades", "Motorhead", 1980));
51 |
52 | DiscJockey crazyLarry = new DiscJockey(everySong);
53 | crazyLarry.GetSongList();
54 | }
55 | }
56 |
57 |
58 | public abstract class SongComponent
59 | {
60 | public virtual void Add(SongComponent component) {}
61 | public virtual void Remove(SongComponent component) {}
62 | public virtual SongComponent Get(int index) { return null; }
63 |
64 | public abstract void DisplaySongInformation();
65 | }
66 |
67 |
68 | public class SongGroup : SongComponent
69 | {
70 | protected List components = new List();
71 | public string groupName { get; protected set; }
72 | public string groupDescription { get; protected set; }
73 |
74 | public SongGroup(string name, string description)
75 | {
76 | this.groupName = name;
77 | this.groupDescription = description;
78 | }
79 |
80 | public override void Add(SongComponent component)
81 | {
82 | components.Add(component);
83 | }
84 |
85 | public override void Remove(SongComponent component)
86 | {
87 | components.Remove(component);
88 | }
89 |
90 | public override SongComponent Get(int i)
91 | {
92 | return components[i];
93 | }
94 |
95 | public override void DisplaySongInformation()
96 | {
97 | Debug.Log (groupName + " - " + groupDescription);
98 |
99 | // now iterate through all groups inside this group
100 | IEnumerator iterator = components.GetEnumerator();
101 | while(iterator.MoveNext())
102 | {
103 | SongComponent songComponent = (SongComponent) iterator.Current;
104 | songComponent.DisplaySongInformation();
105 | }
106 | }
107 | }
108 |
109 | public class Song : SongComponent
110 | {
111 | public string songName { get; protected set; }
112 | public string bandName { get; protected set; }
113 | public int releaseYear { get; protected set; }
114 |
115 | public Song(string name, string band, int year)
116 | {
117 | this.songName = name;
118 | this.bandName = band;
119 | this.releaseYear = year;
120 | }
121 |
122 | public override void DisplaySongInformation()
123 | {
124 | Debug.Log ("Song of " + songName + " - " + bandName + " : " + releaseYear);
125 | }
126 | }
127 |
128 |
129 | public class DiscJockey
130 | {
131 | protected SongComponent songList;
132 |
133 | public DiscJockey(SongComponent songList)
134 | {
135 | this.songList = songList;
136 | }
137 |
138 | public void GetSongList()
139 | {
140 | songList.DisplaySongInformation();
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Composite Design Pattern/CompositeDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4247f29445565be4793f4da763414463
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Decorator Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 88ba70c0cc9ed464b8af62b5063fb1b9
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Decorator Design Pattern/DecoratorDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | // Allows to modify an object dynamically
5 | // use pattern if you want capabilities of inheritance with sublcasses, but need functionality at runtime
6 | // it is more flexible than inheritance
7 | // simplifies code because you can add functionality using many simple classes
8 | // rather than rewrite old code you can extend with new code
9 |
10 |
11 | namespace DecoratorPattern
12 | {
13 | public class DecoratorDesignPattern : MonoBehaviour
14 | {
15 | void OnEnable()
16 | {
17 | Debug.Log ("------------------");
18 | Debug.Log ("DECORATOR DESIGN PATTERN");
19 | // Make Pizzas:
20 | IPizza basicPizza = new TomatoSauce(new Mozzarella(new PlainPizza()));
21 | Debug.Log ("Ingredients of Pizza: " + basicPizza.GetDescription());
22 | Debug.Log ("Total Cost: " + basicPizza.GetCost());
23 | }
24 | }
25 |
26 |
27 |
28 | public interface IPizza
29 | {
30 | string GetDescription();
31 | double GetCost();
32 | }
33 |
34 |
35 | public class PlainPizza : IPizza
36 | {
37 | public string GetDescription()
38 | {
39 | return "Thin Dough";
40 | }
41 |
42 | public double GetCost()
43 | {
44 | return 4.00;
45 | }
46 | }
47 |
48 |
49 |
50 | public abstract class ToppingDecorator : IPizza
51 | {
52 | protected IPizza tempPizza;
53 |
54 | public ToppingDecorator(IPizza newPizza)
55 | {
56 | this.tempPizza = newPizza;
57 | }
58 |
59 |
60 | public virtual string GetDescription()
61 | {
62 | return tempPizza.GetDescription();
63 | }
64 |
65 | public virtual double GetCost()
66 | {
67 | return tempPizza.GetCost();
68 | }
69 | }
70 |
71 |
72 |
73 | public class Mozzarella : ToppingDecorator
74 | {
75 | public Mozzarella(IPizza newPizza) : base(newPizza)
76 | {
77 | Debug.Log ("Adding Dough");
78 | Debug.Log ("Adding Morarella");
79 | }
80 |
81 | public override string GetDescription()
82 | {
83 | return tempPizza.GetDescription() + ", Mozzarella";
84 | }
85 |
86 | public override double GetCost()
87 | {
88 | return tempPizza.GetCost() + 0.50;
89 | }
90 | }
91 |
92 |
93 | public class TomatoSauce : ToppingDecorator
94 | {
95 | public TomatoSauce(IPizza newPizza) : base(newPizza)
96 | {
97 | Debug.Log ("Adding Sauce");
98 | }
99 |
100 | public override string GetDescription()
101 | {
102 | return tempPizza.GetDescription() + ", Tomato Sauce";
103 | }
104 |
105 | public override double GetCost()
106 | {
107 | return tempPizza.GetCost() + 0.35;
108 | }
109 | }
110 |
111 |
112 |
113 |
114 | namespace BadStyleExample
115 | {
116 | public abstract class Pizza
117 | {
118 | public abstract void SetDescription(string newDescription);
119 | public abstract string GetDescription();
120 | public abstract double GetCost();
121 | //public abstract bool HasFontina();
122 | }
123 |
124 | // this way would force to create an infinite amount of subclasses for each type of pizza
125 | // and if cost if calculated off of individual topings you would have to change cost for all pizzas
126 | // if cost for one topping chages
127 | public class ThreeCheesePizza : Pizza
128 | {
129 | public override void SetDescription(string newDescription)
130 | {
131 | }
132 |
133 | public override string GetDescription()
134 | {
135 | return "Mozarella, Fontina, Parmesan, Cheese Pizza";
136 | }
137 |
138 | public override double GetCost()
139 | {
140 | return 10.00;
141 | }
142 |
143 | }
144 | }
145 |
146 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Decorator Design Pattern/DecoratorDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dde837945fb180842a2d96cd8f8f5fef
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Facade Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 047fecb1df09af14993754b6e69bcc78
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Facade Design Pattern/FacadeDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | /* Use when you create a simplified interface that performs many other actions behind the scenes
5 | *
6 | * e.g. Can I withdraw $50 from the bank
7 | * -> check if account nr is corrent
8 | * -> check if security code if valid
9 | * -> check if funds are available
10 | * -> make changes accordingly
11 | *
12 | * */
13 |
14 |
15 | namespace FacadePattern
16 | {
17 | public class FacadeDesignPattern : MonoBehaviour
18 | {
19 | void OnEnable ()
20 | {
21 | Debug.Log ("------------------");
22 | Debug.Log ("FACADE DESIGN PATTERN");
23 |
24 | BankAccountFacade bankAccount = new BankAccountFacade (12345678, 1234);
25 |
26 | Debug.Log ("\"I want to withdraw $50 dollars!\"");
27 | bankAccount.WithdrawCash (50.00);
28 |
29 | Debug.Log ("\"Mh ok now let me withdraw $5000 dollars!?\"");
30 | bankAccount.WithdrawCash (5000.00);
31 |
32 | Debug.Log ("\"What tf... maybe save some cash, here are $300 bucks ;-)\"");
33 | bankAccount.DepositCash (300.00);
34 | }
35 | }
36 |
37 | public class WelcomeToBank
38 | {
39 | public WelcomeToBank ()
40 | {
41 | Debug.Log ("Welcome to ABC Bank");
42 | Debug.Log ("We are happy to deposit your money :-)");
43 | }
44 | }
45 |
46 | public class AccountNumberCheck
47 | {
48 | private int accountNumber = 12345678;
49 |
50 | public int GetAccountNumber ()
51 | {
52 | return accountNumber;
53 | }
54 |
55 | public bool AccountActive (int accNumber)
56 | {
57 | if (accNumber == accountNumber)
58 | return true;
59 | else
60 | return false;
61 | }
62 | }
63 |
64 | public class SecurityCodeCheck
65 | {
66 | private int securityCode = 1234;
67 |
68 | public int GetSecurityCode ()
69 | {
70 | return securityCode;
71 | }
72 |
73 | public bool IsCodeCorrect (int code)
74 | {
75 | if (code == securityCode)
76 | return true;
77 | else
78 | return false;
79 | }
80 | }
81 |
82 | public class FundsCheck
83 | {
84 | private double cashInAccount = 1000.00;
85 |
86 | public double GetCashInAccount ()
87 | {
88 | return cashInAccount;
89 | }
90 |
91 | protected void DecreaseCashInAccount (double cash)
92 | {
93 | cashInAccount -= cash;
94 | }
95 |
96 | protected void IncreaseCashInAccount (double cash)
97 | {
98 | cashInAccount += cash;
99 | }
100 |
101 | public bool HaveEnoughMoney (double cashToWithdraw)
102 | {
103 | if (cashToWithdraw > GetCashInAccount ())
104 | {
105 | Debug.Log ("You don't have enouth money.");
106 | return false;
107 | }
108 | else
109 | {
110 | return true;
111 | }
112 | }
113 |
114 | public void MakeDeposit (double cash)
115 | {
116 | IncreaseCashInAccount (cash);
117 | Debug.Log ("Deposit complete. Current Balance is: " + GetCashInAccount ());
118 | }
119 |
120 | public void WithdrawMoney (double cash)
121 | {
122 | DecreaseCashInAccount (cash);
123 | Debug.Log ("Withdraw complete. Current Balance is: " + GetCashInAccount ());
124 | }
125 | }
126 |
127 | public class BankAccountFacade
128 | {
129 | private int accountNumber;
130 | private int securityCode;
131 | AccountNumberCheck accChecker;
132 | SecurityCodeCheck codeChecker;
133 | FundsCheck fundChecker;
134 | WelcomeToBank bankWelcome;
135 |
136 | public BankAccountFacade (int accountNumber, int newSecurityCode)
137 | {
138 | this.accountNumber = accountNumber;
139 | this.securityCode = newSecurityCode;
140 |
141 | bankWelcome = new WelcomeToBank ();
142 | codeChecker = new SecurityCodeCheck ();
143 | accChecker = new AccountNumberCheck ();
144 | fundChecker = new FundsCheck ();
145 | }
146 |
147 | public int GetAccountNumber ()
148 | {
149 | return accountNumber;
150 | }
151 |
152 | public int GetSecurityCode ()
153 | {
154 | return securityCode;
155 | }
156 |
157 | public void WithdrawCash (double cash)
158 | {
159 | if (accChecker.AccountActive (GetAccountNumber ())
160 | && codeChecker.IsCodeCorrect (GetSecurityCode ())
161 | && fundChecker.HaveEnoughMoney (cash))
162 | {
163 | fundChecker.WithdrawMoney(cash);
164 | Debug.Log ("Transaction complete.");
165 | }
166 | else
167 | {
168 | Debug.Log ("Transaction failed.");
169 | }
170 | }
171 |
172 | public void DepositCash(double cash)
173 | {
174 | if (accChecker.AccountActive (GetAccountNumber ())
175 | && codeChecker.IsCodeCorrect (GetSecurityCode ()))
176 | {
177 | fundChecker.MakeDeposit(cash);
178 | Debug.Log ("Transaction complete.");
179 | }
180 | else
181 | {
182 | Debug.Log ("Transaction failed.");
183 | }
184 | }
185 | }
186 |
187 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Facade Design Pattern/FacadeDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 23a470fbbe0d6ce4e84edb30c7f2330b
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Flyweight Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 961d6e087854dcb478c53c43fcc39367
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Flyweight Design Pattern/FlyWeightDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | /*
6 | * Used when Creation of a large number of similar objects is needed
7 | * e.g. for 100.000 objects
8 | *
9 | * This pattern is to reduce memory usage by sharing objects that are similar in some way rarther than creating new ones
10 | *
11 | * Remember Intrinsic Properties (like sharing a Color) and Extrinsic Properties (like having individual sizes)
12 | *
13 | * */
14 |
15 |
16 | namespace FlyWeightPattern
17 | {
18 |
19 | public class FlyWeightDesignPattern : MonoBehaviour
20 | {
21 | // shared colors:
22 | Color[] shapeColor =
23 | {
24 | Color.red,
25 | Color.blue,
26 | Color.gray,
27 | Color.black,
28 | Color.green,
29 | Color.white
30 | };
31 |
32 | void Start ()
33 | {
34 | Debug.Log ("------------------");
35 | Debug.Log ("FLYWEIGHT DESIGN PATTERN");
36 | Debug.Log ("Not implemented yet");
37 | }
38 | }
39 |
40 |
41 | public class FlyWeightTest
42 | {
43 |
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Flyweight Design Pattern/FlyWeightDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f5ee136a00ec1e64f956ac9482561a23
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Proxy Design Pattern.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 38ccb44d34ccc3e4385151b08dbe149d
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Proxy Design Pattern/ProxyDesignPattern.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 |
5 | /*
6 | * Use when you want to provide limited access to another class
7 | *
8 | * Maybe for security reasons because an object is intensive to create
9 | * or is accessed from a remote location
10 | *
11 | * */
12 |
13 |
14 | // using the state pattern here for getting access to the ATMMachine object that we created in the StatePattern Namespace
15 | using StatePattern;
16 |
17 | namespace ProxyPattern
18 | {
19 | public class ProxyDesignPattern : MonoBehaviour
20 | {
21 |
22 | // Use this for initialization
23 | void OnEnable ()
24 | {
25 | Debug.Log ("------------------");
26 | Debug.Log ("PROXY DESIGN PATTERN");
27 |
28 | GetATMData realATMMachine = new ATMMachine();
29 | GetATMData atmProxy = new ATMProxy();
30 | Debug.Log ("Current State: " + atmProxy.GetCurrentState());
31 | Debug.Log ("Current Cash in Machine: " + atmProxy.GetCashInMachine());
32 |
33 | //atmProxy.setCashInMachine << not possible because not defined in the interface
34 |
35 | }
36 | }
37 |
38 |
39 |
40 | public interface GetATMData
41 | {
42 | ATMState GetCurrentState();
43 | int GetCashInMachine();
44 | }
45 |
46 |
47 | public class ATMProxy : GetATMData
48 | {
49 | public ATMState GetCurrentState()
50 | {
51 | ATMMachine atm = new ATMMachine();
52 | return atm.GetCurrentState();
53 | }
54 |
55 | public int GetCashInMachine()
56 | {
57 | ATMMachine atm = new ATMMachine();
58 | return atm.GetCashInMachine();
59 | }
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/Assets/_PATTERNS/Structural Design Patterns/Proxy Design Pattern/ProxyDesignPattern.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6f1cf883b8d308347acdf9909a4dd937
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/NavMeshLayers.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/UnityDesignPatternsExampleProject-csharp.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 11.00
2 | # Visual Studio 2008
3 |
4 | Project("{705CCF44-FC28-688A-C9FB-50BE1B0546F0}") = "UnityDesignPatternsExampleProject", "Assembly-CSharp-vs.csproj", "{58EC1F47-4052-5294-D9FA-F1E1A0075EC8}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(MonoDevelopProperties) = preSolution
21 | StartupItem = Assembly-CSharp.csproj
22 | Policies = $0
23 | $0.TextStylePolicy = $1
24 | $1.inheritsSet = null
25 | $1.scope = text/x-csharp
26 | $0.CSharpFormattingPolicy = $2
27 | $2.inheritsSet = Mono
28 | $2.inheritsScope = text/x-csharp
29 | $2.scope = text/x-csharp
30 | $0.TextStylePolicy = $3
31 | $3.FileWidth = 120
32 | $3.TabWidth = 4
33 | $3.IndentWidth = 4
34 | $3.EolMarker = Unix
35 | $3.inheritsSet = Mono
36 | $3.inheritsScope = text/plain
37 | $3.scope = text/plain
38 | EndGlobalSection
39 |
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/UnityDesignPatternsExampleProject-csharp.v12.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marwie/Design-Patterns-in-Unity-Example/86fdf1bfc0e0654e87c92054e9f1e3613c090813/UnityDesignPatternsExampleProject/UnityDesignPatternsExampleProject-csharp.v12.suo
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/UnityDesignPatternsExampleProject.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 11.00
2 | # Visual Studio 2008
3 |
4 | Project("{705CCF44-FC28-688A-C9FB-50BE1B0546F0}") = "UnityDesignPatternsExampleProject", "Assembly-CSharp.csproj", "{58EC1F47-4052-5294-D9FA-F1E1A0075EC8}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {58EC1F47-4052-5294-D9FA-F1E1A0075EC8}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(MonoDevelopProperties) = preSolution
21 | StartupItem = Assembly-CSharp.csproj
22 | Policies = $0
23 | $0.TextStylePolicy = $1
24 | $1.inheritsSet = null
25 | $1.scope = text/x-csharp
26 | $0.CSharpFormattingPolicy = $2
27 | $2.inheritsSet = Mono
28 | $2.inheritsScope = text/x-csharp
29 | $2.scope = text/x-csharp
30 | $0.TextStylePolicy = $3
31 | $3.FileWidth = 120
32 | $3.TabWidth = 4
33 | $3.IndentWidth = 4
34 | $3.EolMarker = Unix
35 | $3.inheritsSet = Mono
36 | $3.inheritsScope = text/plain
37 | $3.scope = text/plain
38 | EndGlobalSection
39 |
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/UnityDesignPatternsExampleProject/UnityDesignPatternsExampleProject.userprefs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------