smart-interactive-display/Assets/GadGame/Scripts/MainFlow.cs

66 lines
2.1 KiB
C#
Raw Normal View History

using System;
using GadGame.Manager;
2024-04-11 01:55:35 -07:00
using GadGame.SO;
using GadGame.State;
2024-04-15 04:10:00 -07:00
using GadGame.State.MainFlowState;
using Sirenix.OdinInspector;
2024-05-24 01:16:15 -07:00
using GadGame.Network;
2024-06-18 23:34:19 -07:00
using UnityEngine;
using System.Net.NetworkInformation;
2024-04-11 01:55:35 -07:00
2024-04-15 04:10:00 -07:00
namespace GadGame
2024-04-11 01:55:35 -07:00
{
public class MainFlow : SingletonStateRunner<MainFlow>
2024-04-11 01:55:35 -07:00
{
public SceneFlowConfig SceneFlowConfig;
public event Action<float> OnReadyCountDown;
2024-06-18 23:34:19 -07:00
public event Action<bool> OnReady;
2024-04-11 01:55:35 -07:00
2024-05-24 01:16:15 -07:00
protected override async void Awake()
2024-04-11 01:55:35 -07:00
{
base.Awake();
DontDestroyOnLoad(gameObject);
2024-06-18 23:34:19 -07:00
string _macAddress = GetMacAddressString();
Debug.Log(_macAddress);
await P4PGraphqlManager.Instance.LoginMachine(_macAddress);
2024-04-11 01:55:35 -07:00
}
2024-04-25 04:54:33 -07:00
private async void Start()
2024-04-11 01:55:35 -07:00
{
2024-04-25 04:54:33 -07:00
await LoadSceneManager.Instance.LoadSceneWithTransitionAsync(SceneFlowConfig.PassByScene.ScenePath);
2024-04-15 04:10:00 -07:00
SetState<IdleState>();
2024-04-11 01:55:35 -07:00
}
public void ReadyCountDown(float duration)
{
OnReadyCountDown?.Invoke(duration);
}
public void Ready(bool ready)
{
OnReady?.Invoke(ready);
}
2024-06-18 23:34:19 -07:00
private string GetMacAddressString()
{
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in networkInterfaces)
{
// Filter out loopback and virtual interfaces
if (networkInterface.NetworkInterfaceType != NetworkInterfaceType.Ethernet &&
networkInterface.NetworkInterfaceType != NetworkInterfaceType.Wireless80211)
continue;
PhysicalAddress physicalAddress = networkInterface.GetPhysicalAddress();
byte[] bytes = physicalAddress.GetAddressBytes();
string macAddress = "";
for (int i = 0; i < bytes.Length; i++)
{
macAddress += bytes[i].ToString("X2");
}
return macAddress;
}
return "";
}
2024-04-11 01:55:35 -07:00
}
}