[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

ビヨンドランチのメンバーを抽出するツールの改修

お疲れ様です。
システム開発室、松山です。

前回、ビヨンドランチのグループ分けをする簡単なツールを作成しました。
前回のブログはこちら
お陰様で組織文化委員会のメンバーからとても感謝されています。(妄想)
が、やはり単にランダムでグループ分けするだけでは機能が足りないと、
原岡社長から厳しくも温かいご指摘を頂いたので、もう少し作り込んでみましょう。(現実)

要件

① 毎月開催されるので、月指定できるようにする
② 抽選したデータを保存(読み込み)できるようにする
③ 抽選済みの月を選択したら、決定しているグループを表示
④ 前月と同じメンバーが被らないようにする(なるべく)
※ Unity 2019.4.18f1(LTS)にアップデート

こんな感じですかね。
Unity 機能的には ②, ③ で PlayerPrefs を使うくらいでしょうか。
あとはプログラム次第な感じです。

① 月指定できるようにする

前回、抽選ボタンを作ったあたりに、月指定する UI(Button と Text)を追加していきます。
こんな感じです。

日付については、System.DateTime を使えばよいので、起動時に現在の日時を取得して、
左右ボタン(◀︎ / ▶︎)で AddMonth() により更新します。
表示は年月のみなので、year と month を Text に設定してあげます。

あと、画面サイズについて見直します。
WebGL のデフォルトの解像度は 960x600 ですが、ProjectSettings で変更できたので 1960x1080 に設定します。

Canvas のサイズも変更して、UI のレイアウトも調整していきます。

全体は、こんな感じです。
左右スカスカですが、ご愛嬌ということで。

② 抽選したデータを保存(読み込み)できるようにする

抽選したグループのデータ(メンバー)を保存します。
ローカルでの保存は PlayerPrefs を使うのがよいですね。
PlayerPrefs の説明はこちら

任意の Key に対して、値(Value)を設定できるので、まずは Key のルールを決めます。
年月とグループ番号でユニークなキーとします。

string key = string.Format("group_{0}_{1}_{2}", GroupNo, date.Year, date.Month);

保存する値はメンバーの名前ですね。
あとで Split() でバラすのでスペース(半角)で区切って文字列にします。

string val = "";
for(int i=0; i<memberNames.Count; i++)
{
    if (i > 0) val += " ";
    val += memberNames[i];            
}

これで、Key と Value を用意できたので、PlayerPrefs に保存します。

PlayerPrefs.SetString(key, val);
PlayerPrefs.Save();

簡単ですね。
仕事などでまじめに使う際は暗号化してから保存しますが、今回は社内ツールなので平文でいいかなと。

③ 抽選済みの月を選択したら、決定しているグループを表示

② で保存したデータを PlayerPrefs から読み込みます。

string val = PlayerPrefs.GetString(key);
string[] members = val.Split(' ');

あとは読み込んだデータを UI に反映させれば OK です。

④ 前月と同じメンバーが被らないようにする(なるべく)

最後に抽選時に、前回(先月)と同じメンバーが被らないように判定を追加します。
今回は、以下の場合に再抽選するようにします。
1. 前月と同じグループ(リーダー)に入らない
2. 前月と同じメンバーと被らない
ただし、無限ループ対策として、5回連続で再抽選になった場合は、被っていても OK とします。

まず、各グループの先月のメンバーを読み込んでおきます。
その後、候補をランダムで抽選してから以下の判定を行います。

前月と同じグループ(リーダー)に入らない

抽選した候補者が、先月同じグループにいたか判定します。
先月のメンバーは List に格納されているので、Contains() で確認します。
もし、同じ場合は再抽選。

前月と同じメンバーと被らない

抽選した候補者が、先月どのグループにいたか調べます。
先月のグループメンバーと、今月入る予定のグループに既に登録されているメンバーを比較し、
同じメンバーがいたら再抽選。
どちらのメンバーリストも List なので、foreach で回して Contains() で確認します。

public bool IsSameMember(List<string> lastManthMembers)
{
    // 今月のメンバーに、先月のメンバーがいないかチェック
    bool isSame = false;
    foreach (string mem in memberNames)
    {
        if(lastManthMembers.Contains(mem))
        {
            isSame = true;
            break;
        }
    }
    return isSame;
}

ん〜、微妙にイケてない感ありますが、良いアイデアがでないです。
が、正しく動作はすると思います。

まとめ

なんとか要件は満たせたのかなと思います。
・月指定できる(System.DateTime)
・抽選したメンバーを保存(読み込み)する(PlayerPrefs)
・先月メンバーと被らないようにする(自前実装)
・ついでに解像度を調整(WebGL)
今回も基本的な機能だけで組み立ててます。

とりあえず、ビヨンドランチのツールはこれで完成(ver1.0.0)とします。
もし要望あれば機能改修しますので、お気軽にお問い合わせください。
それでは、今回のお話はこれまでになります。

Git は更新しておきます。
何かの参考にでもなれば幸いです。
Unity サンプル

最後に

私が所属するシステム開発のサービスサイト「SEKARAKU Lab(セカラク ラボ)」を開設しました。
ビヨンドは、サーバーの設計・構築から運用までをワンストップでお任せいただけますので、サーバーサイド開発でお困りの方はお気軽にお問い合わせください。
SEKARAKU Lab:[https://sekarakulab.beyondjapan.com/](https://sekarakulab.beyondjapan.com/)

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
0
読み込み中...
0 票, 平均: 0.00 / 10
413
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Kensho Matsuyama

For a long time, he worked at a game development company, working in programs and project management.
Joined Beyond Co., Ltd. in 2019.
He works in the Yokohama office. He is mainly responsible for project management of server-side development work.
(Sometimes programming) His hobbies are cycling (road racer) and watching horse races.