Пример #1
0
        protected override IState BuildState()
        {
            var root = new State();

            var context = Context.GlobalContext;

            var types = GetType().Assembly.GetTypes()
                        .Where(x => typeof(GameProcedure <TProcedureController, TProcedureIndex>).IsAssignableFrom(x));

            var procedures = new List <GameProcedure <TProcedureController, TProcedureIndex> >();

            foreach (var type in types)
            {
                if (!(context.Create(type) is GameProcedure <TProcedureController, TProcedureIndex> instance))
                {
                    continue;
                }

                instance.SetContext((TProcedureController)this);
                procedures.Add(instance);
            }

            procedures = procedures.OrderBy(x => x.Index).ToList();

            foreach (var procedure in procedures)
            {
                var id = procedure.Index;

                if (Indices.ContainsKey(id))
                {
                    Debug.LogErrorFormat("{0}[{1}] already added.", id, procedure.GetType().Name);
                    continue;
                }

                Indices.Add(id, procedure);
                IndexLookup.Add(procedure, id);
                root.AddChild(id.ToString(CultureInfo.InvariantCulture), procedure);
            }

            Root = root;
            if (procedures.Count <= 0)
            {
                return(Root);
            }

            if (procedures.Any(p => p.Index.Equals(InitState)))
            {
                ChangeState(InitState);
            }
            else
            {
                var first = procedures[0].Index;
                Her.Warn($"Procedure of [{InitState}] is no available, change to {first} instead.");
                ChangeState(first);
            }

            return(Root);
        }
Пример #2
0
        public void SetViewModel(object context)
        {
            if (context is TViewModel viewModel)
            {
                DataContext = viewModel;
            }
            else
            {
                Her.Warn($"{context} is not matching {typeof(TViewModel)}");
            }

            DataReadyEvent?.Invoke();
        }
Пример #3
0
        protected override void Awake()
        {
            if (_instance == null)
            {
                _instance = this;

                RegisterServices();
                InitServices();
                Inject(Her.Current);
            }
            else
            {
                Her.Warn("HermitKernel can only have one instance.");
                Destroy(gameObject);
            }
        }