示例#1
0
        public virtual void OnAttached()
        {
            Task.Run(() => ProcessOutQueue(this));
            Task.Run(() => ProcessInQueue(this));

            //setup the utilities
            Utilities = new GameUtilities(this);
        }
示例#2
0
        public void LoadStates(string assemblyPath)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                return;
            }
            if (!File.Exists(assemblyPath))
            {
                return;
            }

            //ensure utils are initialized.
            if (Utilities == null)
            {
                Utilities = new GameUtilities(this);
            }

            try
            {
                var asm   = Assembly.LoadFrom(assemblyPath);
                var types = asm.GetTypes();

                foreach (var type in types)
                {
                    if (type.IsClass && type.IsSubclassOf(typeof(GameState)))
                    {
                        var tempState = (GameState)Activator.CreateInstance(type);
                        tempState.Client            = this;
                        tempState.SettingsInterface = new StateSettings(tempState)
                        {
                            Dock = DockStyle.Fill
                        };
                        tempState.SettingsInterface.OnSettingsUpdated += SettingsInterface_OnSettingsUpdated;
                        tempState.InitState();

                        if (!StateMachine.States.Contains(tempState))
                        {
                            StateMachine.States.Add(tempState);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }