clean project
This commit is contained in:
189
Assets/Oculus/SampleFramework/Usage/Firebase/AnalyticsUI.cs
Normal file
189
Assets/Oculus/SampleFramework/Usage/Firebase/AnalyticsUI.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if OVR_SAMPLES_ENABLE_FIREBASE
|
||||
using Firebase.Analytics;
|
||||
#endif
|
||||
|
||||
public class AnalyticsUI : MonoBehaviour
|
||||
{
|
||||
#if OVR_SAMPLES_ENABLE_FIREBASE
|
||||
const int target = DebugUIBuilder.DEBUG_PANE_LEFT;
|
||||
|
||||
bool analyticsCollectionEnabled = true;
|
||||
RectTransform textFieldSessionTimeoutDuration;
|
||||
RectTransform textFieldUserId;
|
||||
|
||||
RectTransform textFieldName;
|
||||
RectTransform textFieldProperty;
|
||||
|
||||
RectTransform textFieldEventName;
|
||||
|
||||
List<(RectTransform, RectTransform)> intParams = new List<(RectTransform, RectTransform)>();//, FltParms, StrParams;
|
||||
List<(RectTransform, RectTransform)> fltParams = new List<(RectTransform, RectTransform)>();//, FltParms, StrParams;
|
||||
List<(RectTransform, RectTransform)> strParams = new List<(RectTransform, RectTransform)>();//, FltParms, StrParams;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
DebugUIBuilder ui = DebugUIBuilder.instance;
|
||||
ui.AddButton("ResetAnalyticsData", ResetAnalyticsData, target);
|
||||
ui.AddButton("SetAnalyticsCollectionEnabled", SetAnalyticsCollectionEnabled, target);
|
||||
ui.AddToggle("CollectionEnabled", delegate (Toggle t) { analyticsCollectionEnabled = t.enabled; },
|
||||
analyticsCollectionEnabled, target);
|
||||
|
||||
//ui.AddButton("SetDefaultEventParameters", SetDefaultEventParameters, target);
|
||||
|
||||
ui.AddButton("SetSessionTimeoutDuration", SetSessionTimeoutDuration, target);
|
||||
textFieldSessionTimeoutDuration = ui.AddTextField("500000", target);
|
||||
|
||||
ui.AddButton("SetUserId", SetUserId, target);
|
||||
textFieldUserId = ui.AddTextField("UserId", target);
|
||||
|
||||
ui.AddButton("SetUserProperty", SetUserProperty, target);
|
||||
textFieldName = ui.AddTextField("Name", target);
|
||||
textFieldProperty = ui.AddTextField("Nroperty", target);
|
||||
|
||||
// log event UI
|
||||
ui.AddButton("LogEvent", LogEvent, 3);
|
||||
textFieldEventName = ui.AddTextField("EventName", 3);
|
||||
ui.AddButton("AddInt", AddInt, 3);
|
||||
ui.AddButton("AddFlt", AddFlt, 3);
|
||||
ui.AddButton("AddStr", AddStr, 3);
|
||||
ui.AddButton("Clear", Clear, 3);
|
||||
|
||||
ui.Show();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
DebugUIBuilder ui = DebugUIBuilder.instance;
|
||||
var field = typeof(DebugUIBuilder).GetField("insertedElements", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||
var relayout = typeof(DebugUIBuilder).GetMethod("Relayout", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||
List<RectTransform> elements = ((List<RectTransform>[])field.GetValue(ui))[3];
|
||||
foreach ((RectTransform a, RectTransform b) in intParams)
|
||||
{
|
||||
elements.Remove(a);
|
||||
elements.Remove(b);
|
||||
a.SetParent(null);
|
||||
b.SetParent(null);
|
||||
}
|
||||
foreach ((RectTransform a, RectTransform b) in fltParams)
|
||||
{
|
||||
elements.Remove(a);
|
||||
elements.Remove(b);
|
||||
a.SetParent(null);
|
||||
b.SetParent(null);
|
||||
}
|
||||
foreach ((RectTransform a, RectTransform b) in strParams)
|
||||
{
|
||||
elements.Remove(a);
|
||||
elements.Remove(b);
|
||||
a.SetParent(null);
|
||||
b.SetParent(null);
|
||||
}
|
||||
relayout.Invoke(ui, new object[] { });
|
||||
}
|
||||
|
||||
void AddInt()
|
||||
{
|
||||
DebugUIBuilder ui = DebugUIBuilder.instance;
|
||||
var name = ui.AddTextField("INT_PARAM", 3);
|
||||
var value = ui.AddTextField("0", 3);
|
||||
intParams.Add((name, value));
|
||||
}
|
||||
|
||||
void AddFlt()
|
||||
{
|
||||
DebugUIBuilder ui = DebugUIBuilder.instance;
|
||||
var name = ui.AddTextField("FLT_PARAM", 3);
|
||||
var value = ui.AddTextField("0.0", 3);
|
||||
intParams.Add((name, value));
|
||||
}
|
||||
|
||||
void AddStr()
|
||||
{
|
||||
DebugUIBuilder ui = DebugUIBuilder.instance;
|
||||
var name = ui.AddTextField("STR_PARAM", 3);
|
||||
var value = ui.AddTextField("None", 3);
|
||||
intParams.Add((name, value));
|
||||
}
|
||||
|
||||
private List<Parameter> GetParameterList()
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
foreach ((RectTransform a, RectTransform b) in intParams)
|
||||
{
|
||||
string name = a.GetComponentInChildren<Text>().text;
|
||||
int value;
|
||||
if(int.TryParse(b.GetComponentInChildren<Text>().text, out value))
|
||||
{
|
||||
parameters.Add(new Parameter(name, value));
|
||||
}
|
||||
}
|
||||
foreach ((RectTransform a, RectTransform b) in fltParams)
|
||||
{
|
||||
string name = a.GetComponentInChildren<Text>().text;
|
||||
float value;
|
||||
if (float.TryParse(b.GetComponentInChildren<Text>().text, out value))
|
||||
{
|
||||
parameters.Add(new Parameter(name, value));
|
||||
}
|
||||
}
|
||||
foreach ((RectTransform a, RectTransform b) in fltParams)
|
||||
{
|
||||
string name = a.GetComponentInChildren<Text>().text;
|
||||
string value = b.GetComponentInChildren<Text>().text;
|
||||
parameters.Add(new Parameter(name, value));
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
void LogEvent()
|
||||
{
|
||||
Debug.Log("LogEvent");
|
||||
List<Parameter> parameters = GetParameterList();
|
||||
string eventName = textFieldEventName.GetComponentInChildren<Text>().text;
|
||||
FirebaseAnalytics.LogEvent(eventName, parameters.ToArray());
|
||||
|
||||
}
|
||||
|
||||
void ResetAnalyticsData()
|
||||
{
|
||||
Debug.Log("ResetAnalyticsData");
|
||||
FirebaseAnalytics.ResetAnalyticsData();
|
||||
}
|
||||
|
||||
void SetAnalyticsCollectionEnabled()
|
||||
{
|
||||
Debug.Log(string.Format("SetAnalyticsCollectionEnabled({0})", analyticsCollectionEnabled));
|
||||
FirebaseAnalytics.SetAnalyticsCollectionEnabled(analyticsCollectionEnabled);
|
||||
}
|
||||
|
||||
void SetSessionTimeoutDuration()
|
||||
{
|
||||
long ms;
|
||||
if( long.TryParse(textFieldSessionTimeoutDuration.GetComponentInChildren<Text>().text, out ms) )
|
||||
{
|
||||
Debug.Log(string.Format("SetSessionTimeoutDuration({0})", ms));
|
||||
FirebaseAnalytics.SetSessionTimeoutDuration(System.TimeSpan.FromMilliseconds(ms));
|
||||
}
|
||||
}
|
||||
|
||||
void SetUserId()
|
||||
{
|
||||
string userId = textFieldUserId.GetComponentInChildren<Text>().text;
|
||||
Debug.Log(string.Format("SetUserId({0})", userId));
|
||||
FirebaseAnalytics.SetUserId(userId);
|
||||
}
|
||||
|
||||
void SetUserProperty()
|
||||
{
|
||||
string name = textFieldName.GetComponentInChildren<Text>().text;
|
||||
string property = textFieldProperty.GetComponentInChildren<Text>().text;
|
||||
FirebaseAnalytics.SetUserProperty(name, property);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6d76db561fffe94987d3c29fb777c0c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Oculus/SampleFramework/Usage/Firebase/README.md
Normal file
21
Assets/Oculus/SampleFramework/Usage/Firebase/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Description
|
||||
This sample shows how to capture Firebase Analytics and Crashlytics metrics in your Oculus app
|
||||
|
||||
# Prerequisites
|
||||
## Install Firebase
|
||||
1. Before enabling this sample, please follow steps 1 through 4 oulined in the article ["Add Firebase to your Unity project"](https://firebase.google.com/docs/unity/setup). Step 5 is not required as it is included in the sample code.
|
||||
|
||||
2. From the `firebase_unity_sdk` that you downloaded, import `dotnet4/FirebaseAnalytics.unitypackage` and `dotnet4/FirebaseCrashlytics.unitypackage`
|
||||
|
||||
3. Make sure to enable the Android Auto-Resolver if prompted
|
||||
|
||||
4. Replace the template `google-services.json` with your own
|
||||
|
||||
## Enable Project Code
|
||||
Once Firebase Analytics and Crashlytics are added to the project, enable the sample code through the Oculus menu: `Oculus > Samples > Firebase > Enable Firebase Sample`
|
||||
|
||||
## Allow 'unsafe'
|
||||
In order to force a crash, the Crashlytics sample makes use of `C#`'s `unsafe` keyword. This is prohibited by default, you'll have to enable it in the player settings: `Edit > Project Settings... > Player > Android settings > Allow 'unsafe' code`
|
||||
|
||||
## Build and Run
|
||||
At this point you should be able to open the sample scene and trigger some events and crashes, which will show up in your [Firebase console](https://console.firebase.google.com/).
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 969abaa8a3755234f8eace4a64be4825
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Oculus/SampleFramework/Usage/Firebase/SampleUI.cs
Normal file
89
Assets/Oculus/SampleFramework/Usage/Firebase/SampleUI.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SampleUI : MonoBehaviour
|
||||
{
|
||||
RectTransform collectionButton;
|
||||
RectTransform inputText;
|
||||
RectTransform valueText;
|
||||
bool inMenu;
|
||||
|
||||
void Start()
|
||||
{
|
||||
#if OVR_SAMPLES_ENABLE_FIREBASE
|
||||
DebugUIBuilder.instance.AddButton("Log", Log);
|
||||
DebugUIBuilder.instance.AddButton("Record Exception", RecordException);
|
||||
collectionButton = DebugUIBuilder.instance.AddButton("Toggle Crashlytics Collection (true)", ToggleCrashlyticsCollection);
|
||||
DebugUIBuilder.instance.AddButton("Set Custom Key", ToggleCrashlyticsCollection);
|
||||
DebugUIBuilder.instance.AddButton("Set User ID", SetUserID);
|
||||
DebugUIBuilder.instance.AddButton("Crash", Crash);
|
||||
|
||||
DebugUIBuilder.instance.AddLabel("(Text input used by most methods)", DebugUIBuilder.DEBUG_PANE_RIGHT);
|
||||
inputText = DebugUIBuilder.instance.AddTextField("Input Text", DebugUIBuilder.DEBUG_PANE_RIGHT);
|
||||
DebugUIBuilder.instance.AddLabel("(The value of Set Custom Key)", DebugUIBuilder.DEBUG_PANE_RIGHT);
|
||||
valueText = DebugUIBuilder.instance.AddTextField("Value", DebugUIBuilder.DEBUG_PANE_RIGHT);
|
||||
#else
|
||||
DebugUIBuilder.instance.AddLabel("Enable Firebase in your project before running this sample", DebugUIBuilder.DEBUG_PANE_RIGHT);
|
||||
#endif
|
||||
DebugUIBuilder.instance.Show();
|
||||
inMenu = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (OVRInput.GetDown(OVRInput.Button.Two) || OVRInput.GetDown(OVRInput.Button.Start))
|
||||
{
|
||||
if (inMenu) DebugUIBuilder.instance.Hide();
|
||||
else DebugUIBuilder.instance.Show();
|
||||
inMenu = !inMenu;
|
||||
}
|
||||
}
|
||||
|
||||
string GetText()
|
||||
{
|
||||
return inputText.GetComponentInChildren<InputField>().text;
|
||||
}
|
||||
#if OVR_SAMPLES_ENABLE_FIREBASE
|
||||
void Log()
|
||||
{
|
||||
Firebase.Crashlytics.Crashlytics.Log(GetText());
|
||||
}
|
||||
|
||||
void RecordException()
|
||||
{
|
||||
Firebase.Crashlytics.Crashlytics.LogException(new System.Exception(GetText()));
|
||||
}
|
||||
|
||||
void ToggleCrashlyticsCollection()
|
||||
{
|
||||
Firebase.Crashlytics.Crashlytics.IsCrashlyticsCollectionEnabled = !Firebase.Crashlytics.Crashlytics.IsCrashlyticsCollectionEnabled;
|
||||
Text buttonText = collectionButton.GetComponentInChildren<Text>();
|
||||
if(buttonText)
|
||||
{
|
||||
buttonText.text = string.Format("Toggle Crashlytics Collection ({0})", Firebase.Crashlytics.Crashlytics.IsCrashlyticsCollectionEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
void SetCustomKey()
|
||||
{
|
||||
Firebase.Crashlytics.Crashlytics.SetCustomKey(GetText(), valueText.GetComponentInChildren<InputField>().text);
|
||||
}
|
||||
|
||||
void SetUserID()
|
||||
{
|
||||
Firebase.Crashlytics.Crashlytics.SetUserId(GetText());
|
||||
}
|
||||
|
||||
void Crash()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
int* i = null;
|
||||
*i = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ce7e49b6fbfe84db3ccea903d0c104
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
public class StartCrashlytics : MonoBehaviour
|
||||
{
|
||||
#if OVR_SAMPLES_ENABLE_FIREBASE
|
||||
Firebase.FirebaseApp app;
|
||||
void Start()
|
||||
{
|
||||
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
|
||||
var dependencyStatus = task.Result;
|
||||
if (dependencyStatus == Firebase.DependencyStatus.Available)
|
||||
{
|
||||
// Create and hold a reference to your FirebaseApp,
|
||||
// where app is a Firebase.FirebaseApp property of your application class.
|
||||
app = Firebase.FirebaseApp.DefaultInstance;
|
||||
|
||||
// Set a flag here to indicate whether Firebase is ready to use by your app.
|
||||
Firebase.Crashlytics.Crashlytics.IsCrashlyticsCollectionEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogError(System.String.Format(
|
||||
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
|
||||
// Firebase Unity SDK is not safe to use here.
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2666e0e6695507f4eb8365bdcc5f1ce3
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "",
|
||||
"firebase_url": "",
|
||||
"project_id": "",
|
||||
"storage_bucket": ""
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "",
|
||||
"android_client_info": {
|
||||
"package_name": ""
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "",
|
||||
"certificate_hash": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_id": "",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": ""
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a436b70f34194434695d8a4d4d43038e
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user