「Unity/Firebase/CloudFunctions」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→import) |
|||
行4: | 行4: | ||
==import== | ==import== | ||
FirebaseFunctions.unitypackage をunityのAssets/ImportPackage/CustomPackageからImportする | FirebaseFunctions.unitypackage をunityのAssets/ImportPackage/CustomPackageからImportする | ||
+ | |||
+ | ==firebaseのサーバー側変更== | ||
+ | <pre> | ||
+ | const functions = require('firebase-functions'); | ||
+ | const admin = require('firebase-admin'); | ||
+ | admin.initializeApp(); | ||
+ | exports.addEntry = functions | ||
+ | .region('asia-northeast1') | ||
+ | .https.onCall((data, context) => | ||
+ | { | ||
+ | const entry = { | ||
+ | name : data.name, | ||
+ | point : data.point | ||
+ | }; | ||
+ | return admin.firestore().collection('entries') | ||
+ | .add(entry) | ||
+ | .then((snapshot) => | ||
+ | { | ||
+ | return 'OK'; | ||
+ | }); | ||
+ | }); | ||
+ | |||
+ | // トップcount件のEntryを取得 | ||
+ | exports.getTopEntries = functions | ||
+ | .region('asia-northeast1') | ||
+ | .https.onCall((data, context) => | ||
+ | { | ||
+ | const count = data.count; | ||
+ | |||
+ | return admin.firestore().collection('entries') | ||
+ | .orderBy('point', 'desc') | ||
+ | .limit(count) | ||
+ | .get() | ||
+ | .then((qSnapshot) => | ||
+ | { | ||
+ | return { | ||
+ | entries : qSnapshot.docs.map(x => x.data()) | ||
+ | }; | ||
+ | }); | ||
+ | }); | ||
+ | </pre> | ||
==参考== | ==参考== | ||
https://devlog.hassaku.blue/2019/03/unity-firebase-firebase.html | https://devlog.hassaku.blue/2019/03/unity-firebase-firebase.html |
2019年7月2日 (火) 18:32時点における版
準備
Gcp/Firebase/CloudFunctions [ショートカット]
import
FirebaseFunctions.unitypackage をunityのAssets/ImportPackage/CustomPackageからImportする
firebaseのサーバー側変更
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.addEntry = functions .region('asia-northeast1') .https.onCall((data, context) => { const entry = { name : data.name, point : data.point }; return admin.firestore().collection('entries') .add(entry) .then((snapshot) => { return 'OK'; }); }); // トップcount件のEntryを取得 exports.getTopEntries = functions .region('asia-northeast1') .https.onCall((data, context) => { const count = data.count; return admin.firestore().collection('entries') .orderBy('point', 'desc') .limit(count) .get() .then((qSnapshot) => { return { entries : qSnapshot.docs.map(x => x.data()) }; }); });
参考
https://devlog.hassaku.blue/2019/03/unity-firebase-firebase.html