Made serilaized static values be set

This commit is contained in:
2026-01-26 16:00:04 +00:00
parent edc272945c
commit 728464a327
6 changed files with 17 additions and 22 deletions

View File

@@ -46,15 +46,6 @@ namespace PashaBibko.Pacore.Editor.Drawers
public static void DrawStaticFields(Object target)
{
Type type = target.GetType();
AllowStaticInspectorFieldsAttribute attr = type.GetCustomAttribute<AllowStaticInspectorFieldsAttribute>();
if (attr == null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Static Fields (disabled for class)", EditorStyles.boldLabel);
return;
}
StaticInspectorFieldCache.FieldData[] fields
= StaticInspectorFieldCache.GetAllFieldsOfType(type);

View File

@@ -2,9 +2,6 @@
namespace PashaBibko.Pacore.Attributes
{
[AttributeUsage(validOn: AttributeTargets.Class)]
public class AllowStaticInspectorFieldsAttribute : Attribute { }
[AttributeUsage(validOn: AttributeTargets.Field)]
public class StaticInspectorFieldAttribute : Attribute { }
}

View File

@@ -1,9 +1,8 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System;
using PashaBibko.Pacore.DevTools;
using PashaBibko.Pacore.Data;
using UnityEngine;
namespace PashaBibko.Pacore
@@ -54,6 +53,10 @@ namespace PashaBibko.Pacore
AttributeCache[type].Add(current);
}
}
/* Initializes PacoreDataLoader as it requires this to have been loaded first */
// TODO: Add a way for this to trigger an event that can be run by other scripts dynamically
PacoreDataLoader.LoadAndApplyStaticValues();
}
}
}

View File

@@ -14,8 +14,7 @@ namespace PashaBibko.Pacore.Data
public static string FullResourcesPath => Path.Join(Application.dataPath, BASE_PATH);
public static string ResourcesPath => Path.Join("Assets", BASE_PATH);
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
private static void LoadAndApplyStaticValues()
public static void LoadAndApplyStaticValues()
{
/* Loads the static values from the serialized file */
string filename = Path.Join(PATH_FROM_RESOURCES, "StaticFieldValues");

View File

@@ -36,6 +36,10 @@ namespace PashaBibko.Pacore.Threading
Instance = this;
}
private void OnDestroy()
{
Instance = null; // Allows the Dispatcher to be destroyed
}
public static void QueueMultistep(IEnumerator routine) => MainThreadMultistepQueue.Enqueue(routine);
public static void QueueImmediate(Action action) => MainThreadImmediateQueue.Enqueue(action);

View File

@@ -1,21 +1,22 @@
using PashaBibko.Pacore.Attributes;
using UnityEngine;
[CreateInstanceOnStart, AllowStaticInspectorFields]
public class TestMonoBehaviour : MonoBehaviour
[CreateInstanceOnStart] public class TestMonoBehaviour : MonoBehaviour
{
public int TestValue;
[StaticInspectorField] private static string StaticText;
[StaticInspectorField] private static string OtherStaticText;
[StaticInspectorField] private static int StaticInt;
[StaticInspectorField] private static int StaticInt = 0;
[StaticInspectorField] private static int OtherStaticInt = 0;
[InspectorCallable(nameof(PrintStaticFields))]
public void PrintStaticFields()
{
Debug.Log
(
$"{nameof(TestValue)}: [{TestValue}] " +
$"{nameof(StaticInt)}: [{StaticInt}] " +
$"{nameof(OtherStaticInt)}: [{OtherStaticInt}] " +
$"{nameof(StaticText)}: [{StaticText}] " +
$"{nameof(OtherStaticText)}: [{OtherStaticText}]"
);