<commit_before>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class HUD : MonoBehaviour {
	public Camera mainCamera;
	public Camera insetCamera;
	public SelectUnits selection;
	private GameObject selectedUnit = null;

	private CameraSettings camStart = new CameraSettings();
	private CameraSettings camTop = new CameraSettings();
	private CameraSettings camISO = new CameraSettings();
	private CameraSettings camUnit = new CameraSettings();

	private Rect GUIArea = new Rect(10f, 10f, 100, 200);

	void Start() {
		camStart.position = mainCamera.transform.position;
		camStart.rotation = mainCamera.transform.localEulerAngles;
		
		camTop.position = new Vector3(0, 60f, 0);
		camTop.rotation = new Vector3(90f, 0, 0);

		camUnit.position = new Vector3(0, 0, 0);
		camUnit.rotation = new Vector3(90f, 180f, 0);

		camISO.position = new Vector3(0, 0, 0);
		camISO.rotation = new Vector3(30f, 315f, -8f);
		camISO.othographic = true;
		camISO.orthographicSize = 20f;
		camISO.nearClipPlane = -35f;
	}

	public Camera getBestGuessCameraFromScreenPoint(Vector3 point){
		return (insetCamera.pixelRect.Contains(point)) ? insetCamera : mainCamera;
	}

	void OnGUI () {
		GUILayout.BeginArea(GUIArea);

		GUILayout.Label("Camera");

		GUILayout.BeginHorizontal();
		if (GUILayout.Button("Top")) {
			UpdateCamera(camTop);
		}

		if (GUILayout.Button("ISO")) {
			UpdateCamera(camISO);
		}
		GUILayout.EndHorizontal();
		
		if (GUILayout.Button("Unit")) {
			if (selection.selectedUnits.Count > 0) {
				camUnit.parentTransform = selection.LastSelected.transform;
				UpdateCamera(camUnit);
			}
		}

		if (GUILayout.Button("Reset")) {
			UpdateCamera(camStart);
		}

		GUILayout.Label("Inset Camera");
		
		GUILayout.BeginHorizontal();
		if (GUILayout.Button("Top")) {
			insetCamera.enabled = true;
			UpdateCamera(insetCamera, camTop);
		}
		
		if (GUILayout.Button("ISO")) {
			insetCamera.enabled = true;
			UpdateCamera(insetCamera, camISO);
		}
		GUILayout.EndHorizontal();
		
		if (GUILayout.Button("Unit")) {
			if (selection.selectedUnits.Count > 0) {
				insetCamera.enabled = true;
				camUnit.parentTransform = selection.LastSelected.transform;
				UpdateCamera(insetCamera, camUnit);
			}
		}
		
		if (GUILayout.Button("Reset")) {
			insetCamera.enabled = false;
		}
		
		GUILayout.EndArea();
	}
	
	void UpdateCamera(CameraSettings settings) {
		UpdateCamera(mainCamera, settings);
	}
	
	void UpdateCamera(Camera camera, CameraSettings settings) {
		camera.transform.parent = settings.parentTransform;
		camera.transform.localPosition = settings.position;
		camera.transform.localEulerAngles = settings.rotation;
		camera.orthographic = settings.othographic;
		camera.orthographicSize = settings.orthographicSize;
		camera.nearClipPlane = settings.nearClipPlane;
	}

	void AttachCamera() {
		if (selectedUnit != null)
			mainCamera.transform.parent = selectedUnit.transform;
	}
}

public class CameraSettings {
	public Vector3 position;
	public Vector3 rotation;
	public bool othographic = false;
	public float orthographicSize = 5f;
	public float nearClipPlane = 0.3f;
	public Transform parentTransform = null;<commit_msg>Don't show controls for or try to interact with inset camera if it is not set<commit_after>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class HUD : MonoBehaviour {
	public Camera mainCamera;
	public Camera insetCamera = null;
	public SelectUnits selection;
	private GameObject selectedUnit = null;

	private CameraSettings camStart = new CameraSettings();
	private CameraSettings camTop = new CameraSettings();
	private CameraSettings camISO = new CameraSettings();
	private CameraSettings camUnit = new CameraSettings();

	private Rect GUIArea = new Rect(10f, 10f, 100, 200);

	void Start() {
		camStart.position = mainCamera.transform.position;
		camStart.rotation = mainCamera.transform.localEulerAngles;
		
		camTop.position = new Vector3(0, 60f, 0);
		camTop.rotation = new Vector3(90f, 0, 0);

		camUnit.position = new Vector3(0, 0, 0);
		camUnit.rotation = new Vector3(90f, 180f, 0);

		camISO.position = new Vector3(0, 0, 0);
		camISO.rotation = new Vector3(30f, 315f, -8f);
		camISO.othographic = true;
		camISO.orthographicSize = 20f;
		camISO.nearClipPlane = -35f;
	}

	public Camera getBestGuessCameraFromScreenPoint(Vector3 point){
		if (insetCamera == null)
			return mainCamera;
		else
			return (insetCamera.pixelRect.Contains(point)) ? insetCamera : mainCamera;
	}

	void OnGUI () {
		GUILayout.BeginArea(GUIArea);

		GUILayout.Label("Camera");

		GUILayout.BeginHorizontal();
		if (GUILayout.Button("Top")) {
			UpdateCamera(camTop);
		}

		if (GUILayout.Button("ISO")) {
			UpdateCamera(camISO);
		}
		GUILayout.EndHorizontal();
		
		if (GUILayout.Button("Unit")) {
			if (selection.selectedUnits.Count > 0) {
				camUnit.parentTransform = selection.LastSelected.transform;
				UpdateCamera(camUnit);
			}
		}

		if (GUILayout.Button("Reset")) {
			UpdateCamera(camStart);
		}

		if (insetCamera != null) {
			GUILayout.Label("Inset Camera");
			
			GUILayout.BeginHorizontal();
			if (GUILayout.Button("Top")) {
				insetCamera.enabled = true;
				UpdateCamera(insetCamera, camTop);
			}
			
			if (GUILayout.Button("ISO")) {
				insetCamera.enabled = true;
				UpdateCamera(insetCamera, camISO);
			}
			GUILayout.EndHorizontal();
			
			if (GUILayout.Button("Unit")) {
				if (selection.selectedUnits.Count > 0) {
					insetCamera.enabled = true;
					camUnit.parentTransform = selection.LastSelected.transform;
					UpdateCamera(insetCamera, camUnit);
				}
			}
			
			if (GUILayout.Button("Reset")) {
				insetCamera.enabled = false;
			}
		}
		
		GUILayout.EndArea();
	}
	
	void UpdateCamera(CameraSettings settings) {
		UpdateCamera(mainCamera, settings);
	}
	
	void UpdateCamera(Camera camera, CameraSettings settings) {
		camera.transform.parent = settings.parentTransform;
		camera.transform.localPosition = settings.position;
		camera.transform.localEulerAngles = settings.rotation;
		camera.orthographic = settings.othographic;
		camera.orthographicSize = settings.orthographicSize;
		camera.nearClipPlane = settings.nearClipPlane;
	}

	void AttachCamera() {
		if (selectedUnit != null)
			mainCamera.transform.parent = selectedUnit.transform;
	}
}

public class CameraSettings {
	public Vector3 position;
	public Vector3 rotation;
	public bool othographic = false;
	public float orthographicSize = 5f;
	public float nearClipPlane = 0.3f;
	public Transform parentTransform = null;
{'fraction_non_alphanumeric': 0.11174126302881668, 'fraction_numerical': 0.01655426118945432, 'mean_word_length': 4.41044776119403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5076749', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2008, 'n_words': 444}