1.Model
using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class Model : MonoBehaviour { ???public int Level; ???public int Coin; ???public static Model instead; ???public void Awake() ???{ ???????instead = this; ???} ???//级别 ???public int PlayerLevel ???{ ???????get ???????{ ???????????return Level; ???????} ???????set ???????{ ???????????Level = value; ???????} ???} ???//金币 ???public int PlayerCoin ???{ ???????get ???????{ ???????????return Coin; ???????}set ???????{ ???????????Coin = value; ???????} ???}}
2.View
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class View : MonoBehaviour { ???public Text Level; ???public Text Coin; ???????// Update is called once per frame ???void Update () { ???????Level.text = Model.instead.Level.ToString(); ???????Coin.text = Model.instead.Coin.ToString(); ???} ????}
3.Controller
using System.Collections;using System.Collections.Generic;using UnityEngine;public class Controller : MonoBehaviour { ???public static Controller instead; ???public void Awake() ???{ ???????instead = this; ???} ???// Use this for initialization ???void Start () { ???????????} ???????// Update is called once per frame ???void Update () { ???????????} ???????public void ChangeLevel() ???{ ???????Model.instead.PlayerLevel++; ???} ???public void ChangeCoin() ???{ ??????Model.instead.PlayerCoin+=10; ???}}
最简单的单链MVC
原文地址:https://www.cnblogs.com/wuwenbo/p/9293294.html