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

CustomEditor for SceneAsset

Discussion in 'Editor & General Support' started by smonbrogg, Nov 27, 2015.

  1. smonbrogg

    smonbrogg

    Joined:
    Dec 11, 2012
    Posts:
    17
    I'd like to create a custom editor for a SceneAsset.
    It works, but everything in the editor is disabled.
    Is there a way to fix this?

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(SceneAsset))]
    7. public class SceneCustomEditor : Editor {
    8.  
    9.     private string text = "hello";
    10.  
    11.     public override void OnInspectorGUI(){
    12.         DrawDefaultInspector();
    13.         SceneAsset s = (SceneAsset) target;
    14.         text = EditorGUILayout.TextField(text);
    15.     }
    16. }
    17.  
     
  2. smonbrogg

    smonbrogg

    Joined:
    Dec 11, 2012
    Posts:
    17
    Hide flags of a SceneAsset are set to NotEditable. Can this be changed?
     
  3. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    Just a question, is there a reason why you want to do this? There's nothing in a sceneAsset that you could directly use anyway.
     
  4. smonbrogg

    smonbrogg

    Joined:
    Dec 11, 2012
    Posts:
    17
    An "Add to Build Settings" button is a simple example.

    I'd like to use it for a level management system. I store metadata about the level (scene) like wether it's locked, accessible or completed etc. It would be nice to display this data when the scene.unity is selected.
     
  5. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    926
    But the SceneAsset files are not usable in the standalone, so you would have to save the metadata elsewhere anyway. And for adding them to the build settings, you could write a simple editor window that enumerates all assets and lists them. Or one that accepts a SceneAsset and displays the corresponding data from the associated metadata file.
     
  6. smonbrogg

    smonbrogg

    Joined:
    Dec 11, 2012
    Posts:
    17
    I'm saving scene metadata in a scriptable object (and serializing it to disk when changed at runtime). The instance of the scene metadata belongs to a scene in my setup. I wanted to create a link to the scene metadata in the scene inspector. I also wanted to add the metadata object to the scene.unity via AssetDatabase.AddObjectToAsset(sceneMetadata, path/to/scene.unity); so that moving the scene or the metadata file wouldn't confuse my setup. This dosn't seem possible, so I'm going to keep it simple and just not move scenes or the scriptable object instances :)