Unity Position Tracker Metric

During one of our classes we got the assignment to make a metric for unity. I thought it would be useful to be able to track the players movement in game and then be able to redraw it.

Because we got this assignment during Rapid Prototyping we were only allowed to work on it for 90 minutes at a time, once a week and for only around 4 weeks. I unfortunately lost the version I made during this period so I tried to recreate it later in about the same time span.

Challenges:

This was my first time working with XML, I used XML because I wanted it to be understandable even if you went to just read the file.

Another challenge was serializing the transform of an object which I ended up working around using structs and classes.


Specifications:

The tool was made in Unity with C#, it also makes use of XML.

public void Save(string path)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(PlayerDataList));
        using (FileStream stream = new FileStream(path, FileMode.Create))
        {
            serializer.Serialize(stream, _PLayerDatas);
        }
    }

    public void AddPlayerData(PlayerData data)
    {
        Debug.Log(data.Position);
        _PLayerDatas.Add(data);
    }

    public int GetPlayerDataListCount()
    {
        return _PLayerDatas.list.Count;
    }

    public static PlayerDataList Load(string path)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(PlayerDataList));
        using (FileStream stream = new FileStream(path, FileMode.Open))
        {
            return (PlayerDataList)serializer.Deserialize(stream);
        }
    }

    public static PlayerData LoadFromText(string text)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(PlayerData));
        return (PlayerData)serializer.Deserialize(new StringReader(text));
    }
LineRenderer _LineRenderer;
    MovementTrackerXML _MovementTrackerXML;

    private List<Vector3> _Positions;

	private void Start ()
    {
        _Positions = new List<Vector3>();

        _MovementTrackerXML = FindObjectOfType<MovementTrackerXML>();
        _LineRenderer = GetComponent<LineRenderer>();

        PlayerDataList playerDataList = MovementTrackerXML.Load(Path.Combine(Application.persistentDataPath, "Positions.xml"));

        Debug.Log(playerDataList.list.Count);
       
        for(int i = 0; i < playerDataList.list.Count; i++)
        {
            _Positions.Add(playerDataList.list[i].Position);
        }

        Debug.Log(_Positions.Count);

        _LineRenderer.positionCount = _Positions.Count;
        _LineRenderer.SetPositions(_Positions.ToArray());
    }