Exemplo n.º 1
0
 void Start()
 {
     _text    = GetComponent <Text>();
     _tmpText = GetComponent <TextMeshProUGUI>();
     if (_text == null && _tmpText == null)
     {
         Debug.LogError("Added a LocalizedText component to a gameobject with no ui text");
         return;
     }
     if (string.IsNullOrEmpty(_key))
     {
         if (_text != null)
         {
             _key = _text.text;
         }
         else if (_tmpText != null)
         {
             _key = _tmpText.text;
         }
     }
     _service = SharedServices.GetService <ILocalizationService>();
     if (_service == null)
     {
         _service = new LocalLocalizationService();
         _service.Initialize(UpdateText);
         SharedServices.RegisterService <ILocalizationService>(_service);
     }
     _service.OnLocalizationChanged += UpdateText;
 }
Exemplo n.º 2
0
 public EventTracker()
 {
     if (System.IO.File.Exists(_path))
     {
         string text = System.IO.File.ReadAllText(_path);
         try
         {
             JSONObject jsonfile = JSON.JSON.LoadString(text) as JSONObject;
             foreach (var kvp in jsonfile)
             {
                 uint id = 0;
                 if (uint.TryParse(kvp.Key, out id))
                 {
                     _pending.Add(id, kvp.Value.AsObject());
                     if (id > _lastId)
                     {
                         _lastId = id;
                     }
                 }
                 else
                 {
                     SharedServices.GetService <ICustomLogger>()?.LogError("Corrupted key in tracks file: {" + kvp.Key + ": " + kvp.Value);
                 }
             }
             System.IO.File.WriteAllText(_path, "{}");
         }
         catch (MalformedJSONException e)
         {
             SharedServices.GetService <ICustomLogger>()?.LogError("Error parsing saved tracks: " + e.Message);
         }
     }
 }
Exemplo n.º 3
0
        internal SFXPlayer(AudioClipsStorer clipsStorer)
        {
            var updater = SharedServices.GetService <IUpdateScheduler>();

            if (updater == null)
            {
                updater = new UnityUpdateScheduler();
                SharedServices.RegisterService(updater);
            }
            var dispatcher = SharedServices.GetService <EventDispatcher>();

            if (dispatcher == null)
            {
                dispatcher = new EventDispatcher();
                SharedServices.RegisterService(dispatcher);
            }

            updater.ScheduleUpdate(this);
            dispatcher.AddListener <SceneManagementService.SceneUnloadedEvent>(OnSceneUnloaded);
            _clipStorer = clipsStorer;
            for (int i = 0; i < 10; ++i)
            {
                CreateHandler();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method gets the list of clients for the relevant listeners.
        /// </summary>
        protected override void StartInternal()
        {
            mResourceTracker = SharedServices.GetService <IResourceTracker>();

            if (mResourceTracker == null)
            {
                throw new ArgumentNullException("ResourceTracker cannot be retrieved.");
            }
        }
Exemplo n.º 5
0
 public void Dispose()
 {
     SharedServices.GetService <IUpdateScheduler>().UnscheduleUpdate(this);
     foreach (var handler in _handlers)
     {
         UnityEngine.Object.Destroy(handler.gameObject);
     }
     SharedServices.GetService <EventDispatcher>().RemoveListener <SceneManagementService.SceneUnloadedEvent>(OnSceneUnloaded);
 }
        /// <summary>
        /// This method gets the list of clients for the relevant listeners.
        /// </summary>
        protected override void StartInternal()
        {
            //Get the resource tracker that will be used to reduce message in
            mResourceTracker = SharedServices.GetService <IResourceTracker>();

            if (mResourceTracker == null)
            {
                throw new ArgumentNullException("ResourceTracker cannot be retrieved.");
            }
        }
Exemplo n.º 7
0
        IEnumerator CrossFadeCoroutine(string fadeTo, float duration)
        {
            float halfDuraion = duration * 0.5f;

            SharedServices.GetService <CoroutineRunner>().StartCoroutine(this, FadeOutCoroutine(halfDuraion));
            yield return(new WaitForSeconds(halfDuraion));

            Play(fadeTo);
            SharedServices.GetService <CoroutineRunner>().StartCoroutine(this, FadeInCoroutine(halfDuraion));
        }
Exemplo n.º 8
0
 public void Dispose()
 {
     if (_playingClip != null)
     {
         _source.Stop();
         _playingClip.ReferencedClip.ReleaseAsset();
     }
     SharedServices.GetService <CoroutineRunner>().StopAllCoroutines(this);
     UnityEngine.Object.Destroy(_source.gameObject);
 }
        /// <summary>
        /// This method starts the service and retrieves the services required for connectivity.
        /// </summary>
        protected override void StartInternal()
        {
            var resourceTracker = SharedServices.GetService <IResourceTracker>();

            if (resourceTracker != null && mResourceProfile != null)
            {
                mResourceConsumer = resourceTracker.RegisterConsumer("CacheV2" + mResourceProfile.Id, mResourceProfile);
            }

            base.StartInternal();
        }
Exemplo n.º 10
0
        protected override void StartInternal()
        {
            var resourceTracker = SharedServices.GetService <IResourceTracker>();

            if (resourceTracker != null && mPolicy.ResourceProfile != null)
            {
                mPolicy.ResourceConsumer = resourceTracker.RegisterConsumer(EntityType, mPolicy.ResourceProfile);
            }

            base.StartInternal();
        }
Exemplo n.º 11
0
 public SFXData GetClipByName(string clipName)
 {
     foreach (var clip in _clips)
     {
         if (string.Equals(clip.ClipName, clipName, System.StringComparison.InvariantCultureIgnoreCase))
         {
             return(clip);
         }
     }
     SharedServices.GetService <ICustomLogger>()?.LogError("Trying to get a nonexistent audio clip: " + clipName);
     return(null);
 }
Exemplo n.º 12
0
        public void TrackPending()
        {
            var pending_copy = new Dictionary <uint, JSONObject>(_pending);

            _pending.Clear();
            foreach (var obj in pending_copy.Values)
            {
                var id = ++_lastId;
                SharedServices.GetService <CommandQueue>().AddCommand(new TrackEventCommand(id, obj, OnTrackResponse));
                _pending.Add(id, obj.Clone().AsObject());
            }
        }
Exemplo n.º 13
0
 private async Task CallMeAsWell(Schedule schedule)
 {
     try
     {
         //throw new Exception("Don't care");
         var serv   = SharedServices.GetService <IRepositoryAsync <Guid, MondayMorningBlues> >();
         var result = await serv.Read(new Guid("414f06b5-7c16-403a-acc5-40d2b18f08a1"));
     }
     catch (Exception ex)
     {
         //throw;
     }
 }
Exemplo n.º 14
0
 void OnClipLoaded(AudioClip clip)
 {
     if (clip == null)
     {
         SharedServices.GetService <ICustomLogger>()?.LogError("Cannot load audio clip: " + _playingClip.ClipName);
         return;
     }
     _source.clip   = clip;
     _source.loop   = _playingClip.Loop;
     _source.pitch  = _playingClip.Pitch;
     _source.volume = _playingClip.Volume * _volume;
     _source.Play();
 }
Exemplo n.º 15
0
        public void TrackEvent(string category, string userID, JSONObject data = null)
        {
            JSONObject toSend = new JSONObject();

            toSend["user_id"]  = userID;
            toSend["ts"]       = TimeUtils.Timestamp;
            toSend["category"] = category;
            if (data != null)
            {
                toSend["data"] = data;
            }
            var id = ++_lastId;

            SharedServices.GetService <CommandQueue>().AddCommand(new TrackEventCommand(id, toSend, OnTrackResponse));
            _pending.Add(id, toSend);
        }
Exemplo n.º 16
0
        static IEnumerator SendCoroutine(Petition petition, Action <Petition> onFinish)
        {
            NetworkError error    = null;
            string       response = string.Empty;
            int          retries  = 0;

            do
            {
                var uploader = new UploadHandlerRaw(petition.GetRawData());
                uploader.contentType = "application/json";

                var downloadHandler = new DownloadHandlerBuffer();

                var request = new UnityWebRequest(petition.Url);
                request.method          = petition.Method == Petition.SendMethod.Post ? UnityWebRequest.kHttpVerbPOST : UnityWebRequest.kHttpVerbGET;
                request.useHttpContinue = false;
                request.redirectLimit   = 50;
                request.timeout         = 60;
                if (petition.Method == Petition.SendMethod.Post)
                {
                    request.SetRequestHeader("Content-Type", "application/json");
                }
                request.uploadHandler   = uploader;
                request.downloadHandler = downloadHandler;

                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    error = new NetworkError((int)request.responseCode, request.error);
                    SharedServices.GetService <ICustomLogger>().LogError("Network error error: {" + error.Code + ": " + error.Message + "} for petition: " + petition.GetData());
                }
                else
                {
                    response = request.downloadHandler.text;
                    error    = null;
                }
                ++retries;
            }while(error != null && retries < petition.Retries);

            petition.SetResponse(response);
            petition.Error = error;
            onFinish?.Invoke(petition);
        }
Exemplo n.º 17
0
        private void ProcessInputFile()
        {
            try
            {
                if (_challengeConfiguration != null)
                {
                    if (SharedServices.HasService(typeof(ChallengeInitializationService)))
                    {
                        _challenge = SharedServices.GetService <ChallengeInitializationService>().InitializeChallenge(_challengeConfiguration);
                        OnReportMessageSet(this, new EventArgs.HandlerEventArgs(this, "Toy Robot Challenge initialized...", false));

                        if (!String.IsNullOrEmpty(_inputCommandFilePath))
                        {
                            List <string> stringCommands = null;

                            if (SharedServices.HasService(typeof(CommandParsingService)))
                            {
                                stringCommands = SharedServices.GetService <CommandParsingService>().ParseCommandFile(_inputCommandFilePath);

                                if (stringCommands != null && SharedServices.HasService(typeof(CommandConversionService)))
                                {
                                    List <List <IRobotCommand> > robotCommands = SharedServices.GetService <CommandConversionService>().ConvertStringCommands(stringCommands);

                                    if (robotCommands != null && robotCommands.Count > 0 && SharedServices.HasService(typeof(CommandExecutionService)))
                                    {
                                        SharedServices.GetService <CommandExecutionService>().CommandExecuted += CommandExecutionService_CommandExecuted;

                                        foreach (List <IRobotCommand> commandlist in robotCommands)
                                        {
                                            SharedServices.GetService <CommandExecutionService>().ExecuteCommands(_challenge.ActiveRobot, commandlist);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _errMsg = String.Format("Unable to process the configuration due to an error. {0}", ex.Message);
                throw new Exception(_errMsg);
            }
        }
Exemplo n.º 18
0
 void OnLoaded(AudioClip clip)
 {
     if (clip == null)
     {
         SharedServices.GetService <ICustomLogger>()?.LogError("Cannot load audio clip: " + data.ClipName);
         return;
     }
     gameObject.SetActive(true);
     gameObject.name      = data.ClipName;
     _source.volume       = data.Volume * _volume;
     _source.pitch        = data.Pitch;
     _source.clip         = clip;
     _source.loop         = data.Loop;
     _source.spatialBlend = 0f;
     _source.Play();
     _toFollow = null;
     _looping  = data.Loop;
     _duration = clip.length;
 }
Exemplo n.º 19
0
        private async Task CallMe(Schedule schedule)
        {
            try
            {
                var id = Guid.NewGuid();
                //throw new Exception("Don't care");
                var serv    = SharedServices.GetService <IRepositoryAsync <Guid, MondayMorningBlues> >();
                var result2 = await serv.Create(new MondayMorningBlues()
                {
                    Id = id
                });

                var result = await serv.Read(id);
            }
            catch (Exception ex)
            {
                //throw;
            }
        }
        public void Initialize(System.Action onFinishedLoading = null)
        {
            Initialized = false;
            var language = _chosenLanguage;

            if (!LocalizationFiles.ContainsKey(language))
            {
                language = _defaultLanguage;
                SharedServices.GetService <ICustomLogger>()?.LogError("Chosen language is not available in localization files");
            }
            string    fileName = "localization_" + LocalizationFiles[language];
            TextAsset content  = Resources.Load <TextAsset>(fileName);

            if (content == null)
            {
                SharedServices.GetService <ICustomLogger>()?.LogError("Can not load the localization file. Trying to load default localization file.");
                fileName = "localization_" + LocalizationFiles[_defaultLanguage];
                content  = Resources.Load <TextAsset>(fileName);
                if (content == null)
                {
                    SharedServices.GetService <ICustomLogger>()?.LogError("Can not load the default localization file.");
                    onFinishedLoading?.Invoke();
                    return;
                }
            }
            try
            {
                _currentLocalization.FromJSON(JSON.JSON.LoadString(content.text));
            }
            catch (System.Exception)
            {
                SharedServices.GetService <ICustomLogger>()?.LogError("Error parsing localization file: " + fileName);
            }
            Initialized = true;
            OnLocalizationChanged();
            onFinishedLoading?.Invoke();
        }
Exemplo n.º 21
0
        /// <summary>
        /// This method configures the mapping.
        /// </summary>
        protected override void StartInternal()
        {
            var resourceTracker = SharedServices?.GetService <IResourceTracker>();

            if (resourceTracker != null && mResourceProfile != null)
            {
                mResourceConsumer = resourceTracker.RegisterConsumer(GetType().Name, mResourceProfile);
            }

            mSupported = new Dictionary <DataCollectionSupport, Action <EventHolder> >();

            SupportLoadDefault();

            var support = mSupported.Select((k) => k.Key).Aggregate((a, b) => a | b);

            if (mSupportMapSubmitted.HasValue)
            {
                mSupportMapActual = support & mSupportMapSubmitted.Value;
            }
            else
            {
                mSupportMapActual = support;
            }
        }
Exemplo n.º 22
0
 public void Send(Petition petition, Action <Petition> onFinish = null)
 {
     SharedServices.GetService <CoroutineRunner>().StartCoroutine(this, SendCoroutine(petition, onFinish));
 }
Exemplo n.º 23
0
 public void CrossFade(string name, float duration)
 {
     SharedServices.GetService <CoroutineRunner>().StopAllCoroutines(this);
     SharedServices.GetService <CoroutineRunner>().StartCoroutine(this, CrossFadeCoroutine(name, duration));
 }