最近在一个新项目中需要使用Robotlegs这套框架来重构代码
博主学习了下这套开源框架,还是很容易上手的
源码下载地址点击打开链接
博主学习了这套框架后也写了一个Demo
本文内容是围绕这个Demo来写的,大家可以下载参考Demo来学习点击打开链接
框架入口
using System.Collections;
using System.Collections.Generic;
using Robotlegs.Bender.Framework.API;
using Robotlegs.Bender.Framework.Impl;
using Robotlegs.Bender.Platforms.Unity.Bundles;
using Robotlegs.Bender.Platforms.Unity.Extensions.ContextViews.Impl;
using UnityEngine;
public class MyText : MonoBehaviour
{
IContext context;
public void Start()
{
context = new Context();
context.Install<UnitySingleContextBundle>().Configure<MyTextConfig>().Configure(new TransformContextView(this.transform));
}
}
Config
实例化框架后将安装配置信息using System;
using System.Collections;
using System.Collections.Generic;
using Robotlegs.Bender.Extensions.EventCommand.API;
using Robotlegs.Bender.Extensions.Mediation.API;
using Robotlegs.Bender.Framework.API;
using UnityEngine;
public class MyTextConfig : IConfig
{
[Inject]
public IEventCommandMap eventCommandMap;
[Inject]
public IMediatorMap mediatorMap;
[Inject]
public IInjector injector;