Search Unity

Writing a script for the scene view itself, not an editorwindow or custom inspector?

Discussion in 'Scripting' started by mdeforge07, Jan 5, 2015.

  1. mdeforge07

    mdeforge07

    Joined:
    Jun 4, 2012
    Posts:
    9
    Is there a way to write an editor script that doesn't require an EditorWindow and doesn't require a GameObject (such as a custom inspector)?

    I'm trying to write a grid manager tool for the editor. As I mouse over each tile on the grids, I would like to change the color of the gizmo/place a marker object at the tile location on the grid. From there I'll implement tile selection. Each grid is a single mesh upon which I'm using raycasting to determine tile location.

    I don't want this functionality to be a part of each grid because there can be multiple grids. I want to avoid doing the same work twice for each grid.

    At first I turned to EditorWindows but those only work as long as the EditorWindow has focus. The second you close it or click off, it doesn't update.

    Secondly, I tried just using an object in my scene view but A) that clutters things up and B) I have the same problem... the object needs to be selected. The second you deselect, the script stops running.

    What are my options here?

    TL;DR I'm trying to enhance how the mouse works in the editor but editor windows and custom inspector scripts aren't cutting it.
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Code (CSharp):
    1.     [InitializeOnLoad]
    2.     public class MySceneClass
    3.     {
    4.         static MySceneClass()
    5.         {
    6.             SceneView.onSceneGUIDelegate += Update;
    7.         }
    8.  
    9.         public static void Update(SceneView view)
    10.         {
    11.             // stuff
    12.         }
    13.     }
     
    Mycroft likes this.