Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Cinemachine defines

Discussion in 'Cinemachine' started by IndieForger, Dec 5, 2022.

  1. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    92
    I have been working on a camera plugin for standard camera but would like to integrate it with Cinemachine as well. My understanding is that I can achieve that using C# preprocessor directives.

    I am seeking a define I could use to check cinemachine is installed to dynamically adjust my component behaviours.

    Is there a define I could use, eg:
    Code (CSharp):
    1. #if CINEMACHINE_ENABLED
    2. // cinemachine integration code
    3. #elseif
    4. // regular code
    5. #endif
     
  2. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    92
    Digging a bit more into the forum... I have found Cinemachine Compiler Directives thread.

    Where @Gregoryl responds with

    Response links to Assembly definitions#define-symbols docs but following the steps from docs I can't really see the cinemachine resource in the list of resources.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    You won't see the resources you're looking for because they're private to Cinemachine. You have to use the asmdef asset to define your own symbols conditionally in the presence of the Cinemachine package.

    In other words, you use it to say: "if the Cinemachine package is present, define this symbol".
     
  4. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    92
    Yeah. Was about to post again. Seems I was being a bit daft. It's all fine once I actually installed the package. *facepalm*
     
  5. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    92
    Just for the reference here is what I ended up with...
    upload_2022-12-5_23-6-17.png

    And the code...


    Code (CSharp):
    1.     public class CinemachineDirectiveTest : MonoBehaviour
    2.     {
    3.  
    4.         void Start()
    5.         {
    6. #if ENABLED_CINEMACHINE
    7.             Debug.Log("Cinemachine ENABLED");
    8. #else
    9.             Debug.Log("Cinemachine DISABLED");
    10. #endif
    11.  
    12. #if ENABLED_CINEMACHINE_v_2_7
    13.     Debug.Log("Cinemachine ver 2.7 installed");
    14. #endif
    15.  
    16. #if ENABLED_CINEMACHINE_v_2_8
    17.     Debug.Log("Cinemachine ver 2.8 installed");
    18. #endif
    19.         }
    20.     }
    Which nicely logs
    Code (csharp):
    1. Cinemachine ENABLED
    and
    Code (csharp):
    1. Cinemachine ver 2.8 installed
    Works as expected. Unity forums to the rescue one more time!
    Thanks @Gregoryl for quick response.