예제 #1
0
        private void Awake()
        {
            var tableComponent = gameObject.GetComponent <TableAuthoring>();

            Table        = tableComponent.CreateTable();
            _ballManager = new BallManager(Table, TableToWorld);
        }
예제 #2
0
        void IApi.OnInit(BallManager ballManager)
        {
            base.OnInit(ballManager);
            Init?.Invoke(this, EventArgs.Empty);

            _mainCoil = new DeviceCoil(Player, OnMainCoilEnabled, OnMainCoilDisabled);
            _holdCoil = new DeviceCoil(Player, OnHoldCoilEnabled, OnHoldCoilDisabled);
        }
예제 #3
0
        void IApi.OnInit(BallManager ballManager)
        {
            base.OnInit(ballManager);
            Init?.Invoke(this, EventArgs.Empty);

            PullCoil = new DeviceCoil(Player, PullBack, Fire);
            FireCoil = new DeviceCoil(Player, Fire);
        }
예제 #4
0
        void IApi.OnInit(BallManager ballManager)
        {
            _teleporterCoil = new DeviceCoil(_player, OnTeleport);
            _fromKicker     = _player.TableApi.Kicker(_component.FromKicker);
            _toKicker       = _player.TableApi.Kicker(_component.ToKicker);

            Init?.Invoke(this, EventArgs.Empty);
        }
예제 #5
0
        void IApi.OnInit(BallManager ballManager)
        {
            _surfaceApi = _player.TableApi.Surface(_slingshotComponent.SlingshotSurface.MainComponent);

            if (_surfaceApi != null)
            {
                _surfaceApi.Slingshot += OnSlingshot;
            }

            Init?.Invoke(this, EventArgs.Empty);
        }
예제 #6
0
        /// <summary>
        /// Queues the ball to be destroyed at the next cycle.
        /// </summary>
        ///
        /// <remarks>
        /// If there is not ball in the kicker, this does nothing.
        /// </remarks>
        public void DestroyBall()
        {
            var entityManager       = World.DefaultGameObjectInjectionWorld.EntityManager;
            var kickerCollisionData = entityManager.GetComponentData <KickerCollisionData>(Entity);
            var ballEntity          = kickerCollisionData.BallEntity;

            if (ballEntity != Entity.Null)
            {
                BallManager.DestroyEntity(ballEntity);
                SimulationSystemGroup.QueueAfterBallCreation(() => DestroyBall(Entity));
            }
        }
예제 #7
0
        void IApiInitializable.OnInit(BallManager ballManager)
        {
            // playfield elements
            _entryKicker = TableApi.Kicker(Data.EntryKicker);
            _exitKicker  = TableApi.Kicker(Data.ExitKicker);
            _jamTrigger  = TableApi.Trigger(Data.JamSwitch);

            // setup entry kicker handler
            if (_entryKicker != null)
            {
                _entryKicker.Hit += OnEntryKickerHit;
            }

            // in case we need also need to handle jam events here, uncomment
            // if (_jamTrigger != null) {
            //  _jamTrigger.Hit += OnJamTriggerHit;
            //  _jamTrigger.UnHit += OnJamTriggerUnHit;
            // }

            // create switches to hook up
            _ballSwitches = new DeviceSwitch[Data.SwitchCount];
            foreach (var sw in Item.AvailableSwitches)
            {
                if (int.TryParse(sw.Id, out var id))
                {
                    _ballSwitches[id - 1] = CreateSwitch(false);
                    _switchLookup[sw.Id]  = _ballSwitches[id - 1];
                }
                else if (sw.Id == Trough.JamSwitchId)
                {
                    // we short-wire the jam trigger to the switch, so we don't care about it here,
                    // all the jam trigger does push its switch events to the gamelogic engine. in
                    // case we need to hook into the jam trigger logic here, uncomment those two
                    // lines and and relay the events manually to the engine.
                    //_jamSwitch = CreateSwitch(false);
                    //_switchLookup[sw.Id] = _jamSwitch;
                }
                else
                {
                    Logger.Warn($"Unknown switch ID {sw.Id}");
                }
            }

            // setup eject coil
            _ejectCoil = new TroughEjectCoil(this);

            // finally, emit the event for anyone else to chew on
            Init?.Invoke(this, EventArgs.Empty);
        }
예제 #8
0
        public void OnInit(TableApi tableApi, BallManager ballManager)
        {
            _tableApi    = tableApi;
            _ballManager = ballManager;

            _switchStatus[SwLeftFlipper]     = false;
            _switchStatus[SwLeftFlipperEos]  = false;
            _switchStatus[SwRightFlipper]    = false;
            _switchStatus[SwRightFlipperEos] = false;
            _switchStatus[SwPlunger]         = false;
            _switchStatus[SwCreateBall]      = false;

            // debug print stuff
            OnCoilChanged += DebugPrintCoil;
        }
예제 #9
0
        void IApi.OnInit(BallManager ballManager)
        {
            _hittable = _player.TableApi.Hittable(_collisionSwitchComponent.GetComponentInParent <MonoBehaviour>());

            if (_hittable != null)
            {
                _hittable.Hit += OnHit;
            }
            else
            {
                Logger.Error($"{_collisionSwitchComponent.name} not connected to a hittable component");
            }

            Init?.Invoke(this, EventArgs.Empty);
        }
예제 #10
0
        void IApiInitializable.OnInit(BallManager ballManager)
        {
            _entryKicker = TableApi.Kicker(Data.EntryKicker);
            _exitKicker  = TableApi.Kicker(Data.ExitKicker);

            if (_entryKicker != null)
            {
                _entryKicker.Hit += OnEntryKickerHit;
            }

            if (_exitKicker != null)
            {
                _exitKicker.Hit += OnExitKickerFire;
            }

            Init?.Invoke(this, EventArgs.Empty);
        }
예제 #11
0
        public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
        {
            _player      = player;
            _ballManager = ballManager;

            OnDisplaysRequested?.Invoke(this, new RequestedDisplays(new DisplayConfig(DisplayDmd, DmdWidth, DmdHeight)));

            // debug print stuff
            OnCoilChanged += DebugPrintCoil;

            // eject ball onto playfield
            OnCoilChanged?.Invoke(this, new CoilEventArgs(CoilTroughEject, true));
            _player.ScheduleAction(100, () => OnCoilChanged?.Invoke(this, new CoilEventArgs(CoilTroughEject, false)));

            _playfieldComponent = GetComponentInChildren <PlayfieldComponent>();

            OnStarted?.Invoke(this, EventArgs.Empty);
        }
        public void OnInit(TableApi tableApi, BallManager ballManager)
        {
            _tableApi    = tableApi;
            _ballManager = ballManager;

            // flippers
            _leftFlipper = _tableApi.Flipper("LeftFlipper")
                           ?? _tableApi.Flipper("FlipperLeft")
                           ?? _tableApi.Flipper("FlipperL")
                           ?? _tableApi.Flipper("LFlipper");
            _rightFlipper = _tableApi.Flipper("RightFlipper")
                            ?? _tableApi.Flipper("FlipperRight")
                            ?? _tableApi.Flipper("FlipperR")
                            ?? _tableApi.Flipper("RFlipper");

            // debug print stuff
            OnCoilChanged += DebugPrintCoil;
        }
예제 #13
0
 /// <summary>
 /// Destroys the ball and simulates a drain.
 /// </summary>
 private void OnEntry(object sender, SwitchEventArgs args)
 {
     if (args.IsEnabled)
     {
         Logger.Info("Draining ball into trough.");
         if (_drainSwitch is KickerApi kickerApi)
         {
             kickerApi.DestroyBall();
         }
         else
         {
             BallManager.DestroyEntity(args.BallEntity);
         }
         DrainBall();
     }
     else
     {
         Logger.Error("Draining ball into trough.");
     }
 }
        public void Init(TableAuthoring tableAuthoring)
        {
            _entityManager    = World.DefaultGameObjectInjectionWorld.EntityManager;
            _flipperDataQuery = _entityManager.CreateEntityQuery(
                ComponentType.ReadOnly <FlipperMovementData>(),
                ComponentType.ReadOnly <FlipperStaticData>(),
                ComponentType.ReadOnly <SolenoidStateData>()
                );

            _ballManager   = BallManager.Instance(tableAuthoring.Table, tableAuthoring.gameObject.transform.localToWorldMatrix);
            _ballDataQuery = _entityManager.CreateEntityQuery(ComponentType.ReadOnly <BallData>());

            var visualPinballSimulationSystemGroup = _entityManager.World.GetOrCreateSystem <VisualPinballSimulationSystemGroup>();
            var simulateCycleSystemGroup           = _entityManager.World.GetOrCreateSystem <SimulateCycleSystemGroup>();

            visualPinballSimulationSystemGroup.Enabled = true;
            simulateCycleSystemGroup.PhysicsEngine     = this;         // needed for flipper status update we don't do in all engines

            _worldToLocal = tableAuthoring.gameObject.transform.worldToLocalMatrix;
        }
        void IApi.OnInit(BallManager ballManager)
        {
            _enabled     = false;
            _currentStep = 0;
            _direction   = Direction.Forward;

            _motorCoil = new DeviceCoil(_player, OnMotorCoilEnabled, OnMotorCoilDisabled);

            _marks    = _component.Marks.ToDictionary(m => m.SwitchId, m => m);
            _switches = _component.Marks.ToDictionary(m => m.SwitchId, m => new DeviceSwitch(m.SwitchId, false, SwitchDefault.NormallyOpen, _player));
            var i = 0;

            foreach (var sw in _switches.Values)
            {
                sw.SetSwitch(i == 0);
                i++;
            }

            Init?.Invoke(this, EventArgs.Empty);
        }
        public virtual void OnAwake(TableApi table, BallManager ballManager)
        {
            // table.Plunger("Plunger").Init += (sender, args) => {
            //  KickNewBallToPlunger(table);
            // };
            //
            // table.Kicker("Drain").Hit += (sender, args) => {
            //  ((KickerApi)sender).DestroyBall();
            //  KickNewBallToPlunger(table);
            // };

            table.Init += (sender, args) => {
                ballManager.CreateBall(new DebugBallCreator(200f, 620f));
                ballManager.CreateBall(new DebugBallCreator(330f, 360f));
                ballManager.CreateBall(new DebugBallCreator(400f, 700f));
                ballManager.CreateBall(new DebugBallCreator(620f, 820f));
                ballManager.CreateBall(new DebugBallCreator(720f, 400f));
                ballManager.CreateBall(new DebugBallCreator(830f, 870f));
                ballManager.CreateBall(new DebugBallCreator(470f, 230f));
                ballManager.CreateBall(new DebugBallCreator(620f, 1200f));
            };
        }
예제 #17
0
        private void Awake()
        {
            var tableComponent  = gameObject.GetComponent <TableAuthoring>();
            var engineComponent = GetComponent <IGameEngineAuthoring>();

            Table         = tableComponent.CreateTable(tableComponent.Data);
            BallManager   = new BallManager(Table, TableToWorld);
            _inputManager = new InputManager();

            if (engineComponent != null)
            {
                GameEngine = engineComponent.GameEngine;
            }

            EngineProvider <IPhysicsEngine> .Set(physicsEngineId);

            EngineProvider <IPhysicsEngine> .Get().Init(tableComponent, BallManager);

            if (!string.IsNullOrEmpty(debugUiId))
            {
                EngineProvider <IDebugUI> .Set(debugUiId);
            }
        }
예제 #18
0
 void IApi.OnInit(BallManager ballManager)
 {
     base.OnInit(ballManager);
     Init?.Invoke(this, EventArgs.Empty);
     _initialized = true;
 }
예제 #19
0
 void IApi.OnInit(BallManager ballManager)
 {
     base.OnInit(ballManager);
     Init?.Invoke(this, EventArgs.Empty);
 }
예제 #20
0
 protected override void OnStartRunning()
 {
     _currentPhysicsTime   = GetTargetTime();
     _nextPhysicsFrameTime = _currentPhysicsTime + PhysicsConstants.PhysicsStepTime;
     BallManager.Init();
 }
예제 #21
0
 void IApi.OnInit(BallManager ballManager)
 {
     LifterCoil = new DeviceCoil(_player, OnLifterCoilEnabled, OnLifterCoilDisabled);
     _gateApi   = _player.TableApi.Gate(_gateComponent);
     Init?.Invoke(this, EventArgs.Empty);
 }
예제 #22
0
        void IApi.OnInit(BallManager ballManager)
        {
            base.OnInit(ballManager);

            // reference playfield elements
            _drainSwitch = TableApi.Switch(MainComponent.PlayfieldEntrySwitch, MainComponent.PlayfieldEntrySwitchItem);
            _ejectCoil   = TableApi.Coil(MainComponent.PlayfieldExitKicker, MainComponent.PlayfieldExitKickerItem);
            _ejectKicker = TableApi.Kicker(MainComponent.PlayfieldExitKicker);

            // setup entry handler
            if (_drainSwitch != null)
            {
                _drainSwitch.Switch += OnEntry;
            }

            // setup switches
            if (MainComponent.Type != TroughType.ModernOpto && MainComponent.Type != TroughType.ModernMech)
            {
                EntrySwitch = CreateSwitch(TroughComponent.EntrySwitchId, false, SwitchDefault.NormallyOpen);
                _switchLookup[TroughComponent.EntrySwitchId] = EntrySwitch;
            }

            if (MainComponent.Type == TroughType.TwoCoilsOneSwitch)
            {
                _stackSwitches = new[] {
                    CreateSwitch(TroughComponent.TroughSwitchId, false, SwitchDefault.NormallyOpen)
                };
                _switchLookup[TroughComponent.TroughSwitchId] = StackSwitch();
            }
            else
            {
                _stackSwitches = new DeviceSwitch[MainComponent.SwitchCount];

                // ball_switch_# switches created in TroughComponent
                var ballSwitchRegex = new Regex(@"^ball_switch_(\d+)$");
                foreach (var @switch in MainComponent.AvailableSwitches)
                {
                    var match = ballSwitchRegex.Match(@switch.Id);
                    if (match.Success)
                    {
                        int.TryParse(match.Groups[1].Value, out int id);
                        if (id > 0)
                        {
                            _stackSwitches[id - 1]    = CreateSwitch(@switch.Id, false, MainComponent.Type == TroughType.ModernOpto ? SwitchDefault.NormallyClosed : SwitchDefault.NormallyOpen);
                            _switchLookup[@switch.Id] = _stackSwitches[id - 1];
                        }
                    }
                }

                // pull next ball on modern
                if (MainComponent.Type == TroughType.ModernOpto || MainComponent.Type == TroughType.ModernMech)
                {
                    _stackSwitches[MainComponent.SwitchCount - 1].Switch += OnLastStackSwitch;
                }
            }

            if (MainComponent.JamSwitch)
            {
                JamSwitch = CreateSwitch(TroughComponent.JamSwitchId, false, MainComponent.Type == TroughType.ModernOpto ? SwitchDefault.NormallyClosed : SwitchDefault.NormallyOpen);
                _switchLookup[TroughComponent.JamSwitchId] = JamSwitch;
            }

            // setup coils
            EntryCoil = new DeviceCoil(Player, OnEntryCoilEnabled);
            ExitCoil  = new DeviceCoil(Player, () => EjectBall());

            // fill up the ball stack
            var ballCount = MainComponent.Type == TroughType.ClassicSingleBall ? 1 : MainComponent.BallCount;

            for (var i = 0; i < ballCount; i++)
            {
                AddBall();
            }

            // finally, emit the event for anyone else to chew on
            Init?.Invoke(this, EventArgs.Empty);
        }
예제 #23
0
 protected void OnInit(BallManager ballManager)
 {
     BallManager    = ballManager;
     TableComponent = GameObject.GetComponentInParent <TableComponent>();
 }
예제 #24
0
        private static Mesh _unitySphereMesh;         // used to cache ball mesh from GameObject

        public static BallManager Instance(Table table, Matrix4x4 ltw) => _instance ?? (_instance = new BallManager(table, ltw));
예제 #25
0
 void IApiInitializable.OnInit(BallManager ballManager)
 {
     Init?.Invoke(this, EventArgs.Empty);
 }
예제 #26
0
 void IApiInitializable.OnInit()
 {
     _ballManager = BallManager.Instance(Player.Table, Player.TableToWorld);
     Init?.Invoke(this, EventArgs.Empty);
 }