Exemplo n.º 1
0
    public void UpdateTargetInformation(string target_id)
    {
        int indexNumber = vtc.targetSummaryList.FindIndex(item => item.target_id == target_id);

        if (indexNumber > -1)
        {
            vtc.targetSummaryList.RemoveAt(indexNumber);
        }

        string targetSumString = GetTargetSummary(target_id);

        if (targetSumString == "fail")
        {
            VtTargetSummary blank = new VtTargetSummary();
            blank.target_id   = target_id;
            blank.target_name = "New Target, Try Refresh";
            blank.upload_date = DateTime.Now.Date.ToString();
        }
        else
        {
            VtTargetSummary targetSummary = JsonUtility.FromJson <VtTargetSummary>(targetSumString);
            targetSummary.target_id = target_id;
            string   dateSplit    = targetSumString.Split(new string[] { @"""upload_date"":""" }, StringSplitOptions.None)[1].Remove(10);
            string[] dateYYYYMMDD = dateSplit.Split('-');
            targetSummary.upload_date = dateYYYYMMDD[1] + "/" + dateYYYYMMDD[2] + "/" + dateYYYYMMDD[0];
            vtc.targetSummaryList.Insert(indexNumber, targetSummary);
        }
    }
Exemplo n.º 2
0
    public List <string> GetAllTargetNames()
    {
        vtc.targetSummaryList = new List <VtTargetSummary>();
        string requestPath = "/targets";
        string serviceURI  = url + requestPath;
        string httpAction  = "GET";
        string contentType = "";
        string requestBody = "";

        UnityWebRequest webRequest    = UnityWebRequest.Get(serviceURI);
        string          requestString = VuforiaRequest(requestPath, httpAction, contentType, requestBody, webRequest);

        List <string> stringToReturn = GetTargetIDsFromString(requestString);

        List <string> characterList = new List <string>();

        for (int i = 0; i < stringToReturn.Count; i++)
        {
            //Makes a query to the server for each target ID to get the target name
            //then adds the target names to the arraylist

            string          targetSumString = GetTargetSummary((string)stringToReturn[i]);
            VtTargetSummary targetSummary   = JsonUtility.FromJson <VtTargetSummary>(targetSumString);
            targetSummary.target_id = (string)stringToReturn[i];
            string   dateSplit    = targetSumString.Split(new string[] { @"""upload_date"":""" }, StringSplitOptions.None)[1].Remove(10);
            string[] dateYYYYMMDD = dateSplit.Split('-');
            targetSummary.upload_date = dateYYYYMMDD[1] + "/" + dateYYYYMMDD[2] + "/" + dateYYYYMMDD[0];
            vtc.targetSummaryList.Add(targetSummary);
            characterList.Add(targetSummary.target_name);

            if (characterList.Count > 0)
            {
                float percentComplete = ((float)characterList.Count / stringToReturn.Count);
                EditorUtility.DisplayProgressBar("Populating Target Information", characterList.Count + "/" + stringToReturn.Count + ": " + targetSummary.target_name, percentComplete);
            }
        }
        if (characterList.Count > 0)
        {
            EditorUtility.ClearProgressBar();
        }

        string[]      namesList   = AssetDatabase.GetAllAssetBundleNames();
        List <string> sortedNames = new List <string>();

        foreach (string name1 in characterList)
        {
            sortedNames.Add(name1);
        }

        return(sortedNames);
    }
Exemplo n.º 3
0
    private bool UploadTarget(string targetName, float width, string imagePath, bool active, string metaData)
    {
        string requestPath = "/targets";
        string serviceURI  = url + requestPath;
        string httpAction  = "POST";
        string contentType = "application/json";

        byte[]   imgBytes      = File.ReadAllBytes(imagePath);
        string   imageEncode64 = Convert.ToBase64String(imgBytes);
        JsonPost targetPost    = new JsonPost(targetName, width, imageEncode64, active, metaData);
        string   requestBody   = JsonUtility.ToJson(targetPost);

        //Post request requires string input, but the requestBody will cause a 401 unauthorized error,
        //so you need to use kHttpVerbPost, then set the upload handler separately
        UnityWebRequest  webRequest      = UnityWebRequest.Post(serviceURI, UnityWebRequest.kHttpVerbPOST);
        UploadHandlerRaw MyUploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(requestBody));

        webRequest.uploadHandler = MyUploadHandler;

        string returnString = VuforiaRequest(requestPath, httpAction, contentType, requestBody, webRequest);

        VtTargetSummary    newItem = new VtTargetSummary();
        VtUploadResultCode code    = JsonUtility.FromJson <VtUploadResultCode>(returnString);

        newItem.target_id = code.target_id;
        vtc.targetSummaryList.Add(newItem);
        UpdateTargetInformation(code.target_id);
        if (returnString == "fail")
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }