Skip to content

Commit

Permalink
Add a MapDrawer component to render map items
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanahman committed Aug 27, 2014
1 parent 11579c3 commit 00d2a96
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 29 deletions.
24 changes: 1 addition & 23 deletions Assets/Game/Cameras/Code/MapCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ public class MapCamera : HUDBase, IMapLoader {

// Transforms
public Transform target;
public Transform mapPlayerIconTransform;
public Transform minimapMaskTransform;
private Transform cameraTransform; // Used to fetch the reference of the player
private Transform cameraTransform;

// Camera
private Camera mapCamera;
Expand Down Expand Up @@ -107,26 +105,13 @@ void updateCamera(Transform t)
{
Vector3 tmp;

// Update map icon position (y = unchanged)
tmp = mapPlayerIconTransform.transform.position;
tmp.x = t.position.x;
tmp.z = t.position.z;
mapPlayerIconTransform.transform.position = tmp;

// Update map icon rotation (x,z = unchanged)
tmp = mapPlayerIconTransform.eulerAngles;
tmp.y = t.eulerAngles.y;
mapPlayerIconTransform.eulerAngles = tmp;

// Minimap snapshot used as reference during toggle (the fullscreen
// snapshot are known and do not need to be uptades every frame)
if (!fullscreen) {
// Camera and mask position
tmp = t.position;
tmp.y = cameraTransform.position.y;
snapshotPosition = tmp;
tmp.y = minimapMaskTransform.position.y;
snapshotMaskPosition = tmp;

// Camera rotation
tmp = cameraTransform.eulerAngles;
Expand All @@ -138,7 +123,6 @@ void updateCamera(Transform t)
if (!toggling) {
cameraTransform.position = snapshotPosition;
cameraTransform.eulerAngles = snapshotRotation;
minimapMaskTransform.transform.position = snapshotMaskPosition;
}
}

Expand Down Expand Up @@ -191,8 +175,6 @@ private void toggleFullscreenMap(Transform t)
tmp.x = 0f;
tmp.z = 0f;
snapshotPosition = tmp;
tmp.y = minimapMaskTransform.transform.position.y;
snapshotMaskPosition = tmp;

// Camera rotation
tmp = cameraTransform.eulerAngles;
Expand All @@ -219,8 +201,6 @@ private IEnumerator CameraSmoothTransition()
yield return true;
cameraTransform.position = Vector3.Lerp(cameraTransform.position, snapshotPosition, deltaT / zoomDuration);
cameraTransform.eulerAngles = Vector3.Lerp(cameraTransform.eulerAngles, snapshotRotation, deltaT / rotationDuration);
minimapMaskTransform.transform.position = Vector3.Lerp(minimapMaskTransform.transform.position, snapshotMaskPosition, deltaT / zoomDuration);

}
toggling = false;
}
Expand All @@ -232,7 +212,6 @@ private IEnumerator CameraZoomMinimap() {
deltaT += Time.deltaTime;
yield return true;
mapCamera.orthographicSize = Mathf.Lerp(mapCamera.orthographicSize, minimapZoom, deltaT / zoomDuration);
minimapMaskTransform.transform.localScale = Vector3.Lerp(minimapMaskTransform.transform.localScale, new Vector3(3000f, minimapMaskTransform.transform.localScale.y, 3000f), deltaT / zoomDuration);
}
}
}
Expand All @@ -244,7 +223,6 @@ private IEnumerator CameraZoomFullscrenMap()
deltaT += Time.deltaTime;
yield return true;
mapCamera.orthographicSize = Mathf.Lerp(mapCamera.orthographicSize, mapZoom, deltaT / zoomDuration);
minimapMaskTransform.transform.localScale = Vector3.Lerp(minimapMaskTransform.transform.localScale, new Vector3(24000f, minimapMaskTransform.transform.localScale.y, 24000f), deltaT / zoomDuration);
}
}

Expand Down
44 changes: 44 additions & 0 deletions Assets/Game/HUD/Code/Map/MapDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using UnityEngine;
using System.Collections;

public class MapDrawer : MonoBehaviour {

private GameObject textureObject;
private Transform textureTransform;
public Texture2D texture;
public bool navigatable = false;
public Texture2D nagivationTexture;

// Use this for initialization
void Start () {

// Create a cylinder game object and assign it to the map layer
textureObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
textureObject.name = "MapItem";
textureObject.layer = LayerMask.NameToLayer(HUDConstants.LAYER_MAP);

// Transform properties
textureTransform = textureObject.transform;

// TODO: Fix player transform
//textureTransform.parent = gameObject.transform;
//textureTransform.localScale = new Vector3(4f, 0f, 4f);
// For now:
textureTransform.parent = gameObject.GetComponentInChildren<CarHandling>().transform;
textureTransform.localScale = new Vector3(10f, 0f, 10f);

textureTransform.localPosition = new Vector3(0f, 1f, 0f);

// Add texture
Material mat = textureObject.renderer.material;
mat.SetTexture("_MainTex", texture);
mat.shader = Shader.Find("Unlit/Transparent");
Destroy(textureObject.collider);
}

// Update is called once per frame
void Update () {

}

}
8 changes: 8 additions & 0 deletions Assets/Game/HUD/Code/Map/MapDrawer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Material:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: MinimapArrow
m_Name: MapArrowWhite
m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: []
m_CustomRenderQueue: -1
Expand Down
8 changes: 4 additions & 4 deletions Assets/Game/Networking/Code/PlayerSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public void CreateLocalPlayer(Team team)
// Player newPlayer = newPlayerObject.GetComponentInChildren<Player>();
// newPlayer.SetTeam( team );

MapDrawer mapDrawer = newPlayerObject.AddComponent<MapDrawer>();
mapDrawer.texture = Resources.Load("Textures/Map/MapArrowWhite") as Texture2D;

// Init cameras
GameObject mainCamera = GameObject.FindGameObjectWithTag(CameraConstants.TAG_MAIN_CAMERA);
mainCamera.GetComponent<SmoothFollowCustom>().SetTarget(newPlayerObject.GetComponentInChildren<CarHandling>().transform);
GameObject mapCamera = GameObject.FindGameObjectWithTag(CameraConstants.TAG_MAP_CAMERA);
mapCamera.GetComponent<MapCamera>().setTarget(newPlayerObject.GetComponentInChildren<CarHandling>().transform);
GameObject mpi = Instantiate(Resources.Load("Prefabs/MapPlayerIcon")) as GameObject;
GameObject mm = Instantiate(Resources.Load("Prefabs/MinimapMask")) as GameObject;
mapCamera.GetComponent<MapCamera>().mapPlayerIconTransform = mpi.transform;
mapCamera.GetComponent<MapCamera>().minimapMaskTransform = mm.transform;

}

}
1 change: 0 additions & 1 deletion Assets/Scenes/MedievalTown.unity
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
target: {fileID: 0}
mapPlayerIconTransform: {fileID: 0}
minimapMaskTransform: {fileID: 0}
--- !u!92 &995429979
Behaviour:
Expand Down

0 comments on commit 00d2a96

Please sign in to comment.