public override void OnServerDisconnect(NetworkConnection conn)
        {
            MyDebug.LogF("NetworkManagerCallbacks,OnServerDisconnect: {0})", conn.address);
            base.OnServerDisconnect(conn);

            if (NetworkPlayManager.Instance.OnServerDisconnect != null)
            {
                NetworkPlayManager.Instance.OnServerDisconnect();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Plays an audio clip using the first available effect audio source
        /// </summary>
        /// If no available audio sources are available then a new one will be created.
        /// <param name="clip"></param>
        /// <param name="pitchLow"></param>
        /// <param name="pitchHigh"></param>
        public void PlayEffect(AudioClip clip, float pitchLow = 1, float pitchHigh = 1)
        {
            Assert.IsNotNull(EffectAudioSources, "To make use of the Game Manager audio functions you should add 2 AudioSource components to the same gameobject as the GameManager. The first for background audio, sebsequent ones for effects.");
            Assert.AreNotEqual(0, EffectAudioSources.Length, "To make use of the Game Manager audio functions you should add 2 AudioSource components to the same gameobject as the GameManager. The first for background audio, sebsequent ones for effects.");

            var newPitch = UnityEngine.Random.Range(pitchLow, pitchHigh);

            // try and find a free or similar audio source
            //AudioSource similarAudioSource = null;
            foreach (var audioSource in EffectAudioSources)
            {
                if (audioSource.isPlaying == false)
                {
                    audioSource.clip  = clip;
                    audioSource.pitch = newPitch;
                    audioSource.Play();
                    return;
                }

                //if (Mathf.Approximately(audioSource.pitch, pitchHigh))
                //{
                //    similarAudioSource = audioSource;
                //}
            }

            // no free so play one shot if we have a similar match.
            //if (similarAudioSource != null)
            //{
            //    MyDebug.LogWarningF("Not enough free effect AudioSources for playing {0}, ({1}). Using a similar one - consider adding more AudioSources to the GameManager gameobject for performance.", clip.name, newPitch);
            //    similarAudioSource.PlayOneShot(clip);
            //    return;
            //}

            // otherwise we create and add a new one
            MyDebug.LogF("Not enough free effect AudioSources for playing {0}, ({1}). Adding a new one - consider adding more AudioSources to the GameManager gameobject for performance.", clip.name, newPitch);
            var newAudioSource = gameObject.AddComponent <AudioSource>();

            newAudioSource.playOnAwake = false;
            newAudioSource.volume      = EffectAudioVolume;
            newAudioSource.pitch       = newPitch;
            newAudioSource.clip        = clip;
            newAudioSource.Play();
            EffectAudioSources = EffectAudioSources.Concat(Enumerable.Repeat(newAudioSource, 1)).ToArray();
        }
Beispiel #3
0
        /// <summary>
        /// Scroll the RectTransform so that it is centered on the specified target
        /// </summary>
        /// <param name="target"></param>
        public void CenterOnItem(RectTransform target)
        {
            // Start and target positions
            var itemCenterPositionInScroll = GetWorldPointInWidget(_scrollTransform, GetWidgetWorldPoint(target));
            var targetPositionInScroll     = GetWorldPointInWidget(_scrollTransform, GetWidgetWorldPoint(Viewport));

            // distance to move
            var difference = targetPositionInScroll - itemCenterPositionInScroll;

            difference.z = 0f;

            //clear axis data that is not enabled in the scrollrect
            if (!_scrollRect.horizontal)
            {
                difference.x = 0f;
            }
            if (!_scrollRect.vertical)
            {
                difference.y = 0f;
            }

            var normalizedDifference = new Vector2(
                difference.x / (_content.rect.size.x - _scrollTransform.rect.size.x),
                difference.y / (_content.rect.size.y - _scrollTransform.rect.size.y));
            var newNormalizedPosition = _scrollRect.normalizedPosition - normalizedDifference;

            MyDebug.LogF("Difference ({0}), Normalised({1}), New Normalised ({2})", difference, normalizedDifference, newNormalizedPosition);

            if (_scrollRect.movementType != ScrollRect.MovementType.Unrestricted)
            {
                newNormalizedPosition.x = Mathf.Clamp01(newNormalizedPosition.x);
                newNormalizedPosition.y = Mathf.Clamp01(newNormalizedPosition.y);
                Debug.Log("Clamped normalized position: " + newNormalizedPosition);
            }

            ScrollToPosition(newNormalizedPosition, Time);
        }