示例#1
0
 private void CreateSession()
 {
     if (sessionsTracker.CreateSession(new XString(SessionName)))
     {
         sessionCreationRequested = true;
     }
 }
        private void Update()
        {
            if (previousSessionName != SessionName)
            {
                sessionCreationRequested = false;
                previousSessionName      = SessionName;
            }

            // If we are a Primary Client and can join sessions...
            if (sessionsTracker != null && sessionsTracker.Sessions.Count > 0)
            {
                // Check to see if we aren't already in the desired session
                Session currentSession = sessionsTracker.GetCurrentSession();

                if (currentSession == null ||                                                    // We aren't in any session
                    currentSession.GetName().GetString() != SessionName ||                       // We're in the wrong session
                    currentSession.GetMachineSessionState() == MachineSessionState.DISCONNECTED) // We aren't joined or joining the right session
                {
                    if (SharingStage.Instance.ShowDetailedLogs)
                    {
                        Debug.LogFormat("Session conn {0} Sessions: {1}.", sessionsTracker.IsServerConnected.ToString(), sessionsTracker.Sessions.Count.ToString());
                        Debug.Log("Looking for " + SessionName);
                    }
                    bool sessionFound = false;

                    for (int i = 0; i < sessionsTracker.Sessions.Count; ++i)
                    {
                        Session session = sessionsTracker.Sessions[i];

                        if (session.GetName().GetString() == SessionName)
                        {
                            sessionsTracker.JoinSession(session);
                            sessionFound = true;
                            break;
                        }
                    }

                    if (sessionsTracker.IsServerConnected && !sessionFound && !sessionCreationRequested)
                    {
                        if (SharingStage.Instance.ShowDetailedLogs)
                        {
                            Debug.Log("Didn't find session, making a new one");
                        }

                        if (sessionsTracker.CreateSession(new XString(SessionName)))
                        {
                            sessionCreationRequested = true;
                        }
                    }
                }
            }
        }