Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0024ff8

Browse files
committed
Added Factory pattern
1 parent 719c33d commit 0024ff8

File tree

16 files changed

+621
-4
lines changed

16 files changed

+621
-4
lines changed

‎Assets/Patterns/20. Decorator/Tesla order system/Car parts/Extras/DracoThrusters.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Decorator.OrderSystem
66
{
7+
//Tesla is actually planning to put SpaceX Draco Thrusters on the Roadster to increase the performance so this class is not a lie!
78
public class DracoThruster : _CarExtras
89
{
910
private _Car prevCarPart;

‎Assets/Patterns/20. Decorator/Tesla order system/decorator-order-system.unity‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,51 @@ Transform:
211211
m_LocalScale: {x: 1, y: 1, z: 1}
212212
m_Children: []
213213
m_Father: {fileID: 0}
214-
m_RootOrder: 1
214+
m_RootOrder: 2
215215
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
216+
--- !u!1 &167023543
217+
GameObject:
218+
m_ObjectHideFlags: 0
219+
m_CorrespondingSourceObject: {fileID: 0}
220+
m_PrefabInstance: {fileID: 0}
221+
m_PrefabAsset: {fileID: 0}
222+
serializedVersion: 6
223+
m_Component:
224+
- component: {fileID: 167023545}
225+
- component: {fileID: 167023544}
226+
m_Layer: 0
227+
m_Name: _Controller
228+
m_TagString: Untagged
229+
m_Icon: {fileID: 0}
230+
m_NavMeshLayer: 0
231+
m_StaticEditorFlags: 0
232+
m_IsActive: 1
233+
--- !u!114 &167023544
234+
MonoBehaviour:
235+
m_ObjectHideFlags: 0
236+
m_CorrespondingSourceObject: {fileID: 0}
237+
m_PrefabInstance: {fileID: 0}
238+
m_PrefabAsset: {fileID: 0}
239+
m_GameObject: {fileID: 167023543}
240+
m_Enabled: 1
241+
m_EditorHideFlags: 0
242+
m_Script: {fileID: 11500000, guid: 1f7a2dc5884308b4a8e27e642c4e5484, type: 3}
243+
m_Name:
244+
m_EditorClassIdentifier:
245+
--- !u!4 &167023545
246+
Transform:
247+
m_ObjectHideFlags: 0
248+
m_CorrespondingSourceObject: {fileID: 0}
249+
m_PrefabInstance: {fileID: 0}
250+
m_PrefabAsset: {fileID: 0}
251+
m_GameObject: {fileID: 167023543}
252+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
253+
m_LocalPosition: {x: 0, y: 0, z: 0}
254+
m_LocalScale: {x: 1, y: 1, z: 1}
255+
m_Children: []
256+
m_Father: {fileID: 0}
257+
m_RootOrder: 0
258+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
216259
--- !u!1 &1756844989
217260
GameObject:
218261
m_ObjectHideFlags: 0
@@ -294,5 +337,5 @@ Transform:
294337
m_LocalScale: {x: 1, y: 1, z: 1}
295338
m_Children: []
296339
m_Father: {fileID: 0}
297-
m_RootOrder: 0
340+
m_RootOrder: 1
298341
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

‎Assets/Patterns/21. Factory.meta‎

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

‎Assets/Patterns/21. Factory/Car Factory.meta‎

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

‎Assets/Patterns/21. Factory/Car Factory/Car Factories.meta‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using Decorator.OrderSystem;
4+
using UnityEngine;
5+
6+
namespace Factory.CarFactory
7+
{
8+
public class ChinaFactory : _CarFactory
9+
{
10+
public override _Car ManufactureCar(CarModels carModel, List<CarExtras> carExtras)
11+
{
12+
_Car car = null;
13+
14+
if (carModel == CarModels.ModelS)
15+
{
16+
car = new ModelS();
17+
}
18+
else if (carModel == CarModels.Roadster)
19+
{
20+
car = new Roadster();
21+
}
22+
23+
//Notice that the Cybertruck is missing here, so we cant manufacture it!
24+
if (car == null)
25+
{
26+
Debug.Log("Sorry but this factory cant manufacture this model :(");
27+
28+
return car;
29+
}
30+
31+
32+
//Add the extras
33+
foreach (CarExtras carExtra in carExtras)
34+
{
35+
if (carExtra == CarExtras.DracoThruster)
36+
{
37+
car = new DracoThruster(car, 1);
38+
}
39+
else if (carExtra == CarExtras.EjectionSeat)
40+
{
41+
car = new EjectionSeat(car, 1);
42+
}
43+
else
44+
{
45+
Debug.Log("Sorry but this factory cant add this car extra :(");
46+
}
47+
}
48+
49+
return car;
50+
}
51+
}
52+
}

‎Assets/Patterns/21. Factory/Car Factory/Car Factories/ChinaFactory.cs.meta‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using Decorator.OrderSystem;
4+
using UnityEngine;
5+
6+
namespace Factory.CarFactory
7+
{
8+
public class USFactory : _CarFactory
9+
{
10+
public override _Car ManufactureCar(CarModels carModel, List<CarExtras> carExtras)
11+
{
12+
_Car car = null;
13+
14+
if (carModel == CarModels.Cybertruck)
15+
{
16+
car = new Cybertruck();
17+
}
18+
else if (carModel == CarModels.ModelS)
19+
{
20+
car = new ModelS();
21+
}
22+
else if (carModel == CarModels.Roadster)
23+
{
24+
car = new Roadster();
25+
}
26+
27+
if (car == null)
28+
{
29+
Debug.Log("Sorry but this factory cant manufacture this model :(");
30+
31+
return car;
32+
}
33+
34+
35+
//Add the extras
36+
foreach (CarExtras carExtra in carExtras)
37+
{
38+
if (carExtra == CarExtras.DracoThruster)
39+
{
40+
car = new DracoThruster(car, 1);
41+
}
42+
//Ejection seats are not legal in US so cant manufacture it (but we will still manufacture the rest of the car)
43+
else
44+
{
45+
Debug.Log("Sorry but this factory cant add this car extra :(");
46+
}
47+
}
48+
49+
return car;
50+
}
51+
}
52+
}

‎Assets/Patterns/21. Factory/Car Factory/Car Factories/USFactory.cs.meta‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Decorator.OrderSystem;
5+
6+
namespace Factory.CarFactory
7+
{
8+
public abstract class _CarFactory
9+
{
10+
//This method is called the Factory Method
11+
public abstract _Car ManufactureCar(CarModels carModel, List<CarExtras> carExtras);
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /