Skip to content

Commit

Permalink
Merge pull request #116 from playroomkit/browser-mode-refactor
Browse files Browse the repository at this point in the history
Browser mode and more refactor
  • Loading branch information
momintlh authored Nov 16, 2024
2 parents 156b92f + 42f1380 commit 8ab77f4
Show file tree
Hide file tree
Showing 55 changed files with 3,013 additions and 1,672 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ Assets/Plugins
Assets/PlayroomKit/node_modules.meta
/.idea
Assets/chromedriver*
Assets/msedgedriver.exe
Assets/msedgedriver.exe.meta
23 changes: 17 additions & 6 deletions Assets/PlayroomKit/Editor/PlayroomDevEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class PrkMockInspector : Editor
{
public StyleSheet styleSheet;

public void OnEnable()
{
styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/PlayroomKit/Editor/PlayroomkitDevManagerEditor.uss");
}

public override VisualElement CreateInspectorGUI()
{
VisualElement root = new VisualElement
Expand All @@ -24,6 +29,12 @@ public override VisualElement CreateInspectorGUI()
flexDirection = FlexDirection.Column
}
};

if (styleSheet == null)
{
Debug.LogError("Style sheet is null");
}

root.styleSheets.Add(styleSheet);

VisualElement mockModeContainer = MockModeContainerCreator();
Expand Down Expand Up @@ -112,7 +123,7 @@ private VisualElement MockModeContainerCreator()
var mockModeOptions = new List<string>
{
"Local (simulated)",
// "Browser Bridge (live)"
"Browser Bridge (live)"
};

var mockModeProperty = serializedObject.FindProperty("mockMode");
Expand All @@ -128,16 +139,16 @@ private VisualElement MockModeContainerCreator()
mockModeDropdown.RegisterValueChangedCallback(evt =>
{
var selectedString = evt.newValue;
PlayroomKit.MockModeSelector selectedEnum = PlayroomKit.MockModeSelector.Local; // Default value
PlayroomKit.MockModeSelector selectedEnum = PlayroomKit.MockModeSelector.Local;
if (selectedString == "Local (simulated)")
{
selectedEnum = PlayroomKit.MockModeSelector.Local;
}
// else if (selectedString == "Browser Bridge (live)")
// {
// selectedEnum = PlayroomKit.MockModeSelector.BrowserBridge;
// }
else if (selectedString == "Browser Bridge (live)")
{
selectedEnum = PlayroomKit.MockModeSelector.Browser;
}
mockModeProperty.enumValueIndex = (int)selectedEnum;
serializedObject.ApplyModifiedProperties();
Expand Down
12 changes: 12 additions & 0 deletions Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ PrefabInstance:
propertyPath: insertCoinCaller
value:
objectReference: {fileID: 330732768}
- target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: webDriverDirectory
value: Assets\
objectReference: {fileID: 0}
- target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: mockMode
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: insertCoinCaller
value:
objectReference: {fileID: 330732768}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void Start()
/// </summary>
void HandleScoreUpdate(string data, string caller)
{
var player = PlayroomKit.GetPlayer(caller);
var player = _playroomKit.GetPlayer(caller);
Debug.Log($"Caller: {caller}, Player Name: {player?.GetProfile().name}, Data: {data}");

if (PlayerDict.TryGetValue(caller, out GameObject playerObj))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1429187865}
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.5748165, a: 1}
m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481694, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -343,6 +343,18 @@ PrefabInstance:
propertyPath: insertCoinCaller
value:
objectReference: {fileID: 1903050736}
- target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: browser
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: webDriverDirectory
value: Assets\
objectReference: {fileID: 0}
- target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: insertCoinCaller
value:
objectReference: {fileID: 1903050736}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public class GameManagerIsometric : MonoBehaviour

private static readonly Dictionary<string, GameObject> PlayerDict = new();

[SerializeField] private static bool playerJoined;
[SerializeField] private string roomCode;
[SerializeField] private GameObject playerPrefab;
[SerializeField]
private static bool playerJoined;
[SerializeField]
private string roomCode;
[SerializeField]
private GameObject playerPrefab;

private PlayroomKit _playroomKit = new PlayroomKit();

Expand All @@ -24,8 +27,8 @@ private void Start()
{
maxPlayersPerRoom = 3,
matchmaking = false,
gameId = "<Insert GameID (from dev.joinplayroom.com)>",
discord = true,
gameId = "ii4pV1wfceCjjLvRoo3O",
roomCode = roomCode,
}, () => { _playroomKit.OnPlayerJoin(AddPlayer); }, () => { Debug.Log("OnDisconnect callback"); });
}
Expand All @@ -40,8 +43,7 @@ private void Update()
playerGameObjects[index].GetComponent<IsometricPlayerController>().LookAround();
players[index].SetState("angle", playerGameObjects[index].GetComponent<Transform>().rotation);




playerGameObjects[index].GetComponent<IsometricPlayerController>().Move();
players[index].SetState("move", playerGameObjects[index].GetComponent<Transform>().position);

Expand All @@ -66,6 +68,8 @@ private void Update()

public void AddPlayer(PlayroomKit.Player player)
{
Debug.LogFormat("{0} Is host?: {1}", player.GetProfile().name,_playroomKit.IsHost());

var playerObj = Instantiate(playerPrefab,
new Vector3(Random.Range(-5, 5), 2f, Random.Range(-5, 5)), Quaternion.identity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ public class GameManagerDemo : MonoBehaviour
{
private static readonly List<PlayroomKit.Player> players = new();
private static readonly List<GameObject> playerGameObjects = new();

private static readonly Dictionary<string, GameObject> PlayerDict = new();

[SerializeField] private static bool playerJoined;
[SerializeField] private string roomCode;
[SerializeField] private GameObject playerPrefab;
[SerializeField] private int score;
[SerializeField]
private static bool playerJoined;
[SerializeField]
private string roomCode;
[SerializeField]
private GameObject playerPrefab;
[SerializeField]
private int score;

[Header("UI")]
[SerializeField] private TMP_Dropdown getDropDown;
[SerializeField] private TMP_Dropdown colorDropDown;
[SerializeField] private TextMeshProUGUI logsText;
[SerializeField]
private TMP_Dropdown getDropDown;
[SerializeField]
private TMP_Dropdown colorDropDown;
[SerializeField]
private TextMeshProUGUI logsText;

private PlayroomKit _playroomKit = new();

Expand All @@ -39,11 +45,11 @@ private void Update()
}
}


public void InsertCoin()
{
_playroomKit.InsertCoin(new InitOptions
{
skipLobby = true,
maxPlayersPerRoom = 3,
matchmaking = false,
roomCode = roomCode
Expand Down Expand Up @@ -240,7 +246,7 @@ public void RegisterRpcShoot()

private void HandleScoreUpdate(string data, string caller)
{
var player = PlayroomKit.GetPlayer(caller);
var player = _playroomKit.GetPlayer(caller);
Debug.Log($"Caller: {caller}, Player Name: {player?.GetProfile().name}, Data: {data}");

if (PlayerDict.TryGetValue(caller, out var playerObj))
Expand Down Expand Up @@ -286,7 +292,7 @@ public void IsHost()
logsText.text = $"{_playroomKit.MyPlayer().GetProfile().name} is host?: {isHost}";
}


/// <summary>
/// First Click the WaitForState button, then set the color using the dropdown and pressing the SetState button
/// </summary>
Expand All @@ -298,7 +304,7 @@ public void WaitForState()
{
Debug.Log($"data from WaitForPlayer state, color: {data}");
logsText.text += "\nData from WaitForPlayer state, color: {data}";
logsText.text += $"\nData from WaitForPlayer state, color: {data}";
});
}

Expand All @@ -320,4 +326,14 @@ public void ResetPlayerStates()
}
});
}

public void GlobalSetState()
{
_playroomKit.SetState("winner", "ChickenGamer");
}

public void GlobalGetState()
{
logsText.text = $"getting global (state): Winner is : {_playroomKit.GetState<string>("winner")}";
}
}
Loading

0 comments on commit 8ab77f4

Please sign in to comment.