Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. 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:
    394
    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.