Migrating to Vuforia, Adding multitarget system
This commit is contained in:
47
AR/Assets/PocketBaseDataProvider.cs
Normal file
47
AR/Assets/PocketBaseDataProvider.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using models;
|
||||
using UnityEngine;
|
||||
using CandyCoded.env;
|
||||
using services;
|
||||
|
||||
public class PocketBaseDataProvider : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] public String userToken = null;
|
||||
[SerializeField] public static List<Trash> trashes = new List<Trash>();
|
||||
[SerializeField] public float timeBetweenUpdate = 10f;
|
||||
private float currentCountdown;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
this.currentCountdown = this.timeBetweenUpdate;
|
||||
env.TryParseEnvironmentVariable("API_USER", out string user);
|
||||
env.TryParseEnvironmentVariable("API_PASSWORD", out string password);
|
||||
LoginResponse res = UserService.Login(new LoginRequest(user, password));
|
||||
userToken = res.token;
|
||||
this.UpdateData();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
this.currentCountdown -= Time.deltaTime;
|
||||
if (this.currentCountdown <= 0)
|
||||
{
|
||||
this.currentCountdown = this.timeBetweenUpdate;
|
||||
this.UpdateData();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateData()
|
||||
{
|
||||
TrashList list = TrashService.ListTrash(userToken);
|
||||
foreach (Trash trash in list.items)
|
||||
{
|
||||
DataList trashData = TrashService.ListTrashData(userToken, trash.id);
|
||||
trash.data = trashData.items;
|
||||
}
|
||||
trashes = list.items.ToList();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user