Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by hakankaraduman · Nov 05, 2015 at 08:37 AM · editoreditor-scriptingeditor-classes

How to make a editor script that sets the values of serialized variables in the editor

Hi all,

I want to automate a process I need to do a lot of times.

I want to write a editor script, that does these things:

1- Set variables in the editor, for example I have a script that has a variable : "public Transform myTransform" . I want this script to instantiate a prefab in the editor, put it in a specific place in the hierarchy, and find one of this prefab's children and set it to this 'myTransform' variable's value.

2- Change positions of some of the subobjects of this prefabs.

3- Save one of the gameobject in the hierarchy as prefab in the project folder.

4- If you also can direct me to some learning material that could help me create a new windows, so I can drag my prefab on to it's variable value. And then click a button. and that way it makes these actions.

I don't expect you to step by step teach me these, if you can just give a few tips and tell me where to look to learn to do theese things, would be great. Thanks in advance.

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
3
Best Answer

Answer by ttRevan · Nov 05, 2015 at 11:11 AM

4- you can create editor window by inheriting EditorWindow class and creating menu item to open this window.

3- Use PrefabUtility.CreatePrefab:

 var prefab = new GameObject(prefabName);
 var rigidbody = prefab.AddComponent<Rigidbody>();
 
 PrefabUtility.CreatePrefab("Assets/"+ prefab.name + ".prefab", prefab);
 UnityEngine.Object.DestroyImmediate(prefab);

2- AssetDatabase is your friend:

 var guids = AssetDatabase.FindAssets("SomeQuery t:prefab", new[] { "Assets/Prefab" });
 for (int i = 0; i < guids.Length; i++) {
     var path = AssetDatabase.GUIDToAssetPath(guids[i]);
     var prefab = AssetDatabase.LoadAssetAtPath<Transform>(path);
     //modify prefab
     AssetDatabase.SaveAssets();
 }    

1- Not sure what type of script you're talking about, byt in any editor-aware code you can use, again, AssetDatabase to load prefabs and instantiate them as usual via Instantiate method.

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 hakankaraduman · Nov 06, 2015 at 09:21 AM 0
Share

thanks a lot

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

33 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SearchableEditorWindow 2 Answers

The name `StaticOcclusionCullingMode' does not exist in the current context 1 Answer

Remove or disable an EditorGUILayout.PropertyField 0 Answers

Unity Editor script in DLL 1 Answer

Event for loading component in the editor 2 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