Пример #1
0
    IEnumerator displayHelper(DBScene JsonInfo)
    {
        int counter = 0;

        foreach (GameObject obj in currImg)
        {
            if (obj.tag.Equals("img"))
            {
                //take reference time
                refTime = Time.realtimeSinceStartup;
                for (int i = 0; i < JsonInfo.lines[counter].points.Length; i++)
                {
                    float timeElapsed = Time.realtimeSinceStartup - refTime;
                    if (JsonInfo.lines[counter].points[i].timeStamp < timeElapsed)
                    {
                        move(obj, new Vector2(JsonInfo.lines[counter].points[i].x, JsonInfo.lines[counter].points[i].y));
                        yield return(null);
                    }
                    else
                    {
                        i--;
                    }
                }
            }
            counter++;
        }
    }
Пример #2
0
    public DBScene GetDBScene(int id)
    {
        DBScene db = null;

        DictScene.TryGetValue(id, out db);
        return(db);
    }
Пример #3
0
            /// <summary>
            /// For testing - serializes a configuration and writes it to a file
            /// </summary>
            /// <param name="toBuild">Scene configuration</param>
            public static void BuildSceneToFile(DBScene toBuild)
            {
                // TODO: Improve date time formatting
                string curDate = DateTime.Now.ToOADate().ToString();
                string path    = Application.streamingAssetsPath + "/JSON Output/jsonoutput-" + curDate + ".txt";

                System.IO.File.WriteAllText(path, BuildSceneToString(toBuild));
            }
Пример #4
0
        /// <summary>
        /// Deserializes a scene configuration and builds it on the origin location
        /// </summary>
        /// <param name="json">Scene configuration to build</param>
        /// <param name="origin">Parent object to build scene on - should be vumark location</param>
        public void InitializeScene(string json, GameObject origin)
        {
            DBScene scene = Serialize.Utility.CreateFromJSON(json);

            BuildScene(scene, origin);
            StartCoroutine(SetUpWidgets());
            Debug.Log("Finish init");
        }
Пример #5
0
        /// <summary>
        /// Builds an influxSetup component on the given object, and populates it with the configuration specified in conf
        /// passes scene object that contains all widget location info
        /// </summary>
        /// <param name="conf">Scene to build</param>
        /// <param name="sceneObj">Object to parent scene config</param>
        private void BuildScene(DBScene conf, GameObject sceneObj)
        {
            InfluxSetup setup = sceneObj.AddComponent <InfluxSetup>();

            setup.Setup(conf);
            foreach (DBWidget wid in conf.Widgets)
            {
                CreateWidgets(wid, sceneObj);
            }
        }
Пример #6
0
 //set the animation of scene
 void setAnim(DBScene JsonInfo)
 {
     for (int i = 0; i < JsonInfo.pngAddress.Length; i++)
     {
         GameObject image = new GameObject();
         image.AddComponent <Image>();
         StartCoroutine(LoadPNG(image, JsonInfo.pngAddress[i]));
         image.transform.SetParent(imgs.transform);
         lines     = JsonInfo.lines;
         image.tag = "img";
         currImg.Add(image);
     }
 }
Пример #7
0
        //upload json
        public void uploadDBJson(DBScene db, string name)
        {
            //upload json
            ConvertToJson(db);
            string contents = "";
            string urlJson  = "http://18.191.23.16/SceneJsonServer/UnityUpload.php";

            contents = JsonUtility.ToJson(db);
            byte[]  bytes = Encoding.ASCII.GetBytes(contents);
            WWWForm form  = new WWWForm();

            form.AddField("Name", name);
            form.AddBinaryData("post", bytes);
            WWW www = new WWW(urlJson, form);
        }
Пример #8
0
 void setJsonImage(DBScene firstScene)
 {
     //set sprite
     StartCoroutine(LoadPNG(panel, firstScene.mainPngAddr));
     //set the text
     text.text = firstScene.description;
     //set new imgs
     if (currImg.Count != 0)
     {
         foreach (GameObject child in currImg)
         {
             GameObject.Destroy(child);
         }
         currImg.Clear();
     }
     setAnim(firstScene);
     display(firstScene);
     //get the answerlist
     foreach (Transform child in optionContent.transform)
     {
         GameObject.Destroy(child.gameObject);
     }
     if (firstScene.next != null)
     {
         //for each answer, make an option for it
         foreach (SceneAnswerPair pair in firstScene.next)
         {
             GameObject button = Instantiate(answerButtonPrefab);
             button.transform.SetParent(optionContent.transform);
             button.GetComponentInChildren <Text>().text = pair.answer;
             button.GetComponent <Button>().onClick.AddListener(delegate { setJsonImage(slideJson.sceneSet[pair.nextSceneID]); });
         }
     }
     else
     {
         GameObject button = Instantiate(answerButtonPrefab);
         button.transform.SetParent(optionContent.transform);
         button.GetComponentInChildren <Text>().text = "next";
     }
 }
Пример #9
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Awake
        void Awake()
        {
            trackingChanges = new List <Line>();
            trackingAnim    = new Dictionary <GameObject, Line>();
            dbSceneUpload   = new DBScene();
            dbSceneSave     = new DBScene();
            // DEFAULT BRUSH SET HERE
            current_brush = PenBrush;
            //setsprite
            if (DrawingSettings.editingImage == null)
            {
                this.GetComponent <SpriteRenderer>().sprite = GameObject.Find("DrawingSettings").GetComponent <DrawingSettings>().spritePrefabs[this.transform.GetSiblingIndex()];
            }
            else
            {
                this.GetComponent <SpriteRenderer>().sprite = DrawingSettings.editingImage;
            }
            drawable_sprite  = this.GetComponent <SpriteRenderer>().sprite;
            drawable_texture = drawable_sprite.texture;

            if (DrawingSettings.editingImage == null)
            {
                // Initialize clean pixels to use
                clean_colours_array = new Color[(int)drawable_sprite.rect.width * (int)drawable_sprite.rect.height];

                for (int x = 0; x < clean_colours_array.Length; x++)
                {
                    clean_colours_array[x] = Reset_Colour;
                }

                // Should we reset our canvas image when we hit play in the editor?
                if (Reset_Canvas_On_Play)
                {
                    ResetCanvas();
                }
                //initially try to link button with this layer
                this.GetComponent <SpriteRenderer>().sortingOrder = this.transform.GetSiblingIndex();
            }
        }
Пример #10
0
    IEnumerator loadImage(int imageNum, string name)
    {
        Debug.Log(name);
        DBScene                currScene      = LoadDBScene("http://18.191.23.16/SceneJsonServer/files/" + name);
        string                 BackgroundPath = currScene.mainPngAddr;
        UnityWebRequest        wr             = new UnityWebRequest(BackgroundPath);
        DownloadHandlerTexture texDl          = new DownloadHandlerTexture(true);

        wr.downloadHandler = texDl;
        yield return(wr.SendWebRequest());

        if (wr.isNetworkError || wr.isHttpError)
        {
            Debug.Log(wr.error);
        }
        else
        {
            Texture2D t      = texDl.texture;
            Sprite    sprite = Sprite.Create(t, new Rect(0, 0, t.width, t.height), Vector2.zero, 1f);
            images[imageNum].sprite = sprite;
        }
        images[imageNum].gameObject.GetComponent <DragDropSc2>().JsonInfo = currScene;
    }
Пример #11
0
        void ConvertToJson(DBScene dbScene)
        {
            //assign json
            dbScene.lines = new line[trackingAnim.Count];
            int lineNum = 0;

            foreach (Line rline in trackingAnim.Values)
            {
                line jsonLine = new line();
                jsonLine.points = new point[rline.points.Count];
                for (int j = 0; j < rline.points.Count; j++)
                {
                    point jsonP = new point();
                    jsonP.x            = rline.points[j].coordinate.x;
                    jsonP.y            = rline.points[j].coordinate.y;
                    jsonP.timeStamp    = rline.points[j].timeStamp;
                    jsonLine.points[j] = jsonP;
                }
                jsonLine.penWidth      = rline.penWidth;
                jsonLine.isAnim        = rline.isAnim;
                dbScene.lines[lineNum] = jsonLine;
                lineNum++;
            }
        }
Пример #12
0
            /// <summary>
            /// Serialize a given scene configuration into human readable JSON
            /// </summary>
            /// <param name="toBuild">Scene configuration</param>
            /// <returns>json string</returns>
            public static string BuildSceneToString(DBScene toBuild)
            {
                string json = JsonConvert.SerializeObject(toBuild, Formatting.Indented);

                return(json);
            }
Пример #13
0
 public void display(DBScene JsonInfo)
 {
     StartCoroutine(displayHelper(JsonInfo));
 }
Пример #14
0
 /// <summary>
 /// Given a deserialized scene configuration, set all Influx server values from config
 /// </summary>
 /// <param name="sceneToBuild">DBScene object - should be deserializated from setup</param>
 public void Setup(DBScene sceneToBuild)
 {
     host = sceneToBuild.Host;
     port = sceneToBuild.Port;
     db   = sceneToBuild.Db;
 }