Unity游戏的可扩展和可维护架构

我们邀请“ Unity Game Developer。Professional”课程的未来学生参加有关“射击者中的敌人的先进人工智能”主题的开放式网络研讨会

同时,我们建议阅读有用文章的翻译。


介绍

多年来从事许多项目的工作,我已经开发出一种清晰的方法来构造Unity中的游戏项目,事实证明该方法本身特别可扩展且可维护。

很长时间以来,我想写下我的想法,将其转换为适合公众的格式。

本文是我2017年GDC演讲的更新版本(“用于在Unity中快速创建UI的数据绑定体系结构”)。

免责声明:您应该理解,这些只是我提出的反映我的经验和发展观点的实用建议,而不是所有问题的通用解决方案,并且绝对不是每个项目或团队的唯一正确方法。

: , , , , Kolibri Games :

:

, . , -, , . . , , , .

  1. (inversion of control)

  2. (MPI)

  3. / / (MVC)

  4. (Unit testing)

, :

ClassA ServiceA/ServiceB. ClassA .

(DI — Dependency Injection) — . :

(Builder) ClassA, . ClassA , , , , .

Zenject/Extenject. . (reflection-baking), .

--

— . -- (Model-View-Controller — MVC), Unity, :

Monobehaviour- Unity (View), , , Unity. . [SerializeField] drag’n’drop Unity. , .

- . , Unity. , .

, , - . — , .

, (Message Passing). .

, , - . : . .

(notification messages), / (events):

Zenject Signals.

:

struct MessageType {}

bus.Subscribe<MessageType>(()=>Debug.Log("Msg received"));

bus.Fire<MessageType>();

, (Signals) — MVC. — , .

, UniRx, , , , . , , , .

() .

Unity NUnit NSubstitute .

:

var level = Substitute.For<ILevel>();
var buildings = Substitute.For<IBuildings>();

// test subject: 
var build = new BuildController(null,buildings,level);

// smoke test
Assert.AreEqual(0, build.GetCurrentBuildCount());

// assert that `GetCurrent` was exactly called once
level.ReceivedWithAnyArgs(1).GetCurrent();

. , NSubstitute , .

- 0:

var level = Substitute.For<ILevel>();
var bus = _container.Resolve<SignalBus>();
var buildCommandSent = false;
bus.Subscribe<BuildingBuild>(() => buildCommandSent = true);

// test subject 
var build = new BuildController(bus,new BuildingsModel(),level);
// test call
build.Build(0);

Assert.AreEqual(1, build.GetCurrentBuildCount());

// assert signals was fired
Assert.IsTrue(buildCommandSent);

, GetCurrentBuildCount 0. , — , .

"-, , Zenject?" ( )

, , SignalBus , NSubstitute -— , .

, .

. :

, Unity -, Unity , Unity . , Unity ( playmode ).

, , , , , :

  • ,

  • SDK


- "Unity Game Developer. Professional" .

- " " .





All Articles