public static void setObjects(object[] objects, SyncPlayer sp, PlayerMove pMove) { sp.transform.position = (Vector3)objects [POSITION]; pMove.jumped = Convert.ToBoolean((byte)objects [JUMPED]); pMove.inDirtMound = (float)objects [IN_DIRT_MOUND]; sp.playerTime = (float)objects [PLAYER_TIME]; pMove.moveDirection = (Vector3)objects [MOVE_DIRECTION]; pMove.effectDirection = (Vector3)objects [EFFECT_DIRECTION]; pMove.isCrouchedVal = (float)objects [IS_CROUCHED_VAL]; pMove.lastPlayerPosition = (Vector3)objects [LAST_PLAYER_POSITION]; pMove.playerSpeed = (float)objects [PLAYER_SPEED]; pMove.timeSinceTouchingDamageCircle = (float)objects [TIME_SINCE_TOUCHING_DAMAGE_CIRCLE]; // timeSinceTouchingDamageCircle will cause A LOT of prediction errors currently- as the object spawns / despawns & moves if ((float)objects [IS_ARMOR_ON] >= 2) { pMove.isArmorOn = (float)objects [IS_ARMOR_ON] - 2; pMove.puttingArmorOn = false; } else { pMove.isArmorOn = (float)objects [IS_ARMOR_ON]; pMove.puttingArmorOn = true; } pMove.transform.eulerAngles = new Vector3(pMove.transform.eulerAngles.x, (float)objects[ROTATION], pMove.transform.eulerAngles.z); pMove.mainCamera.transform.eulerAngles = new Vector3((float)objects[ROTATION_UP_DOWN], pMove.transform.eulerAngles.y, 0); UnlockSnapshot.setObjects(PLAYER_STATE_TYPES, objects, sp); }
// Use this for initialization void Start() { player = new SyncPlayer(0, 1, 2, true, 'a', 0.1f, 0.2, "abc"); shortAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.ShortValue, shortAction); intAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.IntValue, intAction); longAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.LongValue, longAction); boolAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.BoolValue, boolAction); charAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.CharValue, charAction); floatAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.FloatValue, floatAction); doubleAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.DoubleValue, doubleAction); stringAction = (InPropertyName, InOldValue, InCurrentValue) => { Debug.LogError(string.Format("On property {0} from {1} to {2}.", InPropertyName, InOldValue, InCurrentValue)); }; player.RegisterPropertyChanged((int)SyncPlayerEnum.StringValue, stringAction); }
public bool Register(SyncPlayer s) { var player = Get(s.Id); if (player != null) return false; _Player.ID = s.Id; Register(this); return true; }
public void Recieve(SyncPlayer p) { if (p == null || p.Id != _Player.ID) return; if (!Alive) return; //transform.position = p.Position; _Position.Real = p.Position; transform.rotation = p.Rotation; }
public static object[] createObjectList(SyncPlayer sp, PlayerMove pMove) { int total = getBitChoicesLength(sp.GetComponent <Combat>().team, sp.GetComponent <ClassControl>().classNum); object[] objects = new object[total]; for (int i = 0; i < total; i++) { objects [i] = getObject(i, sp, pMove); } return(objects); }
public override void OnInspectorGUI() { #region Core base.OnInspectorGUI(); SyncPlayer sp = (SyncPlayer)target; DrawTitleBar( "Network Sync Player", "Component that belongs on each player. Will send events over the network like animations, damage, etc.", E_Core.h_playerIcon ); #endregion //Properties GUILayout.BeginHorizontal(_skin.customStyles[1]); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(EditorGUIUtility.FindTexture("animationkeyframe"), GUILayout.ExpandWidth(false)); GUILayout.BeginVertical(); GUILayout.Space(9); GUILayout.Label("Sync Animations Settings", _skin.GetStyle("TextField")); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_skin.window); EditorGUILayout.PropertyField(_syncAnimations, new GUIContent("Sync Animations")); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(_skin.customStyles[1]); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(EditorGUIUtility.FindTexture("d_UnityEditor.AnimationWindow"), GUILayout.ExpandWidth(false)); GUILayout.BeginVertical(); GUILayout.Space(9); GUILayout.Label("Sync Position/Rotation Settings", _skin.GetStyle("TextField")); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_skin.window); GUILayout.BeginVertical(); EditorGUILayout.Slider(_positionLerpRate, 0, 25, new GUIContent("Position Move Speed")); EditorGUILayout.Slider(_rotationLerpRate, 0, 25, new GUIContent("Rotation Move Speed")); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(_skin.customStyles[1]); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(EditorGUIUtility.FindTexture("TerrainInspector.TerrainToolSettings"), GUILayout.ExpandWidth(false)); GUILayout.BeginVertical(); GUILayout.Space(9); GUILayout.Label("None Owner Settings", _skin.GetStyle("TextField")); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_skin.window); GUILayout.BeginVertical(); EditorGUILayout.PropertyField(noneLocalTag, new GUIContent("None Owner Tag")); EditorGUILayout.PropertyField(_nonAuthoritativeLayer, new GUIContent("None Owner Layer")); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(_skin.customStyles[1]); GUILayout.Label(EditorGUIUtility.FindTexture("d_editcollision_16"), GUILayout.ExpandWidth(false)); GUILayout.BeginVertical(); GUILayout.Space(9); GUILayout.Label("Team Settings", _skin.textField); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_skin.window); GUILayout.BeginVertical(); GUI.enabled = false; EditorGUILayout.PropertyField(teamName); GUI.enabled = true; GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(5); EndInspectorGUI(typeof(SyncPlayer)); }
// The saved state is simply saved how the server saves it- with the objects. Each object is then compared in this class! public static object getObject(int num, SyncPlayer sp, PlayerMove pMove) { if (num == POSITION) { return(sp.transform.position); } if (num == JUMPED) { return(Convert.ToByte(pMove.jumped)); } if (num == IN_DIRT_MOUND) { return(pMove.inDirtMound); } if (num == PLAYER_TIME) { return(sp.playerTime); } if (num == MOVE_DIRECTION) { return(pMove.moveDirection); } if (num == EFFECT_DIRECTION) { return(pMove.effectDirection); } if (num == IS_CROUCHED_VAL) { return(pMove.isCrouchedVal); } if (num == LAST_PLAYER_POSITION) { return(pMove.lastPlayerPosition); } if (num == PLAYER_SPEED) { return(pMove.playerSpeed); } if (num == TIME_SINCE_TOUCHING_DAMAGE_CIRCLE) { return(pMove.timeSinceTouchingDamageCircle); } if (num == IS_ARMOR_ON) { if (pMove.puttingArmorOn) { return(pMove.isArmorOn); } else { return(pMove.isArmorOn + 2); } } if (num == ROTATION) { return(pMove.transform.eulerAngles.y); } if (num == ROTATION_UP_DOWN) { return(pMove.mainCamera.transform.eulerAngles.x); } return(UnlockSnapshot.getObject(num - PLAYER_STATE_TYPES, sp)); }
// Use this for initialization void Start() { syncPlayer = new SyncPlayer(); _lastPos = transform.position; }
public static object getObject(int num, SyncPlayer sp) { // Every variable gets synced on every frame, but obviously only ones that are being used will change ClassControl cc = sp.GetComponent <ClassControl> (); Player player = null; if (GameManager.PlayerExists(sp.playerOwner)) { player = GameManager.GetPlayer(sp.playerOwner); } if (num == 0) { return(cc.whichUnlock); } if (num == 1) { return(cc.nextUnlock); } if (num == 2) { return(cc.switchedAt.getPlayerTriggerTime()); } // Sync todo with currently equipped stuff: if (num >= 3 && num <= 7) { if (!cc.isSwitching()) { Unlock unlock = cc.getUnlockEquipped(); if (unlock != null) { if (num == 3) { return(unlock.firedAt.getPlayerTriggerTime()); } if (num == 4) { return(unlock.secondaryFiredAt.getPlayerTriggerTime()); } if (num == 5) { return(unlock.reloadedAt.getPlayerTriggerTime()); } if (num == 6) { return(unlock.equippedAt.getPlayerTriggerTime()); } if (num == 7) { if (unlock is GunScript && ((GunScript)unlock).isReloadableType()) { return((byte)((GunScript)unlock).NumShots); } else { return((byte)0); } } } } if (num == 7) { return((byte)0); } else { return(-1f); } // Class specific stuff that syncs at all times: } else if (cc.classNum == 0) { if (num == 8) { return(sp.GetComponent <PlayerMove> ().movementAbilityCoolDownStartedAt); } if (sp.GetComponent <Combat> ().team == 0) { if (num == 9) { return(cc.getUnlockEquippedWithType <PlaceShield> ().coolDownStartedAt); } } else if (player != null) { if (num == 9) { return(player.trapCoolDownsStartedAt [0]); } if (num == 10) { return(player.trapCoolDownsStartedAt [1]); } } else { return(0f); } } else if (cc.classNum == 1) { if (num == 8) { return(cc.getUnlockEquippedWithType <PlaceIcicle> ().coolDownStartedAt); } if (num == 9) { return(cc.getUnlockEquippedWithType <PlaceIcicle> ().AmmoStored); } if (num == 10) { return(cc.getUnlockEquippedWithType <Pistol> ().mode); } if (sp.GetComponent <Combat>().team == 0) { if (num == 11) { return(cc.getUnlockEquippedWithType <Throwable>().coolDownStartedAt); } } else if (player != null) { if (num == 11) { return(player.trapCoolDownsStartedAt [0]); } if (num == 12) { return(player.trapCoolDownsStartedAt [1]); } } else { return(0f); } } else if (cc.classNum == 2) { if (num == 8) { return(cc.getUnlockEquippedWithType <PlaceEarthMound> ().coolDownStartedAt); } if (sp.GetComponent <Combat>().team == 0) { if (num == 9) { return(cc.getUnlockEquippedWithType <PlaceMirror>().coolDownStartedAt); } } else if (player != null) { if (num == 9) { return(player.trapCoolDownsStartedAt [0]); } if (num == 10) { return(player.trapCoolDownsStartedAt [1]); } } else { return(0f); } } else if (cc.classNum == 3) { if (num == 8) { return(sp.GetComponent <PlayerMove> ().movementAbilityCoolDownStartedAt); } if (num == 9) { return(cc.getUnlockEquippedWithType <ThrowableFootball> ().coolDownStartedAt); } if (sp.GetComponent <Combat> ().team == 0) { if (num == 10) { return(cc.getUnlockEquippedWithType <GolfSwing>().coolDownStartedAt); } } else if (player != null) { if (num == 10) { return(player.trapCoolDownsStartedAt [0]); } if (num == 11) { return(player.trapCoolDownsStartedAt [1]); } } else { return(0f); } } else if (cc.classNum == 4) { if (num == 8) { return(sp.GetComponent <PlayerMove> ().movementAbilityCoolDownStartedAt); } if (sp.GetComponent <Combat> ().team == 0) { } else if (player != null) { if (num == 9) { return(player.trapCoolDownsStartedAt [0]); } if (num == 10) { return(player.trapCoolDownsStartedAt [1]); } } else { return(0f); } } Debug.LogError("Attempting to get: " + num + " when it doesn't exist on class num: " + sp.GetComponent <ClassControl> ().classNum + " / " + sp.GetComponent <Combat> ().team + " <- team"); return(null); }
public static void setObjects(int startIndex, object[] objects, SyncPlayer sp) { object[] finalObjects = new object[objects.Length - startIndex]; Array.Copy(objects, startIndex, finalObjects, 0, objects.Length - startIndex); setObjects(finalObjects, sp); }
public static void setObjects(object[] objects, SyncPlayer sp) { ClassControl cc = sp.GetComponent <ClassControl> (); cc.switchedAt.setPlayerTriggerTime((float)objects [2]); if (cc.whichUnlock != (byte)objects [0]) { cc.enableUnlockEquippedRegardlessOfSwitching(false); cc.whichUnlock = (byte)objects [0]; if (cc.whichUnlock == (byte)objects [1]) // This is because of SetNextUnlock { cc.enableUnlockEquippedRegardlessOfSwitching(true); } } if (cc.nextUnlock != (byte)objects [1]) { cc.SetNextUnlock((byte)objects [1], false, false); } if (!cc.isSwitching()) { Unlock unlock = cc.getUnlockEquipped(); if (unlock != null) { unlock.firedAt.setPlayerTriggerTime((float)objects [3]); unlock.secondaryFiredAt.setPlayerTriggerTime((float)objects [4]); unlock.reloadedAt.setPlayerTriggerTime((float)objects [5]); unlock.equippedAt.setPlayerTriggerTime((float)objects [6]); if (unlock is GunScript && ((GunScript)unlock).isReloadableType()) { ((GunScript)unlock).NumShots = (byte)objects [7]; } } } int team = sp.GetComponent <Combat> ().team; int classNum = sp.GetComponent <ClassControl> ().classNum; if (classNum == 0) { sp.GetComponent <PlayerMove> ().movementAbilityCoolDownStartedAt = (float)objects[8]; if (team == 0) { cc.getUnlockEquippedWithType <PlaceShield> ().coolDownStartedAt = (float)objects [9]; } else if (Player.thisPlayer) { Player.thisPlayer.trapCoolDownsStartedAt [0] = (float)objects [9]; Player.thisPlayer.trapCoolDownsStartedAt [1] = (float)objects [10]; } } else if (classNum == 1) { cc.getUnlockEquippedWithType <PlaceIcicle> ().coolDownStartedAt = (float)objects[8]; cc.getUnlockEquippedWithType <PlaceIcicle> ().AmmoStored = (float)objects[9]; cc.getUnlockEquippedWithType <Pistol> ().setMode((byte)objects [10]); if (team == 0) { cc.getUnlockEquippedWithType <Throwable> ().coolDownStartedAt = (float)objects [11]; } else if (Player.thisPlayer) { Player.thisPlayer.trapCoolDownsStartedAt [0] = (float)objects [11]; Player.thisPlayer.trapCoolDownsStartedAt [1] = (float)objects [12]; } } else if (classNum == 2) { cc.getUnlockEquippedWithType <PlaceEarthMound> ().coolDownStartedAt = (float)objects[8]; if (team == 0) { cc.getUnlockEquippedWithType <PlaceMirror> ().coolDownStartedAt = (float)objects [9]; } else if (Player.thisPlayer) { Player.thisPlayer.trapCoolDownsStartedAt [0] = (float)objects [9]; Player.thisPlayer.trapCoolDownsStartedAt [1] = (float)objects [10]; } } else if (classNum == 3) { sp.GetComponent <PlayerMove> ().movementAbilityCoolDownStartedAt = (float)objects[8]; cc.getUnlockEquippedWithType <ThrowableFootball> ().coolDownStartedAt = (float)objects[9]; if (team == 0) { cc.getUnlockEquippedWithType <GolfSwing> ().coolDownStartedAt = (float)objects [10]; } else if (Player.thisPlayer) { Player.thisPlayer.trapCoolDownsStartedAt [0] = (float)objects [10]; Player.thisPlayer.trapCoolDownsStartedAt [1] = (float)objects [11]; } } else if (classNum == 4) { cc.GetComponent <PlayerMove> ().movementAbilityCoolDownStartedAt = (float)objects [8]; if (team == 0) { } else if (Player.thisPlayer) { Player.thisPlayer.trapCoolDownsStartedAt [0] = (float)objects [9]; Player.thisPlayer.trapCoolDownsStartedAt [1] = (float)objects [10]; } } }