-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileMarkerScript.cs
More file actions
65 lines (53 loc) · 1.81 KB
/
TileMarkerScript.cs
File metadata and controls
65 lines (53 loc) · 1.81 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
60
61
62
63
64
65
using UnityEngine;
using System.Collections;
public class TileMarkerScript : MonoBehaviour {
public int currentObject;
public float MAX_SLOPE;
Vector2 mouseTile;
Vector3 pos;
Projector projector;
void Awake()
{
projector = GetComponentInChildren<Projector>();
mouseTile = new Vector2(-1, -1);
}
// Use this for initialization
void Start () {
MouseController.Instance.marker = this;
}
void OnEnable()
{
projector.enabled = true;
MouseController.Instance.RegisterTileChanged(ChangePosition);
MouseController.Instance.TurnOnTileMode();
}
void ChangePosition (Vector2 coord) {
mouseTile = coord;
if (coord.x >= 0)
{
pos.Set(mouseTile.x + MapController.TILE_SIZE / 2, 0, mouseTile.y + MapController.TILE_SIZE / 2);
gameObject.transform.position = pos;
projector.material.color = CanBuild() ? Color.green : Color.red;
projector.enabled = true;
} else
{
projector.enabled = false;
}
}
void OnDisable()
{
pos.Set(-1, 0, -1);
projector.enabled = false;
MouseController.Instance.UnregisterTileChanged(ChangePosition);
MouseController.Instance.TurnOffModes();
}
public bool CanBuild()
{
if (mouseTile.x < 0) return false;
if (!MapController.Instance.mapData.tileData[(int)mouseTile.x, (int)mouseTile.y].walkable) return false;
if (MapController.Instance.mapData.tileData[(int)mouseTile.x, (int)mouseTile.y].name == Types.Road) return false;
if (MapController.Instance.mapData.GetSlope(mouseTile, 1, 1) > MAX_SLOPE) return false;
if (BuildJobController.Instance.IsBusy(mouseTile)) return false;
return true;
}
}