public static int init(GameObject game_object = null, PlayerEntity player_entity = null)
        {
            // プレイヤーGameObject取得
            if (game_object != null)
            {
                go = game_object;
            }
            else
            {
                //Debug.Log("PlayerService.init : PlayerFactory.createGameObject()");
                go = PlayerFactory.createGameObject();
            }

            // Entity生成
            if (player_entity != null)
            {
                _entity = player_entity;
                return(_entity.equip.id);
            }
            else
            {
                //Debug.Log("PlayerService.init : PlayerFactory.createEntity()");
                _entity = PlayerFactory.createEntity();
            }

            // Lv 1以上のデータなら next_level更新
            if (1 < _entity.lv)
            {
                nextLevel(_entity.lv - 1);
                nextLevel(_entity.lv);
                nextLevel(_entity.lv + 1);
            }


            EquipEntity equip = _entity.equip;

            if (equip == null)
            {
                // 初期装備
                //Debug.Log("PlayerService.init : EquipFactory.createRandomEntity()");
                equip = EquipFactory.createRandomEntity();
                //Debug.Log("equip.name : " + equip.name);
                ItemEquipController iec = equip.game_object.GetComponentInChildren <ItemEquipController>();
                iec.OnTarget();
            }
            else
            {
                // EquipEntityの通りに武器を作ってIDを再設定
            }

            //nextLevel(1);
            //nextLevel(2);
            return(equip.id);
        }
Exemplo n.º 2
0
    void Awake()
    {
        EquipFactory.init(prefabs);
        //EquipService.init();

        MessageBroker.Default.Receive <EquipEvent>().Subscribe(x => {
            Debug.Log("MessageBroker.Default.Receive<EquipEvent>().Subscribe()");
            EquipService.onlyEquip(x.id, x.go, x.update_service_data);
        });

        MessageBroker.Default.Receive <ChangeEquipEvent>().Subscribe(x => {
            Debug.Log("MessageBroker.Default.Receive<ChangeEquipEvent>().Subscribe()");
            EquipService.equipChange(x.id, x.go);
            MessageBroker.Default.Publish <SaveDataSave>(new SaveDataSave());
        });
    }
    public void Start()
    {
        // セーブデータ3つ読み込み
        s1p = SaveDataService.loadPlayer(1);
        s2p = SaveDataService.loadPlayer(2);
        s3p = SaveDataService.loadPlayer(3);

/*
 *      s1p = StorageService.load<PlayerEntity>(1, "Player");
 *      s2p = StorageService.load<PlayerEntity>(2, "Player");
 *      s3p = StorageService.load<PlayerEntity>(3, "Player");
 */
        // スロット1処理(データあればキャラ表示、ボタン表示変更)
        if (s1p != null)
        {
            // データあるのでキャラ表示、ボタン表示変更
            Debug.Log("SelectSceneManager.Start : s1p exist.");
            Debug.Log("SelectSceneManager.Start : s1p : " + s1p.ToString());
            Debug.Log("SelectSceneManager.Start : s1p.equip : " + s1p.equip.name);
            Debug.Log("SelectSceneManager.Start : s1p.lv : " + s1p.lv);
            Debug.Log("SelectSceneManager.Start : s1p.exp : " + s1p.exp);

            s1p.equip = EquipFactory.createEntity(s1p.equip);
            var s1e = EquipFactory.createGameObject(s1p.equip, Vector3.zero);
            s1e.GetComponentInChildren <BoxCollider>().enabled         = false;
            s1e.GetComponentInChildren <ItemEquipController>().enabled = false;
            Debug.Log("SelectSceneManager.Start : s1e : " + s1e.name);

            s1go = PlayerFactory.createGameObject();
            //Debug.Log("SelectSceneManager.Start : s1go.transform.SetPositionAndRotation : " + s1_position.ToString());
            s1go.transform.SetPositionAndRotation(s1_position, Quaternion.Euler(s1_rotation));
            s1go.GetComponent <Animator>().SetInteger("hp", 10);
            s1go.GetComponent <Animator>().enabled         = true;
            s1go.GetComponent <BoxCollider>().enabled      = false;
            s1go.GetComponent <NavMeshAgent>().enabled     = false;
            s1go.GetComponent <PlayerController>().enabled = false;

            Debug.Log("MessageBroker.Default.Publish<EquipEvent>() : s1");
            MessageBroker.Default.Publish <EquipEvent>(new EquipEvent {
                id = s1p.equip.id,
                go = s1go,
                update_service_data = false,
            });

            s1_new_button.SetActive(false);
            s1_load_button.SetActive(true);
            s1_del_button.SetActive(true);
        }
        else
        {
            // データなしはそのまま
        }

        // スロット2処理(データあればキャラ表示、ボタン表示変更)
        if (s2p != null)
        {
            // データあるのでキャラ表示、ボタン表示変更
            Debug.Log("SelectSceneManager.Start : s2p exist.");
            Debug.Log("SelectSceneManager.Start : s2p : " + s2p.ToString());
            Debug.Log("SelectSceneManager.Start : s2p.equip : " + s2p.equip.name);

            s2p.equip = EquipFactory.createEntity(s2p.equip);
            var s2e = EquipFactory.createGameObject(s2p.equip, Vector3.zero);
            s2e.GetComponentInChildren <BoxCollider>().enabled         = false;
            s2e.GetComponentInChildren <ItemEquipController>().enabled = false;
            Debug.Log("SelectSceneManager.Start : s2e : " + s2e.name);

            s2go = PlayerFactory.createGameObject();
            //Debug.Log("SelectSceneManager.Start : s2go.transform.SetPositionAndRotation : " + s2_position.ToString());
            s2go.transform.SetPositionAndRotation(s2_position, Quaternion.Euler(s2_rotation));
            s2go.GetComponent <Animator>().SetInteger("hp", 10);
            s2go.GetComponent <Animator>().enabled         = true;
            s2go.GetComponent <BoxCollider>().enabled      = false;
            s2go.GetComponent <NavMeshAgent>().enabled     = false;
            s2go.GetComponent <PlayerController>().enabled = false;

            Debug.Log("MessageBroker.Default.Publish<EquipEvent>() : s2");
            MessageBroker.Default.Publish <EquipEvent>(new EquipEvent {
                id = s2p.equip.id,
                go = s2go,
                update_service_data = false,
            });

            s2_new_button.SetActive(false);
            s2_load_button.SetActive(true);
            s2_del_button.SetActive(true);
        }
        else
        {
            // データなしはそのまま
        }

        // スロット3処理(データあればキャラ表示、ボタン表示変更)
        if (s3p != null)
        {
            // データあるのでキャラ表示、ボタン表示変更
            Debug.Log("SelectSceneManager.Start : s3p exist.");

            s3p.equip = EquipFactory.createEntity(s3p.equip);
            var s3e = EquipFactory.createGameObject(s3p.equip, Vector3.zero);
            s3e.GetComponentInChildren <BoxCollider>().enabled         = false;
            s3e.GetComponentInChildren <ItemEquipController>().enabled = false;
            Debug.Log("SelectSceneManager.Start : s3e : " + s3e.name);

            s3go = PlayerFactory.createGameObject();
            s3go.transform.SetPositionAndRotation(s3_position, Quaternion.Euler(s3_rotation));
            s3go.GetComponent <Animator>().SetInteger("hp", 10);
            s3go.GetComponent <Animator>().enabled         = true;
            s3go.GetComponent <BoxCollider>().enabled      = false;
            s3go.GetComponent <NavMeshAgent>().enabled     = false;
            s3go.GetComponent <PlayerController>().enabled = false;

            MessageBroker.Default.Publish <EquipEvent>(new EquipEvent {
                id = s3p.equip.id,
                go = s3go,
                update_service_data = false,
            });

            s3_new_button.SetActive(false);
            s3_load_button.SetActive(true);
            s3_del_button.SetActive(true);
        }
        else
        {
            // データなしはそのまま
        }
    }