protected override void OnUpdate() { var config = World.TinyEnvironment().GetConfigData <GameConfig>(); if (!EntityManager.Exists(World.TinyEnvironment().GetEntityByName("Food")) && config.FoodExist == false) { SceneService.LoadSceneAsync(config.FoodSceneReference); config.FoodExist = true; World.TinyEnvironment().SetConfigData(config); } var shouldSpawn = false; Entities.ForEach((Entity snakeEntity, ref SnakeHead snake, ref Translation snakeTransform) => { float3 snakeTrans = snakeTransform.Value; float3 foodTrans = new float3(); Entities.ForEach((Entity foodEntity, ref FoodTag foodTag, ref Translation foodTransform) => { foodTrans = foodTransform.Value; if (math.distance(snakeTrans, foodTrans) < 1) { MoveFood(foodEntity); shouldSpawn = true; } }); if (shouldSpawn) { snake.GrowTail = true; } }); }
protected override void OnUpdate() { var env = World.TinyEnvironment(); var inputSystem = World.GetExistingSystem <InputSystem>(); var puzzleConfig = env.GetConfigData <PuzzleConfiguration>(); if (!puzzleConfig.IsCompleted) { return; } var buttonReplayEntity = Entity.Null; Entities.WithAll <ButtonReplay>().ForEach((Entity entity) => { buttonReplayEntity = entity; }); if (!EntityManager.Exists(buttonReplayEntity)) { return; } var buttonReplayPointerInteraction = EntityManager.GetComponentData <PointerInteraction>(buttonReplayEntity); if (buttonReplayPointerInteraction.clicked || inputSystem.GetKeyDown(KeyCode.Return)) { // Reload the scene var buttonReplay = EntityManager.GetComponentData <ButtonReplay>(buttonReplayEntity); SceneService.UnloadAllSceneInstances(buttonReplay.SceneToLoad); SceneService.LoadSceneAsync(buttonReplay.SceneToLoad); puzzleConfig.IsCompleted = false; env.SetConfigData(puzzleConfig); } }
protected override void OnUpdate() { bool isReq = false; Entities.ForEach(( ref TargetGenInfo gen ) => { if (!gen.Initialized) { gen.Initialized = true; gen.GeneratedCnt = 0; isReq = true; return; } // isReq = gen.IsRequested; }); if (isReq) { int recycled = 0; Entities.ForEach((Entity entity, ref TargetInfo info) => { info.IsActive = true; info.Initialized = false; ++recycled; }); var env = World.TinyEnvironment(); SceneReference tarBase = env.GetConfigData <GameConfig>().TargetScn; for (int i = 0; i < 12 - recycled; i++) { SceneService.LoadSceneAsync(tarBase); } } }
private void LoadStartupScenes(TinyEnvironment environment) { using (var startupScenes = environment.GetConfigBufferData <StartupScenes>().ToNativeArray(Allocator.Temp)) { for (var i = 0; i < startupScenes.Length; ++i) { SceneService.LoadSceneAsync(m_World, startupScenes[i].SceneReference); } } }
private static void LoadStartupScenes() { using (var startupScenes = m_Environment.GetConfigBufferData <StartupScenes>().ToNativeArray(Allocator.Temp)) { var em = m_World.EntityManager; for (var i = 0; i < startupScenes.Length; ++i) { SceneService.LoadSceneAsync(startupScenes[i].SceneReference); } } }
protected override void OnUpdate() { var tinyEnv = World.TinyEnvironment(); var config = World.TinyEnvironment().GetConfigData <GameConfig>(); var startButton = false; Entities.WithAll <StartButton>().ForEach((Entity entity, ref PointerInteraction pointerInteraction, ref Sprite2DRenderer sprite2D) => { startButton = pointerInteraction.clicked; if (config.Start) { sprite2D.color.a = 0; } if (config.Retry) { sprite2D.color.a = 1; } Entities.ForEach((Entity _entity, ref Title title, ref Sprite2DRenderer _sprite2D) => { if (config.Start) { _sprite2D.color.a = 0; } if (config.Retry) { _sprite2D.color.a = 1; } }); }); if (startButton) { config.Start = true; config.Retry = false; config.Collide = false; for (int n = 0; n < 5; n++) { SceneService.LoadSceneAsync(config.BlackScene); SceneService.LoadSceneAsync(config.BlackSceneB); SceneService.LoadSceneAsync(config.BlackSceneC); } tinyEnv.SetConfigData(config); } }
protected override void OnUpdate() { var tinyEnv = World.TinyEnvironment(); var config = World.TinyEnvironment().GetConfigData <GameConfig>(); bool LoadScene = false; if (config.Add) { config.Add = false; LoadScene = true; tinyEnv.SetConfigData(config); } if (LoadScene) { LoadScene = false; if (config.AddNum < config.Score) { if (currentSegs < maxSegs) { SceneService.LoadSceneAsync(config.BlackScene); config.AddNum = config.Score; tinyEnv.SetConfigData(config); } } } Entities.ForEach((Entity entity, ref black black, ref Translation translation) => { if (black.IsCreated) { return; } black.IsCreated = true; translation.Value.y = 4f; Entities.ForEach((DynamicBuffer <blackSegments> segments) => { segments.Add(new blackSegments { blacks = entity }); currentSegs = segments.Length; }); }); }
protected override void OnUpdate() { var env = World.TinyEnvironment(); var isAttacking = env.GetConfigData <AttackConfiguration>().IsAttacking; var deltaTime = env.frameDeltaTime; // Update ship attack timer and count the total number of bullets to spawn var newBulletCount = 0; SceneReference bulletSceneToSpawn = new SceneReference(); Entities.ForEach((Entity entity, ref Ship ship) => { if (!ship.Initialized) { return; } if (isAttacking) { ship.FireTimer -= deltaTime; if (ship.FireTimer <= 0f) { bulletSceneToSpawn = ship.Bullet; newBulletCount++; ship.FireTimer = _random.NextFloat(ship.MinFireCooldown, ship.MaxFireCooldown); ship.SpawningBullet = true; } } else { ship.SpawningBullet = false; } }); // Spawn all the bullets needed if (newBulletCount > 0) { for (int i = 0; i < newBulletCount; i++) { SceneService.LoadSceneAsync(bulletSceneToSpawn); } } }
protected override void OnUpdate() { bool isGenerate = false; Entities.ForEach(( ref FirstSetInfo info ) => { if (!info.Initialized) { info.Initialized = true; isGenerate = true; } }); //Entity blkEntity = Entity.Null; if (isGenerate) { // 初期配置ブロック生成. var env = World.TinyEnvironment(); for (int i = 0; i < FirstBlockNum; ++i) { SceneService.LoadSceneAsync(env.GetConfigData <GameConfig>().PrefabBlockStay); } } #if false if (blkEntity != Entity.Null) { Debug.LogAlways("--------------"); SceneStatus st = SceneService.GetSceneStatus(blkEntity); switch (st) { case SceneStatus.Loading: Debug.LogAlways("loading"); break; case SceneStatus.Loaded: Debug.LogAlways("loaded"); break; } Debug.LogFormatAlways("{0}", (int)st); } #endif }
protected override void OnUpdate() { bool playerDestroy = false; Entities.ForEach((Entity entity, ref Player player) => { if (!player.Collide) { return; } playerDestroy = true; }); if (playerDestroy) { SceneService.LoadSceneAsync(World.TinyEnvironment().GetConfigData <GameConfig>().Effect); SceneService.UnloadAllSceneInstances(World.TinyEnvironment().GetConfigData <GameConfig>().PlayerScene); SceneService.LoadSceneAsync(World.TinyEnvironment().GetConfigData <GameConfig>().RetryScene); //SceneService.UnloadAllSceneInstances(World.TinyEnvironment().GetConfigData<GameConfig>().ControllerScene); } }
protected override void OnUpdate() { bool btnOn = false; Entities.WithAll <BtnTestTag>().ForEach((Entity entity, ref PointerInteraction pointerInteraction) => { if (pointerInteraction.clicked) { //Debug.LogAlways("btn click"); btnOn = true; } }); if (btnOn) { #if false var env = World.TinyEnvironment(); SceneService.UnloadAllSceneInstances(env.GetConfigData <PanelConfig>().PanelRed); SceneService.UnloadAllSceneInstances(env.GetConfigData <PanelConfig>().PanelWhite); Entities.ForEach(( ref PuzzleGen gen ) => { gen.IsGenerate = true; }); #endif SceneReference panelBase = new SceneReference(); var env = World.TinyEnvironment(); panelBase = env.GetConfigData <PanelConfig>().ResultScn; if (!isLoaded) { SceneService.LoadSceneAsync(panelBase); isLoaded = true; } else { SceneService.UnloadAllSceneInstances(panelBase); isLoaded = false; } } }
protected override void OnUpdate() { bool growTail = false; Entities.ForEach((Entity entity, ref SnakeHead snake) => { if (!snake.GrowTail) { return; } else { growTail = true; snake.GrowTail = false; } }); if (growTail) { SceneService.LoadSceneAsync(World.TinyEnvironment().GetConfigData <GameConfig>().SnakeTailSceneReference); } Entities.ForEach((Entity entity, ref SnakeTail tail) => { var count = 0; if (tail.IsCreated) { return; } tail.IsCreated = true; Entities.ForEach((DynamicBuffer <SnakeSegment> segments) => { segments.Add(new SnakeSegment { Reference = entity }); count = segments.Length; }); tail.Number = count; }); }
protected override void OnUpdate() { var env = World.TinyEnvironment(); // Check if the user clicked the button to spawn ships var spawnShips = false; Entities.WithAll <ButtonSpawnShips>().ForEach((Entity entity, ref PointerInteraction pointerInteraction) => { spawnShips = pointerInteraction.clicked; }); // Spawn twice the number of ships we currently have if (spawnShips) { var existingShipCount = 0; Entities.WithAll <Ship>().ForEach((Entity shipEntity) => { existingShipCount++; }); var allyShips = env.GetConfigBufferData <AllyShips>().Reinterpret <SceneReference>().ToNativeArray(Unity.Collections.Allocator.Temp); var enemyShips = env.GetConfigBufferData <EnemyShips>().Reinterpret <SceneReference>().ToNativeArray(Unity.Collections.Allocator.Temp); var toSpawnCount = existingShipCount == 0 ? 2 : existingShipCount; for (int i = 0; i < toSpawnCount; i++) { if (i % 2 == 0) { SceneService.LoadSceneAsync(allyShips[_random.NextInt(allyShips.Length)]); } else { SceneService.LoadSceneAsync(enemyShips[_random.NextInt(enemyShips.Length)]); } } allyShips.Dispose(); enemyShips.Dispose(); } }
protected override void OnUpdate() { ButtonLoadScene scene = new ButtonLoadScene(); bool sceneSelected = false; Entity e = Entity.Null; Entities.WithAll <ButtonLoadScene>().ForEach((Entity entity, ref PointerInteraction pointerInteraction) => { if (pointerInteraction.clicked) { // Go to the referenced scene scene = EntityManager.GetComponentData <ButtonLoadScene>(entity); sceneSelected = true; e = entity; } }); if (sceneSelected) { SceneService.UnloadSceneInstance(e); SceneService.LoadSceneAsync(scene.sceneReference); } }
protected override void OnUpdate() { bool reqResult = false; Entities.ForEach(( ref TimeOverInfo info ) => { info.Timer += World.TinyEnvironment().frameDeltaTime; if (info.Timer > 1.5f) { reqResult = true; info.Timer = 0; } }); if (reqResult) { var env = World.TinyEnvironment(); SceneService.UnloadAllSceneInstances(env.GetConfigData <GameConfig>().TimeOverScn); // リザルト表示. SceneReference resultScn = World.TinyEnvironment().GetConfigData <GameConfig>().ResultScn; SceneService.LoadSceneAsync(resultScn); } }
protected override void OnUpdate() { bool btnOn = false; Entities.WithAll <BtnStartTag>().ForEach((Entity entity, ref PointerInteraction pointerInteraction) => { //Debug.LogAlways( "start btn" ); if (pointerInteraction.clicked) { btnOn = true; } }); if (btnOn) { // タイトルシーンアンロード. SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <GameConfig>().TitleScn; SceneService.UnloadAllSceneInstances(panelBase); SceneReference mainScn = World.TinyEnvironment().GetConfigData <GameConfig>().MainScn; SceneService.LoadSceneAsync(mainScn); } }
protected override void OnUpdate() { bool IsPause = false; Entities.ForEach(( ref GameMngr mngr ) => { if (mngr.IsPause) { IsPause = true; } }); if (IsPause) { return; } var deltaTime = World.TinyEnvironment().frameDeltaTime; float3 playerPos = float3.zero; // プレイヤーのポジション. Entities.ForEach((ref PlayerInfo player, ref Translation trans) => { playerPos = trans.Value; }); int meteoNum = 0; bool reqHitEff = false; bool reqSplit = false; bool reqExpl = false; int score = 0; //float3 hitEffPos = float3.zero; Entities.ForEach((ref MeteoInfo meteo, ref Translation trans, ref Rotation rot, ref NonUniformScale scl, ref Sprite2DRendererOptions opt) => { if (!meteo.IsActive || !meteo.Initialized) { return; } ++meteoNum; if (meteo.IsHit) { meteo.Life -= 1; meteo.IsHit = false; if (meteo.Life == 0) { // 消す. meteo.IsActive = false; scl.Value.x = 0; // 爆発エフェクト. meteo.ReqExpl = true; reqExpl = true; score += 100; } else { // 分裂. if (meteo.Level == 3) { if (meteo.Life == 10) { // 分裂後小さくなる. meteo.Level = 2; meteo.Radius = 140f; meteo.ReqSplit = true; opt.size.x = meteo.Radius * 2f; opt.size.y = meteo.Radius * 2f; reqSplit = true; // 爆発エフェクト. meteo.ReqExpl = true; reqExpl = true; } } meteo.ReqHitEff = true; reqHitEff = true; meteo.IsStop = true; meteo.Timer = 0; } return; } // 回転. quaternion now = rot.Value; quaternion zrot = quaternion.RotateZ(meteo.ZrotSpd * deltaTime); rot.Value = math.mul(now, zrot); if (meteo.IsStop) { meteo.Timer += World.TinyEnvironment().frameDeltaTime; if (meteo.Timer > 0.05f) { meteo.IsStop = false; } return; } // 他の隕石とのあたり. float2 newDir = float2.zero; if (HitCheck(ref meteo, trans.Value, out newDir)) { meteo.MoveDir = newDir; } // 移動. var newPos = trans.Value; var spd = meteo.MoveDir * meteo.BaseSpeed * deltaTime; newPos.x += spd.x; newPos.y += spd.y; //trans.Value = newPos; if (newPos.y > GameMngrSystem.BorderUp - meteo.Radius * 0.5f) { if (meteo.MoveDir.y > 0) { meteo.MoveDir.y *= -1f; } } else if (newPos.y < GameMngrSystem.BorderLow + meteo.Radius * 0.5f) { if (meteo.MoveDir.y < 0) { meteo.MoveDir.y *= -1f; } } if (newPos.x > GameMngrSystem.BorderRight - meteo.Radius * 0.5f) { if (meteo.MoveDir.x > 0) { meteo.MoveDir.x *= -1; } } else if (newPos.x < GameMngrSystem.BorderLeft + meteo.Radius * 0.5f) { if (meteo.MoveDir.x < 0) { meteo.MoveDir.x *= -1; } } trans.Value = newPos; // プレイヤーとの距離の2乗. float distsq = math.distancesq(trans.Value, playerPos); meteo.DistSq = distsq; float rr = (PlayerSystem.PlayerR + meteo.Radius) * (PlayerSystem.PlayerR + meteo.Radius); if (distsq < rr) { #if true //Debug.LogFormatAlways("pl hit {0} {1}", distsq, meteo.Radius); // ゲームオーバー. Entities.ForEach(( ref GameMngr mngr ) => { mngr.IsPause = true; mngr.ReqGameOver = true; }); #endif } //Debug.LogFormatAlways( "pos {0} {1}", pos.x, pos.y ); }); if (reqHitEff) { bool recycled = false; Entities.ForEach((Entity entity, ref HitEffInfo info) => { if (!recycled) { if (!info.IsActive) { info.IsActive = true; info.Initialized = false; recycled = true; } } }); if (!recycled) { var env = World.TinyEnvironment(); SceneReference meteoBase = env.GetConfigData <GameConfig>().PrefabHitEff; SceneService.LoadSceneAsync(meteoBase); } } if (reqExpl) { bool recycled = false; Entities.ForEach((Entity entity, ref ExplEffInfo info) => { if (!recycled) { if (!info.IsActive) { info.IsActive = true; info.Initialized = false; recycled = true; } } }); if (!recycled) { var env = World.TinyEnvironment(); SceneReference meteoBase = env.GetConfigData <GameConfig>().PrefabExplEff; SceneService.LoadSceneAsync(meteoBase); } } // スコア. if (score > 0) { Entities.ForEach(( ref GameMngr mngr ) => { mngr.Score += score; score = mngr.Score; }); // スコア表示. Entities.WithAll <TextScoreTag>().ForEach(( Entity entity ) => { EntityManager.SetBufferFromString <TextString>(entity, score.ToString()); }); } Entities.ForEach(( ref MeteoGenInfo gen ) => { // 今の隕石の個数更新. gen.MeteoNum = meteoNum; // 分裂リクエスト. if (reqSplit) { gen.ReqSplit = true; } }); }
protected override void OnUpdate() { bool IsPause = false; Entities.ForEach(( ref GameMngr mngr ) => { IsPause = mngr.IsPause; }); if (IsPause) { return; } bool reqGen = false; Entities.ForEach(( ref MeteoGenInfo gen ) => { if (!gen.Initialized) { gen.Initialized = true; gen.ReqSplit = false; gen.Timer = 0; gen.TotalTimer = 0; gen.MeteoNum = 0; gen.GeneratedCnt = 0; gen.MeteoMax = 10; return; } float dt = World.TinyEnvironment().frameDeltaTime; gen.TotalTimer += dt; gen.MeteoMax = getMeteoMax(gen.TotalTimer); // 分裂? if (gen.ReqSplit) { gen.ReqSplit = false; reqGen = true; } else { gen.Timer -= dt; if (gen.Timer < 0) { gen.Timer = 2f; if (gen.MeteoNum < gen.MeteoMax) // 個数制限. { reqGen = true; } } } }); if (reqGen) { bool recycled = false; Entities.ForEach((Entity entity, ref MeteoInfo meteo) => { if (!recycled) { if (!meteo.IsActive) { meteo.IsActive = true; meteo.Initialized = false; recycled = true; } } }); //Debug.LogFormatAlways( "bulcnt {0} recycled {1}", bulCnt, recycled ); if (!recycled) { var env = World.TinyEnvironment(); SceneReference meteoBase = env.GetConfigData <GameConfig>().PrefabMeteo; SceneService.LoadSceneAsync(meteoBase); } } }
protected override void OnUpdate() { bool IsPause = false; Entities.ForEach(( ref GameMngr mngr ) => { IsPause = mngr.IsPause; }); if (IsPause) { return; } var deltaTime = World.TinyEnvironment().frameDeltaTime; var moveDirection = float2.zero; var moveMagnitude = 0f; bool isInput = false; // ジョイスティック. Entities.ForEach(( ref Joystick joystick ) => { if (joystick.Direction.x != 0f || joystick.Direction.y != 0f) { moveMagnitude = math.min(1f, math.distance(float2.zero, joystick.Direction)); if (moveMagnitude > 0.3f) { isInput = true; moveDirection = moveMagnitude * math.normalize(joystick.Direction); } } }); // 近い隕石. float minDist = -1f; float3 minPos = float3.zero; Entities.ForEach((ref MeteoInfo meteo, ref Translation trans) => { if (!meteo.IsActive) { return; } if (!meteo.Initialized) { return; } // todo 射程距離考慮. if (minDist < 0 || minDist > meteo.DistSq) { minDist = meteo.DistSq; minPos = trans.Value; } }); bool reqBullet = false; float3 upVec = new float3(0, 0, 1f); Entities.ForEach((Entity entity, ref PlayerInfo player, ref Translation trans, ref Rotation rot) => { if (!player.Initialized) { player.Initialized = true; trans.Value = float3.zero; rot.Value = quaternion.identity; player.Zang = 0; // return; } // 移動. var position = trans.Value; player.PrePos = position; // 取っておく. if (isInput) { float baseSpd = 180f; position.x += moveDirection.x * baseSpd * deltaTime; if (position.x < GameMngrSystem.BorderLeft + PlayerR) { position.x = GameMngrSystem.BorderLeft + PlayerR; } else if (position.x > GameMngrSystem.BorderRight - PlayerR) { position.x = GameMngrSystem.BorderRight - PlayerR; } position.y += moveDirection.y * baseSpd * deltaTime; if (position.y < GameMngrSystem.BorderLow + PlayerR) { position.y = GameMngrSystem.BorderLow + PlayerR; } else if (position.y > GameMngrSystem.BorderUp - PlayerR) { position.y = GameMngrSystem.BorderUp - PlayerR; } trans.Value = position; } // 向き. float preZa = player.Zang; float limZa = math.radians(10f); // リミット. if (minDist > 0) { float3 dir = minPos - position; //float3 dirN = math.normalize( dir ); float za = math.atan2(dir.y, dir.x); za -= math.radians(90f); za = calcAng(za); float da = za - preZa; da = calcAng(da); if (da > limZa) { za = preZa + limZa; } else if (da < -limZa) { za = preZa - limZa; } za = calcAng(za); rot.Value = quaternion.RotateZ(za); player.Zang = za; } else if (isInput) { float za = math.atan2(moveDirection.y, moveDirection.x); za -= math.radians(90f); za = calcAng(za); float da = za - preZa; da = calcAng(da); if (da > limZa) { za = preZa + limZa; } else if (da < -limZa) { za = preZa - limZa; } za = calcAng(za); rot.Value = quaternion.RotateZ(za); player.Zang = za; } // 弾. player.Interval += deltaTime; if (player.Interval > 0.4f) { player.Interval = 0; reqBullet = true; } }); if (reqBullet) { bool recycled = false; int bulCnt = 0; Entities.ForEach((Entity entity, ref BulletInfo bullet) => { bulCnt++; if (!recycled) { if (!bullet.IsActive) { bullet.IsActive = true; bullet.Initialized = false; recycled = true; } } }); //Debug.LogFormatAlways( "bulcnt {0} recycled {1}", bulCnt, recycled ); if (!recycled) { var env = World.TinyEnvironment(); SceneReference bulletBase = env.GetConfigData <GameConfig>().PrefabBullet; SceneService.LoadSceneAsync(bulletBase); } } }
/// <summary> /// Checks for the scenemanager, if not found makes it /// If the scenemanager is found, checks for scenes to spawn /// Checks for GoToScene Components and loads the scene according to the component /// </summary> protected override void OnUpdate() { NativeArray <Entity> sceneHanlderArray = GetEntityQuery(typeof(SceneStatistics)).ToEntityArray(Allocator.Temp); if (sceneHanlderArray.Length == 0) { Entity sceneHanlderEntity = EntityManager.CreateEntity(); EntityManager.AddBuffer <ScenesToLoad>(sceneHanlderEntity); EntityManager.AddBuffer <ScenesToUnload>(sceneHanlderEntity); EntityManager.AddBuffer <ScenesLoaded>(sceneHanlderEntity); EntityManager.AddComponent(sceneHanlderEntity, typeof(Indestructable)); EntityManager.AddComponent(sceneHanlderEntity, typeof(SceneStatistics)); var componentData = EntityManager.GetComponentData <SceneStatistics>(sceneHanlderEntity); componentData.currentID = 0; EntityManager.SetComponentData(sceneHanlderEntity, componentData); Debug.Log("SceneManager Loaded"); _sceneHandler = sceneHanlderEntity; } else { Entity sceneHanlder = sceneHanlderArray[0]; var currentScene = EntityManager.GetComponentData <SceneStatistics>(sceneHanlder); NativeArray <ScenesToLoad> scenesToLoad = EntityManager.GetBuffer <ScenesToLoad>(sceneHanlder).ToNativeArray(Allocator.Temp); foreach (var sceneToLoad in scenesToLoad) { Debug.Log("Loading a scene"); //load the scene itself and attach the components to it var sceneLoaded = SceneService.LoadSceneAsync(sceneToLoad.sceneReference); EntityManager.AddComponent(sceneLoaded, typeof(IsCustomScene)); EntityManager.AddComponent(sceneLoaded, typeof(IsNewScene)); //get the components var newSceneComponent = EntityManager.GetComponentData <IsNewScene>(sceneLoaded); //set the scene ID currentScene.currentID++; //if we want to set the position and/or offset add it to the component if (sceneToLoad.setPos) { newSceneComponent.position = sceneToLoad.pos; } if (sceneToLoad.setOffset) { newSceneComponent.offset = sceneToLoad.offset; } if (sceneToLoad.setPos && sceneToLoad.setOffset) { newSceneComponent.translationType = TranslationType.PositionAndOffset; } else if (sceneToLoad.setPos) { newSceneComponent.translationType = TranslationType.Position; } else if (sceneToLoad.setOffset) { newSceneComponent.translationType = TranslationType.Offset; } else { newSceneComponent.translationType = TranslationType.None; } //if it should make the scene indestructable if (sceneToLoad.makeIndestrucktable) { EntityManager.AddComponent(sceneLoaded, typeof(Indestructable)); } //move the scene from the ToLoad array to the Loaded array EntityManager.GetBuffer <ScenesLoaded>(sceneHanlder).Add(new ScenesLoaded { referenceEntity = sceneLoaded }); EntityManager.GetBuffer <ScenesToLoad>(sceneHanlder).RemoveAt(0); //set the amount of scenes laoded currentScene.currentScenesLoaded = EntityManager.GetBuffer <ScenesLoaded>(sceneHanlder).Length; //save the components EntityManager.SetComponentData(sceneHanlder, currentScene); EntityManager.SetComponentData(sceneLoaded, newSceneComponent); } scenesToLoad.Dispose(); NativeArray <ScenesToUnload> scenesToUnload = EntityManager.GetBuffer <ScenesToUnload>(sceneHanlder).ToNativeArray(Allocator.Temp); foreach (var sceneToUnload in scenesToUnload) { if (sceneToUnload.doByNumber) { UnloadScene(EntityManager, sceneToUnload.sceneNumber); } else { UnloadScene(EntityManager, sceneToUnload.scene); } EntityManager.GetBuffer <ScenesToUnload>(sceneHanlder).RemoveAt(0); } scenesToUnload.Dispose(); } //checks for gotoscene components and loads the referenced scene NativeArray <Entity> goToSceneArray = GetEntityQuery(typeof(GoToScene)).ToEntityArray(Allocator.Temp); if (goToSceneArray.Length > 0) { GoToScene component = EntityManager.GetComponentData <GoToScene>(goToSceneArray[0]); NextScene(component.sceneToGoTo, EntityManager, Entities, true); foreach (var entity in goToSceneArray) { PostUpdateCommands.RemoveComponent <GoToScene>(entity); } } goToSceneArray.Dispose(); //checks for removescene components and unloads the referenced scene NativeArray <Entity> removeSceneArray = GetEntityQuery(typeof(RemoveScene)).ToEntityArray(Allocator.Temp); if (removeSceneArray.Length > 0) { foreach (var entity in removeSceneArray) { RemoveScene sceneToUnload = EntityManager.GetComponentData <RemoveScene>(entity); if (sceneToUnload.isInt) { UnloadScene(EntityManager, sceneToUnload.sceneNumberToUnload); } else { UnloadScene(EntityManager, sceneToUnload.sceneEntityToUnload); } PostUpdateCommands.RemoveComponent <RemoveScene>(entity); } } removeSceneArray.Dispose(); //checks for gotopreviousscene components and goes to previous scene if found NativeArray <Entity> goToPreviousSceneArray = GetEntityQuery(typeof(GoToPreviousScene)).ToEntityArray(Allocator.Temp); if (goToPreviousSceneArray.Length > 0) { PreviousScene(EntityManager, Entities); foreach (var entity in goToPreviousSceneArray) { PostUpdateCommands.RemoveComponent <GoToPreviousScene>(entity); } } goToPreviousSceneArray.Dispose(); //checks for addscene components and loads the scene Entities.ForEach((Entity e, ref AddScene sceneToGoTo) => { LoadSceneAsync(sceneToGoTo.sceneToLoad, sceneToGoTo.makeIndestructable, Entities); PostUpdateCommands.RemoveComponent <AddScene>(e); }); //checks for addscenewithpos components and loads the scene Entities.ForEach((Entity e, ref AddSceneWithTranslation sceneToGoTo) => { switch (sceneToGoTo.translationType) { case (TranslationType.Position): LoadSceneAsyncWithPosition(sceneToGoTo.sceneToLoad, sceneToGoTo.makeIndestructable, Entities, sceneToGoTo.pos); break; case (TranslationType.Offset): LoadSceneAsyncWithOffset(sceneToGoTo.sceneToLoad, sceneToGoTo.makeIndestructable, Entities, sceneToGoTo.offset); break; case (TranslationType.PositionAndOffset): LoadSceneAsyncWithPositionAndOffset(sceneToGoTo.sceneToLoad, sceneToGoTo.makeIndestructable, Entities, sceneToGoTo.pos, sceneToGoTo.offset); break; case TranslationType.None: LoadSceneAsync(sceneToGoTo.sceneToLoad, sceneToGoTo.makeIndestructable, Entities); break; default: LoadSceneAsync(sceneToGoTo.sceneToLoad, sceneToGoTo.makeIndestructable, Entities); break; } PostUpdateCommands.RemoveComponent <AddSceneWithTranslation>(e); }); sceneHanlderArray.Dispose(); GetEntitiesFromSceneGuid(); GetIndestructables(); }
protected override void OnUpdate() { bool isUpdatedScore = false; bool isTimeOver = false; int score = 0; int time = 0; Entities.ForEach(( ref GameMngr mngr ) => { if (!mngr.Initialized) { mngr.Initialized = true; mngr.IsUpdatedScore = false; mngr.IsPause = false; mngr.Score = 0; mngr.Timer = 0; isUpdatedScore = true; return; } if (mngr.IsPause) { return; } if (mngr.IsUpdatedScore) { isUpdatedScore = true; mngr.IsUpdatedScore = false; // ハイスコア更新. if (mngr.Score > mngr.HiScore) { mngr.HiScore = mngr.Score; } score = mngr.Score; } mngr.Timer += World.TinyEnvironment().frameDeltaTime; time = (int)(GameTimeMax - mngr.Timer); if (mngr.Timer > GameTimeMax) { isTimeOver = true; mngr.IsPause = true; } }); // スコア. if (isUpdatedScore) { // スコア表示. Entities.WithAll <TextScoreTag>().ForEach(( Entity entity ) => { EntityManager.SetBufferFromString <TextString>(entity, score.ToString()); }); } // タイム表示. Entities.WithAll <TextTimeTag>().ForEach(( Entity entity ) => { EntityManager.SetBufferFromString <TextString>(entity, time.ToString()); }); if (isTimeOver) { // タイムオーバー表示. SceneReference timeOverScn = World.TinyEnvironment().GetConfigData <GameConfig>().TimeOverScn; SceneService.LoadSceneAsync(timeOverScn); } }
protected override void OnUpdate() { var inputSystem = World.GetExistingSystem <InputSystem>(); bool mouseOn = inputSystem.GetMouseButtonDown(0); bool mouseUp = inputSystem.GetMouseButtonUp(0); bool isHit = false; bool isPause = false; Entities.ForEach(( ref GameMngr mngr ) => { isPause = mngr.IsPause; }); if (isPause) { return; } float dt = World.TinyEnvironment().frameDeltaTime; int score = 0; int reqEffScore = 0; int ballCnt = 0; // 籠情報. float3 boxPos = float3.zero; float2 boxSize = float2.zero; Entities.ForEach((Entity entity, ref BoxInfo box, ref Translation trans, ref Sprite2DRendererOptions opt) => { boxPos = trans.Value; //boxSize = new float2( box.Width + BallRadius, box.Height + BallRadius ); boxSize = new float2(box.Width, box.Height); }); // 半径2個分足したサイズ. float2 boxSizeR = new float2(boxSize.x + BallRadius * 2f, boxSize.y + BallRadius * 2f); //float DebSpeed = 0; // 箱の内側の情報. float boxInsideLeft = boxPos.x - boxSize.x * 0.5f + BallRadius; float boxInsideRight = boxPos.x + boxSize.x * 0.5f - BallRadius; float boxInsideBottom = boxPos.y - boxSize.y * 0.5f + BallRadius; // タッチ判定用. float2 ballRect = new float2(BallRadius * 2.6f, BallRadius * 2.6f); //Debug.LogFormatAlways("y {0} sy {1} r {2} btm {3}", boxPos.y, boxSize.y, BallRadius, boxInsideBottom); Entities.ForEach((Entity entity, ref BallInfo ball, ref Translation trans, ref NonUniformScale scl) => { if (!ball.IsActive || !ball.Initialized) { return; } ballCnt++; float3 pos = float3.zero; switch (ball.Status) { case StNorm: if (isHit) { break; } if (!ball.IsTouched && mouseOn) { float3 mypos = trans.Value; float3 mousePos = inputSystem.GetWorldInputPosition(); //if( isInsideCircle( mousePos, mypos, BallRadius * 1.5f ) ) { if (isInsideRect(mousePos, mypos, ballRect)) { // ヒットチェック1個だけにするため終了に. isHit = true; ball.IsTouched = true; ball.MouseStPos = mousePos; ball.MouseStTime = World.TinyEnvironment().frameTime; } } if (ball.IsTouched && mouseUp) { double time = World.TinyEnvironment().frameTime; float delta = (float)(time - ball.MouseStTime); if (delta > 1f) { ball.IsTouched = false; break; } float3 mpos = inputSystem.GetWorldInputPosition(); //Debug.LogFormatAlways( "mx {0} my {1}", mpos.x, mpos.y ); float3 dv = mpos - ball.MouseStPos; //float len = math.distance( ball.MouseStPos.xy, mpos.xy ); float len = math.length(dv); if (len > 10f) { float spd = len / delta * 0.7f; //Debug.LogFormatAlways( "spd {0} t {1} d {2}", spd, delta, len ); spd = math.clamp(spd, 750f, 1500f); //DebSpeed = spd; ball.MoveSpd = spd; ball.MoveVec = dv / len; ball.IsTouched = false; ball.Status = StMove; ball.Vx = ball.MoveVec.x * spd; ball.Vy = ball.MoveVec.y * spd; //Debug.LogFormatAlways( "vx {0} vy {1} d {2}", ball.Vx, ball.Vy, len ); } else { ball.IsTouched = false; } } break; case StMove: pos = trans.Value; pos.x += ball.Vx * dt; pos.y += ball.Vy * dt; ball.Vy -= Gacc * dt; bool bWallHit = false; // 壁とのあたり. if (pos.x < -WallX) { pos.x = -WallX; ball.Vx *= -BoundRate; trans.Value = pos; bWallHit = true; } else if (pos.x > WallX) { pos.x = WallX; ball.Vx *= -BoundRate; trans.Value = pos; bWallHit = true; } // 天井とのあたり. if (pos.y > TopY) { pos.y = TopY; ball.Vy *= -BoundRate; trans.Value = pos; bWallHit = true; } // 籠とのあたり. if (!bWallHit) { float3 intersectPos = pos; if (isInsideBox(pos, boxPos, boxSizeR, boxSize, trans.Value, ref ball)) { float3 prePos = trans.Value; /*if( ball.UseOldPos ) { * ball.UseOldPos = false; * prePos = ball.OldPos; * Debug.LogFormatAlways("oldpos {0}", prePos); * }*/ int hitType = IntersectCheck(prePos, pos, boxPos, boxSizeR, out intersectPos); if (hitType == 1 || hitType == 2) { // 左右. ball.Vx *= -BoundRate; } else if (hitType == 3) { // 底. ball.Vy *= -BoundRate; } else if (hitType == 4) { // 入った. ball.Status = StIn; ball.Timer = 0; // エフェクト. reqEffScore++; } else { // 籠ワープ後にちょうど籠に入ったら消す. ball.Timer = 3f; } } trans.Value = intersectPos; } ball.Timer += dt; if (ball.Timer > 3f) { ball.Status = StEnd; ball.IsActive = false; scl.Value.x = 0; } break; case StIn: pos = trans.Value; pos.x += ball.Vx * dt; pos.y += ball.Vy * dt; ball.Vy -= Gacc * dt; if (pos.x < boxInsideLeft) { pos.x = boxInsideLeft; ball.Vx *= -BoundRate; } else if (pos.x > boxInsideRight) { pos.x = boxInsideRight; ball.Vx *= -BoundRate; } if (pos.y < boxInsideBottom) { pos.y = boxInsideBottom; } trans.Value = pos; ball.Timer += dt; if (ball.Timer > 0.4f) { // score. score += 100; ball.Status = StEnd; ball.IsActive = false; scl.Value.x = 0; } break; } ball.OldPos = trans.Value; }); // スコア更新. if (score > 0) { Entities.ForEach(( ref GameMngr mngr ) => { mngr.IsUpdatedScore = true; mngr.Score += score; }); } // エフェクト. for (int i = 0; i < reqEffScore; ++i) { bool recycled = false; Entities.ForEach((Entity entity, ref EffScoreInfo eff) => { if (!recycled) { if (!eff.IsActive) { eff.IsActive = true; eff.Initialized = false; recycled = true; } } }); //Debug.LogFormatAlways( "bulcnt {0} recycled {1}", bulCnt, recycled ); if (!recycled) { var env = World.TinyEnvironment(); SceneService.LoadSceneAsync(env.GetConfigData <GameConfig>().ScoreScn); } } // 現在の玉の数. Entities.ForEach((Entity entity, ref BallGenerateInfo gen) => { gen.BallNum = ballCnt; }); #if false //if( DebSpeed > 0 ) { Entities.WithAll <DebTextTab>().ForEach(( Entity entity ) => { #if false // float.ToString()がwebビルドで使えない. int i = (int)DebSpeed; float f = DebSpeed - (int)i; int fi = (int)(f * 1000f); string str = i.ToString() + "." + fi.ToString(); //Debug.LogAlways( str ); #endif string str = ballCnt.ToString(); EntityManager.SetBufferFromString <TextString>(entity, str); }); //} #endif }
protected override void OnUpdate() { bool reqGen = false; bool isPause = false; Entities.ForEach(( ref GameMngr mngr ) => { isPause = mngr.IsPause; }); if (isPause) { return; } Entities.ForEach((Entity entity, ref BallGenerateInfo gen) => { if (!gen.Initialized) { gen.Initialized = true; gen.Timer = 0; gen.BallNum = 0; } float dt = World.TinyEnvironment().frameDeltaTime; float interval = 0.4f; if (gen.BallNum < 20) { interval = 0.1f; } else if (gen.BallNum < 35) { interval = 0.2f; } else if (gen.BallNum > 50) { interval = 0.6f; } gen.Timer += dt; if (gen.Timer > interval) { if (gen.BallNum < BallMax) { reqGen = true; } gen.Timer = 0; } }); if (reqGen) { bool recycled = false; Entities.ForEach((Entity entity, ref BallInfo ball) => { if (!recycled) { if (!ball.IsActive) { ball.IsActive = true; ball.Initialized = false; recycled = true; } } }); //Debug.LogFormatAlways( "bulcnt {0} recycled {1}", bulCnt, recycled ); if (!recycled) { var env = World.TinyEnvironment(); SceneService.LoadSceneAsync(env.GetConfigData <GameConfig>().BallScn); } } }
protected override void OnUpdate() { Entity delEntity = Entity.Null; var inputSystem = World.GetExistingSystem <InputSystem>(); bool IsPause = false; Entities.ForEach(( ref GameMngr mngr ) => { if (mngr.IsPause) { IsPause = true; } }); if (IsPause) { return; } bool mouseOn = false; mouseOn = inputSystem.GetMouseButtonDown(0); // ゲームタイム. float gameTime = 0; Entities.ForEach(( ref GameMngr mngr ) => { gameTime = mngr.GameTimer; }); // 盤面情報収集. // 盤面情報用配列. NativeArray <Entity> infoAry = new NativeArray <Entity>(6 * 8, Allocator.Temp); for (int i = 0; i < 6 * 8; ++i) { infoAry[i] = Entity.Null; } Entities.ForEach((Entity entity, ref BlockInfo block) => { if (!block.Initialized) { return; } // 情報. int idx = block.CellPos.x + block.CellPos.y * 6; infoAry[idx] = entity; }); NativeArray <Entity> delAry = new NativeArray <Entity>(6, Allocator.Temp); for (int i = 0; i < 6; ++i) { delAry[i] = Entity.Null; } int delCnt = 0; int effReqCnt = 0; // エフェクトリクエスト数. Entities.ForEach((Entity entity, ref BlockInfo block, ref Translation trans) => { // 状態チェック. //if( !panel.Initialized || panel.Status != PnlStNormal ) { // isReadyToMove = false; // return; //} switch (block.Status) { case BlkStPrepare: prepareMove(ref entity, ref block, ref trans, ref infoAry); break; case BlkStMove: float vel = getBlockVelocity(gameTime); blockMove(ref entity, ref block, ref trans, ref infoAry, vel, ref effReqCnt); break; case BlkStDisappear: block.Timer += World.TinyEnvironment().frameDeltaTime; if (block.Timer > 0.2f) { delAry[delCnt++] = entity; block.Status = BlkStEnd; float3 effpos = trans.Value; /* * // エフェクト. * Entities.ForEach( ( ref EffStarMngr mngr ) => { * mngr.Requested = true; * mngr.xpos = effpos.x; * mngr.ypos = effpos.y; * } ); */ } break; } //EntityManager.SetBufferFromString<TextString>( entity, block.Status.ToString() ); // マウスとのあたりチェック. if (mouseOn && block.Status == BlkStMove) { float2 size = new float2(InitBlockSystem.BlkSize, InitBlockSystem.BlkSize); float3 mypos = trans.Value; float3 mousePos = inputSystem.GetWorldInputPosition(); bool res = OverlapsObjectCollider(mypos, mousePos, size); if (res) { //Debug.LogAlways( "hit" ); if (++block.Num > 9) { block.Num = 1; } EntityManager.SetBufferFromString <TextString>(entity, block.Num.ToString()); } } }); infoAry.Dispose(); // ブロック削除. for (int i = 0; i < 6; ++i) { if (delAry[i] != Entity.Null) { // エンティティ削除. SceneService.UnloadSceneInstance(delAry[i]); } } delAry.Dispose(); // エフェクト生成. var env = World.TinyEnvironment(); for (int i = 0; i < effReqCnt; ++i) { SceneService.LoadSceneAsync(env.GetConfigData <GameConfig>().PrefabStar); } }
protected override void OnUpdate() { int score = 0; bool reqGameOver = false; bool reqResult = false; Entities.ForEach(( ref GameMngr mngr ) => { float dt = World.TinyEnvironment().frameDeltaTime; switch (mngr.Mode) { case MdGame: if (mngr.ReqGameOver) { mngr.ReqGameOver = false; reqGameOver = true; mngr.Mode = MdGameOver; mngr.ModeTimer = 0; } break; case MdGameOver: mngr.ModeTimer += dt; if (mngr.ModeTimer > 1.5f) { mngr.Mode = MdResult; reqResult = true; } break; } if (mngr.IsPause) { //isPause = true; return; } // タイマー. mngr.GameTimer += dt; #if false timer = mngr.GameTimer; if (timer >= GameTimeLimit) { mngr.IsPause = true; } #endif }); #if false // タイマー表示. if (!isPause) { Entities.WithAll <TextTimerTag>().ForEach(( Entity entity ) => { int t = (int)(GameTimeLimit - timer); EntityManager.SetBufferFromString <TextString>(entity, t.ToString()); }); } #endif if (reqResult) { #if true // ゲームオーバーシーンアンロード. SceneReference gameoverScn = World.TinyEnvironment().GetConfigData <GameConfig>().GameOverScn; SceneService.UnloadAllSceneInstances(gameoverScn); // リザルト表示. SceneReference resultScn = World.TinyEnvironment().GetConfigData <GameConfig>().ResultScn; SceneService.LoadSceneAsync(resultScn); #endif } else if (reqGameOver) { // ゲームオーバー表示. SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <GameConfig>().GameOverScn; SceneService.LoadSceneAsync(panelBase); } }
protected override void OnUpdate() { #if false bool isTitleFinished = false; Entities.ForEach(( ref GameMngr mngr ) => { isTitleFinished = mngr.IsTitleFinished; if (!isTitleFinished) { mngr.IsTitleFinished = true; mngr.IsPause = true; } }); if (!isTitleFinished) { SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <PanelConfig>().TitleScn; SceneService.LoadSceneAsync(panelBase); return; } #endif //float timer = 0; int score = 0; //bool isEnd = false; //bool isPause = false; bool reqGameOver = false; bool reqResult = false; Entities.ForEach(( ref GameMngr mngr ) => { float dt = World.TinyEnvironment().frameDeltaTime; switch (mngr.Mode) { case MdTitle: mngr.Mode = MdGame; break; case MdGame: if (mngr.ReqGameOver) { mngr.ReqGameOver = false; reqGameOver = true; mngr.Mode = MdGameOver; mngr.ModeTimer = 0; } break; case MdGameOver: mngr.ModeTimer += dt; if (mngr.ModeTimer > 1.5f) { mngr.Mode = MdResult; reqResult = true; } break; } if (mngr.IsPause) { //isPause = true; return; } score = mngr.Score; // タイマー. mngr.GameTimer += dt; #if false timer = mngr.GameTimer; if (timer >= GameTimeLimit) { mngr.IsPause = true; } #endif }); #if false // タイマー表示. if (!isPause) { Entities.WithAll <TextTimerTag>().ForEach(( Entity entity ) => { int t = (int)(GameTimeLimit - timer); EntityManager.SetBufferFromString <TextString>(entity, t.ToString()); }); } #endif if (reqResult) { // ゲームオーバーシーンアンロード. SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <GameConfig>().GameOverScn; SceneService.UnloadAllSceneInstances(panelBase); // リザルト表示. //SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <GameConfig>().ResultScn; SceneService.LoadSceneAsync(panelBase); } else if (reqGameOver) { // ゲームオーバー表示. SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <GameConfig>().GameOverScn; SceneService.LoadSceneAsync(panelBase); // ブロック削除. var env = World.TinyEnvironment(); SceneService.UnloadAllSceneInstances(env.GetConfigData <GameConfig>().PrefabBlock); SceneService.UnloadAllSceneInstances(env.GetConfigData <GameConfig>().PrefabBlockStay); SceneService.UnloadAllSceneInstances(env.GetConfigData <GameConfig>().PrefabStar); } }
public const float GameTimeLimit = 90f; // ゲーム時間. protected override void OnUpdate() { bool isTitleFinished = false; Entities.ForEach(( ref GameMngr mngr ) => { isTitleFinished = mngr.IsTitleFinished; if (!isTitleFinished) { mngr.IsTitleFinished = true; mngr.IsPause = true; } }); if (!isTitleFinished) { SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <PanelConfig>().TitleScn; SceneService.LoadSceneAsync(panelBase); return; } float timer = 0; int score = 0; bool isEnd = false; bool isPause = false; Entities.ForEach(( ref GameMngr mngr ) => { if (mngr.IsPause) { isPause = true; return; } score = mngr.Score; // タイマー. mngr.GameTimer += World.TinyEnvironment().frameDeltaTime; timer = mngr.GameTimer; if (timer >= GameTimeLimit) { isEnd = true; //mngr.GameTimer = 0; mngr.IsPause = true; } }); if (isEnd) { // リザルト表示. SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <PanelConfig>().ResultScn; SceneService.LoadSceneAsync(panelBase); } // タイマー表示. if (!isPause) { Entities.WithAll <TextTimerTag>().ForEach(( Entity entity ) => { int t = (int)(GameTimeLimit - timer); EntityManager.SetBufferFromString <TextString>(entity, t.ToString()); }); } #if false Entities.WithAll <TextComboTag>().ForEach(( Entity entity ) => { if (timer < 3f) { EntityManager.SetBufferFromString <TextString>(entity, ""); } else { EntityManager.SetBufferFromString <TextString>(entity, "Combo"); } }); #endif }
protected override void OnUpdate() { bool reqResult = false; int ballCnt = -1; bool reqHitEff = false; Entities.ForEach((Entity entity, ref BallInfo ball, ref Translation trans, ref NonUniformScale scl) => { if (!ball.SeedInitialized) { // 乱数シードセット 1回だけ. ball.SeedInitialized = true; int seed = World.TinyEnvironment().frameNum; //Debug.LogFormatAlways( "seed {0}", seed ); _random.InitState((uint)seed); } if (!ball.Initialized) { ball.Initialized = true; ball.Status = StPrepare; ball.Timer = 0; scl.Value = new float3(1f, 1f, 1f); ball.Speed = _random.NextFloat(400f, 900f); //ball.Speed = 400f; // ボール軌道. float3 stPos = new float3(_random.NextFloat(-20f, 40f), 100f, 0); float3 edPos = new float3(_random.NextFloat(-20f, 40f), -300f, 0); //float3 stPos = new float3( 0, 100f, 0 ); //float3 edPos = new float3( 0, -300f, 0 ); float3 dvec = edPos - stPos; trans.Value = stPos; ball.Dir = math.normalize(dvec); ++ball.Count; return; } float dt = World.TinyEnvironment().frameDeltaTime; switch (ball.Status) { case StPrepare: ball.Timer += dt; if (ball.Timer > 1.0f) { ball.Status = StThrow; ball.Timer = 0; } break; case StThrow: var prePos = trans.Value; var pos = prePos; float3 vel = dt * ball.Speed * ball.Dir; pos += vel; float3 p; float3 n; float refRate; // バットとの当たりチェック. if (checkColliBat(prePos, pos, out p, out n, out refRate)) { // hit. ball.Status = StShot; ball.Timer = 0; ball.Dir = calcReflectVec(ball.Dir, n); trans.Value = p; ball.HitPos = p; //Debug.LogFormatAlways("hitpos {0} {1}", ball.HitPos.x, ball.HitPos.y); ball.Speed *= refRate; if (ball.Speed < 900f) { ball.Speed = 900f; } // hit effect. reqHitEff = true; break; } trans.Value = pos; if (pos.y < -500f) { ball.Status = StEnd; ball.Timer = 0; scl.Value.x = 0; } break; case StShot: var prePos2 = trans.Value; var pos2 = prePos2; float3 vel2 = dt * ball.Speed * ball.Dir; pos2 += vel2; float3 refv; // ターゲットとの当たりチェック. if (checkTarget(prePos2, pos2, ball.Dir, out refv)) { //ball.Speed *= 0.9f; ball.Dir = refv; // 跳ね返り. break; } trans.Value = pos2; ball.Timer += dt; if (ball.Timer > 2.5f) { ball.Status = StEnd; scl.Value.x = 0; ball.Timer = 0; } break; case StEnd: ball.Timer += dt; if (ball.Timer > 1f) { if (ball.Count >= 10) { // todo リザルト. //ball.Initialized = false; // 仮. ball.Count = 0; ball.Status = StPause; reqResult = true; } else { ball.Initialized = false; } ballCnt = ball.Count + 1; } break; } }); if (ballCnt != -1) { dispBallCount(ballCnt); } if (reqHitEff) { // ヒットエフェクト. Entities.ForEach((Entity entity, ref HitEffInfo info) => { info.IsActive = true; Debug.LogAlways("eff req"); }); } if (reqResult) { // リザルト表示. SceneReference resultScn = World.TinyEnvironment().GetConfigData <GameConfig>().ResultScn; SceneService.LoadSceneAsync(resultScn); } }
public const float GenTimeDifference = 0.7f; // ブロック連続生成の時間差. protected override void OnUpdate() { bool isRequest = false; bool isPause = false; float gameTime = 0; Entities.ForEach(( ref GameMngr mngr ) => { gameTime = mngr.GameTimer; isPause = mngr.IsPause; }); if (!isPause) { Entities.ForEach(( ref GeneratorInfo info ) => { if (!info.Initialized) { // 初期化. info.Initialized = true; //info.IntvlTime = IntervalTime; info.IntvlTime = GetInterval(gameTime); info.GenerateNum = 1; info.Timer = TimeForAdjust; info.GenCnt = 0; info.Status = StNorm; return; } float dt = World.TinyEnvironment().frameDeltaTime; if (info.Status == StNorm) { info.Timer += dt; if (info.Timer > info.IntvlTime) { info.Timer = 0; info.Status = StGenerate; info.GenCnt = 0; CheckGenerateNum(ref info, gameTime); // インターバル更新. info.IntvlTime = GetInterval(gameTime); } } else if (info.Status == StGenerate) { // 連続的に生成. info.TimeDifference -= dt; if (info.TimeDifference <= 0) { if (info.GenCnt < info.GenerateNum) { isRequest = true; info.TimeDifference = GenTimeDifference; if (++info.GenCnt >= info.GenerateNum) { // 終了 info.Status = StNorm; info.GenCnt = 0; } } } } }); if (isRequest) { // ブロック生成. var env = World.TinyEnvironment(); SceneReference blockBase = new SceneReference(); blockBase = env.GetConfigData <GameConfig>().PrefabBlock; SceneService.LoadSceneAsync(blockBase); } } }
protected override void OnUpdate() { var env = World.TinyEnvironment(); bool isGen = false; bool isAdd = false; int genCnt = 0; SceneReference panelBase = new SceneReference(); Entities.ForEach(( ref PuzzleGen gen ) => { if (gen.IsGenerate) { isGen = true; gen.IsGenerate = false; genCnt = ++gen.GeneratedCnt; } else if (gen.IsGenAdditive) { isAdd = true; gen.IsGenAdditive = false; gen.ReqAddPanelInit = true; } }); if (isGen) { int redNum = math.min(genCnt, 6); // 最大で6個. int[] redIdices = new int[redNum]; #if true int ix = 0; int iy = 0; for (int i = 0; i < redNum; ++i) { if (i == 0) { ix = getRandFromTime(3); iy = getRand(3); //Debug.LogFormatAlways( "1st {0} {1}", ix, iy ); } else { ix = getRand(4); iy = getRand(4); } int idx = ix + iy * 4; if (idx >= 15) { --idx; } redIdices[i] = idx; } #else for (int i = 0; i < redNum; ++i) { redIdices[i] = i; } #endif for (int i = 0; i < 15; ++i) { bool isRed = false; for (int j = 0; j < redNum; ++j) { if (i == redIdices[j]) { isRed = true; break; } } if (isRed) { panelBase = env.GetConfigData <PanelConfig>().PanelRed; } else { panelBase = env.GetConfigData <PanelConfig>().PanelWhite; } SceneService.LoadSceneAsync(panelBase); } } else if (isAdd) { // 追加パネル. panelBase = env.GetConfigData <PanelConfig>().PanelWhite; SceneService.LoadSceneAsync(panelBase); } }