SimulateOwner() - Missing GetKeyDown Events [Bolt 104 Tutorial]

Options
Has anyone else noticed the Photon Bolt's SimulateOwner() method doesn't capture the "GetKeyDown" events consistently?

I can't find anything that says it is a known issue... so maybe it is just me. However, I changed the code in the Bolt 104 tutorial to use Update() on 'getting weapon' key press and it resolved the issue.

Is SimulateOwner() really supposed to be like Update() or FixedUpdate()? (it is behaving like FixedUpdate())
https://doc.photonengine.com/en-us/bolt/current/getting-started/bolt-102-properties-and-callbacks

Comments

  • McCann
    McCann
    edited November 2016
    Options

    So, to remove the inconsistent behavior in obtaining Input.GetKeyDown and still leverage SimulateOwner()



    using UnityEngine; using System.Collections; public class CubeBehaviour : Bolt.EntityEventListener<ICubeState> { public GameObject[] WeaponObjects; float resetColorTime; Renderer renderer; int newWeaponIndex = 0; public override void Attached() { renderer = GetComponent<Renderer>(); state.SetTransforms(state.CubeTransform, transform); if (entity.isOwner) { state.CubeColor = new Color(Random.value, Random.value, Random.value); for (int i = 0; i < state.WeaponArray.Length; ++i) { state.WeaponArray[i].WeaponID = i; // Random.Range(0, WeaponObjects.Length); state.WeaponArray[i].WeaponAmmo = Random.Range(50, 100); } // by default we don't have any weapon up, so set index to -1 state.WeaponActiveIndex = -1; newWeaponIndex = -1; } state.AddCallback("CubeColor", ColorChanged); // we also setup a callback for whenever the index changes state.AddCallback("WeaponActiveIndex", WeaponActiveIndexChanged); } void ColorChanged() { renderer.material.color = state.CubeColor; } void WeaponActiveIndexChanged() { for (int i = 0; i < WeaponObjects.Length; ++i) { WeaponObjects[i].SetActive(false); } if (state.WeaponActiveIndex >= 0) { int objectId = state.WeaponArray[state.WeaponActiveIndex].WeaponID; WeaponObjects[objectId].SetActive(true); } } public override void SimulateOwner() { var speed = 4f; var movement = Vector3.zero; if (Input.GetKey(KeyCode.W)) { movement.z += 1; } if (Input.GetKey(KeyCode.S)) { movement.z -= 1; } if (Input.GetKey(KeyCode.A)) { movement.x -= 1; } if (Input.GetKey(KeyCode.D)) { movement.x += 1; } // NEW: Input polling for weapon selection if (newWeaponIndex != state.WeaponActiveIndex) { state.WeaponActiveIndex = newWeaponIndex; } if (movement != Vector3.zero) { transform.position = transform.position + (movement.normalized * speed * BoltNetwork.frameDeltaTime); } if (Input.GetKeyDown(KeyCode.F)) { var flash = FlashColorEvent.Create(entity); flash.FlashColor = Color.red; flash.Send(); } } public override void OnEvent(FlashColorEvent evnt) { resetColorTime = Time.time + 4f; renderer.material.color = evnt.FlashColor; } void Update() { if (resetColorTime < Time.time) { renderer.material.color = state.CubeColor; } if (Input.GetKeyDown(KeyCode.Alpha1)) newWeaponIndex = 0; if (Input.GetKeyDown(KeyCode.Alpha2)) newWeaponIndex = 1; if (Input.GetKeyDown(KeyCode.Alpha3)) newWeaponIndex = 2; if (Input.GetKeyDown(KeyCode.Alpha0)) newWeaponIndex = -1; } void OnGUI() { if (entity.isOwner) { GUI.color = state.CubeColor; GUILayout.Label("@@@"); GUI.color = Color.white; } } }