na most talán ez a geci mukodik???
This commit is contained in:
114
Main.cs
114
Main.cs
@@ -9,11 +9,11 @@ using KCM.Packets.State;
|
||||
using KCM.StateManagement.Observers;
|
||||
using KCM.StateManagement.Sync;
|
||||
using KCM.StateManagement.BuildingState;
|
||||
using KCM.Enums;
|
||||
using Riptide;
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
@@ -74,7 +74,7 @@ namespace KCM
|
||||
if (helper != null)
|
||||
helper.Log(message ?? string.Empty);
|
||||
else
|
||||
Debug.Log(message ?? string.Empty);
|
||||
UnityEngine.Debug.Log(message ?? string.Empty);
|
||||
}
|
||||
|
||||
public static void Log(Exception ex)
|
||||
@@ -104,6 +104,116 @@ namespace KCM
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(scene);
|
||||
}
|
||||
|
||||
public static void TransitionTo(MenuState menuState)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GameState.inst != null && GameState.inst.mainMenuMode != null)
|
||||
{
|
||||
GameState.inst.SetNewMode(GameState.inst.mainMenuMode);
|
||||
SetMainMenuState(GameState.inst.mainMenuMode, (int)menuState);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log(ex);
|
||||
}
|
||||
|
||||
TransitionTo(menuState.ToString());
|
||||
}
|
||||
|
||||
private static void SetMainMenuState(object mainMenuMode, int menuStateValue)
|
||||
{
|
||||
if (mainMenuMode == null)
|
||||
return;
|
||||
|
||||
Type type = mainMenuMode.GetType();
|
||||
const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
|
||||
string[] methodNames = new string[]
|
||||
{
|
||||
"SetMenuState",
|
||||
"SetState",
|
||||
"GoToState",
|
||||
"GotoState",
|
||||
"TransitionToState",
|
||||
"TransitionTo",
|
||||
};
|
||||
|
||||
MethodInfo[] methods = type.GetMethods(flags);
|
||||
for (int i = 0; i < methodNames.Length; i++)
|
||||
{
|
||||
string name = methodNames[i];
|
||||
for (int j = 0; j < methods.Length; j++)
|
||||
{
|
||||
MethodInfo method = methods[j];
|
||||
if (method == null || method.Name != name)
|
||||
continue;
|
||||
|
||||
ParameterInfo[] parameters = method.GetParameters();
|
||||
if (parameters == null || parameters.Length != 1)
|
||||
continue;
|
||||
|
||||
Type paramType = parameters[0].ParameterType;
|
||||
if (paramType == typeof(int))
|
||||
{
|
||||
method.Invoke(mainMenuMode, new object[] { menuStateValue });
|
||||
return;
|
||||
}
|
||||
|
||||
if (paramType != null && paramType.IsEnum)
|
||||
{
|
||||
object enumValue = Enum.ToObject(paramType, menuStateValue);
|
||||
method.Invoke(mainMenuMode, new object[] { enumValue });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FieldInfo[] fields = type.GetFields(flags);
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
FieldInfo field = fields[i];
|
||||
if (field == null)
|
||||
continue;
|
||||
|
||||
if (field.FieldType == typeof(int))
|
||||
{
|
||||
field.SetValue(mainMenuMode, menuStateValue);
|
||||
return;
|
||||
}
|
||||
|
||||
if (field.FieldType != null && field.FieldType.IsEnum)
|
||||
{
|
||||
field.SetValue(mainMenuMode, Enum.ToObject(field.FieldType, menuStateValue));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PropertyInfo[] properties = type.GetProperties(flags);
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
{
|
||||
PropertyInfo prop = properties[i];
|
||||
if (prop == null || !prop.CanWrite)
|
||||
continue;
|
||||
|
||||
if (prop.PropertyType == typeof(int))
|
||||
{
|
||||
prop.SetValue(mainMenuMode, menuStateValue, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop.PropertyType != null && prop.PropertyType.IsEnum)
|
||||
{
|
||||
prop.SetValue(mainMenuMode, Enum.ToObject(prop.PropertyType, menuStateValue), null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Log($"TransitionTo(MenuState) could not set state value={menuStateValue} on {type.FullName}");
|
||||
}
|
||||
|
||||
public static void ResetMultiplayerState()
|
||||
{
|
||||
// Reset multiplayer state
|
||||
|
||||
Reference in New Issue
Block a user