Essentials + extra crap
Loadings Startups Movement Camera
This commit is contained in:
1 parent
662f4a1d05
commit
5f5ace1b52
734 files changed
+107323
-1713
No files matched your search
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
namespace Code.Infrastructure.Generators
|
||||
{
|
||||
public class StateMachine : Attribute
|
||||
{
|
||||
public Type StateMachineContextType;
|
||||
public Type StateMachineEnumType;
|
||||
|
||||
public StateMachine(Type stateMachineContextType, Type stateMachineEnumType)
|
||||
{
|
||||
StateMachineContextType = stateMachineContextType;
|
||||
StateMachineEnumType = stateMachineEnumType;
|
||||
}
|
||||
}
|
||||
|
||||
public class State : Attribute
|
||||
{
|
||||
public Type StateEnum;
|
||||
public Type StateMachineContext;
|
||||
public bool SilentBitch; // Поэтому нейминг переменных очень важен
|
||||
|
||||
public State(Type stateEnum,Type stateMachineContext, bool silentBitch = false)
|
||||
{
|
||||
StateEnum = stateEnum;
|
||||
StateMachineContext = stateMachineContext;
|
||||
SilentBitch = silentBitch;
|
||||
}
|
||||
}
|
||||
public class StateRaisingEvent : Attribute
|
||||
{
|
||||
}
|
||||
public class Config : Attribute
|
||||
{
|
||||
public bool Multiple;
|
||||
public string MenuName;
|
||||
public Config(string menuName, bool multiple = false)
|
||||
{
|
||||
Multiple = multiple;
|
||||
MenuName = menuName;
|
||||
}
|
||||
}
|
||||
public class ToConfig : Attribute
|
||||
{
|
||||
}
|
||||
public class SceneIdEnum : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03e07712b53c4a3d8f6c8033af003369
|
||||
timeCreated: 1765563884
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Linq;
|
||||
using Unity.VisualScripting;
|
||||
using UnityCodeGen;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Code.Infrastructure.Generators
|
||||
{
|
||||
[Generator]
|
||||
public class ConfigGenerator : ICodeGenerator
|
||||
{
|
||||
public void Execute(GeneratorContext context)
|
||||
{
|
||||
var configs = TypeCache.GetTypesWithAttribute<Config>();
|
||||
|
||||
var configsCode = "";
|
||||
var configAddCode = "";
|
||||
var configReferencesCode = "";
|
||||
var configReferencesUsingsCode = "";
|
||||
var configOfConfigsCode = "";
|
||||
|
||||
foreach (var cfg in configs)
|
||||
{
|
||||
var configFields = "";
|
||||
var configUsings = "";
|
||||
|
||||
var mem = cfg.GetFields();
|
||||
var members = mem.Where(m => m.HasAttribute<ToConfig>()).ToList();
|
||||
foreach (var m in members)
|
||||
{
|
||||
configUsings += $"using {m.FieldType.Namespace};\n";
|
||||
configFields += $"public {m.FieldType.FullName} {m.Name};\n";
|
||||
}
|
||||
|
||||
var attribute = cfg.GetAttribute<Config>();
|
||||
|
||||
configUsings += @"
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
";
|
||||
var configCode = $@"
|
||||
#pragma warning disable CS0105
|
||||
{configUsings}
|
||||
namespace {cfg.Namespace}{{
|
||||
#pragma warning restore CS0105
|
||||
[CreateAssetMenu(fileName = ""{cfg.Name}Config"", menuName = ""{attribute.MenuName}"")]
|
||||
public class {cfg.Name}Config : ScriptableObject
|
||||
{{
|
||||
{configFields}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
context.AddCode($"{cfg.Name}Config.Generated.cs", configCode);
|
||||
|
||||
configReferencesUsingsCode += $"using {cfg.Namespace};\n";
|
||||
|
||||
if (attribute.Multiple)
|
||||
{
|
||||
configReferencesCode += $"public string {cfg.Name};\n";
|
||||
configAddCode += $@"
|
||||
_multipleConfigReferences.Add(typeof({cfg.FullName}Config), systemConfigsReferences.{cfg.Name});
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
configReferencesCode += $"public AssetReference {cfg.Name};\n";
|
||||
configAddCode += $@"
|
||||
_singleConfigReferences.Add(typeof({cfg.FullName}Config), systemConfigsReferences.{cfg.Name});
|
||||
";
|
||||
}
|
||||
}
|
||||
configsCode += $@"
|
||||
#pragma warning disable CS0105
|
||||
{configReferencesUsingsCode}
|
||||
using UnityEngine;
|
||||
#pragma warning restore CS0105
|
||||
|
||||
namespace Code.Infrastructure.Configs
|
||||
{{
|
||||
|
||||
public partial class ConfigLocator
|
||||
{{
|
||||
partial void LoadConfigs()
|
||||
{{
|
||||
SystemConfigsReferences systemConfigsReferences = Resources.Load<SystemConfigsReferences>(""SystemConfigsReferences"");
|
||||
{configAddCode}
|
||||
//_singleConfigReferences.Add(typeof(ScenesAssetReferences), systemConfigsReferences.scenesAssetReferences);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
context.AddCode($"ConfigLocator.Generated.cs", configsCode);
|
||||
|
||||
configOfConfigsCode += $@"
|
||||
#pragma warning disable CS0105
|
||||
{configReferencesUsingsCode}
|
||||
using UnityEngine.AddressableAssets;
|
||||
#pragma warning restore CS0105
|
||||
|
||||
namespace Code.Infrastructure.Configs{{
|
||||
public partial class SystemConfigsReferences
|
||||
{{
|
||||
{configReferencesCode}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
context.AddCode($"SystemConfigsReferences.Generated.cs", configOfConfigsCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 026403be8eae4546adcb407308031c1d
|
||||
timeCreated: 1765660396
|
||||
@@ -0,0 +1,148 @@
|
||||
using System.Linq;
|
||||
using Unity.VisualScripting;
|
||||
using UnityCodeGen;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Generators
|
||||
{
|
||||
[Generator]
|
||||
public class SceneLoaderGenerator : ICodeGenerator
|
||||
{
|
||||
public void Execute(GeneratorContext context)
|
||||
{
|
||||
var Enum = TypeCache.GetTypesWithAttribute<SceneIdEnum>();
|
||||
|
||||
var loaderCode = "";
|
||||
var dictionaryCode = "";
|
||||
var interfacesCode = "";
|
||||
var interfacesUsingsCode = $@"
|
||||
using Code.Infrastructure.EventBus;
|
||||
";
|
||||
|
||||
foreach (var en in Enum)
|
||||
{
|
||||
if (!en.IsEnum) return;
|
||||
|
||||
var members = en.GetFields();
|
||||
foreach (var member in members)
|
||||
{
|
||||
if(member.FieldType.FullName != en.FullName) continue;
|
||||
interfacesCode += $@"
|
||||
public interface IOn{member.Name}SceneLoadedHandler : IGlobalSubscriber
|
||||
{{
|
||||
void On{member.Name}SceneLoaded();
|
||||
}}
|
||||
";
|
||||
dictionaryCode += $@"
|
||||
|
||||
_scenesActions.Add(SceneId.{member.Name},() => _eventBus.RaiseEvent<IOn{member.Name}SceneLoadedHandler>(h=> h.On{member.Name}SceneLoaded()));
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
loaderCode = $@"
|
||||
#pragma warning disable CS0105
|
||||
{interfacesUsingsCode}
|
||||
#pragma warning restore CS0105
|
||||
|
||||
namespace Code.Infrastructure.SceneLoader
|
||||
{{
|
||||
public partial class SceneLoader{{
|
||||
partial void SetupScenesInfo(){{
|
||||
{dictionaryCode}
|
||||
}}
|
||||
}}
|
||||
{interfacesCode}
|
||||
}}
|
||||
";
|
||||
context.AddCode($"SceneLoader.Generated.cs", loaderCode);
|
||||
// var configsCode = "";
|
||||
// var configCode = "";
|
||||
// var configUsings = "";
|
||||
// var configFields = "";
|
||||
// var configAddCode = "";
|
||||
// var configReferencesCode = "";
|
||||
// var configReferencesUsingsCode = "";
|
||||
// var configOfConfigsCode = "";
|
||||
//
|
||||
// foreach (var cfg in configs)
|
||||
// {
|
||||
// var mem = cfg.GetFields();
|
||||
// var members = mem.Where(m => m.HasAttribute<ToConfig>()).ToList();
|
||||
// foreach (var m in members)
|
||||
// {
|
||||
// configUsings += $"using {m.FieldType.Namespace};\n";
|
||||
// configFields += $"public {m.FieldType.FullName} {m.Name};\n";
|
||||
// }
|
||||
//
|
||||
// var attribute = cfg.GetAttribute<Config>();
|
||||
//
|
||||
// configUsings += @"
|
||||
// using UnityEngine;
|
||||
// using UnityEngine.AddressableAssets;
|
||||
// ";
|
||||
// configCode = $@"
|
||||
// {configUsings}
|
||||
// namespace {cfg.Namespace}{{
|
||||
// [CreateAssetMenu(fileName = ""{cfg.Name}Config"", menuName = ""{attribute.MenuName}"")]
|
||||
// public class {cfg.Name}Config : ScriptableObject
|
||||
// {{
|
||||
// {configFields}
|
||||
// }}
|
||||
// }}
|
||||
// ";
|
||||
// context.AddCode($"{cfg.Name}Config.Generated.cs", configCode);
|
||||
//
|
||||
// configReferencesUsingsCode += $"using {cfg.Namespace};\n";
|
||||
//
|
||||
// if (attribute.Multiple)
|
||||
// {
|
||||
// configReferencesCode += $"public String {cfg.Name};\n";
|
||||
// configAddCode += $@"
|
||||
// _multipleConfigReferences.Add(typeof({cfg.FullName}), systemConfigsReferences.{cfg.Name});
|
||||
// ";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// configReferencesCode += $"public AssetReference {cfg.Name};\n";
|
||||
// configAddCode += $@"
|
||||
// _singleConfigReferences.Add(typeof({cfg.FullName}Config), systemConfigsReferences.{cfg.Name});
|
||||
// ";
|
||||
// }
|
||||
// }
|
||||
// configsCode += $@"
|
||||
// {configReferencesUsingsCode}
|
||||
// using UnityEngine;
|
||||
//
|
||||
// namespace Code.Infrastructure.Configs
|
||||
// {{
|
||||
//
|
||||
// public partial class ConfigLocator
|
||||
// {{
|
||||
// partial void LoadConfigs()
|
||||
// {{
|
||||
// SystemConfigsReferences systemConfigsReferences = Resources.Load<SystemConfigsReferences>(""SystemConfigsReferences"");
|
||||
// {configAddCode}
|
||||
// //_singleConfigReferences.Add(typeof(ScenesAssetReferences), systemConfigsReferences.scenesAssetReferences);
|
||||
// }}
|
||||
// }}
|
||||
// }}
|
||||
// ";
|
||||
// context.AddCode($"ConfigLocator.Generated.cs", configsCode);
|
||||
//
|
||||
// configOfConfigsCode += $@"
|
||||
// {configReferencesUsingsCode}
|
||||
// using UnityEngine.AddressableAssets;
|
||||
//
|
||||
// namespace Code.Infrastructure.Configs{{
|
||||
// public partial class SystemConfigsReferences
|
||||
// {{
|
||||
// {configReferencesCode}
|
||||
// }}
|
||||
// }}
|
||||
// ";
|
||||
// context.AddCode($"SystemConfigsReferences.Generated.cs", configOfConfigsCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92ec56ffd46d4a569bb9a7d436790439
|
||||
timeCreated: 1766423754
|
||||
@@ -0,0 +1,131 @@
|
||||
using System.Linq;
|
||||
using Unity.VisualScripting;
|
||||
using UnityCodeGen;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Code.Infrastructure.Generators
|
||||
{
|
||||
[Generator]
|
||||
public class StateMachineGenerator : ICodeGenerator
|
||||
{
|
||||
public void Execute(GeneratorContext context)
|
||||
{
|
||||
GenerateStates(context);
|
||||
|
||||
GenerateStateMachine(context);
|
||||
}
|
||||
|
||||
private void GenerateStateMachine(GeneratorContext context)
|
||||
{
|
||||
var stateMachines = TypeCache.GetTypesWithAttribute<StateMachine>();
|
||||
|
||||
foreach (var sm in stateMachines)
|
||||
{
|
||||
var attribute = sm.GetAttribute<StateMachine>();
|
||||
|
||||
var states = TypeCache.GetTypesWithAttribute<State>()
|
||||
.Where(st =>
|
||||
st.GetAttribute<State>().StateMachineContext.FullName ==
|
||||
attribute.StateMachineContextType.FullName);
|
||||
|
||||
var statesCode = "";
|
||||
var statesNamespacesCode = "";
|
||||
|
||||
foreach (var st in states)
|
||||
{
|
||||
statesNamespacesCode += $@"
|
||||
using {st.Namespace};
|
||||
";
|
||||
statesCode += $@"
|
||||
var state{st.Name} = new {st.Name}(StateMachineContext,eventBus);
|
||||
States.Add(state{st.Name}.myState, state{st.Name});
|
||||
";
|
||||
}
|
||||
|
||||
var stateMachineCode =
|
||||
$@"
|
||||
// <auto-generated/>
|
||||
#pragma warning disable CS0105
|
||||
using Code.Infrastructure.StateMachine;
|
||||
{statesNamespacesCode}
|
||||
#pragma warning restore CS0105
|
||||
namespace {sm.Namespace}
|
||||
{{
|
||||
|
||||
public partial class {sm.Name} : AbstractStateMachine<{attribute.StateMachineEnumType.FullName},{attribute.StateMachineContextType.FullName}>
|
||||
{{
|
||||
|
||||
public {sm.Name}({attribute.StateMachineContextType.FullName} context, EventBus.EventBus eventBus) : base(context)
|
||||
{{
|
||||
{statesCode}
|
||||
}}
|
||||
|
||||
protected override bool CheckTransitionAllowed({attribute.StateMachineEnumType.FullName} nextState) => AllowedStates.HasFlag(nextState);
|
||||
protected override void ResetAllowedTransitions() => AllowedStates = 0;
|
||||
}}
|
||||
|
||||
public static class {sm.Name}Extensions
|
||||
{{
|
||||
public static AbstractStateMachine<{attribute.StateMachineEnumType.FullName}, {attribute.StateMachineContextType.FullName}> AllowStateTransition(
|
||||
this AbstractStateMachine<{attribute.StateMachineEnumType.FullName}, {attribute.StateMachineContextType.FullName}> stateMachine, {attribute.StateMachineEnumType.FullName} state)
|
||||
{{
|
||||
if (stateMachine == null) return null;
|
||||
|
||||
stateMachine.AllowedStates |= state;
|
||||
return stateMachine;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
|
||||
";
|
||||
|
||||
context.AddCode($"{sm.FullName}.Generated.cs", stateMachineCode);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateStates(GeneratorContext context)
|
||||
{
|
||||
var states = TypeCache.GetTypesWithAttribute<State>();
|
||||
|
||||
var statesCode = "";
|
||||
foreach (var st in states)
|
||||
{
|
||||
var attribute = st.GetAttribute<State>();
|
||||
|
||||
var fireStatesCode = "";
|
||||
if(st.HasAttribute<StateRaisingEvent>()) fireStatesCode = $@"
|
||||
protected override void _fireEnterState()
|
||||
{{
|
||||
EventBus.RaiseEvent<IEnterStateHandle<{st.FullName}>>(h => h.EnterState());
|
||||
}}
|
||||
|
||||
protected override void _fireExitState()
|
||||
{{
|
||||
EventBus.RaiseEvent<IExitStateHandle<{st.FullName}>>(h => h.ExitState());
|
||||
}}
|
||||
";
|
||||
var genetics = "";
|
||||
if(!attribute.SilentBitch) genetics = $@" : BaseState<{attribute.StateEnum.FullName}, {attribute.StateMachineContext.FullName}>";
|
||||
|
||||
statesCode = $@"
|
||||
|
||||
// retard-generated
|
||||
|
||||
using Code.Infrastructure.StateMachine;
|
||||
|
||||
namespace {st.Namespace}
|
||||
{{
|
||||
public partial class {st.Name} {genetics}
|
||||
{{
|
||||
{fireStatesCode}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
|
||||
context.AddCode($"{st.FullName}.Generated.cs", statesCode);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fb4b6961cd0471d8183511316c15000
|
||||
timeCreated: 1765563824
|
||||
Reference in new issue
Block a user