Skip to content

Commit

Permalink
Merge pull request #110 from nowsprinting/feature/mppm
Browse files Browse the repository at this point in the history
Support Multiplayer Play Mode (MPPM) package
  • Loading branch information
bo40 authored Nov 19, 2024
2 parents 6a913f2 + 25e6a8e commit bc14d37
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions Editor/UI/Settings/AutopilotSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ internal void Launch()
else
{
state.launchFrom = LaunchType.EditMode;
AssetDatabase.SaveAssetIfDirty(state); // Note: Sync with virtual players of MPPM package
EditorApplication.isPlaying = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ The placeholders you can include in the lead and message body template are:
- "{message}": Message with terminate (e.g., error log message)
- "{settings}": Name of running AutopilotSettings
- "{env.KEY}": Environment variables
- "{mppm-tags}": Tags of the [Multiplayer Play Mode](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest) package



Expand Down
1 change: 1 addition & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ Slack Botには次の権限が必要です。
- "{message}": 終了要因メッセージ(エラーログのメッセージなど)
- "{settings}": 実行中の AutopilotSettings 名
- "{env.KEY}": 環境変数
- "{mppm-tags}": [Multiplayer Play Mode](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest) パッケージのタグ



Expand Down
9 changes: 8 additions & 1 deletion Runtime/DeNA.Anjin.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"references": [
"DeNA.Anjin.Annotations",
"Unity.AutomatedQA",
"Unity.Multiplayer.Playmode",
"UniTask",
"TestHelper.Monkey",
"TestHelper.Monkey.Annotations",
Expand All @@ -19,6 +20,12 @@
"defineConstraints": [
"UNITY_INCLUDE_TESTS || DENA_AUTOPILOT_ENABLE"
],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.multiplayer.playmode",
"expression": "",
"define": "ENABLED_MPPM"
}
],
"noEngineReferences": false
}
3 changes: 3 additions & 0 deletions Runtime/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ internal static async UniTaskVoid TeardownLaunchAutopilotAsync(AutopilotState st
{
state.settings = null;
state.exitCode = exitCode;
#if UNITY_EDITOR
AssetDatabase.SaveAssetIfDirty(state); // Note: Sync with virtual players of MPPM package
#endif

if (state.launchFrom == LaunchType.PlayMode) // Note: Editor play mode, Play mode tests, and Player build
{
Expand Down
24 changes: 24 additions & 0 deletions Runtime/Reporters/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeNA.Anjin.Settings;
#if ENABLED_MPPM
using Unity.Multiplayer.Playmode;
#endif

namespace DeNA.Anjin.Reporters
{
Expand All @@ -21,6 +25,7 @@ public static class MessageBuilder
/// - {message}: Message with terminate (e.g., error log message)
/// - {settings}: Name of running AutopilotSettings
/// - {env.KEY}: Environment variables
/// - {mppm-tags}: Tags of the Multiplayer Play Mode package
/// </param>
/// <param name="message">Replace placeholder "{message}" in the template with this string</param>
/// <returns>Messages that replaced placeholders in the template</returns>
Expand All @@ -30,6 +35,9 @@ public static string BuildWithTemplate(string template, string message = null)
var placeholders = GetPlaceholders().ToList();
placeholders.Add(("{message}", message));
placeholders.Add(("{settings}", settings ? settings.Name : "null"));
#if ENABLED_MPPM
placeholders.Add(("{mppm-tags}", ArrayToString(CurrentPlayer.ReadOnlyTags())));
#endif

var replacedMessage = template;
placeholders.ForEach(placeholder =>
Expand All @@ -48,5 +56,21 @@ public static string BuildWithTemplate(string template, string message = null)
yield return ("{env." + key + "}", env[key] as string);
}
}

private static string ArrayToString(string[] tags)
{
var builder = new StringBuilder();
foreach (var tag in tags)
{
if (builder.Length > 0)
{
builder.Append(" ");
}

builder.Append($"`{tag}`");
}

return builder.ToString();
}
}
}
16 changes: 12 additions & 4 deletions Runtime/Settings/AutopilotState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ public class AutopilotState : ScriptableObject
/// <summary>
/// Launch type
/// </summary>
[HideInInspector] public LaunchType launchFrom = LaunchType.NotSet;
[HideInInspector]
public LaunchType launchFrom = LaunchType.NotSet;

/// <summary>
/// Run autopilot settings instance
/// </summary>
[HideInInspector] [CanBeNull] public AutopilotSettings settings;
[HideInInspector]
[CanBeNull]
public AutopilotSettings settings;

/// <summary>
/// Exit code when terminate autopilot from commandline interface
/// </summary>
[HideInInspector] public ExitCode exitCode;
[HideInInspector]
public ExitCode exitCode;

/// <summary>
/// Reset run state
Expand All @@ -42,6 +46,9 @@ public void Reset()
launchFrom = LaunchType.NotSet;
settings = null;
exitCode = ExitCode.Normally;
#if UNITY_EDITOR
AssetDatabase.SaveAssetIfDirty(this); // Note: Sync with virtual players of MPPM package
#endif
}

/// <summary>
Expand All @@ -59,7 +66,8 @@ public bool IsRunning
}
}

[NonSerialized] private static AutopilotState s_instance;
[NonSerialized]
private static AutopilotState s_instance;

/// <summary>
/// <c>AutopilotState</c> instance
Expand Down

0 comments on commit bc14d37

Please sign in to comment.