Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- // @kurtdekker
- //
- // Show ground track data for the last game, if possible.
- //
- // NOTE: if there is no LevelSnapshot available, this is detected in the
- // FlightDataLog scene and the button won't be visible.
- public class FlightGroundTrack : MonoBehaviour
- {
- const string s_Scene_FlightGroundTrack = "FlightGroundTrack";
- public static void Load( string _returnScene = null)
- {
- DSM.Statistics.TimesToGroundTrack.iValue++;
- suggest_orientation.LoadScene(
- wantLandscape: true,
- destinationScene: s_Scene_FlightGroundTrack,
- finishAction: null);
- if (_returnScene != null)
- {
- FlightDataLog.SharedReturnScene = _returnScene;
- }
- }
- void DoDataLog()
- {
- FlightDataLog.Load();
- }
- [Header("The actual backdrop LevelSnapshotter")]
- public RawImage MapImage;
- [Header("Possible ticker marks.")]
- public Image Tick2;
- public Image Tick4;
- public Image Tick8;
- [Header("Full extent of LevelSnapshot map view.")]
- public RectTransform LowerLeft;
- public RectTransform UpperRight;
- [Header("Template FlightDataEventIcon object.")]
- public FlightDataEventIcon FlightDataEventIconTemplate;
- int index;
- // these are snapshots of the Datasacks, which cannot change once we're in here
- Vector3 LevelSnapshotter_Position;
- Vector3 LevelSnapshotter_ArealExtent;
- void Start()
- {
- Tick2.gameObject.SetActive(false);
- Tick4.gameObject.SetActive(false);
- Tick8.gameObject.SetActive(false);
- FlightDataEventIconTemplate.gameObject.SetActive( false);
- var background = LevelSnapshotter.LoadSnapshot();
- if (background)
- {
- MapImage.texture = background;
- // copy for performance
- LevelSnapshotter_Position = DSM.LevelSnapshotter.Position.v3Value;
- LevelSnapshotter_ArealExtent = DSM.LevelSnapshotter.ArealExtent.v3Value;
- }
- else
- {
- // complain?
- }
- index = 0;
- }
- void UpdateRandomTickMarkTest()
- {
- var image = Tick8;
- var copy = Instantiate<Image>( image, image.transform.parent);
- copy.color = Random.ColorHSV();
- copy.transform.position = new Vector3(
- Random.Range( LowerLeft.position.x, UpperRight.position.x),
- Random.Range( LowerLeft.position.y, UpperRight.position.y),
- 0);
- copy.gameObject.SetActive( true);
- }
- const float MinDistance = 2;
- Vector3 LastUIPosition;
- void CreateFlightDataEventIcon( Vector3 UIPosition, FlightDataEventFlags flags)
- {
- var icon = Instantiate<FlightDataEventIcon>( FlightDataEventIconTemplate, FlightDataEventIconTemplate.transform.parent);
- icon.transform.position = UIPosition;
- icon.gameObject.SetActive( true);
- icon.InjectFlightDataEventFlags(flags);
- }
- void UpdateRenderNextPoint()
- {
- while( true)
- {
- if (index >= FlightDataRecorder.Instance.NumPoints())
- {
- return;
- }
- var pt = FlightDataRecorder.Instance.GetDatapoint( index);
- index++;
- var pos = pt.position;
- pos -= LevelSnapshotter_Position;
- // fraction of areal extent
- float fx = Mathf.InverseLerp(
- -LevelSnapshotter_ArealExtent.x,
- LevelSnapshotter_ArealExtent.x,
- pos.x);
- float fz = Mathf.InverseLerp(
- -LevelSnapshotter_ArealExtent.z,
- LevelSnapshotter_ArealExtent.z,
- pos.z);
- // now into UI space
- float px = Mathf.Lerp( LowerLeft.position.x, UpperRight.position.x, fx);
- float py = Mathf.Lerp( LowerLeft.position.y, UpperRight.position.y, fz);
- Vector3 UIPosition = new Vector3( px, py, 0);
- if (pt.flags != 0)
- {
- CreateFlightDataEventIcon( UIPosition, pt.flags);
- }
- if (Vector3.Distance( UIPosition, LastUIPosition) > MinDistance)
- {
- LastUIPosition = UIPosition;
- var image = Tick2;
- var copy = Instantiate<Image>( image, image.transform.parent);
- copy.color = new Color( 0.0f, 1.0f, 0.0f);
- copy.transform.position = UIPosition;
- copy.gameObject.SetActive( true);
- return;
- }
- }
- }
- void Update()
- {
- UpdateRenderNextPoint();
- }
- void OnUserInput( Datasack ds)
- {
- switch(ds.Value)
- {
- case "ButtonBack":
- FlightDataLog.DoEscape();
- break;
- case "ButtonDataLog":
- DoDataLog();
- break;
- }
- }
- void OnEnable()
- {
- DSM.UserIntent.OnChanged += OnUserInput;
- }
- void OnDisable()
- {
- DSM.UserIntent.OnChanged -= OnUserInput;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement