示例#1
0
        private static void WorkerThread(ThreadContext tc)
        {
            while (m_bRunning) //(!m_bImportError)
            {
                try
                {
                    int counter         = 0;
                    int iLiveQueueCount = m_sqMessages.Count;

                    if (!m_liveClient.IsAlive)
                    {
                        m_sqMessages.Clear();
                    }
                    else if (iLiveQueueCount > 0)
                    {
                        while (m_sqMessages.Count > 0)
                        {
                            counter++;

                            LineContainer lc = m_sqMessages.Dequeue();

                            eFileSyncResult fsr = eFileSyncResult.Failed;
                            Debug.Assert(lc != null);

                            try
                            {
                                string     sSrcTime  = lc.Attributes["srctime"];
                                DateTimeSr dtSrcTime = DateTimeSr.FromString(sSrcTime);
                                string     sSrcDelay = (DateTime.UtcNow - dtSrcTime.UtcDateTime).ToString();

                                string     sTime = lc.Attributes["time"];
                                DateTimeSr dt    = DateTimeSr.FromString(sTime);
                                TimeSpan   ts    = DateTime.UtcNow - dt.UtcDateTime;

                                string sType = lc.Attributes.ContainsKey("line") ? lc.Attributes["line"] : "none";

                                m_logger.InfoFormat("Queue={0} Delay={1} Size={2}", iLiveQueueCount, ts, lc.OriginalXml.Length);

                                if (ConfigurationManager.AppSettings["betradar_xml_files"] != null)
                                {
                                    SaveXml(lc, "Live");
                                }


                                fsr = LineSr.SyncRoutines(eUpdateType.LiveBet, string.Format("Host='{0}' Connected={1}; SrcDelay={2}; Delay={3}; Line={4}", m_sHost, DateTime.Now - m_dtConnected, sSrcDelay, ts, sType), DalStationSettings.Instance.UseDatabaseForLiveMatches, null, delegate(object objParam)
                                                          { return(ProviderHelperNew.MergeFromLineContainer(lc)); });
                            }
                            catch (Exception excp)
                            {
                                fsr = eFileSyncResult.Failed;
                                m_logger.Excp(excp, "WorkerThread() ERROR for {0}", lc);
                            }


                            if (fsr == eFileSyncResult.Failed)
                            {
                                m_liveClient.Disconnect();
                                RemoveLiveMatches(eServerSourceType.BtrPre);
                                RemoveLiveMatches(eServerSourceType.BtrLive);
                            }
                        }
                        LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.LiveBet, string.Format("liveUpdate {0} messages", counter));
                    }
                }
                catch (Exception excp)
                {
                    m_logger.Excp(excp, "WorkerThread() general ERROR");
                }

                Thread.Sleep(10);
            }
        }
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginVertical();
        {
            GUILayout.Space(15);
            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label(titleIcon, GUILayout.MinWidth(1));
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label("Version " + LiveHelpers.CurrentVersion(), titleStyle);
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();

            GUILayout.Label("Faceware Live Client for Unity", titleStyle);

            GUILayout.BeginVertical();
            {
                //Server
                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Live Server Hostname: ");
                    FwLive.LiveServerHostIP = EditorGUILayout.TextField("", FwLive.LiveServerHostIP, GUILayout.MinWidth(50));
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndHorizontal();

                //Port
                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Live Server Port: ");
                    FwLive.LiveServerHostPort = EditorGUILayout.IntField("", FwLive.LiveServerHostPort, GUILayout.MinWidth(50));
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    // Character Setup File
                    EditorGUILayout.LabelField("Character Setup File: ");
                    FwLive.ExpressionSetFile = (LiveCharacterSetupFile)EditorGUILayout.ObjectField("", FwLive.ExpressionSetFile, typeof(LiveCharacterSetupFile), false, GUILayout.MinWidth(50));
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndHorizontal();

                // Connect on Start Toggle
                FwLive.ConnectOnPlay = GUILayout.Toggle(FwLive.ConnectOnPlay, "Connect on Play");

                // Reconnect on Server Lost
                FwLive.ReconnectOnLostConnection = GUILayout.Toggle(FwLive.ReconnectOnLostConnection, new GUIContent("Automatic Reconnect", "When connection to Live Server is lost, enabling this checkbox will allow the plugin to automatically attempt reconnecting"));

                // Drop Packets Flag
                FwLive.DropPackets = GUILayout.Toggle(FwLive.DropPackets, new GUIContent("Drop Packets on Update", "Drop packets when there is more than 1 packet from Live Server queued."));

                EditorGUILayout.BeginVertical("Box"); //Begin Live Server Interface
                {
                    EditorGUILayout.LabelField("Live Server", titleStyle);
                    GUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Connect"))
                        {
                            FwLive.Connect();
                        }

                        if (GUILayout.Button("Disconnect"))
                        {
                            FwLive.Disconnect();
                        }
                    }
                    GUILayout.EndHorizontal();
    #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                    if (FwLive.LiveServerHostIP == "localhost" ||
                        FwLive.LiveServerHostIP == "127.0.0.1")
                    {
                        if (GUILayout.Button("Calibrate"))
                        {
                            FwLive.CalibrateLiveServer();
                        }
                    }
    #endif
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndVertical();

            FwLive.EnableRecording = GUILayout.Toggle(FwLive.EnableRecording, new GUIContent("Enable Animation Recording", "Enabling Recording will set up the script to record animation coming from Live and save it to a .anim file."));

            if (FwLive.EnableRecording)
            {
                EditorGUILayout.BeginVertical("Box");
                {
                    if (FwLive.Recording)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField("CURRENTLY RECORDING", warningStyle);
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(new GUIContent("Animation Clip:", "Animation clip that recorded animation will be saved to. If left blank, a new animation clip will be created at the root assets folder."));
                        FwLive.ClipToWriteTo = EditorGUILayout.ObjectField(FwLive.ClipToWriteTo, typeof(AnimationClip), false) as AnimationClip;
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Space();

                    string btnLabel = FwLive.Recording ? "Stop Recording" : "Start Recording";
                    if (GUILayout.Button(btnLabel))
                    {
                        if (EditorApplication.isPlaying)
                        {
                            //Create a clip to write to if user hasn't specified
                            if (FwLive.ClipToWriteTo == null)
                            {
#if UNITY_EDITOR && (UNITY_5 || UNITY_2017 || UNITY_2018 || UNITY_5_4_OR_NEWER)
                                FwLive.ClipToWriteTo = new AnimationClip();

                                AssetDatabase.CreateAsset(FwLive.ClipToWriteTo, "Assets/" + GetNextAvailableClipName());
                                AssetDatabase.SaveAssets();
#else
                                Debug.LogWarning("[Faceware Live] No animation will be recorded due to Animation Clip not being set. Please set it to an .anim file to record animation");
#endif
                            }

                            FwLive.OnToggleRecording();
                        }
                        else
                        {
                            Debug.LogWarning("[Faceware Live] Can't start recording when not playing scene!");
                        }
                    }

                    FwLive.RecordOnStart = GUILayout.Toggle(FwLive.RecordOnStart, new GUIContent("Start Recording on Play", "Animation recording will start on start of the scene"));
#if UNITY_EDITOR && (UNITY_5 || UNITY_2017 || UNITY_2018 || UNITY_5_4_OR_NEWER)
                    if (FwLive.RecordOnStart && FwLive.ClipToWriteTo == null)
                    {
                        FwLive.ClipToWriteTo = new AnimationClip();

                        AssetDatabase.CreateAsset(FwLive.ClipToWriteTo, "Assets/" + GetNextAvailableClipName());
                        AssetDatabase.SaveAssets();
                    }
#endif
                    FwLive.KeyframeOnNewData = GUILayout.Toggle(FwLive.KeyframeOnNewData, new GUIContent("Keyframe only on new Data", "Enable this feature to set keyframes on controls only when their values have changed. Turning this off will yield keyframes for every control whenever Live Server sends new data, resulting is potentially very large .anim files"));

#if UNITY_EDITOR && (UNITY_5 || UNITY_2017 || UNITY_2018)
    #if UNITY_5_4_OR_NEWER
                    FwLive.keyframeTangentMode = (AnimationUtility.TangentMode)EditorGUILayout.EnumPopup(new GUIContent("Animation Curves:", "Curve type used between keyframes recorded. Smoother animation can be achieved by changing this to Auto if you are getting a slower FPS from Live Server. If 'Keyframe only on new Data' is enabled, it is highly recommended to have 'Constant' curves or the end animation may not look correct"), FwLive.keyframeTangentMode);
    #endif
#endif
                    EditorGUILayout.Space();
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                if (FwLive.Recording)
                {
                    FwLive.OnToggleRecording();
                }
                FwLive.Recording = false;
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical("Box"); //Begin help buttons region
            {
                EditorGUILayout.LabelField("Need Help?", titleStyle);

                EditorGUILayout.BeginHorizontal(); //Live client user guide region
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Live Client for Unity - User Guide"))
                    {
                        System.Diagnostics.Process.Start("http://support.facewaretech.com/live-client-for-unity");
                    }
                    GUILayout.FlexibleSpace();
                }
                EditorGUILayout.EndHorizontal();   //End user guide region

                EditorGUILayout.BeginHorizontal(); //Visit website region
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Visit www.facewaretech.com"))
                    {
                        System.Diagnostics.Process.Start("http://www.facewaretech.com/");
                    }
                    GUILayout.FlexibleSpace();
                }
                EditorGUILayout.EndHorizontal();   //End website region

                EditorGUILayout.BeginHorizontal(); //30 day trial region
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button(new GUIContent("30-Day Free Trial", "Click here to get your 30-day free trial of Faceware Live Server.")))
                    {
                        System.Diagnostics.Process.Start("http://facewaretech.com/products/software/free-trial/");
                    }
                    GUILayout.FlexibleSpace();
                }
                EditorGUILayout.EndHorizontal(); //End 30 day trial region
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(FwLive);
            FwLive.OnSettingsChange();
        }
    }