chenxin
2020-10-21 146e39c5ef6bb29927cb7c00d7708fceab30a724
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using Core.Utilities;
using TowerDefense.UI.HUD;
using UnityEngine;
 
namespace TowerDefense.Towers.Placement
{
    /// <summary>
    /// An area suitable for placing a single tower
    /// </summary>
    [RequireComponent(typeof(Collider))]
    public class SingleTowerPlacementArea : MonoBehaviour, IPlacementArea
    {
        /// <summary>
        /// Visualisation prefab to instantiate
        /// </summary>
        public PlacementTile placementTilePrefab;
        
        /// <summary>
        /// Visualisation prefab to instantiate on mobile platforms
        /// </summary>
        public PlacementTile placementTilePrefabMobile;
        
        /// <summary>
        /// <see cref="PlacementTile"/> we've spawned on our spot
        /// </summary>
        PlacementTile m_SpawnedTile;
 
        /// <summary>
        /// If the area is occupied
        /// </summary>
        bool m_IsOccupied;
 
        /// <summary>
        /// Set up visualisation tile
        /// </summary>
        protected void Awake()
        {
            PlacementTile tileToUse;
#if UNITY_STANDALONE
            tileToUse = placementTilePrefab;
#else
            tileToUse = placementTilePrefabMobile;
#endif
            
            if (tileToUse != null)
            {
                m_SpawnedTile = Instantiate(tileToUse);
                m_SpawnedTile.transform.SetParent(transform);
                m_SpawnedTile.transform.localPosition = new Vector3(0f, 0.05f, 0f);
            }
        }
 
        public void startCoinGenMode()
        {
            return;
        }
 
 
        /// <summary>
        /// Returns (0, 0), as there is only one available spot
        /// </summary>
        /// <param name="worldPosition"><see cref="Vector3"/> indicating world space coordinates to convert.</param>
        /// <param name="sizeOffset"><see cref="IntVector2"/> indicating size of object to center.</param>
        public IntVector2 WorldToGrid(Vector3 worldPosition, IntVector2 sizeOffset)
        {
            return new IntVector2(0, 0);
        }
 
        public IntVector2 getdimsize()
        {
            return new IntVector2(1, 1);
        }
 
        /// <summary>
        /// 获取对应位置的充能子弹界面指针.
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public BulletUICtl GetBulletUICtl(int x)
        {
            return null;
        }
 
        /// <summary>
        /// 获取一个可以放置塔防的位置.
        /// </summary>
        /// <returns></returns>
        public IntVector2 getFreePos(int xdim, int ydim, bool forceGet = false)
        {
            return new IntVector2(0, 0);
        }
 
 
        public bool isFreeAtackPos(int x,int y )
        {
            return false;
        }
 
        /// <summary>
        /// 当前是否是反方的TowerPlacementGrid.
        /// </summary>
        public bool isOpponent()
        {
            return false;
        }
 
        /// <summary>
        /// 是否有已开启的可放置攻击位置。
        /// </summary>
        /// <returns></returns>
        public bool hasFreeAttackPos()
        {
            return false;
        }
        /// <summary>
        /// 设置格子为合成状态。
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool SetComboGrid(int x, int y)
        {
            return false;
        }
 
        /// <summary>
        /// 设置塔位的血条血量数据
        /// </summary>
        /// <param name="ix"></param>
        /// <param name="health"></param>
        public void setTowerPosHealth(int ix, float health)
        {
            return;
        }
 
        /// <summary>
        /// 是否是等待购买的攻击塔位.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool isWaitBuyGrid(int x, int y)
        {
            return false;
        }
 
        /// <summary>
        /// 购买对应的待购攻击塔位.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool buyWaitBuyGrid(int x, int y)
        {
            return false;
        }
 
        /// <summary>
        /// 设置某一个格子为已破坏塔位。
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool SetDestroyedGrid(int x, int y)
        {
            return false;
        }
 
 
        /// <summary>
        /// Returns transform.position, as there is only one available spot
        /// </summary>
        /// <param name="gridPosition">The coordinate in grid space</param>
        /// <param name="sizeOffset"><see cref="IntVector2"/> indicating size of object to center.</param>
        public Vector3 GridToWorld(IntVector2 gridPosition, IntVector2 sizeOffset)
        {
            return transform.position;
        }
 
        /// <summary>
        /// Tests whether the placement area is valid.
        /// </summary>
        /// <param name="gridPos">The grid location</param>
        /// <param name="size">The size of the item</param>
        public TowerFitStatus Fits(IntVector2 gridPos, IntVector2 size)
        {
            return m_IsOccupied ? TowerFitStatus.Overlaps : TowerFitStatus.Fits;
        }
 
        /// <summary>
        /// Occupies the area
        /// </summary>
        /// <param name="gridPos"></param>
        /// <param name="size"></param>
        public void Occupy(IntVector2 gridPos, IntVector2 size)
        {
            m_IsOccupied = true;
 
            if (m_SpawnedTile != null)
            {
                //m_SpawnedTile.SetState(PlacementTileState.Filled);
            }
        }
 
        /// <summary>
        /// Clears the area
        /// </summary>
        /// <param name="gridPos"></param>
        /// <param name="size"></param>
        public void Clear(IntVector2 gridPos, IntVector2 size)
        {
            m_IsOccupied = false;
 
            if (m_SpawnedTile != null)
            {
                //m_SpawnedTile.SetState(PlacementTileState.Empty);
            }
        }
 
#if UNITY_EDITOR
        /// <summary>
        /// Draw the spot as a smalls phere in the scene view.
        /// </summary>
        void OnDrawGizmos()
        {
            Color prevCol = Gizmos.color;
            Gizmos.color = Color.cyan;
 
            Matrix4x4 originalMatrix = Gizmos.matrix;
            Gizmos.matrix = transform.localToWorldMatrix;
 
            Gizmos.DrawWireSphere(Vector3.zero, 1);
 
            Gizmos.matrix = originalMatrix;
            Gizmos.color = prevCol;
            
            // Draw icon too
            Gizmos.DrawIcon(transform.position + Vector3.up, "build_zone.png", true);
        }
#endif
    }
}