Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Editor script dll and regular script dll - not adding custominspector scripts

Discussion in 'Editor & General Support' started by Superflat, Oct 11, 2011.

  1. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Hello,

    I have 2 dll's, generated with Monodevelop. One contains editor scripts and the other the regular scripts. In the editor dll i have some custominspectors for scripts in the regular dll.
    The scripts, when not compiled to a dll, add the inspectors fine. But when i compile the two dll's, Unity stops adding the custom inspectors.

    Am I doing something wrong when compiling the libraries or does Unity not support this behavior?

    Cheers,
    Kevin
     
  2. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    I read AngryAnts post on making dll's. So I tried writing a wrapper for one of the editor classes but unity claims it can't find the class in the DLL.
     
  3. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Moving the wrapper that inherits the custom inspector to the editor directory seemed to help but now i'm getting "Failed to load CustomEditor inspected type"
     
  4. andorov

    andorov

    Joined:
    Feb 10, 2011
    Posts:
    1,061
    The Editor DLL must reference the UnityEditor, UnityEngine and the custom DLL.

    The custom DLL must only reference UnityEngine.
     
  5. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Hello Andorov,
    I have two library for the dll's setup in monodevelop. the editor one has only references to engine, editor and the dll below that the custom scripts one. and the custom one only refers to the engine.dll.

    Adding a script that has a custom editor in the editor.dll generates this still: Failed to load CustomEditor inspected type

    Do i need to do anything specific in the class that derives from the custom inspector perhaps?
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    You need to write proxy classes.
    Editor code can not only reside within the dll, there must be plain text code that binds it within the unity project iself.

    Also keep compilation order in mind for CustomEditors, if the class they custom inspect isn't there they will fail ... which might very well happen if you externalize it and forget to externalize the class too
     
  7. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Could you give me an example for such a proxy class?
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    A CustomEditor that has nothing but the 'empty functions' which then call the functions of the real custom editor. They act as 'call forwarder' basically. does this explain it or would you need more than this and the article on angryants blog on the matter which goes into more detail?
    if so just ask and I will see if I can digg out one of my own files
     
  9. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    I thought it would be enough to derive from the CustomEditor. If you have an example from your own files that would be pretty cool.
     
  10. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Proxy class example (untested pseudocode):
    MyProxy.cs
    Code (csharp):
    1. /////////////////////////////////////////////////////////////////
    2. //  MyProxy.cs - the C# source file in your assets
    3. /////////////////////////////////////////////////////////////////
    4.  
    5.  
    6. using UnityEngine;
    7. using UnityEditor;
    8. using MyAssemblyNamespace;
    9.  
    10.  
    11. [CustomEditor (typeof (MyBehaviour))]
    12. public MyProxy : Editor
    13. {
    14.     MyInspector owner;
    15.    
    16.    
    17.     public MyProxy ()
    18.     {
    19.         owner = new MyInspector (this);
    20.     }
    21.    
    22.    
    23.     public override void OnInspectorGUI ()
    24.     {
    25.         owner.OnInspectorGUI ();
    26.     }
    27.    
    28.     /* ... */
    29. }
    30.  
    31.  
    32. /////////////////////////////////////////////////////////////////
    33. //  MyInspector.cs - the actual inspector code built to assembly
    34. /////////////////////////////////////////////////////////////////
    35.  
    36.  
    37. using UnityEngine;
    38. using UnityEditor;
    39.  
    40.  
    41. public class MyInspector
    42. {
    43.     Editor proxy;
    44.    
    45.    
    46.     public MyInspector (Editor proxy)
    47.     {
    48.         this.proxy = proxy;
    49.     }
    50.    
    51.    
    52.     public void OnInspectorGUI ()
    53.     {
    54.         GUILayout.Label ("KAN HAZ INSPECTAR?!");
    55.         GUILayout.Label (string.Format ("Target: {0}", proxy.target == null ? "none" : proxy.target.ToString ()));
    56.     }
    57.    
    58.    
    59.     /* ... */
    60. }
     
    SwimmingBird and Singular-Being like this.