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 JaeikChoe · May 20, 2014 at 08:30 AM · c#editorwindow

How do you use a Undo from EditorWindow?

/*

  • My CustomEditorWindow -> "Ctrl+Z(Undo)" is not working!!

Unity Version 4.3.4f1

*/

using UnityEditor;

public class SampleWindow : EditorWindow {

 [MenuItem( "Window/Sample Window" )]
 static void ShowWindow()
 {
     EditorWindow.GetWindow( typeof( SampleWindow ), false, "Sample Window" );
 }

 private SampleClass1 src1;

 private void OnEnable()
 {
     src1 = AssetDatabase.LoadAssetAtPath( "Assets/Resources/SampleObj1.prefab", typeof( SampleClass1 ) ) as SampleClass1;
 }

 public void OnGUI()
 {
     var c = src1 as SampleClass1;

     string s = EditorGUILayout.TextField( "Text", c.sampleProperty1 );
     if( c.sampleProperty1 != s )
     {strong text
         // Does'nt work.
         Undo.RecordObject( c, "SampleClass1/String/SampleProperty1/Change" );
         c.sampleProperty1 = s;
     }

     float value = EditorGUILayout.Slider( "Value", c.slider, 0f, 1f );
     if( c.slider != value )
     {
         // Does'nt work.
         Undo.RecordObject( c, "SampleClass1/Float/Slider/Change" );
         c.slider = value;
     }
 }

}

Comment
Add comment · Show 3
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 Andres-Fernandez · May 20, 2014 at 08:37 AM 0
Share

What do you mean by "It's not working"? If you explain it a bit more, maybe someone can help you.

avatar image JaeikChoe · May 21, 2014 at 01:47 AM 0
Share

Ok. thanks! Had to modify my question.

avatar image Loius · May 21, 2014 at 02:12 AM 0
Share

I always record target ins$$anonymous$$d of c, not sure why that would do anything but it's worth a shot maybe.

I've always had issues with Unity's old undo skipping every other step, but the new one has worked as far as I can tell.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MakeCodeNow · May 21, 2014 at 04:17 AM

Generally what I'd recommend is that you create an inspector window for your type. Then in your other editor Window, you can use Editor.CreateEditor() and call it's OnInspectorGUI from within your Editor code. That gives you both a nice inspector for the asset but still let's you embed the inspector in a more complex GUI (which looks like what you are trying to do).

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

25 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How can you use Reflection to create an object editor window 1 Answer

How do serialized Texture2D fields store and manage Texture2D data pulled from a dll ? 1 Answer

OnGui elements as objects? 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