Roslyn instead UnityCodeGen

This commit is contained in:
ThomasCharester committed 2026-10-13 18:13:23 +03:00
1 parent e05cf28266
commit e8393a28ad
694 files changed
+24070 -47982

No files matched your search

@@ -98,6 +98,8 @@ namespace Code.Game.TestingLevel
{
Context.InputService.DisableMap(ActionMappings.OpenMovement);
if (Context.StateMachine.NextState == AppStates.BattleState) return;
await Context.SceneLoader.UnloadSceneAsync(SceneId.Testing);
await Context.SceneLoader.UnloadSceneAsync(SceneId.FirstTestingSegment);
await Context.SceneLoader.UnloadSceneAsync(SceneId.SecondTestingSegment);
+2 -2
View File
@@ -1,3 +1,3 @@
fileFormatVersion: 2
guid: daf23f61a4d244d5aec0ffcc9b9c8ac4
timeCreated: 1785767213
guid: 2f235ddfc2684c63a8c734512bda6cc8
timeCreated: 1791904001
@@ -1,3 +1,3 @@
fileFormatVersion: 2
guid: 1f1a9e94d27945afad92fd36ee148c7d
timeCreated: 1785767311
guid: c99b7fb6d98e460da6f5d4c318463fe1
timeCreated: 1791904011
@@ -1,53 +0,0 @@
#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
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: d4380f9fef404347be28b7e95548c008
timeCreated: 1785767222
@@ -1,79 +0,0 @@
#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
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 4dd23f7e41734b9d86b74032d5f7f71d
timeCreated: 1785767609
@@ -1,105 +0,0 @@
#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
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 20bfbd0b7c5840c8a5f351cff2be58e0
timeCreated: 1785767485
@@ -1,28 +0,0 @@
#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
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: b9ad74e45abc4260bee92ebe33d28602
timeCreated: 1785767387
@@ -0,0 +1,15 @@
using Code.Infrastructure.App;
using Code.Infrastructure.Generators;
namespace Code.Game.OfficeGame.GameStates
{
[State(typeof(AppStates), typeof(AppStateMachineContext))]
public partial class BattleState
{
public BattleState(AppStateMachineContext context) : base(context)
{
}
public override AppStates MyState => AppStates.BattleState;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3b4f222765d646499154d711cb64ca51
timeCreated: 1791903072
+2 -1
View File
@@ -2,6 +2,7 @@ namespace Code.Infrastructure.App
{
public enum AppStates
{
Testing
Testing,
BattleState
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e6cdc489574a59f76abcde86010a9982
guid: dce5a728c8d61fd7aa5fe2217e111d73
folderAsset: yes
DefaultImporter:
externalObjects: {}
Binary file not shown.
@@ -0,0 +1,52 @@
fileFormatVersion: 2
guid: 3b3cf7a32e4208cd7a6d0933aac3e309
labels:
- RoslynAnalyzer
PluginImporter:
externalObjects: {}
serializedVersion: 3
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 1
validateReferences: 0
platformData:
Any:
enabled: 0
settings:
Exclude Editor: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Editor:
enabled: 0
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
Linux64:
enabled: 0
settings:
CPU: None
OSXUniversal:
enabled: 0
settings:
CPU: None
Win:
enabled: 0
settings:
CPU: None
Win64:
enabled: 0
settings:
CPU: None
WindowsStoreApps:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
@@ -1,26 +0,0 @@
#pragma warning disable CS0105
// using Code.Infrastructure.Audio;
#pragma warning restore CS0105
namespace Code.Infrastructure.Audio{
public partial class AudioService
{
private partial void InitializeMixer(){
_audioMixerGroups.Add(Code.Infrastructure.Audio.AudioGroupType.Master, _mixer.FindMatchingGroups("Master")[0]);
_audioMixerGroups.Add(Code.Infrastructure.Audio.AudioGroupType.SFX, _mixer.FindMatchingGroups("SFX")[0]);
_audioMixerGroups.Add(Code.Infrastructure.Audio.AudioGroupType.Music, _mixer.FindMatchingGroups("Music")[0]);
_audioMixerGroups.Add(Code.Infrastructure.Audio.AudioGroupType.UIFX, _mixer.FindMatchingGroups("UIFX")[0]);
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 1c6a8c6d1660ca409ab4c120a12f067e
@@ -1,12 +0,0 @@
// retard-generated
using Code.Infrastructure.StateMachine;
namespace Code.Game.Gameplay.Player
{
public partial class OpenMovementCameraState
{
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 4922fe67670851c2e8e3b02ca7a24eba
@@ -1,12 +0,0 @@
// retard-generated
using Code.Infrastructure.StateMachine;
namespace Code.Game.Gameplay.Player
{
public partial class OpenMovementCameraState
{
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: ec58bceef105d22c7913a40162b8ea97
@@ -1,12 +0,0 @@
// retard-generated
using Code.Infrastructure.StateMachine;
namespace Code.Game.TestingLevel
{
public partial class TestingState : BaseState<Code.Infrastructure.App.AppStates, Code.Infrastructure.App.AppStateMachineContext>
{
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 4757cb7e0230a8d4f87972b927bc9691
@@ -1,24 +0,0 @@
// <auto-generated/>
#pragma warning disable CS0105
using Code.Infrastructure.StateMachine;
using Code.Game.TestingLevel;
#pragma warning restore CS0105
namespace Code.Infrastructure.App
{
public partial class AppStateMachine : AbstractStateMachine<Code.Infrastructure.App.AppStates,Code.Infrastructure.App.AppStateMachineContext>
{
public AppStateMachine(Code.Infrastructure.App.AppStateMachineContext context) : base(context)
{
var stateTestingState = new TestingState(StateMachineContext);
States.Add(stateTestingState.MyState, stateTestingState);
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: ad404e49462a4d8d8acc618f8b25d229
@@ -1,34 +0,0 @@
// <auto-generated/>
#pragma warning disable CS0105
using Code.Infrastructure.StateMachine;
using Code.Infrastructure.Camera.CameraStates;
using Code.OfficeGame.Player;
using Code.Game.Gameplay.Player;
#pragma warning restore CS0105
namespace Code.Infrastructure.Camera
{
public partial class CameraStateMachine : AbstractStateMachine<Code.Infrastructure.Camera.CameraMode,Code.Infrastructure.Camera.CameraStateMachineContext>
{
public CameraStateMachine(Code.Infrastructure.Camera.CameraStateMachineContext context) : base(context)
{
var stateNoneCameraState = new NoneCameraState(StateMachineContext);
States.Add(stateNoneCameraState.MyState, stateNoneCameraState);
var stateLocationTransitionState = new LocationTransitionState(StateMachineContext);
States.Add(stateLocationTransitionState.MyState, stateLocationTransitionState);
var stateOpenMovementCameraState = new OpenMovementCameraState(StateMachineContext);
States.Add(stateOpenMovementCameraState.MyState, stateOpenMovementCameraState);
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 6f16416e8345a1520a6fa77c5dfa205d
@@ -1,12 +0,0 @@
// retard-generated
using Code.Infrastructure.StateMachine;
namespace Code.Infrastructure.Camera.CameraStates
{
public partial class NoneCameraState
{
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: f3dd399603d8b504ca1303ba9618c7ec
@@ -1,12 +0,0 @@
// retard-generated
using Code.Infrastructure.StateMachine;
namespace Code.OfficeGame.Player
{
public partial class LocationTransitionState
{
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 82499fbc0e88cf3618bcb722353818f2
@@ -1,53 +0,0 @@
#pragma warning disable CS0105
using Code.Infrastructure.Volume;
using Code.Infrastructure.UI;
using Code.Infrastructure.SceneLoader;
using Code.Game.Gameplay.Player.Factory;
using Code.Infrastructure.Particles;
using Code.Infrastructure.Input;
using Code.Infrastructure.Camera;
using Code.Infrastructure.UI;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Audio;
#pragma warning restore CS0105
namespace Code.Infrastructure.Configs
{
public partial class ConfigLocator
{
partial void LoadConfigs()
{
_multipleConfigReferences.Add(typeof(Code.Infrastructure.Volume.VolumeSettings), _configReferences.VolumeSettings);
_multipleConfigReferences.Add(typeof(Code.Infrastructure.UI.UIPanelSettings), _configReferences.UIPanelSettings);
_multipleConfigReferences.Add(typeof(Code.Infrastructure.SceneLoader.SceneInfo), _configReferences.SceneInfo);
_singleConfigReferences.Add(typeof(Code.Game.Gameplay.Player.Factory.PlayerFactorySettings), _configReferences.PlayerFactorySettings);
_multipleConfigReferences.Add(typeof(Code.Infrastructure.Particles.ParticleInfo), _configReferences.ParticleInfo);
_singleConfigReferences.Add(typeof(Code.Infrastructure.Input.InputServiceConfig), _configReferences.InputServiceConfig);
_singleConfigReferences.Add(typeof(Code.Infrastructure.Camera.GameCamera), _configReferences.GameCamera);
_singleConfigReferences.Add(typeof(Code.Infrastructure.UI.CanvasSettings), _configReferences.CanvasSettings);
_multipleConfigReferences.Add(typeof(Code.Infrastructure.Audio.AudioSourceSettings), _configReferences.AudioSourceSettings);
_singleConfigReferences.Add(typeof(Code.Infrastructure.Audio.AudioSourcePrefab), _configReferences.AudioSourcePrefab);
_singleConfigReferences.Add(typeof(Code.Infrastructure.Audio.AudioMixerSettings), _configReferences.AudioMixerSettings);
_multipleConfigReferences.Add(typeof(Code.Infrastructure.Audio.AudioInfoConfig), _configReferences.AudioInfoConfig);
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 6d621a90c034df8afa04fe3d0016aeec
@@ -1,36 +0,0 @@
#pragma warning disable CS0105
using Code.Infrastructure.Volume;
using Code.Infrastructure.UI;
using Code.Infrastructure.SceneLoader;
using Code.Game.Gameplay.Player.Factory;
using Code.Infrastructure.Particles;
using Code.Infrastructure.Input;
using Code.Infrastructure.Camera;
using Code.Infrastructure.UI;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Audio;
using UnityEngine.AddressableAssets;
#pragma warning restore CS0105
namespace Code.Infrastructure.Configs{
public partial class ConfigReferences
{
public string VolumeSettings;
public string UIPanelSettings;
public string SceneInfo;
public AssetReference PlayerFactorySettings;
public string ParticleInfo;
public AssetReference InputServiceConfig;
public AssetReference GameCamera;
public AssetReference CanvasSettings;
public string AudioSourceSettings;
public AssetReference AudioSourcePrefab;
public AssetReference AudioMixerSettings;
public string AudioInfoConfig;
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: d997d7ecd76aadc81b36f952364e0e8b