Skip to content

Commit

Permalink
Display Room Ownership on the UI
Browse files Browse the repository at this point in the history
Added a RoomOwnershipUpdated action to MultiplayerManager.cs to send updates about room ownership to the multiplayer UI panel. Updated the MultiplayerPanel script and prefab to include a Room Ownership field.
  • Loading branch information
sbanca committed Nov 14, 2024
1 parent 72936ea commit 0ec9c14
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Assets/Editor/MultiplayerManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public override void OnInspectorGUI()

//Room Ownership
string ownership = "";
if (multiplayerManager != null && multiplayerManager.isUserRoomOwner) ownership = "Yes";
else if (multiplayerManager != null && !multiplayerManager.isUserRoomOwner) ownership = "No";
if (multiplayerManager != null && multiplayerManager.IsUserRoomOwner()) ownership = "Yes";
else if (multiplayerManager != null && !multiplayerManager.IsUserRoomOwner()) ownership = "No";
else ownership = "Not Assigned";

EditorGUILayout.BeginHorizontal();
Expand Down
191 changes: 182 additions & 9 deletions Assets/Prefabs/Panels/MultiplayerPanel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ MonoBehaviour:
m_RoomNumber: {fileID: 9160963822650286723}
m_Nickname: {fileID: 4888819335275065630}
m_AlertsErrors: {fileID: 6437857310660163665}
m_RoomOwnership: {fileID: 0}
references:
version: 2
RefIds: []
Expand Down Expand Up @@ -975,7 +976,7 @@ Transform:
m_GameObject: {fileID: 1032351299171828485}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.617, y: -0.323, z: -0.042}
m_LocalPosition: {x: -0.617, y: -0.484, z: -0.042}
m_LocalScale: {x: 0.33, y: 0.33, z: 0.33}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -1165,7 +1166,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0.147, y: 0.035999954}
m_AnchoredPosition: {x: 0.147, y: 0.14799947}
m_SizeDelta: {x: 1.104868, y: 1.4460607}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &3100622910448847287
Expand Down Expand Up @@ -2810,7 +2811,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0.466, y: -0.26}
m_AnchoredPosition: {x: 0.466, y: -0.14800048}
m_SizeDelta: {x: 1.104868, y: 1.4460607}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &8677733851088090031
Expand Down Expand Up @@ -2981,7 +2982,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0.466, y: -0.5540001}
m_AnchoredPosition: {x: 0.466, y: -0.44200057}
m_SizeDelta: {x: 1.104868, y: 1.4460607}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &2426349157769062346
Expand Down Expand Up @@ -3147,7 +3148,7 @@ Transform:
m_GameObject: {fileID: 5899900900417153719}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.62, y: -0.323, z: -0.042}
m_LocalPosition: {x: 0.62, y: -0.48400003, z: -0.042}
m_LocalScale: {x: 0.33, y: 0.33, z: 0.33}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -3527,6 +3528,7 @@ Transform:
- {fileID: 4609499178869085959}
- {fileID: 2677652558882906679}
- {fileID: 8994233172856634412}
- {fileID: 3004064693637687833}
- {fileID: 5239577752120043582}
m_Father: {fileID: 415082}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -3765,7 +3767,7 @@ Transform:
m_GameObject: {fileID: 6530187638887373145}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.208, y: -0.323, z: -0.042}
m_LocalPosition: {x: 0.208, y: -0.48400003, z: -0.042}
m_LocalScale: {x: 0.33, y: 0.33, z: 0.33}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -3921,6 +3923,177 @@ MonoBehaviour:
references:
version: 2
RefIds: []
--- !u!1 &6603807884407399516
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3004064693637687833}
- component: {fileID: 4811598343171871539}
- component: {fileID: 1415528830258304631}
m_Layer: 16
m_Name: Room Ownership Status
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3004064693637687833
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6603807884407399516}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.05}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8346410928580794432}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0.147, y: -0.73}
m_SizeDelta: {x: 1.104868, y: 1.4460607}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &4811598343171871539
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6603807884407399516}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2133298, guid: fce54057bad3d2d4cb3c36ee394be518, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &1415528830258304631
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6603807884407399516}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9541d86e2fd84c1d9990edf0852d74ab, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Room Owner
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: fce54057bad3d2d4cb3c36ee394be518, type: 2}
m_sharedMaterial: {fileID: 2133298, guid: fce54057bad3d2d4cb3c36ee394be518, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 1.5
m_fontSizeBase: 1.5
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: -30
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 0
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: -0.31141979, y: -0.12023544, z: -0.1872099, w: 1.1764753}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
_SortingLayer: 0
_SortingLayerID: 0
_SortingOrder: 0
m_hasFontAssetChanged: 0
m_renderer: {fileID: 4811598343171871539}
m_maskType: 0
--- !u!1 &7101128147202961155
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3950,7 +4123,7 @@ Transform:
m_GameObject: {fileID: 7101128147202961155}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.206, y: -0.323, z: -0.042}
m_LocalPosition: {x: -0.206, y: -0.48400003, z: -0.042}
m_LocalScale: {x: 0.33, y: 0.33, z: 0.33}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -4135,7 +4308,7 @@ Transform:
m_GameObject: {fileID: 7355810358076377629}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.619, y: 0.09, z: -0.042}
m_LocalPosition: {x: -0.619, y: 0.20199952, z: -0.042}
m_LocalScale: {x: 0.15, y: 0.15, z: 0.15}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -4506,7 +4679,7 @@ Transform:
m_GameObject: {fileID: 7521510091458286424}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.619, y: 0.384, z: -0.042}
m_LocalPosition: {x: -0.619, y: 0.496, z: -0.042}
m_LocalScale: {x: 0.15, y: 0.15, z: 0.15}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down
15 changes: 14 additions & 1 deletion Assets/Scripts/GUI/MultiplayerPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class MultiplayerPanel : BasePanel
[SerializeField] private TextMeshPro m_RoomNumber;
[SerializeField] private TextMeshPro m_Nickname;
[SerializeField] private TextMeshPro m_AlertsErrors;
[SerializeField] private TextMeshPro m_RoomOwnership;

public string RoomName
{
Expand Down Expand Up @@ -80,7 +81,11 @@ public void Awake()
CheckIfRoomExist,
};

if (MultiplayerManager.m_Instance != null) MultiplayerManager.m_Instance.StateUpdated += OnStateUpdated;
if (MultiplayerManager.m_Instance != null)
{
MultiplayerManager.m_Instance.StateUpdated += OnStateUpdated;
MultiplayerManager.m_Instance.RoomOwnershipUpdated += OnRoomOwnershipUpdated;
}

}

Expand Down Expand Up @@ -165,10 +170,18 @@ private async void Disconnect()

private void OnStateUpdated(ConnectionState newState)
{
if (!m_State) return;
m_State.text = "State: " + newState.ToString();
UpdateDisplay();
}

private void OnRoomOwnershipUpdated(bool isRoomOwner)
{
if (!m_RoomOwnership) return;
m_RoomOwnership.text = isRoomOwner ? "Room Owner" : "Not Room Owner";
UpdateDisplay();
}

private Tuple<bool, string> CheckAdvancedModeActive()
{
if (PanelManager.m_Instance != null)
Expand Down
17 changes: 16 additions & 1 deletion Assets/Scripts/Multiplayer/MultiplayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class MultiplayerManager : MonoBehaviour
public Action<int> playerLeft;
public Action<List<RoomData>> roomDataRefreshed;
public event Action<ConnectionState> StateUpdated;
public event Action<bool> RoomOwnershipUpdated;
public event Action<ConnectionUserInfo> UserInfoStateUpdated;
private List<RoomData> m_RoomData = new List<RoomData>();

Expand Down Expand Up @@ -94,7 +95,16 @@ public ConnectionUserInfo UserInfo

[HideInInspector] public RoomCreateData data;

[HideInInspector] public bool isUserRoomOwner = false; //temporary public
private bool _isUserRoomOwner = false;
private bool isUserRoomOwner
{
get => _isUserRoomOwner;
set
{
_isUserRoomOwner = value;
RoomOwnershipUpdated?.Invoke(value);
}
}

void Awake()
{
Expand Down Expand Up @@ -540,5 +550,10 @@ public bool CanLeaveRoom()
{
return State == ConnectionState.IN_ROOM;
}

public bool IsUserRoomOwner()
{
return isUserRoomOwner;
}
}
}

0 comments on commit 0ec9c14

Please sign in to comment.