Unity3d MVVM C #

Source: Internet
Author: User

usingUnityengine;usingSystem.Collections; Public InterfaceIstate {voidBeforenter (); voidbeforleave ();} Public Interfaceiscenestate:istate {} Public classGENFSM {istate _state;  PublicGENFSM (istate state) { This. _state =State ;  This. _state.    Beforenter (); }     Public voidchangestate (istate state) { This. _state.        Beforleave ();  This. _state =State ;  This. _state.    Beforenter (); }}namespaceScene { Public classLogin:iscenestate {//UI VMs         Public voidBeforenter () {//UIVM. OnCommand (show UI)        }         Public voidBeforleave () {} Public voidOnlogin () {//sceneviewmodel.changestate (sceneviewmodel.game);        }    }     Public classGame:iscenestate {//Package VMSHeroviewmodel Heroviewmodel;  Public voidBeforenter () {Application.loadlevel (1);  This. Heroviewmodel =NewHeroviewmodel (); }                 Public voidBeforleave () {} }} Public InterfaceHerocmd {voidUseskill (); voidAddblood (); voidSay ();} Public classHeroviewmodel:herocmd { PublicHeroviewmodel () {varPrefab = Gameobject.find ("Hero") asGameobject; Prefab. AddComponent ("Herobehaviour"); Herobehaviour Inst= Prefab. Getcomponent(); INST.VM= This; }     Public voidOnCommand (stringcmd) {Debug.Log ("On command:"+cmd); }     Public voidUseskill () {} Public voidAddblood () {} Public voidSay () {}} Public classHerobehaviour:monobehaviour { PublicHerocmd VMs; voidUpdate () {if(input.anykeydown) {//AnimationVMs.        Useskill (); }    }} Public classUiloginviewmodel {scene.login _l;  PublicUiloginviewmodel (Scene.login L) { This. _l =L; varPrefab = Gameobject.find ("login_ui") asGameobject; Prefab. AddComponent ("Uiclickbehaviour"); }    voidLogin () { This. _l.onlogin (); }} Public classSceneviewmodel {PrivateScene.login _statelogin; PrivateScene.login _stategame;    GENFSM SCENEFSM;  PublicSceneviewmodel () { This. _statelogin =NewScene.login ();  This. SCENEFSM =NewGENFSM ( This. _statelogin); }    //Command     Public voidchangestate (iscenestate state) {SCENEFSM.    Changestate (state); }}

Unity3d MVVM C #

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.