/* * This file is part of the CatLib package. * * (c) CatLib * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * Document: http://catlib.io/ */ using System; using UnityEngine; namespace CatLib { /// /// CatLib for unity application /// public class UnityApplication : Application { /// /// Mono Behaviour /// protected MonoBehaviour Behaviour { get; private set; } /// /// 构造一个 CatLib for unity application /// /// 驱动器 public UnityApplication(MonoBehaviour behaviour) { if (behaviour == null) { return; } this.Singleton(() => behaviour) .Alias(); Behaviour = behaviour; } /// /// 初始化服务提供者 /// public override void Init() { if (Behaviour) { Behaviour.StartCoroutine(CoroutineInit()); return; } base.Init(); } /// /// 注册服务提供者 /// /// 服务提供者 /// 为true则强制注册 public override void Register(IServiceProvider provider, bool force = false) { var component = provider as Component; if (component != null && !component) { throw new CodeStandardException( "Service providers inherited from MonoBehaviour only be registered mounting on the GameObject."); } if (Behaviour) { Behaviour.StartCoroutine(CoroutineRegister(provider, force)); return; } base.Register(provider, force); } /// /// 是否是无法被构建的类型 /// /// 类型 /// 是否是无法被构建的 protected override bool IsUnableType(Type type) { return typeof(Component).IsAssignableFrom(type) || base.IsUnableType(type); } } }