Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Managing references to a custom class from a custom editor window

Discussion in 'Extensions & OnGUI' started by LochMessMonster, Apr 26, 2018.

  1. LochMessMonster

    LochMessMonster

    Joined:
    Apr 26, 2018
    Posts:
    1
    Hello

    I am planning on creating a custom editor window (using C#) that is essentially a node editor. Each node will contain a list of custom class objects (called Trigger for now). The Trigger will be sort of similar to the Animator Trigger which is used for triggering animation states. Each node will actively monitor whether the listed Triggers have met the specified conditions. After all the Trigger conditions have been met, it will begin to call it's other functions.

    GameObjects in a scene will store a reference to these Trigger objects and the Trigger conditions will be fired off during run-time.

    I thought of creating a custom component that contains a list of Triggers. These components will be attached to GameObjects so that they can fire off the Triggers during run-time (using GetComponent() and then find the appropriate Trigger from the list). However I am not sure how to go about connecting the Triggers from the component to the nodes in the node editor.

    Could you please suggest a way of achieving this? Or perhaps is there a better way of managing the Trigger objects so a GameObject can find and store a reference to the Triggers without attaching a custom component?

    Thank you.
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    180
    I would probably make a Singleton (proabably a scriptable object to have it all serialized -- I use this one: https://github.com/TrinketBen/ScriptableObjectSingleton ).
    that singleton either stores all triggers themselves or stores all graphs which in turn contain the triggers.

    From the MonoBehaviour you can then access that singleton to get the data you need.