/****************************************************************************************************/
    public bool SaveExpressionSet(string filename)
    {
        string jsonStr = LiveJsonParser.Serialize(data);

        // write out json object
        StreamWriter writer = new StreamWriter(filename);

        writer.Write(jsonStr);
        writer.Close();
        return(true);
    }
Esempio n. 2
0
 /****************************************************************************************************/
 public Dictionary <string, float> Update()
 {
     if (reconnect)
     {
         reconnectTimer -= Time.deltaTime;
         if (reconnectTimer <= 0)
         {
             Connect(mHost, mPort);
             reconnect = false;
         }
     }
     else if (tcp != null && tcp.Connected)
     {
         if (hasNewData)
         {
             hasNewData   = false;
             timeoutTimer = 0.5f;
             TrackerData result = ( TrackerData )LiveJsonParser.Deserialize(prevTrackerData, trackerData, data);
             if (result != null)
             {
                 prevTrackerData = trackerData;
                 trackerData     = result;
                 StartRead();
                 return(trackerData.animationValues);
             }
             else if (prevTrackerData != null)
             {
                 return(prevTrackerData.animationValues);
             }
             else
             {
                 Debug.Log("GRRR");
                 return(null);
             }
         }
         else
         {
             timeoutTimer -= Time.deltaTime;
             if (timeoutTimer <= 0)
             {
                 Debug.Log("Lost Connection");
                 Disconnect();
                 reconnect    = true;
                 timeoutTimer = 0.5f;
             }
         }
     }
     return(null);
 }
Esempio n. 3
0
 /****************************************************************************************************/
 private void CreateFileGUI()
 {
     EditorGUILayout.BeginVertical();
     {
         EditorGUILayout.LabelField("Faceware Live Client for Unity - Character Setup", titleStyle, GUILayout.ExpandHeight(true));
         EditorGUILayout.LabelField("Current File: " + charSetupFilename);
         EditorGUILayout.BeginHorizontal();
         {
             GUILayoutOption buttonWidth = GUILayout.Width(162);
             if (GUILayout.Button("New", buttonWidth))
             {
                 charSetupData.Init();
                 controlSelection.Clear();
                 addedControls.Clear();
                 charSetupFilename = "";
                 sceneControlObjectList.Clear();
             }
             if (GUILayout.Button("Open...", buttonWidth))
             {
                 string filename = EditorUtility.OpenFilePanel("Open Character Setup", "", "json");
                 if (filename != null && filename != "")
                 {
                     if (charSetupData.LoadExpressionSet(filename, false))
                     {
                         charSetupFilename = filename;
                         controlSelection.Clear();
                         InitAddedControls();
                         sceneControlObjectList = LiveUnityInterface.GetControls(charSetupData.GetControlList());
                         LiveJsonParser.Serialize(charSetupData);
                     }
                 }
             }
             if (GUILayout.Button("Save As...", buttonWidth))
             {
                 charSetupFilename = SaveExpressionSet() ?? "";
             }
         }
         EditorGUILayout.EndHorizontal();
     }
     EditorGUILayout.EndVertical();
     CreateSpace(2);
 }
    /****************************************************************************************************/
    private void Load(string content)
    {
        data = new Data();
        Data result = (Data)LiveJsonParser.Deserialize(null, data, content);

        if (result == null)
        {
            ReportError("Load Error", "Bad file content.");
            return;
        }

        if (data.Meta.Application != "Live")
        {
            ReportError("Load Error", "Bad expression set definition file.");
            return;
        }

        ExpressionAttr_LD11ToRT40();
        ExpressionAttr_LD15ToLD11();
    }