예제 #1
0
    public void Hit()
    {
        //Debug.Log("PlayerController.Hit()");
        var check_start_offset = 0.3f;

        var check_max_distance = 1.5f;

        var check_radius = 0.1f;

        RaycastHit rayHit;

        Ray ray = new Ray(
            transform.position +
            new Vector3(0f, 0.5f, 0f) +
            transform.forward * -check_start_offset,
            transform.forward
            );


        int  layer_mask = (1 << LayerMask.NameToLayer("Player"));
        bool onhit      = false;

        if (Physics.SphereCast(ray, check_radius, out rayHit, check_max_distance, layer_mask))
        {
            //if (Physics.Raycast(ray, out rayHit, attack_distance, layer_mask)) {
            //Debug.Log("EnemyController.Hit: " + rayHit.transform.tag);
            if (rayHit.transform.tag == "Player")
            {
                onhit = true;
            }
            else
            if (rayHit.transform.tag == "PlayerDead")
            {
                DoIdleMode();
                return;
            }
        }

        if (onhit)
        {
            var se_name = SeService.getEnemyAttack(entity.rank);
            MessageBroker.Default.Publish <PlaySe>(new PlaySe {
                name = se_name
            });

            rayHit.transform.SendMessage("OnDamage", entity.atk);
            //Debug.Log("OnDamage: " + entity.atk);
        }
        else
        {
            // miss
            PlayerService.OnMiss();
            //Debug.Log("OnMiss");
        }
    }
예제 #2
0
    void Start()
    {
        player_detect_speed = EnemyService.get_detect_interval(entity.rank);
        nmSurface           = GameObject.FindGameObjectWithTag("SystemManager").GetComponent <NavMeshSurface>();
        nmAgent             = GetComponent <NavMeshAgent>();
        animator            = GetComponent <Animator>();
        outline             = GetComponentInChildren <Outline>();
        collider            = GetComponent <Collider>();

        Observable.Interval(TimeSpan.FromMilliseconds(player_detect_speed)).Subscribe(x => {
            // プレイヤー位置を取得する
            player_position = PlayerService.position();
        }).AddTo(this);

        character_control = true;
        DoMoveMode();

        //Debug.Log("EnemyController : id : " + id);
        //Debug.Log("EnemyController : entity.name : " + entity.name);

        //this.UpdateAsObservable().ObserveOnMainThread().Subscribe(x => {
        //});
    }
예제 #3
0
    private void DoDeadMove()
    {
        state         = EnemyState.Dead;
        transform.tag = "EnemyDead";
        //if (animator) animator.SetTrigger("Die");
        PlayerService.OnEnemyDead();
        //Debug.Log("PlayerService.OnEnemyDead()");
        outline.enabled  = false;
        collider.enabled = false;

        nmAgent.enabled = false;

/*
 *      Observable.NextFrame().Subscribe(x => {
 *          nmAgent.radius = 0.08f;
 *          nmSurface.BuildNavMesh();
 *      }).AddTo(this);
 */
        MessageBroker.Default.Publish <PlaySe>(new PlaySe {
            name = entity.dead_voice
        });
        PlayerService.add_exp(entity.exp);
    }
    private void loadGame(
        int slot,
        GameObject player_game_object = null,
        PlayerEntity player_entity    = null
        )
    {
        SaveDataService.use_slot = slot;
        //var game_stage_service = StorageService.load<GameStageService>(slot, "Stage");
        var stage_save_data = SaveDataService.loadStage(slot);

        if (player_game_object != null &&
            player_entity != null &&
            stage_save_data != null
            )
        {
            DontDestroyOnLoad(player_game_object);

            MessageBroker.Default.Publish <SceneChangeSimple>(new SceneChangeSimple {
                add_scene    = "Maze",
                del_scene    = "Select",
                active_scene = "Maze",
                post_action  = () => {
                    SceneService.EnableAllGameObjects("Maze", new List <string>());

                    // キャラデータを新シーンで展開
                    UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(
                        player_game_object,
                        UnityEngine.SceneManagement.SceneManager.GetSceneByName("Maze")
                        );

                    Debug.Log("SelectSceneManager.loadGame()");
                    Debug.Log("SelectSceneManager.loadGame() : player_entity.lv : " + player_entity.lv);
                    Debug.Log("SelectSceneManager.loadGame() : player_entity.exp : " + player_entity.exp);
                    PlayerService.nextLevel(player_entity.lv - 1);
                    PlayerService.nextLevel(player_entity.lv);
                    PlayerService.nextLevel(player_entity.lv + 1);

                    player_game_object.transform.position = player_default_position;
                    player_game_object.GetComponent <Animator>().enabled         = true;
                    player_game_object.GetComponent <BoxCollider>().enabled      = true;
                    player_game_object.GetComponent <NavMeshAgent>().enabled     = true;
                    player_game_object.GetComponent <PlayerController>().enabled = true;
                    PlayerService.init(player_game_object, player_entity);

                    Debug.Log("SelectSceneManager.loadGame() : player_entity.equip : " + player_entity.equip.name);

                    // 装備しなおし
                    MessageBroker.Default.Publish <EquipEvent>(new EquipEvent {
                        id = player_entity.equip.id,
                        go = player_game_object,
                        update_service_data = true,
                    });

                    // ステージデータを新シーンで展開
                    GameStageService.room_clear_count = stage_save_data.room_clear_count;
                    GameStageService.enemy_strength   = stage_save_data.enemy_strength;
                    GameStageService.enemy_num        = stage_save_data.enemy_num;

                    // GUI起動
                    MessageBroker.Default.Publish <ChangeGuiMode>(new ChangeGuiMode {
                        mode = GuiState.Room
                    });
                },
            });

            return;
        }

        MessageBroker.Default.Publish <SceneChangeSimple>(new SceneChangeSimple {
            add_scene    = "Maze",
            del_scene    = "Select",
            active_scene = "Maze",
            post_action  = () => {
                SceneService.EnableAllGameObjects("Maze", new List <string>());

                // 新しいプレイヤーを生成、初期武器ID取得
                int equip_id = PlayerService.init(null, null);

                // 初期武器を装備
                MessageBroker.Default.Publish <ChangeEquipEvent>(new ChangeEquipEvent {
                    id = equip_id,
                });

                // 新規ステージデータ設定
                GameStageService.room_clear_count = room_clear_count_default;
                GameStageService.enemy_strength   = enemy_strength_default;
                GameStageService.enemy_num        = enemy_num_default;

                // GUI起動
                MessageBroker.Default.Publish <ChangeGuiMode>(new ChangeGuiMode {
                    mode = GuiState.Room
                });
            },
        });
    }