Unity uFrame 1.6 MVVM 学习笔记(一)

未写完......

Sub System

  

  生成一个类:

    1.UISysLoader

      可重写方法:

        Load

      属性,方法:

        this.EventAggregator   事件聚合器(虽然有些类也有该方法,看源码好像有些不一样,待检验异同)

        this.Container      怀疑是集合类型的容器,即集合的父节点,待检验

        this.CreateViewModel   怀疑是创建一个ViewModel。

        this.GetView        得到参数下的ViewBase类

        this.GetViewModel    内部通过GetView方法得到View,再取得View下的ViewModelObject属性

Scene Type:

  生成三个类:

    1.MainScene

      可重写方法执行顺序:

        Start,KernelLoading,KernelLoaded,OnDestroy

      属性,方法:

        this.DefaultKernelScene  内核场景的名字

        this.EventAggregator   事件聚合器

        this.OnEvent      Wait for an Event to occur on the global event aggregator

        this.Publish        Publishes a command to the event aggregator. Publish the class data you want, and let any "OnEvent" subscriptions handle them.

        this.Settings      对应生成的MainSceneSettings类,不知是否只能通过this.Settings = new MainSceneSettings();来赋值

        this._SettingsObject  作为this.Settings的内部赋值变量

    2.MainSceneLoader

      可重写方法执行顺序:

        Start,KernelLoading,KernelLoaded,LoadScene,UnloadScene,OnDestroy

      属性,方法:

        this.EventAggregator   事件聚合器

        this.OnEvent      Wait for an Event to occur on the global event aggregator

        this.Publish        Publishes a command to the event aggregator. Publish the class data you want, and let any "OnEvent" subscriptions handle them.

        this.SceneType     暂时未知有什么作用。

    3.MainSceneSettings

Element

  

  生成两个类:

    1.LoginSceneViewModel

      可重写方法执行顺序:

        Bind,FillProperties,FillCommands

        未知:

        ExecuteLogin,MethodAccessException,,Read,Unbind,WireCommands,Write

      属性,方法:

        太多,日后挑重要写。

        this.SetupBindings()  This method will ensure that a view-model exists and then call the bind method when it‘s appropriate.设置重新绑定,但要在合适的时机调用,比如在AfterBind()里调用会卡死。

      API解释:

      OnPropertyChanged  当ViewModel中的属性更改时触发该方法。如果View有绑定属性改变事件,该事件先于OnPropertyChanged执行。

      Write,Read  主要负责数据序列化与反序列化的工作

    2.LoginSceneController

      可重写方法执行顺序:

        Setup,SetupAsync,Create,CreateEmpty,InitializeLoginScene,Initialize

        未知:CreateLoginScene,DisposingViewModel,Dispose

        条件顺序:Login,LoginHandler(触发对应的事件一起执行)

      属性,方法:

        this.Container      怀疑是集合类型的容器,即集合的父节点,待检验

        this.EventAggregator     事件聚合器

        this.OnEvent      Wait for an Event to occur on the global event aggregator

        this.Publish        Publishes a command to the event aggregator. Publish the class data you want, and let any "OnEvent" subscriptions handle them.

        this.LoginSceneViewModelManager  暂时故名思意,即ViewModel管理者,看了源码,主要有添加/删除ViewModel的功能。主要是相关联的ViewModel的管理类属性

        this.LoginSceneViewModels       暂时故名思意,即ViewModels,看了源码,从LoginSceneViewModelManager取得

        this.ObserveEveryValueChanged   Publish target property when value is changed. If source is destroyed/destructed, publish OnCompleted.

      备注:

        1.在Commands里写的方法会在Controller里重写两个方法,一个Login,LoginHandler(后执行),但LoginHandler参数command.sender是对应的ViewModel,因此猜测这个方法主要用来执行完Login后的一些处理。

View(必须连一个Element)

  

  生成一个类:

    1.LoginView

      可重写方法执行顺序:

         OnEnable,Start,Update,SetIdentifierSilently,PreBind,Bind,AfterBind,KernelLoading,KernelLoaded,OnDisable,DisposeBindings,Unbind,OnDestroy

        未知:InitializeViewModel(在面板点击InitializeViewModel才会执行),ExecuteLogin,Write,Read

      属性,方法:

        太多,日后挑重要写。主要是一些绑定处理。

      API解释:

        1.ExecuteLogin对应Controller的Login和LoginHandler方法,也就是说View可以直接执行Controller的方法?



备注:

  1.View的一些执行比内核快(例如Update),也比uFrame场景加载快(为什么这么设计?),或者这就是在View里直接使用ViewModel会报空指针的原因

    View里直接使用ViewModel要在Bind后使用,因为Update比Bind先执行

  2.Controller的Step和SetupAsync执行比较早

  3.在MainSceneLoader的OnDestory前最好执行一遍UnloadScene,因为怀疑他没有卸载场景。

  4.坑点:因为Service里不能直接注入不是Instance的是ViewModel,因此我把一个ViewModel在uFrame设计中设置为了Instances.

      但是在Service中注入使用时发现没有同步View面板InitializeViewModel自己初始化的数据。

      需要在面板InitializeViewModel上点击Use Rigistered ...才可以同步。那这个Use Rigistered到底是什么?

      在这里大胆猜测是创建一个实例给其他地方通过引用来使用。否则就是创建多个实例。

时间: 2024-08-02 22:58:01

Unity uFrame 1.6 MVVM 学习笔记(一)的相关文章

蓝鸥Unity开发基础——If 语句学习笔记

蓝鸥Unity开发基础--If 语句学习笔记 本节内容:程序的三种结构,if语句,问号表达式 程序的三种结构 顺序结构:顺序执行语句 分支结构:通过进行判断,在多个语句块中选择某一个执行 循环结构:条件满足时,反复执行同一语句块 If语句 用if语句可以构成分支结构 它根据给定的条件进行判定,用来决定要执行某个程序段 一.if(条件表达式){语句1} using System; namespace Lesson11{    class MainClass    {        public s

MVVM学习笔记

MVVM学习笔记 1.MVVM的简介 MVVM模式是Model-View-ViewModel模式的简称,也就是由模型(Model).视图(View).视图模型(ViewModel),其目的是为了实现将业务和界面分开,降低耦合度. 2.示例(绑定TextBox和Combox控件) 总体结构: View层代码: <Label Content="购买数:" Style="{StaticResource LabStyle}" Grid.Row="3"

蓝鸥Unity开发基础—— 一维数组学习笔记

蓝鸥Unity开发基础-- 一维数组学习笔记 一.数组 之前我们学过很多数据类型,今天我们来学习数字,数字也是一种数据类型,那么,具体的数组是如何定义的? 数组:相同数据类型的成员组成的一组数据 Int类型数组:4  7  12  3  5--数组元素 Float数据类型数字:11.5 4.62 7.1 2.21 9.3--数组元素 数组中每一个元素都会分配一个数组下标,数组下标是从0开始的,有序排列,如:0 1 2 3 4 二.声明并初始化数组: 数组也是数据类型,所以也可以声明变量.使用ne

蓝鸥Unity开发基础——For语句学习笔记

一.For循环语句 For循环语句一般用于循环次数已知的情况 For(初始化:循环条件:循环增量){ 循环体--} 举例说明: using System; namespace Lesson14{    class MainClass    {        public static void Main (string[] args)        {            //for(初始化表达式:循环条件表达式:循环增量表达式){循环体} //循环100次            int nu

蓝鸥Unity开发基础——使用字符串学习笔记

蓝鸥Unity开发基础使用字符串 本节内容:使用字符串:字符串拼接.转义字符 一.字符串拼接:字符串可以使用+或+=进行字符串拼接!! 二.转移字符--举例\n(表示回车.换行) 转移字符 转义_转义意义 \n_表示换行或回车 \t_表示制表符 \"_表示双引号 \'_表示单引号 \\_表示反斜杠 在字符串前面加@符号,会使字符串的转义字符失效! 字符串中转义字符失效之后,我们需要使用两个双引号来打印双引号 源代码 using System; namespace Lesson08{    cla

ListBox mvvm 学习笔记

1. ListBox  MvvM 例子1. 简单的绑定,ItemsSource 绑定到一个实现了IEnumerable 的类上.一般该绑定都是双向的,所以优先考虑使用 ObservableCollection<T> 的类.这样界面和后台数据就同步了.针对于ListBox 的控件,我们比较关心的是SelectedItem,在mvvm 中,为了解耦前端界面和后台的逻辑,我们采用 如下的方式,SelectedItem 双向绑定到ViewModel上的一个公用属性上.同时,该公用属性要实现INotif

蓝鸥Unity开发基础——Switch语句学习笔记

一.Switch语法 属于多分支语句,通过判断表达式的值,来决定执行哪个分支 Break用于结束某个case,然后执行switch之外的语句 Switch-开关:case-情况开关决定发生的情况 二.Switch基本语法 Switch(表达式){ Case 值1: 语句1 Break: Case 值2: 语句2 Break: -- Case 值n: 语句n Break: Default: 语句 Break: } 三.注意事项 整个defaul语句都可以舍掉,default语句最多只能由一个 Sw

蓝鸥Unity开发基础——控制台输入输出学习笔记

控制台输入输出:本节内容控制台输入输出.格式化输出 using System; namespace Lesson09{    class MainClass    {        public static void Main (string[] args)        {            /* 控制台输出语句             * 1.Console.WriteLine("");             * 2.Console.Write (" "

unity官方教程Space Shooter 学习笔记

我觉得这个教程对我最大的启发就是其中的一句话, 子物体是贴图,父物体是属性.所以我们在创建物体前最好先建立一个空的gameobject, 这样既可以保持hierarchy面板整洁便于管理,又能实现刚才说的话.好了, 下面步入正题. 如何创建一个子弹? 我们先创建一个平面,然后将子弹的贴图赋给这个平面,然后再将shader选项选中mobile的particles的additive,这样就只有激光那部分可以显示出来, 黑色部分就会小时,最后在给子弹添加rigidbody组件和capsule Coll