-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlacedObject.cs
41 lines (29 loc) · 1.28 KB
/
PlacedObject.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlacedObject : MonoBehaviour
{
public static PlacedObject Create(Vector3 worldPosition, Vector2Int origin, PlacedObjectTypeSO.Dir dir, PlacedObjectTypeSO placedObjectTypeSO) {
Transform placedObjectTransform = Instantiate(placedObjectTypeSO.prefab, worldPosition, Quaternion.Euler(0, placedObjectTypeSO.GetRotationAngle(dir), 0));
PlacedObject placedObject = placedObjectTransform.GetComponent<PlacedObject>();
placedObject.Setup(placedObjectTypeSO, origin, dir);
return placedObject;
}
private PlacedObjectTypeSO placedObjectTypeSO;
private Vector2Int origin;
private PlacedObjectTypeSO.Dir dir;
private void Setup(PlacedObjectTypeSO placedObjectTypeSO, Vector2Int origin, PlacedObjectTypeSO.Dir dir) {
this.placedObjectTypeSO = placedObjectTypeSO;
this.origin = origin;
this.dir = dir;
}
public List<Vector2Int> GetGridPositionList() {
return placedObjectTypeSO.GetGridPositionList(origin, dir);
}
public void DestroySelf() {
Destroy(gameObject);
}
public override string ToString() {
return placedObjectTypeSO.nameString;
}
}