码迷,mamicode.com
首页 > Web开发 > 详细

最简单的单链MVC

时间:2018-07-11 12:43:04      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:turn   class   style   bsp   static   change   get   eve   coin   

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

标签:turn   class   style   bsp   static   change   get   eve   coin   

原文地址:https://www.cnblogs.com/wuwenbo/p/9293294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!