Unity3d Development (v) Undo Action for editor

Source: Internet
Author: User


article Songyang

This article is from the Asura road , prohibited for commercial purposes, reproduced please indicate the source.  

original link:replaceme


/p>





Undo

In the Unity3d editor extension, it is often necessary to work with undo as follows: Cmd/Ctrl + z . Undo.RecordObjectsThis work can be done in the Unity3d corresponding interface.

Packaging

Since its parameters require the components of the object we manipulate, I have encapsulated an operation class for him. Called by a managed method.

Realize

The implementation functions are as follows:

using unityengine;using system.collections;using system.collections.generic;using  Unityeditor;/*usage:var go = selection.activetransform;  undooperate BC = new Undooperate ("Batch Operate"); Bc.    Add (Go, () =>{go.localposition = new Vector3 (1,2,1);  Go.localscale = new Vector3 (1,2,1);  }); var comp = go.  Getcomponent<test> (); Bc.  ADD (comp, () =>{comp.str= "Hello Songyang";  }); Bc.    Flush (); */public class Undooperate {public delegate void Callback ();    list<object> targetlist = new list<object> ();    list<callback> calllist = new list<callback> ();        String M_name;    Public undooperate (string name) {m_name = name;        } public void Add (Object obj,callback call) {Targetlist.add (obj);    Calllist.add (call);        } public void Flush () {undo.recordobjects (Targetlist.toarray (), m_name);        foreach (var. calllist) {each (); }    }};

If you think this article is helpful to you, you can take a Top , not only do not want to be a father, but also let more people can see it ...

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unity3d Development (v) Undo Action for editor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.