Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Blankzz · Jul 15, 2011 at 04:16 PM · editorinspectorextend

Possible to extend class derived from Editor?

Hi,

I have a script called Actions which other actions are extended from. Actions holds non-static variables that are common to all actions. What I would like to do is have an ActionsEditor class that will expose the common values in the editor for each action that extends from editor then extend this editor for other actions. My problem is I cant seem to find a way of not re-declaring the variables in the extended ActionsEditor. It kind of defeats the object if theres not a way. If I remove declarations from the extended ActionEditor it says the variables I am trying to access through target are not implemented on Action. It seems like the problem lies in the fact that the target has to be assigned in OnEnable. Can anybody think of any solutions?

 Action : MonoBehaviour
 SomeAction : Action - derives from action and inherits its values
 ActionEditor : Editor - exposes actions' values in the inspector
 SomeActionEditor: Editor - exposes its own values in the inspector aswell as Actions values

ActionsEditor

 [CustomEditor(typeof(Action))]
 public class ActionEditor : Editor
 {
     public Action _target;
     protected Boolean _showTags = false;
     protected int _tagsArraySize;
     protected List<String> _tagsTemp;
 
     public virtual void OnEnable()
     {
         _target = (Action)target;
         _tagsTemp = _target.tags;
         _tagsArraySize = _target.tags.Count;
     }
 
 
     public override void OnInspectorGUI()
     {
         GUILayout.Label("INPUT");
         _target.useKeyboardButtonTrigger = EditorGUILayout.Toggle("Use Keyboard Trigger", _target.useKeyboardButtonTrigger);
         if (_target.useKeyboardButtonTrigger == true)
         {
             _target.keyboardButtonTrigger = EditorGUILayout.TextField("Keyboard Button Trigger", _target.keyboardButtonTrigger);
         }
         _target.useMouseButtonTrigger = EditorGUILayout.Toggle("Use Mouse Trigger", _target.useMouseButtonTrigger);
         if (_target.useMouseButtonTrigger == true)
         {
             _target.mouseButtonTrigger = EditorGUILayout.IntField("Mouse Button Trigger", _target.mouseButtonTrigger);
         }
         _target.useGestureTrigger = EditorGUILayout.Toggle("Use Gesture Trigger", _target.useGestureTrigger);
         if (_target.useGestureTrigger == true)
         {
         }
         GUILayout.Label("TARGET FINDING");
         _showTags = EditorGUILayout.Foldout(_showTags, "Target Tags");
         if (_showTags)
         {
             _tagsArraySize = EditorGUILayout.IntField("Tag Count", _tagsArraySize);
             Event e = Event.current;
             if (e.isKey == true && e.type == EventType.keyUp && e.keyCode == KeyCode.Return)
             {
                 if (_tagsArraySize != _target.tags.Count)
                 {
                     _tagsTemp = new List<String>(_tagsArraySize);
                     for (int tagIndex = 0; tagIndex < _tagsArraySize; tagIndex++)
                     {
                         _tagsTemp.Add("");
                     }
 
                     _target.tags = new List<String>(_tagsTemp);
                     EditorUtility.SetDirty(_target);
                 }
             }
 
             for (int tagIndex = 0; tagIndex < _target.tags.Count; tagIndex++)
             {
                 _target.tags[tagIndex] = EditorGUILayout.TagField("Target tag " + (tagIndex + 1).ToString() + ":", _target.tags[tagIndex]);
                 EditorUtility.SetDirty(_target);
             }
         }
 
         GUILayout.Label("View Settings");
         _target.viewRestriction = (TargetFinding.ViewRestrictions)EditorGUILayout.EnumPopup("View Restrictions",
             _target.viewRestriction);
         if (_target.viewRestriction != TargetFinding.ViewRestrictions.InAndOut)
         {
             _target.targetFindingCam = (Camera)EditorGUILayout.ObjectField("Camera", _target.targetFindingCam, typeof(Camera));
             _target.debugCam = EditorGUILayout.Toggle("Debug Camera", _target.debugCam);
         }
 
         GUILayout.Label("Area Settings");
         _target.areaRestriction = (TargetFinding.AreaRestrictions)EditorGUILayout.EnumPopup("Area Restriction",
             _target.areaRestriction);
         switch (_target.areaRestriction)
         {
             case TargetFinding.AreaRestrictions.None:
                 break;
             case TargetFinding.AreaRestrictions.Sphere:
                 _target.sphereRadius = EditorGUILayout.Slider("Sphere Radius", _target.sphereRadius, 0.0f, 250.0f);
                 _target.debugSphere = EditorGUILayout.Toggle("Debug Sphere", _target.debugSphere);
                 break;
             case TargetFinding.AreaRestrictions.Cone:
                 _target.coneDistance = EditorGUILayout.Slider("Cone Distance", _target.coneDistance, 0.0f, 250.0f);
                 _target.coneViewAngle = EditorGUILayout.Slider("Cone View Angle", _target.coneViewAngle, 1.0f, 179.99f);
                 _target.debugCone = EditorGUILayout.Toggle("Debug Cone", _target.debugCone);
                 break;
             case TargetFinding.AreaRestrictions.InFront:
                 break;
             case TargetFinding.AreaRestrictions.Behind:
                 break;
         }
         GUILayout.Label("GUI");
         _target.isHidden = EditorGUILayout.Toggle("Hidden", _target.isHidden);
         _target.isEnabled = EditorGUILayout.Toggle("Enabled", _target.isEnabled);
         GUILayout.Label("ACTION SETTINGS");
         _target.coolDownTime = EditorGUILayout.FloatField("Cool Down Time", _target.coolDownTime);
         _target.globalCoolDownTime = EditorGUILayout.FloatField("Global Cool Down Time", _target.globalCoolDownTime);
         //DrawDefaultInspector();
     }
 }

DerivedActionEditor

[CustomEditor(typeof(DropAction))] public class DropActionEditor : ActionEditor { public DropAction _target; protected Boolean _showTags = false; protected int _tagsArraySize; protected List _tagsTemp;

 public override void OnEnable()
 {
     base.OnEnable();

     _target = (DropAction)target;
     _tagsTemp = _target.tags;
     _tagsArraySize = _target.tags.Count;
 }


 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();

     _target.peakHeight = EditorGUILayout.Slider("Peak Height", _target.peakHeight, 0.0f, 50.0f);
     _target.peakTime = EditorGUILayout.Slider("Peak Time", _target.peakTime, 0.0f, 50.0f);
     _target.rotationAngle = EditorGUILayout.Slider("Rotation Angle", _target.rotationAngle, 0.0f, 359.99f);

     //DrawDefaultInspector();
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Change position using custom and native editor 1 Answer

Create inspector drop-down button based on the content of a list in editor mode 1 Answer

Assign texture to shader bypassing material (in Unity Editor) 1 Answer

Get if inspector field labels are on separate line 1 Answer

Unity inspector scripting - scriptable objects - card game 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges