Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class DK_MapSystem : MonoBehaviour {
- public float ScrollSpeed = 20.0f;
- public float ZoomSpeed = 10.0f;
- public float RotateSpeed = 5.0f;
- public float Scroll_Width = 10.0f;
- public int CameraHeight = 60;
- private GameObject[][] ShiftMap = new GameObject[50][];
- private Vector2 TileSize;
- private Mesh SingleTile;
- private GameObject MapHolder;
- private Vector3 mousePos;
- private Vector3 mouserayPos;
- private Vector3 camangle;
- private Vector3 rayget;
- private Vector3 Tempv = new Vector3(0,0,0);
- private Vector2 scroller;
- private Ray mouseray;
- private Ray ray;
- private RaycastHit hit;
- private float hitdistance;
- private float zoomer;
- private float camX, camY;
- DK_Tiles DKTiles;
- DK_TileSystem DK_TileOption;
- // Use this for initialization
- void Start () {
- for(int ax=0; ax<50; ax++){
- ShiftMap[ax] = new GameObject[40];
- }
- DKTiles = transform.gameObject.GetComponent<DK_Tiles>();
- SingleTile = DKTiles.MapPrefabs[0].GetComponent<MeshFilter>().sharedMesh;
- TileSize = new Vector2(SingleTile.bounds.size.x, SingleTile.bounds.size.z);
- for(int ax=0; ax<50; ax++){
- for(int ay=0; ay<40; ay++){
- ShiftMap[ax][ay] = Instantiate(DKTiles.MapPrefabs[0], new Vector3(ax*TileSize.x, 0, ay*TileSize.y), Quaternion.identity) as GameObject;
- ShiftMap[ax][ay].transform.name = "Position: " + ax + " | " + ay;
- DK_TileOption = ShiftMap[ax][ay].GetComponent<DK_TileSystem>();
- DK_TileOption.Tile_Position = new Vector2(ax, ay);
- DK_TileOption.Tile_ID = 1;
- }
- }
- MapHolder = new GameObject();
- MapHolder.transform.name = "TilemapHolder";
- for(int ax=0; ax<50; ax++){
- for(int ay=0; ay<40; ay++){
- ShiftMap[ax][ay].transform.parent = MapHolder.transform;
- }
- }
- DKTiles.TheCamera.transform.position = new Vector3(0, CameraHeight, -34);
- DKTiles.TheCamera.transform.eulerAngles = new Vector3(50.000f, 0.000f, 0.000f);
- DKTiles.TheCameraParent.transform.position = new Vector3((50*TileSize.x)/2, 0, (40*TileSize.y)/2);
- }
- // Update is called once per frame
- void Update () {
- //==================================================================================================================
- // SCROLL & ZOOM
- //==================================================================================================================
- if(Input.GetAxis("Horizontal") > 0 ){scroller.x = 1;}else if(Input.GetAxis("Horizontal") < 0 ){scroller.x = -1;}
- else if(Input.mousePosition.x < Scroll_Width){scroller.x = -1;}
- else if(Input.mousePosition.x > Screen.width - Scroll_Width){scroller.x = 1;}
- else{scroller.x = 0;}
- if(Input.GetAxis("Vertical") > 0 ){scroller.y = 1;}else if(Input.GetAxis("Vertical") < 0 ){scroller.y = -1;}
- else if(Input.mousePosition.y < Scroll_Width){scroller.y = -1;}
- else if(Input.mousePosition.y > Screen.height - Scroll_Width){scroller.y = 1;}
- else{scroller.y = 0;}
- DKTiles.TheCameraParent.transform.Translate((scroller.x*ScrollSpeed*(Input.GetKey(KeyCode.LeftShift) ? 2 : 1))*Time.deltaTime, 0, (scroller.y*ScrollSpeed*(Input.GetKey(KeyCode.LeftShift) ? 2 : 1))*Time.deltaTime);
- camX = DKTiles.TheCameraParent.transform.position.x;
- camY = DKTiles.TheCameraParent.transform.position.z;
- camX = Mathf.Clamp(camX, 10, 999);
- camY = Mathf.Clamp(camY, 10, 999);
- Tempv.x = camX;
- Tempv.y = 0;
- Tempv.z = camY;
- DKTiles.TheCameraParent.transform.position = Tempv;
- if(Input.GetAxis("Mouse ScrollWheel") > 0){zoomer = -1f;} else if(Input.GetAxis("Mouse ScrollWheel") < 0){zoomer = 1f;}
- else if(Input.GetKey(KeyCode.End)){zoomer = 0.5f;}
- else if(Input.GetKey(KeyCode.Home)){zoomer = -0.5f;}
- else{zoomer = 0f;}
- if(Input.GetKey(KeyCode.Delete)){DKTiles.TheCameraParent.transform.Rotate(0,RotateSpeed*Time.deltaTime,0);}
- else if(Input.GetKey(KeyCode.PageDown)){DKTiles.TheCameraParent.transform.Rotate(0,-RotateSpeed*Time.deltaTime,0);}
- else if(Input.GetKey(KeyCode.PageUp)){camangle.x=0;camangle.y=0;camangle.z=0;DKTiles.TheCameraParent.transform.eulerAngles = camangle;}
- DKTiles.TheCamera.fieldOfView += (zoomer * ZoomSpeed)*Time.deltaTime;
- DKTiles.TheCamera.fieldOfView = Mathf.Clamp(DKTiles.TheCamera.fieldOfView, 15, 35);
- //==================================================================================================================
- // SHIFT MAPPING
- //==================================================================================================================
- //==================================================================================================================
- // CURSOR
- //==================================================================================================================
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if(Physics.Raycast(ray, out hit))
- {
- hitdistance = Vector3.Distance(DKTiles.TheCamera.transform.position, hit.point);
- Tempv.x = Input.mousePosition.x;
- Tempv.y = Input.mousePosition.y;
- Tempv.z = hitdistance-2;
- mouserayPos = DKTiles.TheCamera.ScreenToWorldPoint(Tempv);
- Tempv.x = mouserayPos.x;
- Tempv.y = 10;
- Tempv.z = mouserayPos.z;
- rayget.x = mouserayPos.x;
- rayget.y = 10;
- rayget.z = mouserayPos.z;
- DKTiles.CursorLamp.transform.position = rayget;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement