builds
This commit is contained in:
1314
Scripts/Statistics/GraphHandler.cs
Normal file
1314
Scripts/Statistics/GraphHandler.cs
Normal file
File diff suppressed because it is too large
Load Diff
143
Scripts/Statistics/GraphPanelScript.cs
Normal file
143
Scripts/Statistics/GraphPanelScript.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using Assets.Scripts;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
using XCharts.Runtime;
|
||||
|
||||
public class GraphPanelScript : MonoBehaviour
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public SessionData Session { get; private set; }
|
||||
public LineChart LineChart {get; set; }
|
||||
|
||||
#endregion
|
||||
#region VARIABLES
|
||||
|
||||
//public VisualTreeAsset graphPanelTemplate;
|
||||
//public RenderTexture renderTexture;
|
||||
|
||||
|
||||
public UIDocument _document;
|
||||
private StatsMenuController _statsController;
|
||||
|
||||
|
||||
|
||||
private VisualElement root;
|
||||
private VisualElement graphContainer;
|
||||
private VisualElement graphPanel;
|
||||
|
||||
private VisualElement[,] anchors;
|
||||
|
||||
#endregion
|
||||
#region EVENTS
|
||||
|
||||
#endregion
|
||||
#region ENDPOINTS
|
||||
|
||||
|
||||
#endregion
|
||||
#region METHODS
|
||||
|
||||
////void UpdateChartPositionAndSize(RectTransform chartRectTransform, VisualElement chartContainer)
|
||||
////{
|
||||
//// // Obtenir les dimensions et la position du conteneur en pixels
|
||||
//// Rect containerRect = chartContainer.worldBound;
|
||||
|
||||
//// // Convertir la position du VisualElement en coordonn<6E>es du Canvas
|
||||
//// var canvasRectTransform = _statsController.Canvas.GetComponent<RectTransform>();
|
||||
//// Vector2 containerSize = containerRect.size;
|
||||
//// Vector2 containerPosition = containerRect.position - new Vector2(canvasRectTransform.rect.width / 2, canvasRectTransform.rect.height / 2);
|
||||
|
||||
//// // Ajuster la taille et la position du RectTransform pour qu'il corresponde au VisualElement
|
||||
//// chartRectTransform.anchorMin = Vector2.zero;
|
||||
//// chartRectTransform.anchorMax = Vector2.zero;
|
||||
//// chartRectTransform.pivot = new Vector2(0.5f, 0.5f);
|
||||
//// chartRectTransform.sizeDelta = containerSize;
|
||||
//// chartRectTransform.anchoredPosition = containerPosition;
|
||||
////}
|
||||
|
||||
void UpdateChartPositionAndSize(int anchorRow, int anchorCol)
|
||||
{
|
||||
//if (anchorRow < 0 || anchorRow >= 3 || anchorCol < 0 || anchorCol >= 3)
|
||||
//{
|
||||
// Debug.LogError("Invalid anchor position");
|
||||
// return;
|
||||
//}
|
||||
|
||||
//VisualElement anchor = anchors[anchorRow, anchorCol];
|
||||
|
||||
// Positionner le LineChart
|
||||
//RectTransform lineChartRectTransform = LineChart.GetComponent<RectTransform>();
|
||||
|
||||
//lineChartRectTransform.anchoredPosition = new Vector3(480, -184, -1);
|
||||
}
|
||||
|
||||
//private Vector2 ConvertUIToCanvasPosition(VisualElement uiElement)
|
||||
//{
|
||||
// // Trouver la cam<61>ra
|
||||
// Camera camera = Camera.main;
|
||||
|
||||
// // Trouver la position de l'ancre dans l'espace du monde
|
||||
// Vector3 worldPosition = uiElement.worldBound.center;
|
||||
|
||||
// // Convertir la position du monde en position de l'<27>cran
|
||||
// Vector3 screenPosition = camera.WorldToScreenPoint(worldPosition);
|
||||
|
||||
// // Convertir la position de l'<27>cran en position de la toile (canvas)
|
||||
// RectTransform canvasRectTransform = lineChart.GetComponentInParent<Canvas>().GetComponent<RectTransform>();
|
||||
// Vector2 canvasPosition;
|
||||
// RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, screenPosition, camera, out canvasPosition);
|
||||
|
||||
// return canvasPosition;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#region LIFECYCLE
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
_statsController = StatsMenuController.Instance;
|
||||
_document = _statsController.GetComponent<UIDocument>();
|
||||
root = _document.rootVisualElement;
|
||||
|
||||
graphContainer = root.Q<VisualElement>("ChartsParentContainer");
|
||||
|
||||
LineChart = gameObject.GetComponent<LineChart>();
|
||||
|
||||
var serie = LineChart.AddSerie<Line>();
|
||||
serie.AddXYData(0, 10);
|
||||
serie.AddXYData(1, 20);
|
||||
serie.AddXYData(2, 15);
|
||||
|
||||
// Synchroniser la position et les dimensions du LineChart avec le VisualElement
|
||||
RectTransform chartRectTransform = LineChart.GetComponent<RectTransform>();
|
||||
|
||||
|
||||
graphContainer.style.width = new StyleLength(Length.Percent(100));
|
||||
graphContainer.style.height = new StyleLength(Length.Percent(100));
|
||||
|
||||
anchors = new VisualElement[3, 3];
|
||||
int k = 0;
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
k++;
|
||||
anchors[i, j] = graphContainer.Q<VisualElement>($"Anchor{k}");
|
||||
}
|
||||
}
|
||||
|
||||
UpdateChartPositionAndSize(1, 1);
|
||||
//graphContainer.RegisterCallback<GeometryChangedEvent>(evt => UpdateChartPositionAndSize(lineChart.GetComponent<RectTransform>(), 1, 1, 300, 200));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
331
Scripts/Statistics/GraphSettings.cs
Normal file
331
Scripts/Statistics/GraphSettings.cs
Normal file
@@ -0,0 +1,331 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class GraphSettings : MonoBehaviour
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[Header("Graph Settings")]
|
||||
[Space]
|
||||
public int updatePeriod = 5;
|
||||
[SerializeField] private Vector2 graphSize = new Vector2(800f, 400f);
|
||||
public Vector2 GraphSize
|
||||
{
|
||||
get { return graphSize; }
|
||||
set { graphSize = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePositionAndScale | UpdateMethod.UpdateContent | UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[SerializeField] private Vector2 graphScale = new Vector2(100f, 100f);
|
||||
public Vector2 GraphScale
|
||||
{
|
||||
get { return graphScale; }
|
||||
set { graphScale = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePositionAndScale | UpdateMethod.UpdateContent | UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[Header("Graph Visuals")]
|
||||
[Space]
|
||||
[SerializeField] private Color backgroundColor = new Color(0, 0, 0, 1f);
|
||||
public Color BackgroundColor
|
||||
{
|
||||
get { return backgroundColor; }
|
||||
set { backgroundColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateOutlines); }
|
||||
}
|
||||
[SerializeField] private float outlineWidth = 5f;
|
||||
public float OutlineWidth
|
||||
{
|
||||
get { return outlineWidth; }
|
||||
set { outlineWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdateOutlines); }
|
||||
}
|
||||
|
||||
[SerializeField] private Color outlineColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color OutlineColor
|
||||
{
|
||||
get { return outlineColor; }
|
||||
set { outlineColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateOutlines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float lineWidth = 8f;
|
||||
public float LineWidth
|
||||
{
|
||||
get { return lineWidth; }
|
||||
set { lineWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdateContent); }
|
||||
}
|
||||
[SerializeField] private Color lineColor = new Color(1f, 0.35f, 0f, 1f);
|
||||
public Color LineColor
|
||||
{
|
||||
get { return lineColor; }
|
||||
set { lineColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateContent); }
|
||||
}
|
||||
[Space]
|
||||
public Sprite PointSprite;
|
||||
[SerializeField] private float pointRadius = 5f;
|
||||
public float PointRadius
|
||||
{
|
||||
get { return pointRadius; }
|
||||
set { pointRadius = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[SerializeField] private Color pointColor = new Color(1f, 0.35f, 0f, 1f);
|
||||
public Color PointColor
|
||||
{
|
||||
get { return pointColor; }
|
||||
set { pointColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float pointHoverRadius = 15f;
|
||||
public float PointHoverRadius
|
||||
{
|
||||
get { return pointHoverRadius; }
|
||||
set { pointHoverRadius = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
public float PointHoverSpeed = 5f;
|
||||
|
||||
[SerializeField] private Color pointHoverColor = new Color(1, 0.6f, 0, 1f);
|
||||
public Color PointHoverColor
|
||||
{
|
||||
get { return pointHoverColor; }
|
||||
set { pointHoverColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float pointLockedRadius = 17f;
|
||||
public float PointLockedRadius
|
||||
{
|
||||
get { return pointLockedRadius; }
|
||||
set { pointLockedRadius = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
public float PointLockedSpeed = 5f;
|
||||
|
||||
[SerializeField] private Color pointLockedColor = new Color(1, 0.8f, 0, 1f);
|
||||
public Color PointLockedColor
|
||||
{
|
||||
get { return pointLockedColor; }
|
||||
set { pointLockedColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float unfixedPointOutlineWidth = 10f;
|
||||
public float UnfixedPointOutlineWidth
|
||||
{
|
||||
get { return unfixedPointOutlineWidth; }
|
||||
set { unfixedPointOutlineWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[SerializeField] private Color unfixedPointOutlineColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color UnfixedPointOutlineColor
|
||||
{
|
||||
get { return unfixedPointOutlineColor; }
|
||||
set { unfixedPointOutlineColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float unfixedPointOutlineHoverWidth = 15f;
|
||||
public float UnfixedPointOutlineHoverWidth
|
||||
{
|
||||
get { return unfixedPointOutlineHoverWidth; }
|
||||
set { unfixedPointOutlineHoverWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
public float UnfixedPointOutlineHoverSpeed = 5f;
|
||||
|
||||
[Space]
|
||||
[SerializeField] private Color unfixedPointOutlineHoverColor = new Color(0, 0.5f, 1f, 1f);
|
||||
public Color UnfixedPointOutlineHoverColor
|
||||
{
|
||||
get { return unfixedPointOutlineHoverColor; }
|
||||
set { unfixedPointOutlineHoverColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float fixedPointOutlineWidth = 17f;
|
||||
public float FixedPointOutlineWidth
|
||||
{
|
||||
get { return fixedPointOutlineWidth; }
|
||||
set { fixedPointOutlineWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
public float FixedPointOutlineSpeed = 5f;
|
||||
[SerializeField] private Color fixedPointOutlineColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color FixedPointOutlineColor
|
||||
{
|
||||
get { return fixedPointOutlineColor; }
|
||||
set { fixedPointOutlineColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdatePointVisuals); }
|
||||
}
|
||||
|
||||
[Space]
|
||||
[Header("Grid Settings")]
|
||||
[Space]
|
||||
|
||||
public TMP_FontAsset GridTextFont;
|
||||
[SerializeField] private Vector2 gridSpacing = new Vector2(1, 1);
|
||||
public Vector2 GridSpacing
|
||||
{
|
||||
get { return gridSpacing; }
|
||||
set { gridSpacing = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float xAxisWidth = 3f;
|
||||
public float XAxisWidth
|
||||
{
|
||||
get { return xAxisWidth; }
|
||||
set { xAxisWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
|
||||
[SerializeField] private Color xAxisColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color XAxisColor
|
||||
{
|
||||
get { return xAxisColor; }
|
||||
set { xAxisColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private Color xAxisTextColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color XAxisTextColor
|
||||
{
|
||||
get { return xAxisTextColor; }
|
||||
set { xAxisTextColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[SerializeField] private float xAxisTextSize = 10f;
|
||||
public float XAxisTextSize
|
||||
{
|
||||
get { return xAxisTextSize; }
|
||||
set { xAxisTextSize = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[SerializeField] private float xAxisTextOffset = 10f;
|
||||
public float XAxisTextOffset
|
||||
{
|
||||
get { return xAxisTextOffset; }
|
||||
set { xAxisTextOffset = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float yAxisWidth = 3f;
|
||||
public float YAxisWidth
|
||||
{
|
||||
get { return yAxisWidth; }
|
||||
set { yAxisWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
|
||||
[SerializeField] private Color yAxisColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color YAxisColor
|
||||
{
|
||||
get { return yAxisColor; }
|
||||
set { yAxisColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private Color yAxisTextColor = new Color(0, 0.8f, 1f, 1f);
|
||||
public Color YAxisTextColor
|
||||
{
|
||||
get { return yAxisTextColor; }
|
||||
set { yAxisTextColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[SerializeField] private float yAxisTextSize = 10f;
|
||||
public float YAxisTextSize
|
||||
{
|
||||
get { return yAxisTextSize; }
|
||||
set { yAxisTextSize = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[SerializeField] private float yAxisTextOffset = 10f;
|
||||
public float YAxisTextOffset
|
||||
{
|
||||
get { return yAxisTextOffset; }
|
||||
set { yAxisTextOffset = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float xGridWidth = 2f;
|
||||
public float XGridWidth
|
||||
{
|
||||
get { return xGridWidth; }
|
||||
set { xGridWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[SerializeField] private Color xGridColor = new Color(0, 0.8f, 1f, 0.6f);
|
||||
public Color XGridColor
|
||||
{
|
||||
get { return xGridColor; }
|
||||
set { xGridColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private float yGridWidth = 2f;
|
||||
public float YGridWidth
|
||||
{
|
||||
get { return yGridWidth; }
|
||||
set { yGridWidth = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
|
||||
[SerializeField] private Color yGridColor = new Color(0, 0.8f, 1f, 0.6f);
|
||||
public Color YGridColor
|
||||
{
|
||||
get { return yGridColor; }
|
||||
set { yGridColor = value; GH.UpdateGraphInternal(UpdateMethod.UpdateGridLines); }
|
||||
}
|
||||
|
||||
[Space]
|
||||
[SerializeField] private Color zoomSelectionColor = new Color(0, 0.8f, 1f, 0.2f);
|
||||
public Color ZoomSelectionColor
|
||||
{
|
||||
get { return zoomSelectionColor; }
|
||||
set { zoomSelectionColor = value; GH.UpdateGraphInternal(UpdateMethod.MouseAction); }
|
||||
}
|
||||
[SerializeField] private float zoomSelectionOutlineWidth = 5f;
|
||||
public float ZoomSelectionOutlineWidth
|
||||
{
|
||||
get { return zoomSelectionOutlineWidth; }
|
||||
set { zoomSelectionOutlineWidth = value; GH.UpdateGraphInternal(UpdateMethod.MouseAction); }
|
||||
}
|
||||
[SerializeField] private Color zoomSelectionOutlineColor = new Color(0, 0.8f, 1f, 0.6f);
|
||||
public Color ZoomSelectionOutlineColor
|
||||
{
|
||||
get { return zoomSelectionOutlineColor; }
|
||||
set { zoomSelectionOutlineColor = value; GH.UpdateGraphInternal(UpdateMethod.MouseAction); }
|
||||
}
|
||||
[Space]
|
||||
[SerializeField] private Color pointSelectionColor = new Color(1, 0.35f, 0f, 0.2f);
|
||||
public Color PointSelectionColor
|
||||
{
|
||||
get { return pointSelectionColor; }
|
||||
set { pointSelectionColor = value; GH.UpdateGraphInternal(UpdateMethod.MouseAction); }
|
||||
}
|
||||
[SerializeField] private float pointSelectionOutlineWidth = 5f;
|
||||
public float PointSelectionOutlineWidth
|
||||
{
|
||||
get { return pointSelectionOutlineWidth; }
|
||||
set { pointSelectionOutlineWidth = value; GH.UpdateGraphInternal(UpdateMethod.MouseAction); }
|
||||
}
|
||||
[SerializeField] private Color pointSelectionOutlineColor = new Color(1, 0.35f, 0f, 0.4f);
|
||||
public Color PointSelectionOutlineColor
|
||||
{
|
||||
get { return pointSelectionOutlineColor; }
|
||||
set { pointSelectionOutlineColor = value; GH.UpdateGraphInternal(UpdateMethod.MouseAction); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region VARIABLES
|
||||
|
||||
[Space]
|
||||
public float ZoomSpeed = 5f;
|
||||
public float SmoothZoomSpeed = 20f;
|
||||
public float SmoothMoveSpeed = 20f;
|
||||
|
||||
private GraphHandler GH;
|
||||
|
||||
#endregion
|
||||
#region EVENTS
|
||||
|
||||
|
||||
#endregion
|
||||
#region ENDPOINTS
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#region METHODS
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#region LIFECYCLE
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GH = GetComponent<GraphHandler>();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
71
Scripts/Statistics/SessionsListView.cs
Normal file
71
Scripts/Statistics/SessionsListView.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class SessionsListView : MonoBehaviour
|
||||
{
|
||||
#region PROPERTIES
|
||||
#endregion
|
||||
#region VARIABLES
|
||||
|
||||
[SerializeField] private UIDocument uiDocument;
|
||||
private StatsMenuController _statsController;
|
||||
|
||||
#endregion
|
||||
#region EVENTS
|
||||
|
||||
private void OnButtonClick(SessionData sessionData)
|
||||
{
|
||||
_statsController.OnSessionSelected(sessionData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region METHODS
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#region LIFECYCLE
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_statsController = StatsMenuController.Instance;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var sessionDataList = _statsController.Sessions;
|
||||
var root = uiDocument.rootVisualElement;
|
||||
|
||||
var listView = root.Q<ListView>("ListViewSessions");
|
||||
|
||||
listView.itemsSource = sessionDataList;
|
||||
listView.makeItem = () => new Button();
|
||||
listView.bindItem = (element, index) =>
|
||||
{
|
||||
var button = element as Button;
|
||||
var sessionData = sessionDataList[index];
|
||||
button.text = $"Session {sessionData.SessionNumber} | {sessionData.Date.ToString("ddd, dd MMM yyy")}";
|
||||
button.AddToClassList("list-button");
|
||||
button.style.backgroundColor = new Color(0, 0, 0, 0.2f);
|
||||
button.style.height = 50;
|
||||
button.style.marginLeft = 10;
|
||||
button.style.marginRight = 10;
|
||||
button.style.marginBottom = 2;
|
||||
button.style.color = Color.white;
|
||||
// Ajouter un callback pour lorsque le bouton est cliqu<71>
|
||||
button.clicked += () => OnButtonClick(sessionData);
|
||||
};
|
||||
|
||||
listView.fixedItemHeight = 52;
|
||||
listView.selectionType = SelectionType.Single;
|
||||
listView.style.flexGrow = 1.0f;
|
||||
|
||||
listView.Rebuild();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
180
Scripts/Statistics/StatsMenuController.cs
Normal file
180
Scripts/Statistics/StatsMenuController.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using Assets.Scripts;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
using XCharts.Runtime;
|
||||
|
||||
public class StatsMenuController : SingletonMB<StatsMenuController>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public List<SessionData> Sessions { get; private set; }
|
||||
public Canvas Canvas { get { return _canvas; } private set { _canvas = value; } }
|
||||
[SerializeField] private Canvas _canvas;
|
||||
|
||||
#endregion
|
||||
#region VARIABLES
|
||||
|
||||
[SerializeField] private GameObject graphPanelTemplate;
|
||||
private UIDocument _document;
|
||||
private Button _exitButton;
|
||||
private Button _storageButton;
|
||||
private List<LineChart> lineCharts;
|
||||
|
||||
#endregion
|
||||
#region EVENTS
|
||||
|
||||
private void OnExitButton(ClickEvent e)
|
||||
{
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
}
|
||||
private void OnStorageButton(ClickEvent e)
|
||||
{
|
||||
string path = Path.Combine(Application.persistentDataPath, "SessionsData");
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.RevealInFinder(path);
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
path = path.Replace("/", "\\"); // Remplacer les / par \ pour Windows
|
||||
Process.Start("explorer.exe", path);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
Process.Start("open", path);
|
||||
#elif UNITY_STANDALONE_LINUX
|
||||
Process.Start("xdg-open", path);
|
||||
#else
|
||||
Debug.LogWarning("Opening the file explorer is not supported on this platform.");
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region ENDPOINTS
|
||||
|
||||
public void OnSessionSelected(SessionData session)
|
||||
{
|
||||
if (lineCharts != null)
|
||||
{
|
||||
for (int i = 0; i < lineCharts.Count; i++)
|
||||
{
|
||||
Destroy(lineCharts[i]);
|
||||
}
|
||||
lineCharts.Clear();
|
||||
}
|
||||
|
||||
UnityEngine.Debug.Log("Session Chart " + session.SessionNumber);
|
||||
|
||||
int n = 0;
|
||||
foreach (var attempt in session.Attempts)
|
||||
{
|
||||
n++;
|
||||
if (n > 4) break;
|
||||
|
||||
var instance = Instantiate(graphPanelTemplate, Canvas.transform).GetComponent<GraphPanelScript>().LineChart;
|
||||
instance.RemoveAllSerie();
|
||||
|
||||
lineCharts.Add(instance);
|
||||
|
||||
|
||||
var position = new Vector3(480, -184, -1);
|
||||
var nextColumnPosition = new Vector3(instance.chartWidth + 2, 0, 0);
|
||||
var nextLinePosition = new Vector3(0, -instance.chartHeight - 2, 0);
|
||||
switch (lineCharts.IndexOf(instance))
|
||||
{
|
||||
case 0:
|
||||
instance.GetComponent<RectTransform>().anchoredPosition = position;
|
||||
break;
|
||||
case 1:
|
||||
instance.GetComponent<RectTransform>().anchoredPosition = position + nextColumnPosition;
|
||||
break;
|
||||
case 2:
|
||||
instance.GetComponent<RectTransform>().anchoredPosition = position + nextLinePosition;
|
||||
break;
|
||||
case 3:
|
||||
instance.GetComponent<RectTransform>().anchoredPosition = position + nextLinePosition + nextColumnPosition;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Definir nom de la chart
|
||||
var chartName = instance.EnsureChartComponent<Title>();
|
||||
chartName.text = $"Scores dans le temps | round {attempt.AttemptNumber}";
|
||||
|
||||
|
||||
// D<>finir les noms des axes
|
||||
var xAxis = instance.EnsureChartComponent<XAxis>();
|
||||
xAxis.type = Axis.AxisType.Value;
|
||||
AxisName xName = new();
|
||||
xName.name = "Temps (ticks)";
|
||||
xAxis.axisName = xName;
|
||||
|
||||
var yAxis = instance.EnsureChartComponent<YAxis>();
|
||||
yAxis.type = Axis.AxisType.Value;
|
||||
AxisName yName = new();
|
||||
yName.name = "Score";
|
||||
yAxis.axisName = yName;
|
||||
|
||||
// Ajouter une l<>gende
|
||||
var legend = instance.EnsureChartComponent<Legend>();
|
||||
legend.show = true;
|
||||
|
||||
foreach (var playerAttempt in attempt.PlayersAttempts)
|
||||
{
|
||||
var scoreOverTime = playerAttempt.Value.PlayerScoresOverTicksTime;
|
||||
|
||||
// Ajouter une nouvelle s<>rie avec une l<>gende
|
||||
var serie = instance.AddSerie<Line>(playerAttempt.Value.PlayerName);
|
||||
serie.serieName = playerAttempt.Value.PlayerName;
|
||||
//serie.legendName = playerAttempt.Value.PlayerName;
|
||||
scoreOverTime.ForEach(score =>
|
||||
{
|
||||
serie.AddXYData(score.X, score.Y);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#region METHODS
|
||||
|
||||
private List<SessionData> LoadSessionData()
|
||||
{
|
||||
string directoryPath = Path.Combine(Application.persistentDataPath, "SessionsData");
|
||||
var sessionDataList = new List<SessionData>();
|
||||
|
||||
var files = Directory.GetFiles(directoryPath, "*.json");
|
||||
foreach (var file in files)
|
||||
{
|
||||
var json = File.ReadAllText(file);
|
||||
var sessionData = JsonConvert.DeserializeObject<SessionData>(json);
|
||||
sessionDataList.Add(sessionData);
|
||||
}
|
||||
|
||||
return sessionDataList.OrderBy<SessionData, int>(s => s.SessionNumber).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region LIFECYCLE
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
Sessions = LoadSessionData();
|
||||
|
||||
_document = GetComponent<UIDocument>();
|
||||
_exitButton = _document.rootVisualElement.Q("ExitButton") as Button;
|
||||
_exitButton.RegisterCallback<ClickEvent>(OnExitButton);
|
||||
_storageButton = _document.rootVisualElement.Q("StorageButton") as Button;
|
||||
_storageButton.RegisterCallback<ClickEvent>(OnStorageButton);
|
||||
|
||||
lineCharts = new();
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
Reference in New Issue
Block a user