-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyweightPattern.cs
More file actions
59 lines (47 loc) · 1.73 KB
/
FlyweightPattern.cs
File metadata and controls
59 lines (47 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//Flyweight pattern main classı
namespace FlyweightPattern
{
public class Flyweight : MonoBehaviour
{
//Tüm uzaylıları tutan liste
List<Alien> allAliens = new List<Alien>();
List<Vector3> eyePositions;
List<Vector3> legPositions;
List<Vector3> armPositions;
void Start()
{
//Flyweight etkinleştirildiğinde kullanılan liste
eyePositions = GetBodyPartPositions();
legPositions = GetBodyPartPositions();
armPositions = GetBodyPartPositions();
//Tüm uzaylıları oluşturuyoruz
for (int i = 0; i < 10000; i++)
{
Alien newAlien = new Alien();
//göz ve bacak pozisyonları
//Flyweight olmadan!!
newAlien.eyePositions = GetBodyPartPositions();
newAlien.armPositions = GetBodyPartPositions();
newAlien.legPositions = GetBodyPartPositions();
//Flyweight ile!!
//newAlien.eyePositions = eyePositions;
//newAlien.armPositions = legPositions;
//newAlien.legPositions = armPositions;
allAliens.Add(newAlien);
}
}
//listeyı generate ediyoruz
List<Vector3> GetBodyPartPositions(){//Yenı list oluşturuyoruz
List<Vector3> bodyPartPositions = new List<Vector3>();
//vücut parçalarını listeye ekliyoruz
for (int i = 0; i < 1000; i++)
{
bodyPartPositions.Add(new Vector3());
}
return bodyPartPositions;
}
}
}