1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class MapItem : MapObject
- {
- public const int BIGGER = 1;
- public Texture[] textureArr;
- public int id;
- private List<int> tileIndexs;
- public override void Init (Map map)
- {
- base.Init (map);
- tileIndexs = new List<int>();
- }
- // public override TeamUtil.Team team {
- // get {
- // return base.team;
- // }
- // set {
- // base.team = value;
- // int index = value.GetHashCode() - 1;
- // Renderer[] renderers = this.GetComponentsInChildren<Renderer>();
- // for(int i=0; i<renderers.Length; i++)
- // {
- // renderers[i].material.mainTexture = textureArr[index];
- // }
- // }
- // }
- public void SetPosition(Vector3 pos)
- {
- this.transform.position = pos;
- }
- public List<int> GetTileIndexs()
- {
- return tileIndexs;
- }
- public void TakeTiles()
- {
- int col = Map.XToColumn(position.x);
- int row = Map.ZToRow(position.z);
- CleanTiles();
- AddTile(col, row);
- AddTile(col-1, row);
- AddTile(col, row-1);
- AddTile(col+1, row);
- AddTile(col, row+1);
- AddTile(col+1, row+1);
- AddTile(col+1, row-1);
- AddTile(col-1, row+1);
- AddTile(col-1, row-1);
- }
- private void AddTile(int col, int row)
- {
- int index = map.GetIndexByGrid(col, row);
- tileIndexs.Add(index);
- map.MapItemPlace(index, this);
- }
- protected void CleanTiles()
- {
- map.MapItemClean(this);
- tileIndexs.Clear();
- }
- public override void Remove ()
- {
- CleanTiles();
- map.RemoveMapItem(this);
- Destroy(this.gameObject);
- }
- }
|