Search Unity

Managing references to a custom class from a custom editor window

Discussion in 'Immediate Mode GUI (IMGUI)' 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:
    1,096
    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.