From 6979da8b701b7ac3df7497e4262b08b4f69a4e5b Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 11 Jan 2024 09:55:48 -0800 Subject: [PATCH] refmt --- .../BotManagement/RGBotSynchronizer.cs | 19 +- .../CodeGenerators/BuildAutoProcessor.cs | 8 +- .../CodeGenerators/CodeGeneratorUtils.cs | 2 +- .../CodeGenerators/GenerateRGActionClasses.cs | 46 ++-- .../GenerateRGActionMapClass.cs | 30 +-- .../GenerateRGSerializationClass.cs | 4 +- .../CodeGenerators/GenerateRGStateClasses.cs | 26 +-- .../Scripts/CodeGenerators/RGCodeGenerator.cs | 65 +++--- .../Editor/Scripts/RGBotReplayWindow.cs | 82 +++---- .../Editor/Scripts/RGEntityStatesJson.cs | 2 +- .../Editor/Scripts/RGSettingsUIRegistrar.cs | 38 +-- .../Editor/Scripts/RGStateAttributesInfo.cs | 2 +- .../Editor/Scripts/RGStatesInfo.cs | 2 +- .../Editor/Scripts/RGTickInfoActionManager.cs | 24 +- .../Editor/Scripts/ReplayModelManager.cs | 28 +-- .../Scripts/Startup/RegressionPackagePopup.cs | 52 ++--- .../Runtime/Scripts/ActiveRGBotUIElement.cs | 6 +- .../Scripts/BehaviorTree/BehaviorTreeNode.cs | 10 +- .../Scripts/BehaviorTree/Decorators.cs | 6 +- .../Scripts/BehaviorTree/NodeStatus.cs | 4 +- .../Scripts/BehaviorTree/RGBehaviorTreeBot.cs | 2 +- .../Runtime/Scripts/BehaviorTree/RootNode.cs | 4 +- .../Scripts/BehaviorTree/SelectorNode.cs | 2 +- .../Scripts/BehaviorTree/SequenceNode.cs | 2 +- .../DataCollection/RGDataCollection.cs | 15 +- .../Scripts/DebugUtils/BillboardText.cs | 26 +-- .../Runtime/Scripts/DebugUtils/RGGizmos.cs | 21 +- .../Runtime/Scripts/DictionaryExtensions.cs | 8 +- .../Runtime/Scripts/RGBotConfigs/RGAction.cs | 96 ++++---- .../RGBotConfigs/RGAction_ClickButton.cs | 2 +- .../Scripts/RGBotConfigs/RGAction_KeyPress.cs | 50 ++-- .../Runtime/Scripts/RGBotConfigs/RGAgent.cs | 2 +- .../Runtime/Scripts/RGBotConfigs/RGEntity.cs | 24 +- .../Runtime/Scripts/RGBotConfigs/RGState.cs | 14 +- .../RGStatePlatformer2DPlayerStatsProvider.cs | 8 +- .../RGState_Platformer2DLevel.cs | 24 +- .../RGState_Platformer2DPlayer.cs | 34 +-- .../Runtime/Scripts/RGBotLocalRuntime/RG.cs | 5 +- .../Scripts/RGBotLocalRuntime/RGBotAsset.cs | 2 +- .../RGBotLocalRuntime/RGBotAssetsManager.cs | 2 +- .../RGBotLocalRuntime/RGBotLifecycle.cs | 4 +- .../Scripts/RGBotLocalRuntime/RGBotRunner.cs | 2 +- .../RGBotLocalRuntime/RGBotRuntimeManager.cs | 4 +- .../Scripts/RGBotLocalRuntime/RGUserBot.cs | 6 +- .../SampleBot/RGSampleBot.cs | 4 +- .../Runtime/Scripts/RGBotServerListener.cs | 218 +++++++++--------- .../Runtime/Scripts/RGBotSpawnManager.cs | 26 +-- .../Runtime/Scripts/RGCertificateHolder.cs | 2 +- .../Runtime/Scripts/RGDebug.cs | 12 +- .../Runtime/Scripts/RGEnvConfigs.cs | 6 +- .../Runtime/Scripts/RGIconPulse.cs | 6 +- .../Runtime/Scripts/RGOverlayMenu.cs | 36 +-- .../Runtime/Scripts/RGRuntimeProperties.cs | 6 +- .../Runtime/Scripts/RGServiceManager.cs | 12 +- .../Runtime/Scripts/RGSettings.cs | 14 +- .../Scripts/RGSettingsDynamicEnabler.cs | 2 +- .../Runtime/Scripts/RGUserSettings.cs | 8 +- .../Runtime/Scripts/RGUtils.cs | 2 +- .../StateActionTypes/IRGStateEntity.cs | 4 +- .../StateActionTypes/RGActionRequest.cs | 4 +- .../RGStateActionReplayData.cs | 10 +- .../Scripts/StateActionTypes/RGStateEntity.cs | 2 +- .../StateActionTypes/RGStateEntity_Button.cs | 2 +- .../StateActionTypes/RGTickInfoData.cs | 4 +- .../StateActionTypes/RGValidationResult.cs | 6 +- .../Runtime/Scripts/Types/RGAuthRequest.cs | 2 +- .../Runtime/Scripts/Types/RGBotInstance.cs | 6 +- .../RGBotInstanceExternalConnectionInfo.cs | 2 +- .../Scripts/Types/RGBotInstanceList.cs | 2 +- .../Scripts/Types/RGClientConnection.cs | 6 +- .../Scripts/Types/RGClientConnection_Local.cs | 6 +- .../Types/RGClientConnection_Remote.cs | 8 +- .../Types/RGCreateBotInstanceRequest.cs | 2 +- .../Runtime/Scripts/Types/RGServerPlayerId.cs | 2 +- .../Scripts/Types/RGValidationSummary.cs | 2 +- 75 files changed, 625 insertions(+), 614 deletions(-) diff --git a/src/gg.regression.unity.bots/Editor/Scripts/BotManagement/RGBotSynchronizer.cs b/src/gg.regression.unity.bots/Editor/Scripts/BotManagement/RGBotSynchronizer.cs index 997fc76cf..e5f3f9dda 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/BotManagement/RGBotSynchronizer.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/BotManagement/RGBotSynchronizer.cs @@ -19,9 +19,9 @@ namespace RegressionGames.Editor.BotManagement public class RGBotSynchronizer { #if UNITY_EDITOR - private static readonly RGBotSynchronizer _this = new (); + private static readonly RGBotSynchronizer _this = new(); - private static RGServiceManager _rgServiceManager = new (); // editor, not game/scene so don't look for one, make one + private static RGServiceManager _rgServiceManager = new(); // editor, not game/scene so don't look for one, make one // This must match RGBotRuntimeManagement.cs private const string BOTS_PATH = "Assets/RegressionGames/Runtime/Bots"; @@ -165,7 +165,7 @@ await _rgServiceManager.CreateBot( var countUpdated = 0; foreach (var (botId, (localBot, md5, localLastUpdated)) in localBotZips) { - if(remoteBots.FirstOrDefault(b => b.id == botId) is not {} remoteBot) + if (remoteBots.FirstOrDefault(b => b.id == botId) is not { } remoteBot) { RGDebug.LogError($"Unable to find remote bot with id {botId} to update."); continue; @@ -481,7 +481,7 @@ private void CreateNewBotAssets(string folderName, string botName, long botId) private void CreateBotAssetFile(string folderName, string botName, long botId, string botChecksum) { var botRecordAssetPath = $"{folderName}/BotRecord.asset"; - if ( AssetDatabase.GetMainAssetTypeAtPath( botRecordAssetPath ) == null) + if (AssetDatabase.GetMainAssetTypeAtPath(botRecordAssetPath) == null) { RGDebug.LogDebug($"Writing {botRecordAssetPath}"); RGBot botRecord = new RGBot() @@ -495,7 +495,7 @@ private void CreateBotAssetFile(string folderName, string botName, long botId, s RGBotAsset botRecordAsset = ScriptableObject.CreateInstance(); botRecordAsset.Bot = botRecord; botRecordAsset.ChecksumAtLastSync = botChecksum; - AssetDatabase.CreateAsset(botRecordAsset, botRecordAssetPath ); + AssetDatabase.CreateAsset(botRecordAsset, botRecordAssetPath); AssetDatabase.SaveAssets(); } } @@ -503,7 +503,8 @@ private void CreateBotAssetFile(string folderName, string botName, long botId, s // Extension code borrowed from StackOverflow to allow creating a zip of directory // while filtering out certain contents - public static class ZipHelper { + public static class ZipHelper + { public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, CompressionLevel compressionLevel = CompressionLevel.Fastest, @@ -511,10 +512,12 @@ public static void CreateFromDirectory(string sourceDirectoryName, Predicate exclusionFilter = null ) { - if (string.IsNullOrEmpty(sourceDirectoryName)) { + if (string.IsNullOrEmpty(sourceDirectoryName)) + { throw new ArgumentNullException("sourceDirectoryName"); } - if (string.IsNullOrEmpty(destinationArchiveFileName)) { + if (string.IsNullOrEmpty(destinationArchiveFileName)) + { throw new ArgumentNullException("destinationArchiveFileName"); } var filesToAdd = Directory.GetFiles(sourceDirectoryName, "*", SearchOption.AllDirectories); diff --git a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/BuildAutoProcessor.cs b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/BuildAutoProcessor.cs index a0f2ae085..5ab2e167d 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/BuildAutoProcessor.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/BuildAutoProcessor.cs @@ -9,18 +9,18 @@ namespace RegressionGames.Editor.CodeGenerators class BuildAutoPreProcessor : IPreprocessBuildWithReport { public int callbackOrder { get { return 0; } } - + public void OnPreprocessBuild(BuildReport report) { BuildAssetPostProcessor.TriggerGeneration(); } } - + class BuildAssetPostProcessor : UnityEditor.AssetPostprocessor { static bool _enabled = true; - + public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload) { @@ -39,7 +39,7 @@ public static void TriggerGeneration() { _enabled = false; RGDebug.LogInfo("Generating Regression Games scripts automatically due to asset change or build."); - RGCodeGenerator.GenerateRGScripts(); + RGCodeGenerator.GenerateRGScripts(); } } } diff --git a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/CodeGeneratorUtils.cs b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/CodeGeneratorUtils.cs index fa2426786..d195590d0 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/CodeGeneratorUtils.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/CodeGeneratorUtils.cs @@ -9,7 +9,7 @@ namespace RegressionGames public class CodeGeneratorUtils { public static readonly string HeaderComment = $"/*\r\n* This file has been automatically generated. Do not modify.\r\n*/\r\n\r\n"; - + public static string SanitizeActionName(string name) { return Regex.Replace(name.Replace(" ", "_"), "[^0-9a-zA-Z_]", "_"); diff --git a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionClasses.cs b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionClasses.cs index ae935c232..e85d04ecb 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionClasses.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionClasses.cs @@ -19,7 +19,7 @@ public static class GenerateRGActionClasses { public static void Generate(List actionInfos) { - Dictionary fileWriteTasks = new(); + Dictionary fileWriteTasks = new(); // Iterate through BotActions foreach (var botAction in actionInfos) { @@ -41,7 +41,7 @@ public static void Generate(List actionInfos) } var projectNamespace = CodeGeneratorUtils.GetNamespaceForProject(); - + botAction.GeneratedClassName = $"{projectNamespace}.RGAction_{CodeGeneratorUtils.SanitizeActionName(botAction.ActionName)}"; @@ -60,7 +60,7 @@ public static void Generate(List actionInfos) $"RGAction_{CodeGeneratorUtils.SanitizeActionName(botAction.ActionName)}") .AddModifiers( SyntaxFactory.Token(SyntaxKind.PublicKeyword) - // Only add one of the "class" keywords here + // Only add one of the "class" keywords here ) .AddBaseListTypes( SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName("RGAction")) @@ -78,7 +78,7 @@ public static void Generate(List actionInfos) $"RGActionRequest_{CodeGeneratorUtils.SanitizeActionName(botAction.ActionName)}") .AddModifiers( SyntaxFactory.Token(SyntaxKind.PublicKeyword) - // Only add one of the "class" keywords here + // Only add one of the "class" keywords here ) .AddBaseListTypes( SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName("RGActionRequest")) @@ -99,7 +99,7 @@ public static void Generate(List actionInfos) string fileContents = CodeGeneratorUtils.HeaderComment + formattedCode; Directory.CreateDirectory(Path.GetDirectoryName(filePath)); - var task= File.WriteAllTextAsync(filePath, fileContents); + var task = File.WriteAllTextAsync(filePath, fileContents); fileWriteTasks[filePath] = task; } } @@ -167,7 +167,7 @@ private static MemberDeclarationSyntax GenerateGetActionNameMethod(RGActionAttri return getActionNameMethod; } - + private static ArgumentSyntax GenerateActionDelegate(RGActionAttributeInfo action) { // Generate the GetComponent().MethodName piece for both cases (0 and non-0 parameters) @@ -236,14 +236,14 @@ private static MemberDeclarationSyntax GenerateStartActionMethod(RGActionInfo ac foreach (var parameter in action.Parameters) { string paramName = parameter.Name; - + methodInvocationArguments.Add(paramName); parameterParsingStatements.Add(SyntaxFactory.ParseStatement($"{parameter.Type} {paramName} = default;")); parameterParsingStatements.Add(SyntaxFactory.IfStatement(IfCondition(parameter), IfBody(parameter), ElseBody(parameter))); } - string methodInvocationArgumentsString = methodInvocationArguments.Count > 0 ? - ", " + string.Join(", ", methodInvocationArguments) : + string methodInvocationArgumentsString = methodInvocationArguments.Count > 0 ? + ", " + string.Join(", ", methodInvocationArguments) : string.Empty; parameterParsingStatements.Add(SyntaxFactory.ParseStatement($"Invoke(\"{action.ActionName}\"{methodInvocationArgumentsString});")); @@ -264,16 +264,16 @@ private static InvocationExpressionSyntax IfCondition(RGParameterInfo param) { return SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.IdentifierName("input"), + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.IdentifierName("input"), SyntaxFactory.IdentifierName("TryGetValue") )).WithArgumentList( SyntaxFactory.ArgumentList( - SyntaxFactory.SeparatedList(new List - { + SyntaxFactory.SeparatedList(new List + { SyntaxFactory.Argument( SyntaxFactory.LiteralExpression( - SyntaxKind.StringLiteralExpression, + SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(param.Name) ) ), @@ -309,7 +309,7 @@ private static StatementSyntax IfBody(RGParameterInfo param) { var paramType = param.Type; var paramName = param.Name; - + string tryParseStatement; if (paramType.ToLower() == "string" || paramType.ToLower() == "system.string") { @@ -368,15 +368,15 @@ private static ElseClauseSyntax ElseBody(RGParameterInfo param) { return default(ElseClauseSyntax); } - + // Validation check for key existence if param must be non-null - return SyntaxFactory.ElseClause(SyntaxFactory.Block(new StatementSyntax[] + return SyntaxFactory.ElseClause(SyntaxFactory.Block(new StatementSyntax[] { SyntaxFactory.ExpressionStatement( SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.IdentifierName("RGDebug"), + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.IdentifierName("RGDebug"), SyntaxFactory.IdentifierName("LogError") ) ).WithArgumentList( @@ -384,14 +384,14 @@ private static ElseClauseSyntax ElseBody(RGParameterInfo param) SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxFactory.LiteralExpression( - SyntaxKind.StringLiteralExpression, + SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal($"No parameter '{param.Name}' found") ) ) ) ) ) - ), SyntaxFactory.ReturnStatement() + ), SyntaxFactory.ReturnStatement() } )); } @@ -400,7 +400,7 @@ private static MemberDeclarationSyntax GenerateActionRequestConstructor(RGAction { var methodParameters = new List(); var parameterParsingStatements = new List(); - + foreach (var rgParameterInfo in action.Parameters) { methodParameters.Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(rgParameterInfo.Name)) @@ -416,7 +416,7 @@ private static MemberDeclarationSyntax GenerateActionRequestConstructor(RGAction } inputString += "\r\n};"; - + parameterParsingStatements.Add( SyntaxFactory.ParseStatement(inputString) ); diff --git a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionMapClass.cs b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionMapClass.cs index 5dfb795f3..834281d62 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionMapClass.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGActionMapClass.cs @@ -34,11 +34,11 @@ public static void Generate(List botActions) NamespaceDeclarationSyntax namespaceDeclaration = SyntaxFactory .NamespaceDeclaration(SyntaxFactory.ParseName(CodeGeneratorUtils.GetNamespaceForProject())) .AddUsings( - usings.Select(v=>SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(v))).ToArray() + usings.Select(v => SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(v))).ToArray() ) .AddMembers(GenerateClass(botActions)); - - + + // Create a compilation unit and add the namespace declaration CompilationUnitSyntax compilationUnit = SyntaxFactory.CompilationUnit() .AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System"))) @@ -52,10 +52,10 @@ public static void Generate(List botActions) string filePath = Path.Combine(Application.dataPath, "RegressionGames", "Runtime", "GeneratedScripts", fileName); string fileContents = CodeGeneratorUtils.HeaderComment + formattedCode; Directory.CreateDirectory(Path.GetDirectoryName(filePath)); - File.WriteAllText(filePath, fileContents); + File.WriteAllText(filePath, fileContents); RGDebug.Log($"Successfully Generated {filePath}"); } - + private static ClassDeclarationSyntax GenerateClass(List botActions) { var methodsList = new List(); @@ -66,27 +66,27 @@ private static ClassDeclarationSyntax GenerateClass(List .AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)) .WithBody(SyntaxFactory.Block(filteredActions .GroupBy(b => b.Object) - .SelectMany(g => + .SelectMany(g => { - var innerIfStatements = g.Select(b => + var innerIfStatements = g.Select(b => SyntaxFactory.ExpressionStatement( SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.IdentifierName("gameObject"), + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.IdentifierName("gameObject"), SyntaxFactory.IdentifierName($"AddComponent") ) ) ) ).ToArray(); - - return new StatementSyntax[] + + return new StatementSyntax[] { SyntaxFactory.IfStatement( SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - SyntaxFactory.ThisExpression(), + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.ThisExpression(), SyntaxFactory.GenericName("TryGetComponent") .WithTypeArgumentList( SyntaxFactory.TypeArgumentList( @@ -98,8 +98,8 @@ private static ClassDeclarationSyntax GenerateClass(List ), SyntaxFactory.ArgumentList(SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( - null, - SyntaxFactory.Token(SyntaxKind.OutKeyword), + null, + SyntaxFactory.Token(SyntaxKind.OutKeyword), SyntaxFactory.DeclarationExpression( SyntaxFactory.IdentifierName("var"), SyntaxFactory.DiscardDesignation(SyntaxFactory.Token(SyntaxKind.UnderscoreToken)) diff --git a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGSerializationClass.cs b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGSerializationClass.cs index 8f9c118a1..a6caf4a62 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGSerializationClass.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGSerializationClass.cs @@ -52,14 +52,14 @@ private static ClassDeclarationSyntax GenerateClass(List { continue; } - + foreach (RGParameterInfo parameter in botAction.Parameters) { if (RGUtils.IsCSharpPrimitive(parameter.Type)) { continue; } - + if (!processedTypes.Contains(parameter.Type)) { processedTypes.Add(parameter.Type); diff --git a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGStateClasses.cs b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGStateClasses.cs index 393071d8a..ba1235ff9 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGStateClasses.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/CodeGenerators/GenerateRGStateClasses.cs @@ -20,7 +20,7 @@ public static class GenerateRGStateClasses { public static void Generate(List rgStateAttributesInfos) { - Dictionary fileWriteTasks = new(); + Dictionary fileWriteTasks = new(); foreach (var rgStateAttributeInfo in rgStateAttributesInfos) { if (rgStateAttributeInfo.ShouldGenerateCSFile) @@ -62,7 +62,7 @@ public static void Generate(List rgStateAttributesInfos) // Create the Start method var startMethod = GenerateStartMethod(componentType, rgStateAttributeInfo.State); - + // Create the SEInstance method var seInstanceMethod = GenerateGetTypeForStateEntityMethod(componentType); @@ -81,7 +81,7 @@ public static void Generate(List rgStateAttributesInfos) ClassDeclaration($"RGStateEntity_{rgStateAttributeInfo.ClassName}") .AddModifiers( Token(SyntaxKind.PublicKeyword) - // Only add one of the "class" keywords here + // Only add one of the "class" keywords here ) .AddBaseListTypes( SimpleBaseType( @@ -116,8 +116,8 @@ public static void Generate(List rgStateAttributesInfos) string filePath = Path.Combine(Application.dataPath, subfolderName, fileName); string fileContents = CodeGeneratorUtils.HeaderComment + formattedCode; Directory.CreateDirectory(Path.GetDirectoryName(filePath)); - - var task= File.WriteAllTextAsync(filePath, fileContents); + + var task = File.WriteAllTextAsync(filePath, fileContents); fileWriteTasks[filePath] = task; } } @@ -201,7 +201,7 @@ private static MethodDeclarationSyntax GenerateGetTypeForStateEntityMethod(strin Identifier("GetTypeForStateEntity")) .WithModifiers( TokenList( - new []{ + new[]{ Token(SyntaxKind.ProtectedKeyword), Token(SyntaxKind.OverrideKeyword)})) .WithBody( @@ -229,7 +229,7 @@ private static MethodDeclarationSyntax GenerateGetStateMethod(string componentTy // Add statements to add each state variable to the dictionary statements.AddRange(memberInfos.Select(mi => { - ExpressionSyntax valueExpression = mi.FieldType == "method" + ExpressionSyntax valueExpression = mi.FieldType == "method" ? InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, @@ -276,9 +276,9 @@ private static MethodDeclarationSyntax GenerateGetStateMethod(string componentTy return getStateMethod; } - - - + + + private static MemberDeclarationSyntax[] GenerateStateEntityFields(List memberInfos) { var fields = new List(); @@ -286,19 +286,19 @@ private static MemberDeclarationSyntax[] GenerateStateEntityFields(List ExcludeDirectories = new() { - "ThirdPersonDemoURP" + private static readonly HashSet ExcludeDirectories = new() + { + "ThirdPersonDemoURP" }; private static bool _hasExtractProblem = false; @@ -581,33 +582,33 @@ private static List CreateStateInfoFromRGStateEntities() switch (member) { case FieldDeclarationSyntax fieldDeclaration: - { - fieldName = fieldDeclaration.Declaration.Variables.First().Identifier.ValueText; - type = RemoveGlobalPrefix(semanticModel - .GetTypeInfo(fieldDeclaration.Declaration.Type) - .Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)); - if (!fieldDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword)) { - RecordWarning($"Field '{fieldDeclaration.Declaration.Variables.First().Identifier.ValueText}' in class '{className}' is not public and will not be included in the available state fields."); - continue; + fieldName = fieldDeclaration.Declaration.Variables.First().Identifier.ValueText; + type = RemoveGlobalPrefix(semanticModel + .GetTypeInfo(fieldDeclaration.Declaration.Type) + .Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)); + if (!fieldDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword)) + { + RecordWarning($"Field '{fieldDeclaration.Declaration.Variables.First().Identifier.ValueText}' in class '{className}' is not public and will not be included in the available state fields."); + continue; + } + + break; } - - break; - } case PropertyDeclarationSyntax propertyDeclaration: - { - fieldName = propertyDeclaration.Identifier.ValueText; - type = RemoveGlobalPrefix(semanticModel - .GetTypeInfo(propertyDeclaration.Type) - .Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)); - if (!propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword)) { - RecordWarning($"Property '{propertyDeclaration.Identifier.ValueText}' in class '{className}' is not public and will not be included in the available state properties."); - continue; + fieldName = propertyDeclaration.Identifier.ValueText; + type = RemoveGlobalPrefix(semanticModel + .GetTypeInfo(propertyDeclaration.Type) + .Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)); + if (!propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword)) + { + RecordWarning($"Property '{propertyDeclaration.Identifier.ValueText}' in class '{className}' is not public and will not be included in the available state properties."); + continue; + } + + break; } - - break; - } default: // no methods continue; @@ -719,7 +720,7 @@ private static (List, List) CreateState var allEntities = Object.FindObjectsOfType().Where(v => !string.IsNullOrEmpty(v.objectType)); foreach (var entity in allEntities) { - var (stateClassNames,actionClassNames) = entity.LookupStatesAndActions(); + var (stateClassNames, actionClassNames) = entity.LookupStatesAndActions(); var entityStateActionJson = DeriveStateAndActionJsonForEntity(entity.objectType, stateClassNames, actionClassNames, statesInfos, actionInfos); @@ -775,7 +776,7 @@ private static (List, List) CreateState RGEntity prefabComponent = prefab.GetComponent(); if (prefabComponent != null && !string.IsNullOrEmpty(prefabComponent.objectType)) { - var (stateClassNames,actionClassNames) = prefabComponent.LookupStatesAndActions(); + var (stateClassNames, actionClassNames) = prefabComponent.LookupStatesAndActions(); var prefabStateActionJson = DeriveStateAndActionJsonForEntity(prefabComponent.objectType, stateClassNames, actionClassNames, statesInfos, actionInfos); CheckForMisMatchedStateOrActionsOnEntity(prefabComponent, prefabStateActionJson, result); @@ -789,20 +790,20 @@ private static (List, List) CreateState } } - (List, List) listResult = new () + (List, List) listResult = new() { Item1 = result.Item1.ToList(), Item2 = result.Item2.ToList() }; - listResult.Item1.Sort((a,b) => a.ObjectType.CompareTo(b.ObjectType)); - listResult.Item2.Sort((a,b) => a.ObjectType.CompareTo(b.ObjectType)); + listResult.Item1.Sort((a, b) => a.ObjectType.CompareTo(b.ObjectType)); + listResult.Item2.Sort((a, b) => a.ObjectType.CompareTo(b.ObjectType)); return listResult; } - private static void CheckForMisMatchedStateOrActionsOnEntity(RGEntity entity, (RGEntityStatesJson, RGEntityActionsJson) entityStateActionJson, (HashSet, HashSet)result) + private static void CheckForMisMatchedStateOrActionsOnEntity(RGEntity entity, (RGEntityStatesJson, RGEntityActionsJson) entityStateActionJson, (HashSet, HashSet) result) { - if(result.Item1.TryGetValue(entityStateActionJson.Item1, out var existingItem1)) + if (result.Item1.TryGetValue(entityStateActionJson.Item1, out var existingItem1)) { // this is a bit expensive, but necessary to ensure all RGStateEntities of the same ObjectType expose the same state/Actions if (existingItem1.States.Count != entityStateActionJson.Item1.States.Count || @@ -821,7 +822,7 @@ private static void CheckForMisMatchedStateOrActionsOnEntity(RGEntity entity, (R RecordWarning($"RGEntity of ObjectType: {entity.objectType} has conflicting state definitions on different game objects or prefabs; state lists: [{string.Join(", ", entityStateActionJson.Item1.States)}] <-> [{string.Join(", ", existingItem1.States)}]"); } } - if(result.Item2.TryGetValue(entityStateActionJson.Item2, out var existingItem2)) + if (result.Item2.TryGetValue(entityStateActionJson.Item2, out var existingItem2)) { // this is a bit expensive, but necessary to ensure all RGStateEntities of the same ObjectType expose the same state/Actions if (existingItem2.Actions.Count != entityStateActionJson.Item2.Actions.Count || diff --git a/src/gg.regression.unity.bots/Editor/Scripts/RGBotReplayWindow.cs b/src/gg.regression.unity.bots/Editor/Scripts/RGBotReplayWindow.cs index 5a68b26ad..47965512a 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/RGBotReplayWindow.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/RGBotReplayWindow.cs @@ -22,7 +22,7 @@ namespace RegressionGames.Editor public class RGBotReplayWindow : EditorWindow { public const string PREFAB_PATH = "Packages/gg.regression.unity.bots/Editor/Prefabs"; - + //TODO: Get this from game engine private const int PHYSICS_TICK_RATE = 20; // 0.02 sec or 20 ms per physics tick private readonly Color _darkerColor = Color.white * 0.1f; @@ -89,21 +89,21 @@ private void OnGUI() EditorGUI.BeginDisabledGroup(fileName == null || fileName.Length < 1); if (GUILayout.Button("Reload ...", GUILayout.ExpandWidth(false))) Reload(); EditorGUI.EndDisabledGroup(); - + GUILayout.FlexibleSpace(); - + EditorGUILayout.EndHorizontal(); - + GUILayout.Space(5); - + if (!ReplayModelManager.GetInstance().HasEntries()) { EditorGUILayout.HelpBox("Custom Replay Models have not been configured for this project.\nLoad your first replay zip to auto populate the entity types, then configure their model associations using the `Configure Custom Replay Models` button.\n(You can also manually add, edit, or remove associations at any time.)", MessageType.Warning, true); } - + // Button for registering custom replay models - if (GUILayout.Button("Configure Custom Replay Models", new GUILayoutOption[] {GUILayout.ExpandWidth(false)})) + if (GUILayout.Button("Configure Custom Replay Models", new GUILayoutOption[] { GUILayout.ExpandWidth(false) })) { // create or load the prefabs list ShowReplayModelsInspector(); @@ -257,7 +257,7 @@ private void CreateTimelineHeaders() headerContent = new GUIContent("Actions", "Actions entity took in the current tick."), headerTextAlignment = TextAlignment.Center }); - + _columns.Add(new MultiColumnHeaderState.Column { allowToggleVisibility = false, @@ -504,43 +504,43 @@ private void RenderTimelineView() if (isSpawned) { var actions = dataTickInfo.actions; - + // Fit each action equally into the space with text hover help for (var j = 0; j < actions.Length; j++) { // draw a colored rect var actionRect = CreateInfoRect(columnIndex, rowRect.y, actions.Length, j); EditorGUI.DrawRect(actionRect, Color.gray * Color.yellow); - + // then put a label in it var label = new GUIContent($"{actions[j].action}", $"{textForAction(j + 1, actions[j])}"); EditorGUI.DropShadowLabel(actionRect, label, actionLabelGUIStyle); } } - - // Validations column - ++columnIndex; - if (_multiColumnHeader.IsColumnVisible(columnIndex)) - if (isSpawned) + + // Validations column + ++columnIndex; + if (_multiColumnHeader.IsColumnVisible(columnIndex)) + if (isSpawned) + { + var validationResults = dataTickInfo.validationResults; + + // Fit each validation equally into the space with text hover help + for (var j = 0; j < validationResults.Length; j++) { - var validationResults = dataTickInfo.validationResults; - - // Fit each validation equally into the space with text hover help - for (var j = 0; j < validationResults.Length; j++) - { - var currentValidation = validationResults[j]; - - // draw a colored rect - var validationRect = CreateInfoRect(columnIndex, rowRect.y, validationResults.Length, j); - var color = currentValidation.passed ? Color.green : Color.red; - EditorGUI.DrawRect(validationRect, Color.gray * color); - - // then put a label in it - var tooltip = (currentValidation.passed ? "[PASSED] " : "[FAILED] ") + currentValidation.message; - var label = new GUIContent(currentValidation.message, tooltip); - EditorGUI.DropShadowLabel(validationRect, label, validationLabelGUIStyle); - } + var currentValidation = validationResults[j]; + + // draw a colored rect + var validationRect = CreateInfoRect(columnIndex, rowRect.y, validationResults.Length, j); + var color = currentValidation.passed ? Color.green : Color.red; + EditorGUI.DrawRect(validationRect, Color.gray * color); + + // then put a label in it + var tooltip = (currentValidation.passed ? "[PASSED] " : "[FAILED] ") + currentValidation.message; + var label = new GUIContent(currentValidation.message, tooltip); + EditorGUI.DropShadowLabel(validationRect, label, validationLabelGUIStyle); } + } ++a; } @@ -569,7 +569,7 @@ private Rect CreateInsetRect(int columnIndex, float height, Vector2? padding) insetRect.y += padding.Value.y; insetRect.height -= padding.Value.y * 2; } - + return insetRect; } @@ -580,12 +580,12 @@ private Rect CreateInsetRect(int columnIndex, float height, Vector2? padding) private Rect CreateInfoRect(int columnIndex, float height, int componentsPerRow, int xOffset) { var insetRect = CreateInsetRect(columnIndex, height, null); - + const float minWidth = 5f; const float maxWidth = 150f; var width = insetRect.width / Math.Max(1, componentsPerRow); width = Math.Min(Math.Max(width, minWidth), maxWidth); - + // leave a 1 pixel gap .. this keeps many actions from flowing together insetRect.width = width - 1; insetRect.x += width * xOffset; @@ -597,7 +597,7 @@ public static void ShowWindow() { GetWindow(typeof(RGBotReplayWindow), false, "RG Bot Replay"); } - + // Did not add to the top menu yet, but might in the future //[MenuItem("Regression Games/Configure Custom Replay Models")] public static void ShowReplayModelsInspector() @@ -706,12 +706,12 @@ private void UpdatePlayerForGameState(RGEntityDataForTick tickData) { position = ti.state.position; } - + if (ti?.state?.rotation != null) { rotation = ti.state.rotation; } - + var typeRootName = $"{tickData.data.type}s"; var typeRoot = findChildByName(rootObject.transform, typeRootName); if (typeRoot == null) @@ -1011,7 +1011,7 @@ private bool ParseFile(string filename) tickInfoManager.processTick(tickIndexNumber, rData.tickInfo); if (rData.playerId != null && rData.playerId != -1) tickInfoManager.processReplayData(tickIndexNumber, (long)rData.playerId, rData); - + if (rData.tickRate != null) // get the right tickRate tickRate = (int)rData.tickRate; @@ -1019,7 +1019,7 @@ private bool ParseFile(string filename) ++tickIndexNumber; } } - + // save any assets we created, like replay model associations // we do this once here instead of internally when adding the asset for // performance reasons.. this is expensive @@ -1089,5 +1089,5 @@ private void doStepForward() if (currentTick == priorTick) playing = false; } } - #endif +#endif } diff --git a/src/gg.regression.unity.bots/Editor/Scripts/RGEntityStatesJson.cs b/src/gg.regression.unity.bots/Editor/Scripts/RGEntityStatesJson.cs index 501a99e83..a0035ec1c 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/RGEntityStatesJson.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/RGEntityStatesJson.cs @@ -4,7 +4,7 @@ namespace RegressionGames.Editor { - + [Serializable] // ReSharper disable InconsistentNaming public class RGEntityStatesJson diff --git a/src/gg.regression.unity.bots/Editor/Scripts/RGSettingsUIRegistrar.cs b/src/gg.regression.unity.bots/Editor/Scripts/RGSettingsUIRegistrar.cs index 093b60b5e..b243f1118 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/RGSettingsUIRegistrar.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/RGSettingsUIRegistrar.cs @@ -19,7 +19,7 @@ namespace RegressionGames.Editor public class RGSettingsUIRegistrar { - private static RGServiceManager rgServiceManager = new (); // editor, not game/scene so don't look for one, make one + private static RGServiceManager rgServiceManager = new(); // editor, not game/scene so don't look for one, make one private static string token = null; private static string priorUser = null; @@ -44,31 +44,31 @@ public static SettingsProvider CreateRGSettingsProvider() SerializedObject settings = RGSettings.GetSerializedSettings(); SerializedObject userSettings = RGUserSettings.GetSerializedUserSettings(); EditorGUI.BeginChangeCheck(); - + SerializedProperty hostField = settings.FindProperty("rgHostAddress"); hostField.stringValue = EditorGUILayout.TextField("RG Host URL", hostField.stringValue); - + SerializedProperty emailField = userSettings.FindProperty("email"); emailField.stringValue = EditorGUILayout.TextField("RG Email", emailField.stringValue); SerializedProperty passwordField = userSettings.FindProperty("password"); passwordField.stringValue = EditorGUILayout.PasswordField("RG Password", passwordField.stringValue); - + SerializedProperty logLevel = settings.FindProperty("logLevel"); logLevel.enumValueIndex = (int)(DebugLogLevel)EditorGUILayout.EnumPopup("Log Level", (DebugLogLevel)logLevel.enumValueIndex); SerializedProperty enableOverlay = settings.FindProperty("enableOverlay"); enableOverlay.boolValue = EditorGUILayout.Toggle("Enable Screen Overlay ?", enableOverlay.boolValue); - + SerializedProperty useSystemSettings = settings.FindProperty("useSystemSettings"); useSystemSettings.boolValue = EditorGUILayout.Toggle("Use Global Bot Settings ?", useSystemSettings.boolValue); - + EditorGUI.BeginDisabledGroup(useSystemSettings.boolValue != true); SerializedProperty numBotsProp = settings.FindProperty("numBots"); numBotsProp.intValue = EditorGUILayout.IntSlider("Number Of Bots", numBotsProp.intValue, 0, 7, new GUILayoutOption[] { }); SerializedProperty botsSelected = settings.FindProperty("botsSelected"); - if ((EditorApplication.timeSinceStartup-timeOfLastEdit) > 3f && token == null && priorPassword == null && priorHost == null && priorUser == null && passwordField.stringValue.Length > 4 && emailField.stringValue.Length > 4 && hostField.stringValue.Length > 4) + if ((EditorApplication.timeSinceStartup - timeOfLastEdit) > 3f && token == null && priorPassword == null && priorHost == null && priorUser == null && passwordField.stringValue.Length > 4 && emailField.stringValue.Length > 4 && hostField.stringValue.Length > 4) { priorPassword = passwordField.stringValue; priorUser = emailField.stringValue; @@ -84,14 +84,14 @@ await rgServiceManager.GetBotsForCurrentUser(botList => { foreach (var rgBot in botList) { - if (rgBot is { IsUnityBot: true , IsLocal: false}) + if (rgBot is { IsUnityBot: true, IsLocal: false }) { listOfBots.Add(rgBot); } } }, () => { - + }); // get Local bots RGBotAssetsManager.GetInstance()?.RefreshAvailableBots(); @@ -103,7 +103,7 @@ await rgServiceManager.GetBotsForCurrentUser(botList => listOfBots.Add(localBot); } } - listOfBots.Sort((a,b) => String.Compare(a.UIString, b.UIString, StringComparison.Ordinal)); + listOfBots.Sort((a, b) => String.Compare(a.UIString, b.UIString, StringComparison.Ordinal)); bots = listOfBots.ToArray(); } @@ -117,7 +117,7 @@ await rgServiceManager.GetBotsForCurrentUser(botList => botIndexMap[bot.id] = index; return index++; }); - + for (int i = 1; i <= numBotsProp.intValue; i++) { try @@ -131,10 +131,10 @@ await rgServiceManager.GetBotsForCurrentUser(botList => var priorIndex = 0; botIndexMap.TryGetValue(botSelected.longValue, out priorIndex); - var indexSelected = EditorGUILayout.IntPopup($"Bot # {i}", - priorIndex, - botUIStrings.ToArray(), botIndexes.ToArray(), - new GUILayoutOption[] { }); + var indexSelected = EditorGUILayout.IntPopup($"Bot # {i}", + priorIndex, + botUIStrings.ToArray(), botIndexes.ToArray(), + new GUILayoutOption[] { }); if (indexSelected > bots.Length) { indexSelected = 0; @@ -194,14 +194,14 @@ public static async Task Login(string user, string password) var tcs = new TaskCompletionSource(); - await rgServiceManager.Auth(priorUser, priorPassword, - responseToken => + await rgServiceManager.Auth(priorUser, priorPassword, + responseToken => { token = responseToken; bots = null; tcs.SetResult(true); - }, - f => + }, + f => { token = null; bots = null; diff --git a/src/gg.regression.unity.bots/Editor/Scripts/RGStateAttributesInfo.cs b/src/gg.regression.unity.bots/Editor/Scripts/RGStateAttributesInfo.cs index bca0be978..9541f291f 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/RGStateAttributesInfo.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/RGStateAttributesInfo.cs @@ -10,7 +10,7 @@ public class RGStateAttributeInfoWrapper { public List RGStateAttributesInfo { get; set; } } - + [Serializable] public class RGStateAttributesInfo { diff --git a/src/gg.regression.unity.bots/Editor/Scripts/RGStatesInfo.cs b/src/gg.regression.unity.bots/Editor/Scripts/RGStatesInfo.cs index d933fdacd..4d993cf1e 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/RGStatesInfo.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/RGStatesInfo.cs @@ -9,7 +9,7 @@ public class RGStateInfoWrapper { public List RGStatesInfo { get; set; } } - + [Serializable] public class RGStatesInfo { diff --git a/src/gg.regression.unity.bots/Editor/Scripts/RGTickInfoActionManager.cs b/src/gg.regression.unity.bots/Editor/Scripts/RGTickInfoActionManager.cs index a0e021a1a..b7264fda5 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/RGTickInfoActionManager.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/RGTickInfoActionManager.cs @@ -73,23 +73,23 @@ public void processTick(int tickNumber, RGTickInfoData tickData) bool isRuntimeObject = entity.isRuntimeObject; populateReplayDataForEntity(entityId, isPlayer, isRuntimeObject, entity.type); - + // handle strong typing on position / rotation accessors if (entity.ContainsKey("position") && entity["position"] is JObject) { - var jObj = (JObject)entity["position"]; - entity["position"] = new Vector3(jObj["x"].Value(), - jObj["y"].Value(), - jObj["z"].Value()); + var jObj = (JObject)entity["position"]; + entity["position"] = new Vector3(jObj["x"].Value(), + jObj["y"].Value(), + jObj["z"].Value()); } - + if (entity.ContainsKey("rotation") && entity["rotation"] is JObject) { - var jObj = (JObject)entity["rotation"]; - entity["rotation"] = new Quaternion(jObj["x"].Value(), - jObj["y"].Value(), - jObj["z"].Value(), - jObj["w"].Value()); + var jObj = (JObject)entity["rotation"]; + entity["rotation"] = new Quaternion(jObj["x"].Value(), + jObj["y"].Value(), + jObj["z"].Value(), + jObj["w"].Value()); } } } @@ -100,7 +100,7 @@ public void processReplayData(int tickNumber, long entityId, RGStateActionReplay tickInfo.actions = data.actions == null ? Array.Empty() : data.actions; tickInfo.validationResults = data.validationResults == null ? Array.Empty() : data.validationResults; // show path and actions by default only for bot players with actions - populateReplayDataForEntity(entityId, true,false, null, true, + populateReplayDataForEntity(entityId, true, false, null, true, true, true); } diff --git a/src/gg.regression.unity.bots/Editor/Scripts/ReplayModelManager.cs b/src/gg.regression.unity.bots/Editor/Scripts/ReplayModelManager.cs index 5c9f52428..ef9ba07ca 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/ReplayModelManager.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/ReplayModelManager.cs @@ -11,17 +11,18 @@ namespace RegressionGames.Editor #if UNITY_EDITOR public class ReplayModelManager : ScriptableObject { - + public readonly static string ASSET_PATH = "Assets/RegressionGames/Editor/CustomReplayModels.asset"; - - + + [SerializeField] private NamedModel[] models = Array.Empty(); public void OnEnable() { - - if ( AssetDatabase.GetMainAssetTypeAtPath( ASSET_PATH ) != null) { + + if (AssetDatabase.GetMainAssetTypeAtPath(ASSET_PATH) != null) + { _this = AssetDatabase.LoadAssetAtPath(ASSET_PATH); } } @@ -45,11 +46,12 @@ public static ReplayModelManager GetInstance() _this = CreateInstance(); } - if ( AssetDatabase.GetMainAssetTypeAtPath( ASSET_PATH ) == null) { - AssetDatabase.CreateAsset(_this, ASSET_PATH ); + if (AssetDatabase.GetMainAssetTypeAtPath(ASSET_PATH) == null) + { + AssetDatabase.CreateAsset(_this, ASSET_PATH); AssetDatabase.SaveAssets(); } - + return _this; } @@ -60,7 +62,7 @@ public void OpenAssetInspector() AssetDatabase.OpenAsset(_this); } } - + public bool HasEntries() { return models.Length > 0; @@ -80,7 +82,7 @@ public bool AddObjectType(string objectType) return false; } - + [CanBeNull] public GameObject getModelPrefabForType(string type, string charType) { @@ -95,13 +97,13 @@ public GameObject getModelPrefabForType(string type, string charType) nm = models.FirstOrDefault(model => model.objectType == type); if (nm.objectType != null && nm.modelPrefab != null) return nm.modelPrefab; - + GameObject defaultPrefab = AssetDatabase.LoadAssetAtPath( $"{RGBotReplayWindow.PREFAB_PATH}/DefaultModel.prefab"); // could be null return defaultPrefab; - + } [Serializable] @@ -112,7 +114,7 @@ public NamedModel(string objectType, GameObject modelPrefab) this.objectType = objectType; this.modelPrefab = modelPrefab; } - + [CanBeNull] public string objectType; [CanBeNull] public GameObject modelPrefab; } diff --git a/src/gg.regression.unity.bots/Editor/Scripts/Startup/RegressionPackagePopup.cs b/src/gg.regression.unity.bots/Editor/Scripts/Startup/RegressionPackagePopup.cs index 73ba3c7e7..495c2e52f 100644 --- a/src/gg.regression.unity.bots/Editor/Scripts/Startup/RegressionPackagePopup.cs +++ b/src/gg.regression.unity.bots/Editor/Scripts/Startup/RegressionPackagePopup.cs @@ -34,7 +34,7 @@ void OnEnable() string assetsPath = "Assets/Editor/Images/banner.png"; bannerImage = AssetDatabase.LoadAssetAtPath(packagePath); - + if (bannerImage == null) { bannerImage = AssetDatabase.LoadAssetAtPath(assetsPath); @@ -45,7 +45,7 @@ void OnEnable() Debug.LogWarning("Failed to load banner image"); } } - + [MenuItem("Regression Games/Getting Started")] public static async void ShowWindow() { @@ -53,7 +53,7 @@ public static async void ShowWindow() email = RGUserSettings.GetOrCreateUserSettings().GetEmail(); password = RGUserSettings.GetOrCreateUserSettings().GetPassword(); await Login(); - + if (window == null) { Rect windowRect = new Rect(100, 100, 600, 600); @@ -81,16 +81,16 @@ void OnGUI() private void RenderLoginScreen() { if (bannerImage != null) - { + { GUILayout.Box(bannerImage, GUILayout.ExpandWidth(true), GUILayout.Height(200)); } - + // H1 GUIStyle h1Style = new GUIStyle(EditorStyles.largeLabel); h1Style.fontSize = 20; h1Style.fontStyle = FontStyle.Bold; h1Style.normal.textColor = Color.white; - + // P GUIStyle pStyle = new GUIStyle(EditorStyles.label); pStyle.fontSize = 12; @@ -114,7 +114,7 @@ private void RenderLoginScreen() "will help you get started quickly.", pStyle, GUILayout.Width(550)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); - + GUILayout.Space(20); // Email field GUILayout.BeginHorizontal(); @@ -155,7 +155,7 @@ private void RenderLoginScreen() // Create Account and Forgot Password Links GUIStyle linkStyle = new GUIStyle(EditorStyles.label); linkStyle.fontSize = 12; - + GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create Account", linkStyle)) @@ -164,7 +164,7 @@ private void RenderLoginScreen() } GUILayout.Space(10); - + // For mouse hover effect if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) { @@ -182,14 +182,14 @@ private void RenderLoginScreen() if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) { EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); - } + } } private void RenderWelcomeScreen() { // set flags on render as extra check against duplicated popups PlayerPrefs.SetInt(RGGuestCheck, 1); - + // render window info RenderBanner(); RenderAlwaysShowOnStartupCheckbox(); @@ -209,14 +209,14 @@ private void RenderBanner() GUI.color = new Color(0, 0, 0, 0.5f); GUI.DrawTexture(new Rect(0, 0, 600, 120), EditorGUIUtility.whiteTexture); GUI.color = prevColor; - + // Define the text style GUIStyle h1Style = new GUIStyle(EditorStyles.largeLabel) { normal = { textColor = Color.white }, alignment = TextAnchor.MiddleLeft, fontSize = 20, - fontStyle = FontStyle.Bold + fontStyle = FontStyle.Bold }; // Determine the position and size for the label @@ -225,16 +225,16 @@ private void RenderBanner() // Draw the title text GUI.Label(textRect, "Regression Games Setup Guide", h1Style); } - + private void RenderAlwaysShowOnStartupCheckbox() { GUILayout.Space(120); - + // Get the current value from PlayerPrefs bool alwaysShowOnStartup = PlayerPrefs.GetInt(RGWindowCheck, 1) == 1; // Define the style for the label - GUIStyle labelStyle = new GUIStyle(GUI.skin.label) + GUIStyle labelStyle = new GUIStyle(GUI.skin.label) { fontStyle = FontStyle.Bold, fontSize = 12 @@ -242,7 +242,7 @@ private void RenderAlwaysShowOnStartupCheckbox() // Define the position and size for the label Rect labelRect = new Rect(20, 130, 200, 20); - + // Draw the label GUI.Label(labelRect, "Always Show On Startup", labelStyle); @@ -303,7 +303,7 @@ private void RenderQuickstartDocs() Application.OpenURL("https://docs.regression.gg/studios/unity/unity-sdk/creating-bots/csharp/configuration"); } } - + private void RenderSampleQuickstart() { // Define the styles for the sample section @@ -317,7 +317,7 @@ private void RenderSampleQuickstart() { wordWrap = true }; - + GUIStyle boldDescriptionStyle = new GUIStyle(EditorStyles.label) { wordWrap = true, @@ -348,7 +348,7 @@ private void RenderSampleQuickstart() } GUI.enabled = true; } - + private bool IsURPEnabled() { var renderPipelineAsset = GraphicsSettings.currentRenderPipeline; @@ -362,7 +362,7 @@ private bool IsURPEnabled() } return false; } - + private void ImportSample(string sampleName) { string packageName = "gg.regression.unity.bots"; @@ -405,7 +405,7 @@ private void ImportSample(string sampleName) RGDebug.LogError("The sample could not be found or is not in an embedded or local package."); } } - + [InitializeOnLoadMethod] private static void InitializeOnLoadMethod() { @@ -414,7 +414,7 @@ private static void InitializeOnLoadMethod() SessionState.SetBool(RGUnityCheck, true); bool showOnStartup = PlayerPrefs.GetInt(RGWindowCheck, 1) == 1; if (showOnStartup) - { + { EditorApplication.update += ShowOnStartup; } } @@ -428,7 +428,7 @@ private static void ShowOnStartup() ShowWindow(); } } - + private static async Task Login() { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) @@ -456,8 +456,8 @@ private static void ContinueAsGuest() { window.Repaint(); return; - } - + } + // continue without log in PlayerPrefs.SetInt(RGGuestCheck, 1); if (window != null) diff --git a/src/gg.regression.unity.bots/Runtime/Scripts/ActiveRGBotUIElement.cs b/src/gg.regression.unity.bots/Runtime/Scripts/ActiveRGBotUIElement.cs index f06d51700..bceb5a11f 100644 --- a/src/gg.regression.unity.bots/Runtime/Scripts/ActiveRGBotUIElement.cs +++ b/src/gg.regression.unity.bots/Runtime/Scripts/ActiveRGBotUIElement.cs @@ -20,11 +20,11 @@ public void Awake() statusText.text = $"{state}"; } } - + public void Start() { Button b = GetComponentInChildren