Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Apr 14, 2023
2 parents 85e3ec7 + c13c568 commit 64f3185
Show file tree
Hide file tree
Showing 106 changed files with 8,665 additions and 17,951 deletions.
55 changes: 45 additions & 10 deletions Assets/Editor/SourceGenerator/ModuleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class ModuleGenerator
private const string INFO_PATH = "Assets/Editor/SourceGenerator/module-info.json";

#region generate scripts
internal static void WriteExtensionFile(string filePath, string nullableFilePath, PSModuleInfo module)
internal static void WriteExtensionFile(string filePath, PSModuleInfo module)
{
var builder = new StringBuilder();
var isSameAsPrevious = module.Properties.Any() && module.Properties.First().ReleaseVersion == module.ReleaseVersion;
Expand All @@ -25,8 +25,13 @@ internal static void WriteExtensionFile(string filePath, string nullableFilePath
$@"using System;
using System.Runtime.CompilerServices;
using UnityEngine;
using static UnityEngine.ParticleSystem;
#if UNITY_2020_2_OR_NEWER
using System.Diagnostics.CodeAnalysis;
#endif
namespace OUCC.FluentParticleSystem
{{
public static class {module.Type}Extension
Expand All @@ -36,7 +41,18 @@ public static class {module.Type}Extension
/// Edit <see cref=""ParticleSystem.{module.PropertyName}""/>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ParticleSystem Edit{module.PropertyName.c2p()}(this ParticleSystem particleSystem, Action<{module.Type}> moduleEditor)
#if UNITY_2020_2_OR_NEWER
[return: NotNull]
#endif
public static ParticleSystem Edit{module.PropertyName.c2p()}(
#if UNITY_2020_2_OR_NEWER
[DisallowNull]
#endif
this ParticleSystem particleSystem,
#if UNITY_2020_2_OR_NEWER
[DisallowNull]
#endif
Action<{module.Type}> moduleEditor)
{{
Debug.Assert(particleSystem != null, ""particleSystem cannot be null"");
Debug.Assert(moduleEditor != null, ""moduleEditor cannot be null"");
Expand All @@ -61,7 +77,14 @@ public static class {module.Type}Extension
/// Assign a value to <see cref=""{module.Type}.{property.PropertyName}""/>
/// </summary>{obsolete}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ParticleSystem Set{module.PropertyName.c2p()}{property.PropertyName.c2p()}(this ParticleSystem particleSystem, {property.Type} {property.PropertyName.p2c()})
#if UNITY_2020_2_OR_NEWER
[return: NotNull]
#endif
public static ParticleSystem Set{module.PropertyName.c2p()}{property.PropertyName.c2p()}(
#if UNITY_2020_2_OR_NEWER
[DisallowNull]
#endif
this ParticleSystem particleSystem, {property.Type} {property.PropertyName.p2c()})
{{
Debug.Assert(particleSystem != null, ""particleSystem cannot be null"");
var module = particleSystem.{module.PropertyName};
Expand All @@ -73,7 +96,18 @@ public static class {module.Type}Extension
/// Edit <see cref=""{module.Type}.{property.PropertyName}""/>
/// </summary>{obsolete}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ParticleSystem Set{module.PropertyName.c2p()}{property.PropertyName.c2p()}(this ParticleSystem particleSystem, Func<{property.Type}, {property.Type}> {property.PropertyName.p2c()}Changer)
#if UNITY_2020_2_OR_NEWER
[return: NotNull]
#endif
public static ParticleSystem Set{module.PropertyName.c2p()}{property.PropertyName.c2p()}(
#if UNITY_2020_2_OR_NEWER
[DisallowNull]
#endif
this ParticleSystem particleSystem,
#if UNITY_2020_2_OR_NEWER
[DisallowNull]
#endif
Func<{property.Type}, {property.Type}> {property.PropertyName.p2c()}Changer)
{{
Debug.Assert(particleSystem != null, ""particleSystem cannot be null"");
Debug.Assert({property.PropertyName.p2c()}Changer != null, ""{property.PropertyName.p2c()}Changer cannot be null"");
Expand All @@ -96,7 +130,11 @@ public static class {module.Type}Extension
/// Edit <see cref=""{module.Type}.{property.PropertyName}""/>
/// </summary>{obsolete}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static {module.Type} Set{property.PropertyName.c2p()}(this {module.Type} module, Func<{property.Type}, {property.Type}> {property.PropertyName.p2c()}Changer)
public static {module.Type} Set{property.PropertyName.c2p()}(this {module.Type} module,
#if UNITY_2020_2_OR_NEWER
[DisallowNull]
#endif
Func<{property.Type}, {property.Type}> {property.PropertyName.p2c()}Changer)
{{
Debug.Assert({property.PropertyName.p2c()}Changer != null, ""{property.PropertyName.p2c()}Changer cannot be null"");
module.{property.PropertyName} = {property.PropertyName.p2c()}Changer(module.{property.PropertyName});
Expand All @@ -113,8 +151,6 @@ public static class {module.Type}Extension
");

File.WriteAllText(filePath, builder.ToString().Replace("\r\n", "\n"));

File.WriteAllText(nullableFilePath, "#nullable enable\n" + builder.ToString().Replace("\r\n", "\n")); ;
}

/// <summary>
Expand All @@ -132,9 +168,8 @@ public static void GenerateWithReflection()
});
foreach (var module in modules)
{
var filePath = $"Packages/FluentParticleSystem/Runtime/NonNullable/Extensions/{module.Type}Extension.cs";
var nullableFilePath = $"Packages/FluentParticleSystem/Runtime/Nullable/Extensions/{module.Type}Extension.cs";
WriteExtensionFile(filePath, nullableFilePath, module);
var filePath = $"Packages/FluentParticleSystem/Runtime/Extensions/{module.Type}Extension.cs";
WriteExtensionFile(filePath, module);
}
AssetDatabase.Refresh();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class Debug
[Conditional("UNITY_ASSERTIONS")]
internal static void Assert(
#if UNITY_2020_2_OR_NEWER
[DoesNotReturnIf(false)]
[DoesNotReturnIf(false)]
#endif
bool condition, string message)
{
Expand Down
Loading

0 comments on commit 64f3185

Please sign in to comment.