Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 putlucky · Dec 13, 2014 at 02:38 AM · c#editorinheritance

Accessing methods from another script. C#

This is a long one. Thank you so much if you read it all and even more so if you try and help.

I don't think it's as simple as it sounds. I can't use inheritance or getcomponent.

I'm extending the editor and have given one class to deal with all the GUI and the others to deal with the functionality. Now this may not be the best idea but it's all I was able to come up with. Why did I do this? Because I can't figure out how to divvy up my class' single OnGUI() to multiple methods, each one containing code which results in different GUI makeup (not all windows are the same but only one function with which to edit them in, my conclusion was that I needed to use other classes to do this.)

It's all quite complicated because I've just been throwing things around wildly.

  [MenuItem("FFToolKit/Open")]
     public static void ShowWindow()
     {
         EditorWindow.GetWindow(typeof(FFToolKit),false, "");
     }
 
     [MenuItem("FFToolKit/Create")]
     public static void Create()
     { 
     }
 
     [MenuItem("FFToolKit/Create/New ForceField/Sphere ForceField")]
     public static void SphereFF()
     {
 
         EditorWindow.GetWindow(typeof(FFToolKit), false, "Sphere Editor");
 
        
 
 
     }
 
     [MenuItem("FFToolKit/Create/New ForceField/Mesh ForceField")]
     public static void MeshForceField()
     {
 
         EditorWindow.GetWindow(typeof(FFToolKit), false, "Mesh Editor");
 
         
 
     }

My windows. Within the sphereFF method I was hoping on calling a method of my external SphereForceField class, then use the OnGUI() of the class it's being called by to arrange my GUI. Why didn't I just do all my code within the sphereFF method? Because that code requires me to inherit from MonoBehaviour as it uses the ' Destroy(sphere.GetComponent());' method, you get an error if you inherit from the UnityEditor and still try to use this method.

THERE MUST BE A BETTER WAY TO DO THIS, hopefully one which is simpler and actually works. Because now we come to the issue: I can't figure out how to call the method I want from the SphereForceField class. I can't inherit since C# wont allow me to, I have to inherit from UnityEditor in the script I'm calling from because that's the one that has all the code above, dealing with the GUI elements and the windows. I also can't use getcomponent, I tried:

 FFToolKit = GetComponent<SphereForceField>(); 

It doesn't recognize SphereForceField, I even used my noob logic; creating a namespace to using;but clearly I'm shoving the metaphorical cube through the metaphorical circular hole...

Is there a way for me to access the SphereForceField.cs methods?

Side note: This FFToolKit script is within an editor folder, the other is not. I'm going to google the possible significance of this.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · Dec 13, 2014 at 03:32 AM

I have a feeling Editor folder scripts compile into a different assembly then regular scripts. You should be able to see the assembly name in your solution browser. You then need to add a using statement for that assembly at the top of your script.

I could be wrong here. I don't use editor scripting much yet.

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

An OS design issue: File types associated with their appropriate programs 1 Answer

Deriving class that derives from MonoBehaviour not showing in editor... 2 Answers

Create a script that inherits from a class, and than attach multiple inherited classes to unity editor 2 Answers

Working with Unity Editor 1 Answer

Exposing variables in unity based on an enum 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