Search Unity

What's the best way to contribute to cinemachine / vote on upcoming features?

Discussion in 'Cinemachine' started by Meatloaf4, Jul 15, 2019.

  1. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    I see that cinemachine is open sourced, but there doesn't look to be any documentation on the best way to contribute.

    Is there a standard for contributing?

    Also was wondering what the best way to vote / express that a feature is needed? Forum or as an issue on the GitHub repo maybe?

    Great product over all!

    I'm just looking to get an event fired when one camera finishes blending from another. I figured I would either vote on this for a future release or build out myself and add a pull request.

    Thanks in advance!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    You can create an issue on GitHub.

    You'll need to define the feature a little better. Blends can be nested. Do you want a notification when any blend ends? Or just when transitioning from a state of blends to no blend? And what about other manager-style vcams, like StateDrivenCamera and ClearShot? They can have their own blends of their children. Should they issue the event also? What if the brain has a single vcam active (no blend), but that vcam is itself the result of a blend (e.g. SDC or ClearShot)?

    Perhaps the best solution, if you have a specific need, is to implement a simple polling script, as suggested in the other thread on this topic.
     
  3. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    Thanks so much for getting back to me on this.

    I think it would make the most sense to send an event when any blend ends. Perhaps it sends along some additional information with the event though that specifies the from camera / to Camera as well as the manager if any that invoked the blend. This way you should be able to discern where the blend is coming from.

    While I know polling is an option, it's a bit hacky in my opinion and I really think cinemachine should have this functionality built in.
     
  4. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
  5. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    I wen't ahead and came up with one very scary zombie extension method to accomplish what I'm after. Here it is posted below for all to see. Although I myself am not convinced if what I've come up with is a beauty or a monstrosity. Although it does work.

    CinemachineBrainExtensions.cs
    Code (CSharp):
    1.  
    2. public static class CinemachineBrainExtensions
    3. {
    4.     private static event Action<ICinemachineCamera, ICinemachineCamera> OnCameraBlendCompleteEvent;
    5.     private static CinemachineBrain cinemachineBrain;
    6.     private static ICinemachineCamera fromCamera;
    7.  
    8.     public static void SubscribeOnCameraBlendCompleteEvent(this CinemachineBrain cinemachineBrain,
    9.         Action<ICinemachineCamera,ICinemachineCamera> eventHandler)
    10.     {
    11.         CinemachineBrainExtensions.cinemachineBrain = cinemachineBrain;
    12.         cinemachineBrain.m_CameraActivatedEvent.AddListener(OnCameraActivateEvent);
    13.         OnCameraBlendCompleteEvent += eventHandler;
    14.     }
    15.  
    16.     public static void UnsubscribeOnCameraBlendCompleteEvent(this CinemachineBrain cinemachineBrain,
    17.         Action<ICinemachineCamera, ICinemachineCamera> eventHandler)
    18.     {
    19.         OnCameraBlendCompleteEvent -= eventHandler;
    20.     }
    21.  
    22.     private static void OnCameraActivateEvent(ICinemachineCamera toCamera, ICinemachineCamera fromCamera)
    23.     {
    24.         if (fromCamera == null)
    25.         {
    26.             return;
    27.         }
    28.  
    29.         var oldFromCamera = CinemachineBrainExtensions.fromCamera;
    30.         CinemachineBrainExtensions.fromCamera = fromCamera;
    31.         if (oldFromCamera != null)
    32.         {
    33.             return;
    34.         }
    35.         var blendCompleteTimer = new GameObject("Cinemachine Blend Complete Timer");
    36.         blendCompleteTimer.AddComponent<CinemachineBlendCompleteTimer>().CheckBlendingFinished();
    37.    
    38.     }
    39.  
    40.     private class CinemachineBlendCompleteTimer : MonoBehaviour
    41.     {
    42.         public void CheckBlendingFinished()
    43.         {
    44.             InvokeRepeating(nameof(InternalCheckBlendingFinished),0,0.1f);
    45.         }
    46.    
    47.         private void InternalCheckBlendingFinished()
    48.         {
    49.             if (!cinemachineBrain.IsBlending)
    50.             {
    51.                 Destroy(gameObject);
    52.                 OnCameraBlendCompleteEvent?.Invoke(cinemachineBrain.ActiveVirtualCamera,fromCamera);
    53.                 fromCamera = null;
    54.             }
    55.         }
    56.     }
    57. }
    58.  
    Used like this
    Code (CSharp):
    1.  
    2. //to subscribe
    3. cinemachineBrain.SubscribeOnCameraBlendCompleteEvent(OnBlendCompleteHandler);
    4. //to unsubscribe
    5. cinemachineBrain.UnsubscribeOnCameraBlendCompleteEvent(OnBlendCompleteHandler);
    6.  
    7. //some random event handler method you can use for testing
    8. private void OnBlendCompleteHandler(ICinemachineCamera toCamera, ICinemachineCamera fromCamera)
    9.     {
    10.         Debug.LogFormat("FROM CAMERA: {0} TO CAMERA: {1}",fromCamera.Name,toCamera.Name);
    11. }
    12.  
     
    Last edited: Aug 10, 2019
  6. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183