Skin network sync, new server build
This commit is contained in:
@@ -14,14 +14,13 @@ using UnityEngine.SocialPlatforms;
|
||||
using Firebase.Auth;
|
||||
using UnityEngine.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Properties;
|
||||
|
||||
public class playerNetwork : NetworkBehaviour
|
||||
{
|
||||
public const float ATTACK_COOLDOWN = 0.6f;
|
||||
[HideInInspector]
|
||||
public StatManager statManager;
|
||||
public CharacterSelection charSelectionManager;
|
||||
|
||||
//public const int XPFORLEVEL = 10;
|
||||
[SyncVar(hook =nameof(OnHealthChanged))] public int health = 100;
|
||||
public Character4D character;
|
||||
@@ -44,6 +43,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
[SyncVar(hook = nameof(OnXpChanged))]
|
||||
public int XP;
|
||||
|
||||
|
||||
public int lvl2 { get{
|
||||
return GetLevelForKills2(enemyKillCount);
|
||||
}}
|
||||
@@ -124,6 +124,9 @@ public class playerNetwork : NetworkBehaviour
|
||||
[SyncVar]
|
||||
public int playerCoin;
|
||||
|
||||
[SyncVar]
|
||||
public string myCharJson;
|
||||
|
||||
public TMP_Text txtEnemyKillCount;
|
||||
public TMP_Text txtPlayerName;
|
||||
public TMP_Text questText;
|
||||
@@ -200,8 +203,10 @@ public class playerNetwork : NetworkBehaviour
|
||||
// }
|
||||
|
||||
if(!isLocalPlayer){
|
||||
|
||||
canvas.SetActive(false);
|
||||
if(!isServer){
|
||||
CmdRequestCharJson();
|
||||
}
|
||||
}else{
|
||||
|
||||
localPlayerTransform = transform;
|
||||
@@ -216,12 +221,21 @@ public class playerNetwork : NetworkBehaviour
|
||||
|
||||
if(isServer){
|
||||
playerName = gplayAuth.userNameCloud;
|
||||
myCharJson = CharacterSelection.selectedCharJson;
|
||||
RpcBroadcastCharJson(CharacterSelection.selectedCharJson);
|
||||
}
|
||||
else{
|
||||
CmdSetName(gplayAuth.userNameCloud);
|
||||
|
||||
CmdSetCharJson(CharacterSelection.selectedCharJson);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LoadCharFromJson(string json){
|
||||
if(json.Length <=0){return;}
|
||||
character.FromJson(json,true);
|
||||
}
|
||||
|
||||
public void SavePlayerData(){
|
||||
@@ -314,10 +328,28 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
});
|
||||
}
|
||||
[Command]
|
||||
void CmdSetName(string nameValue){
|
||||
playerName = nameValue;
|
||||
}
|
||||
|
||||
|
||||
[Command(requiresAuthority =false)]
|
||||
void CmdRequestCharJson(){
|
||||
RpcBroadcastCharJson(myCharJson);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetCharJson(string newValue){
|
||||
myCharJson = newValue;
|
||||
RpcBroadcastCharJson(newValue);
|
||||
LoadCharFromJson(newValue);
|
||||
}
|
||||
[ClientRpc]
|
||||
void RpcBroadcastCharJson(string newValue){
|
||||
LoadCharFromJson(newValue);
|
||||
}
|
||||
|
||||
void OnDirectionChanged(Vector2 oldVal, Vector2 newVal){
|
||||
character.SetDirection(newVal);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user