In writing the project, I created a method that requires an int parameter . I remember it was uievent. Trigger cannot pass a number directly, it can only pass a Gameobject attribute past (=.= that value does not want to be defined on the component)
The UIButton message component cannot pass parameters.
Uievent Trigger Component passes gameobject properties of a component past
It feels like these two are not exactly right. Write a SendMessage component
:
Component classes:
usingUnityengine;usingSystem.Collections;namespaceplateface{/// <summary> ///Message Send component/// </summary> Public classSendmessageto:monobehaviour { Public enumMestype {@default, @int, @string, @object} PublicGameobject Tager; Public stringfunctionname; PublicMestype MessageType =[email protected]; Public int@int; Public string@string; PublicGameobject @object; voidOnClick () {if(Tager! =NULL&& functionname! ="") { Switch(MessageType) { Case[email protected]: Tager. SendMessage (functionname); Break; Case[email protected]: Tager. SendMessage (functionname, @int); Break; Case[email protected]: Tager. SendMessage (functionname, @string); Break; Case[email protected]: Tager. SendMessage (functionname, @object); Break; default: Break; } } } }}
Inspectoriedtor extension
usingUnityengine;usingUnityeditor;usingSystem.Collections;namespaceplateface{[Customeditor (typeof(Sendmessageto))] Public classSendmessagetoeditor:editor { Public Override voidOninspectorgui () {Sendmessageto Item= Target asSendmessageto; Serializedobject.update (); //Serialization UpdatesItem.tager= Editorguilayout.objectfield ("Target:", Item.tager,typeof(Gameobject)) asGameobject; Item.functionname= Editorguilayout.textfield ("Method Name:", Item.functionname). ToString (); Editorguilayout.propertyfield (Serializedobject.findproperty ("MessageType")); Switch(item. MessageType) { Case[email protected]: Break; Case[email protected]: [email protected]= Editorguilayout.intfield ("parameter (int)", [email protected]); Break; Case[email protected]: [email protected]= Editorguilayout.textfield ("parameter (String)", [email protected]). ToString (); Break; Case[email protected]: [email protected]= Editorguilayout.objectfield ("parameter (object)", [email protected],typeof(Gameobject)) asGameobject; Break; } //updates the edited data. serializedobject.applymodifiedproperties (); } }}
Three script preview graphs:
Unity extension Custom Event Send component