Skip to content
Snippets Groups Projects
Select Git revision
  • c61610a1ca1738b04cb13a65af7c69d74a6e04c0
  • master default
  • dependabot/nuget/source/Sample/Newtonsoft.Json-13.0.1
  • dependabot/nuget/source/MasterDevs.ChromeDevTools.Tests/Newtonsoft.Json-13.0.1
  • dependabot/nuget/source/ProtocolGenerator/Newtonsoft.Json-13.0.1
  • dependabot/nuget/source/ChromeDevTools/Newtonsoft.Json-13.0.1
  • dependabot/nuget/source/ChromeDevTools/System.Net.Http-4.3.4
  • revert-29-revert-24-protocol_62
  • revert-24-protocol_62
  • 1.1.0
  • 1.0.2
  • 1.0.1
  • 1.0.0.40915
13 results

packages.config

Blame
  • Fact.cs 6.78 KiB
    using UnityEngine;
    using UnityEngine.Networking;
    
    public abstract class Fact
    {
        public int Id;
        public GameObject Representation;
        public string backendURI;
        public string backendValueURI; // supposed to be null, for Facts without values eg. Points, OpenLines, OnLineFacts...
    
        public string format(float t) {
            return t.ToString("0.0000").Replace(',', '.');
        }
    }
    
    public class AddFactResponse
    {
        //class to Read AddFact Responses.
        public string factUri;
        public string factValUri;
    
        public static AddFactResponse sendAdd(string path, string body) {
            Debug.Log(body);
            //Put constructor parses stringbody to byteArray internally  (goofy workaround)
            UnityWebRequest www = UnityWebRequest.Put(path, body);
            www.method = UnityWebRequest.kHttpVerbPOST;
            www.SetRequestHeader("Content-Type", "application/json");
            
            AsyncOperation op = www.Send();
            while (!op.isDone) { }
            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                return null;
            }
            else
            {
                string answer = www.downloadHandler.text;
                return JsonUtility.FromJson<AddFactResponse>(answer);
            }
        }
    }
    
    //I am not sure if we ever need to attach these to an object, so one script for all for now...
    public class PointFact : Fact
    {
        public Vector3 Point;
        public Vector3 Normal;
    
        public PointFact(int i,Vector3 P, Vector3 N) {
            this.Id = i;
            this.Point = P;
            this.Normal = N;
    
            string body = @"{ ""a"":" +format(P.x) + @"," + @"""b"":" + format(P.y) + @","+@"""c"":" + format(P.y) + "}";
            Debug.Log(body);
            AddFactResponse res = AddFactResponse.sendAdd("localhost:8081/fact/add/vector", body);
            this.backendURI = res.factUri;
    
        }
    
        public PointFact(int i, float a, float b, float c, string uri)
        {
            this.Id = i;
            this.Point = new Vector3(a,b,c);
            this.Normal = new Vector3(0,1,0);
            this.backendURI = uri;
    
        }