Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,48 @@
|
||||
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 ManualInherit;
|
||||
|
||||
public State(Type stateEnum,Type stateMachineContext, bool manualInherit = false)
|
||||
{
|
||||
StateEnum = stateEnum;
|
||||
StateMachineContext = stateMachineContext;
|
||||
ManualInherit = manualInherit;
|
||||
}
|
||||
}
|
||||
public class Config : Attribute
|
||||
{
|
||||
public bool Multiple;
|
||||
public bool OnlyLocator;
|
||||
public string MenuName;
|
||||
public Config(string menuName, bool multiple = false, bool onlyLocator = false)
|
||||
{
|
||||
Multiple = multiple;
|
||||
MenuName = menuName;
|
||||
OnlyLocator = onlyLocator;
|
||||
}
|
||||
}
|
||||
public class SceneIdEnum : Attribute
|
||||
{
|
||||
}
|
||||
public class AudioMixerEnum : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f1a9e94d27945afad92fd36ee148c7d
|
||||
timeCreated: 1785767311
|
||||
@@ -0,0 +1,53 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityCodeGen;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Code.Infrastructure.Generators
|
||||
{
|
||||
[Generator]
|
||||
public class AudioMixerGenerator : ICodeGenerator
|
||||
{
|
||||
public void Execute(GeneratorContext context)
|
||||
{
|
||||
var Enum = TypeCache.GetTypesWithAttribute<AudioMixerEnum>();
|
||||
|
||||
var initializedCode = "";
|
||||
var serviceCode = "";
|
||||
var interfacesUsingsCode = $@"
|
||||
// using Code.Infrastructure.Audio;
|
||||
";
|
||||
|
||||
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;
|
||||
initializedCode += $@"
|
||||
_audioMixerGroups.Add({en.FullName}.{member.Name}, _mixer.FindMatchingGroups(""{member.Name}"")[0]);
|
||||
|
||||
";
|
||||
}
|
||||
|
||||
serviceCode += $@"
|
||||
#pragma warning disable CS0105
|
||||
{interfacesUsingsCode}
|
||||
#pragma warning restore CS0105
|
||||
namespace Code.Infrastructure.Audio{{
|
||||
public partial class AudioService
|
||||
{{
|
||||
private partial void InitializeMixer(){{
|
||||
{initializedCode}
|
||||
}}
|
||||
}}
|
||||
}}";
|
||||
}
|
||||
|
||||
context.AddCode($"AudioMixer.Generated.cs", serviceCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4380f9fef404347be28b7e95548c008
|
||||
timeCreated: 1785767222
|
||||
@@ -0,0 +1,79 @@
|
||||
#if UNITY_EDITOR
|
||||
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.OrderByDescending(o => o.Name))
|
||||
{
|
||||
var attribute = cfg.GetAttribute<Config>();
|
||||
|
||||
configReferencesUsingsCode += $"using {cfg.Namespace};\n";
|
||||
|
||||
if (attribute.Multiple)
|
||||
{
|
||||
configReferencesCode += $"public string {cfg.Name};\n";
|
||||
configAddCode += $@"
|
||||
_multipleConfigReferences.Add(typeof({cfg.FullName}), _configReferences.{cfg.Name});
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
configReferencesCode += $"public AssetReference {cfg.Name};\n";
|
||||
configAddCode += $@"
|
||||
_singleConfigReferences.Add(typeof({cfg.FullName}), _configReferences.{cfg.Name});
|
||||
";
|
||||
}
|
||||
}
|
||||
configsCode += $@"
|
||||
#pragma warning disable CS0105
|
||||
{configReferencesUsingsCode}
|
||||
#pragma warning restore CS0105
|
||||
|
||||
namespace Code.Infrastructure.Configs
|
||||
{{
|
||||
|
||||
public partial class ConfigLocator
|
||||
{{
|
||||
partial void LoadConfigs()
|
||||
{{
|
||||
{configAddCode}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
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 ConfigReferences
|
||||
{{
|
||||
{configReferencesCode}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
context.AddCode($"ConfigReferences.Generated.cs", configOfConfigsCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dd23f7e41734b9d86b74032d5f7f71d
|
||||
timeCreated: 1785767609
|
||||
@@ -0,0 +1,105 @@
|
||||
#if UNITY_EDITOR
|
||||
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);
|
||||
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) : base(context)
|
||||
{{
|
||||
{statesCode}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
|
||||
";
|
||||
|
||||
context.AddCode($"{sm.FullName}.Generated.cs", stateMachineCode);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateStates(GeneratorContext context)
|
||||
{
|
||||
var states = TypeCache.GetTypesWithAttribute<State>();
|
||||
|
||||
foreach (var st in states)
|
||||
{
|
||||
var attribute = st.GetAttribute<State>();
|
||||
|
||||
var genetics = "";
|
||||
if (!attribute.ManualInherit)
|
||||
genetics =
|
||||
$@" : BaseState<{attribute.StateEnum.FullName}, {attribute.StateMachineContext.FullName}>";
|
||||
|
||||
var statesCode = $@"
|
||||
|
||||
// retard-generated
|
||||
|
||||
using Code.Infrastructure.StateMachine;
|
||||
|
||||
namespace {st.Namespace}
|
||||
{{
|
||||
public partial class {st.Name} {genetics}
|
||||
{{
|
||||
}}
|
||||
}}
|
||||
";
|
||||
|
||||
|
||||
context.AddCode($"{st.FullName}.Generated.cs", statesCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20bfbd0b7c5840c8a5f351cff2be58e0
|
||||
timeCreated: 1785767485
|
||||
@@ -0,0 +1,28 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Code.Infrastructure.Generators
|
||||
{
|
||||
public static class TypeExtensions
|
||||
{
|
||||
public static string GetFriendlyName(this Type type)
|
||||
{
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
if (type.FullName != null)
|
||||
{
|
||||
string name = type.FullName.Split('`')[0];
|
||||
|
||||
var genericArgs = type.GetGenericArguments()
|
||||
.Select(t => t.GetFriendlyName());
|
||||
|
||||
return $"{name}<{string.Join(", ", genericArgs)}>";
|
||||
}
|
||||
}
|
||||
|
||||
return type.FullName ?? type.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9ad74e45abc4260bee92ebe33d28602
|
||||
timeCreated: 1785767387
|
||||
Reference in new issue
Block a user