public void Generate(MapPresenter mapPresenter, ItemModel model) { // item object作成 GameObject res = Resources.Load("Object/" + model.modelName.Replace('_', '/')) as GameObject; Vector2Int pos = mapPresenter.GetPopPoint(); GameObject obj = Object.Instantiate(res, new Vector3(pos.x, 0, pos.y), Quaternion.identity) as GameObject; obj.name = "Item;" + serialGuid; obj.layer = 9; obj.transform.parent = transform; // item model作成 ItemPresenter itemPresenter = obj.AddComponent <ItemPresenter>(); itemPresenter.itemView = obj.AddComponent <ItemView>(); itemPresenter.itemView.model = obj; itemPresenter.Initialize(model, serialGuid); itemPresenter.SetMapData( mapPresenter.GetTileModel(pos.x, pos.y).floorId, new Vector3(pos.x, 0, pos.y), new Vector3(0, 0, -1) ); itemListPresenter[serialGuid] = itemPresenter; itemListObject[serialGuid] = obj; serialGuid++; mapPresenter.SetItemModel(pos.x, pos.y, itemPresenter.status); }
private void DefaultAction(CharacterPresenter characterPresenter) { InputAxis axis = InputAxis.GetInputAxis(); bool isShift = Input.GetKey(KeyCode.LeftShift); bool isZ = Input.GetKey(KeyCode.Z); //攻撃 if (Input.GetKeyDown(KeyCode.X) && characterPresenter.status.isAction == false && !characterPresenter.isMove) { characterPresenter.Attack(mapPresenter, characterListPresenter.characterListPresenter); characterListPresenter.Delete(); return; } if (axis.F.x != 0 || axis.F.y != 0) { if (isZ && (axis.F.x == 0 || axis.F.y == 0)) { return; } // 向き変更 if (!characterPresenter.isMove) { characterPresenter.SetDirection(new Vector3(axis.I.x, 0, axis.I.y)); // shiftが押されていたら方向転換だけ if (isShift) { return; } } Vector2Int beforePosition = new Vector2Int((int)characterPresenter.status.position.x, (int)characterPresenter.status.position.z); Vector2Int afterPosition = new Vector2Int(beforePosition.x + axis.I.x, beforePosition.y + axis.I.y); if (mapPresenter.IsCanMove(axis.I, beforePosition, characterPresenter.status.type)) { if (!characterPresenter.isMove && characterPresenter.status.isAction == false) { if (!isShift) { characterPresenter.Move(axis.F.x, axis.F.y); //アイテムがあれば取得 if (mapPresenter.GetTileModel(afterPosition.x, afterPosition.y).itemGuid != 0) { ItemPresenter itemPresenter = itemsListPresenter.Find(mapPresenter.GetTileModel(afterPosition.x, afterPosition.y).itemGuid); if (itemPresenter != null && characterPresenter.SetItem(itemPresenter.status)) { itemsListPresenter.Delete(itemPresenter); mapPresenter.SetItemModel(afterPosition.x, afterPosition.y, null); } else { Debug.Log("Cant Delete:null"); } } //階段あれば移動 if (mapPresenter.GetTileModel(afterPosition) .tileType == TileModel.TileType.Stairs) { mapPresenter.Regenerate(); } //移動元と移動先にキャラクター情報を設定 mapPresenter.SetUserModel(beforePosition, null); mapPresenter.SetUserModel(afterPosition, characterPresenter.status); characterPresenter.SetPosition(new Vector3(afterPosition.x, 0, afterPosition.y)); } } } } }