Skip to content

Commit

Permalink
Feat: Player Colors (#75)
Browse files Browse the repository at this point in the history
* Added different color options to the character shader

* Refactored the character shader, exposed player colors to the material inspector

* More refactoring/cleaning of player color shader

* Edited player materials to work with shader refactor

* Another refactor of the color shader

* Added color switching script

* Added the color changing script to the networked character's mesh

* Update Basic/ClientDriven/Assets/Scripts/ClientPlayerColor.cs

Co-authored-by: Sam Bellomo <[email protected]>

Co-authored-by: Sam Bellomo <[email protected]>
  • Loading branch information
jilfranco-unity and SamuelBellomo authored Dec 7, 2022
1 parent ec1eddd commit 2dbe6ef
Show file tree
Hide file tree
Showing 16 changed files with 9,853 additions and 23 deletions.
17 changes: 17 additions & 0 deletions Basic/ClientDriven/Assets/Prefabs/PlayerArmature_Networked.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ Transform:
m_CorrespondingSourceObject: {fileID: 8338988566280778637, guid: 64dce48905ffd9b4293e595fa6941544, type: 3}
m_PrefabInstance: {fileID: 3616664937583670245}
m_PrefabAsset: {fileID: 0}
--- !u!1 &4877212143847805304 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8187455079231382173, guid: 64dce48905ffd9b4293e595fa6941544, type: 3}
m_PrefabInstance: {fileID: 3616664937583670245}
m_PrefabAsset: {fileID: 0}
--- !u!114 &3615669438616969171
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4877212143847805304}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0bcad93ad8ac5d4449dd8f76d5db9990, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!95 &5969265393934875124 stripped
Animator:
m_CorrespondingSourceObject: {fileID: 6982812146204527121, guid: 64dce48905ffd9b4293e595fa6941544, type: 3}
Expand Down
22 changes: 22 additions & 0 deletions Basic/ClientDriven/Assets/Scripts/ClientPlayerColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Unity.Netcode;
using UnityEngine;

/// <summary>
/// A script to set the color of each player based on OwnerClientId
/// </summary>

public class ClientPlayerColor : NetworkBehaviour
{
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
SkinnedMeshRenderer m_Renderer = GetComponent<SkinnedMeshRenderer>();

foreach (var material in m_Renderer.materials)
{
// OwnerClientId is used here for debugging purposes. A live game should use a session manager to make sure reconnecting players still get the same color, as client IDs could be reused for other clients between disconnect and reconnect. See Boss Room for a session manager example.
material.SetFloat("_Color_Index", OwnerClientId);
}

}
}
11 changes: 11 additions & 0 deletions Basic/ClientDriven/Assets/Scripts/ClientPlayerColor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2dbe6ef

Please sign in to comment.