• 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 d3ullist · Sep 24, 2014 at 10:42 AM · c#editor-scriptingdependencies

Find public assigned values using editor script

I am trying to find out if certain scripts have a material assigned, and if they do if those scripts are used in a scene. If those scripts are used in a scene I would like to find out if they have material publicly assigned .

Is it possible to obtain the publicly assigned materials through editor script? Right now I am using the following script to determine if it contains a material, and if a scene depends on it. But I am not sure on how to approach the read out of public variables over several scenes.

 //finds all monobehaviour scripts (c# java boo)
 foreach (MonoScript m in GetScriptAssetsOfType<MonoBehaviour>())
     {
         //regex for c# array/list/variable
         bool containsmaterial = Regex.IsMatch(m.text, @"\bMaterial\b");
         bool containsmateriallist = Regex.IsMatch(m.text, @"\bList<Material>\b");
         bool containsmaterialarray = Regex.IsMatch(m.text, @"\bMaterial[]\b");

         if (containsmaterial || containsmaterialarray || containsmateriallist)
         {
             Object currentObject = m as Object;
             //check if it has dependencies
             List<Object> results = S_collectDependencies(currentObject);

             if (results.Count >= 1)
             {
                 string currentName = currentObject.name;

                 foreach (Object o in results)
                 {   
                     //if one of the dependencies is a scene
                     if (o.name.EndsWith(".unity"))
                     {
                         //find the public variables for M here 
                     }
                     else
                         continue;
                 }

             }
             else
                 continue;
         }
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 Anxo · Sep 24, 2014 at 02:15 PM

Could you not just select all objects in the scene and iterate through them and their children to check their materials? " Selection.gameObjects static GameObject[] gameObjects; Description

Returns the actual game object selection. Includes prefabs, non-modifyable objects.

When working with objects that are primarily in a scene, it is strongly recommended to use Selection.transforms instead. " Then you could create an list that adds the game objects that contain the material you are looking for and selects it after.

Comment
Add comment · Show 1 · 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
avatar image d3ullist · Sep 24, 2014 at 03:17 PM 0
Share

That would mean there will be a user interaction to select all objects. I prefer to automate that process. This process is only meant to find residue materials in scenes, such as the NGUI materials, they are only referenced in their script and not statically in prefabs. And as they may be spread over several scenes, having to select each scene manually would be annoying.

If it would be possible to get all those objects in a scene for each scene file without the user interaction of selecting it, then that would be the functionality I am looking for right now .

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C#: Include Custom Editor features for a custom Classes while avoiding dependencies? 0 Answers

Show camera view in an editor window 1 Answer

Editor Script into .dll(Solved) 1 Answer


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