using UnityEngine;
using System.Collections;
public class Point{
int X;
int Y;
int Z;
public Point(int x, int y, int z){
X = x;
Y = y;
Z = z;
}
public override string ToString ()
{
return "[ "+ X + " " + Y + " " + Z + "] ";
}
}
public class Hexa : MonoBehaviour {
Point MapPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void SetMapPos(Point pos){
MapPos = pos;
}
public void SetMapPos(int x, int y, int z){
MapPos = new Point(x, y, z);
}
public void OnMouseDown(){
PlayerManager pm = PlayerManager.GetInstance();
Debug.Log("A" + MapPos + "OnMouseDown");
pm.MovePlayer(pm.players[pm.CurTurnIndex].CurHexa , this);
}
}
using UnityEngine;
using System.Collections;
public class MapManager : MonoBehaviour {
public static MapManager inst = null;
public GameObject Hexa_prefab;
public float HexW;
public float HexH;
public int MapSizeX;
public int MapSizeY;
public int MapSizeZ;
Hexa[][][] Map;
void Awake(){
inst = this;
SetSizeHexa();
}
public static MapManager GetInstance(){
print ("map manager" + inst);
return inst;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void SetSizeHexa(){
HexW = Hexa_prefab.transform.renderer.bounds.size.x;
HexW = Hexa_prefab.transform.renderer.bounds.size.z;
}
public Vector3 GetWorldPos(int x, int y, int z){
float X = 0;
float Z = 0;
X = x * HexW + ( z * HexW * 0.5f);
Z = ( -z ) * HexH * 0.75f;
return new Vector3(X, 0, Z);
}
public void CreateMap(){
Map = new Hexa[MapSizeX * 2 + 1][][];
for(int x = -MapSizeX; x <= MapSizeX; x++){
Map[x + MapSizeX] = new Hexa[MapSizeY * 2 + 1][];
for(int y = -MapSizeY; y <= MapSizeY; y++){
Map[x + MapSizeX][y + MapSizeY] = new Hexa[MapSizeZ * 2 + 1];
for(int z = -MapSizeZ; z <= MapSizeZ; z++){
if(x + y + z == 0){
Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ] = ((GameObject)Instantiate(Hexa_prefab)).GetComponent<Hexa>();
Vector3 pos = GetWorldPos(x, y, z);
//print (pos);
Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ].transform.position = pos;
Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ].SetMapPos(x, y, z);
}
}
}
}
}
public Hexa GetPlayerHexaPosition(int x, int y, int z){
return Map[x + MapSizeX][y + MapSizeY][z + MapSizeZ];
}
}
using UnityEngine;
using System.Collections;
public class PlayerBase : MonoBehaviour {
public Hexa CurHexa;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
'Computer Language > 유니티' 카테고리의 다른 글
잼과 이동관련 (0) | 2014.11.26 |
---|---|
3인칭 시점 (0) | 2014.11.13 |
사인과 코사인 응용 방안 (0) | 2014.11.12 |
Dialog() 다이아로그 (0) | 2014.11.10 |
더미와 다이어로그 (0) | 2014.11.10 |