コード例 #1
0
 /// Just in case
 private void OnDestroy()
 {
     Pushable?.OnPullInterrupt().RemoveAllListeners();
     Pushable?.OnStartMove().RemoveAllListeners();
     Pushable?.OnTileReached().RemoveAllListeners();
     Pushable?.OnUpdateRecieved().RemoveAllListeners();
     Pushable?.OnClientStartMove().RemoveAllListeners();
     Pushable?.OnClientTileReached().RemoveAllListeners();
 }
コード例 #2
0
    //syncvar hook invoked client side when the buckledTo changes
    private void OnBuckledChangedHook(uint newBuckledTo)
    {
        //unsub if we are subbed
        if (buckledObject != NetId.Invalid)
        {
            var directionalObject = ClientScene.FindLocalObject(buckledObject).GetComponent <Directional>();
            if (directionalObject != null)
            {
                directionalObject.OnDirectionChange.RemoveListener(OnBuckledObjectDirectionChange);
            }

            IPushable pushable = null;
            if (NetworkIdentity.spawned[buckledObject].TryGetComponent(out pushable))
            {
                pushable.OnStartMove().RemoveListener(OnBuckledObjectPositionChange);
            }
        }

        if (PlayerManager.LocalPlayer == gameObject)
        {
            //have to do this with a lambda otherwise the Cmd will not fire
            UIManager.AlertUI.ToggleAlertBuckled(newBuckledTo != NetId.Invalid, () => CmdUnbuckle());
        }

        buckledObject = newBuckledTo;
        //sub
        if (buckledObject != NetId.Invalid)
        {
            var directionalObject = ClientScene.FindLocalObject(buckledObject).GetComponent <Directional>();
            if (directionalObject != null)
            {
                directionalObject.OnDirectionChange.AddListener(OnBuckledObjectDirectionChange);
            }

            // Hook a change of position event handler for when the buckled-to object change position (the object is pushed or pulled)
            IPushable pushable = null;
            if (NetworkIdentity.spawned[buckledObject].TryGetComponent(out pushable))
            {
                pushable.OnStartMove().AddListener(OnBuckledObjectPositionChange);
            }
        }

        //ensure we are in sync with server
        playerScript?.PlayerSync?.RollbackPrediction();
    }