Exemple #1
0
        /// <summary>
        /// Loads the framework resource of the given name. The method will look for the resource in
        /// the cascading search path for framework resources - currently, that means first the
        /// LocalFramework folder, then the Framework folder (both must be under a "Resources"
        /// parent somewhere.
        /// </summary>
        /// <returns>The framework resource.</returns>
        /// <param name="name">Name.</param>
        public static TResource LoadFrameworkResource <TResource>(string name)
            where TResource : Object
        {
            //string pathSeaparator = Path.AltDirectorySeparatorChar;
            string pathSeparator = "/";

            string localResourcePath         = "Local" + s_frameworkResourcePath;
            string platformLocalResourcePath = Application.platform.ToString() + pathSeparator + localResourcePath;
            string platformResourcePath      = Application.platform.ToString() + pathSeparator + s_frameworkResourcePath;

            TResource resource = Resources.Load <TResource>(platformLocalResourcePath + pathSeparator + name);

            if (resource == null)
            {
                CoreLogger.LogInfo(LoggerModules.GameApplication, string.Format("resource {0} not found in {1}, looking in {2}...", name, platformLocalResourcePath, localResourcePath));
                resource = Resources.Load <TResource>(localResourcePath + pathSeparator + name);
                if (resource == null)
                {
                    CoreLogger.LogInfo(LoggerModules.GameApplication, string.Format("resource {0} not found in {1}, looking in {2}...", name, localResourcePath, platformResourcePath));
                    resource = Resources.Load <TResource>(platformResourcePath + pathSeparator + name);
                    if (resource == null)
                    {
                        CoreLogger.LogInfo(LoggerModules.GameApplication, string.Format("resource {0} not found in {1}, looking in {2}...", name, platformResourcePath, s_frameworkResourcePath));
                        resource = Resources.Load <TResource>(s_frameworkResourcePath + pathSeparator + name);
                    }
                }
            }

            if (resource == null)
            {
                CoreLogger.LogWarning(LoggerModules.GameApplication, string.Format("resource {0} not found in framework paths!", name));
            }

            return(resource);
        }
Exemple #2
0
        public void Connect()
        {
            if (_socket != null)
            {
                _socket.Disconnect(false);

                _socket = null;
            }

            CoreLogger.LogDebug("ServerLoggerProvider", "creating socket...");

            try {
                AddressFamily addressFamily = AddressFamily.InterNetwork;
                SocketType    socketType    = SocketType.Stream;
                ProtocolType  protocolType  = ProtocolType.Tcp;
                _socket = new Socket(addressFamily, socketType, protocolType);
                CoreLogger.LogInfo("ServerLoggerProvider", "socket created");
                _socket.SendTimeout = sendTimeout;
            } catch (Exception ex) {
                CoreLogger.LogWarning("ServerLoggerProvider", string.Format("failed to create socket: {0}, stack: {1} - reverting to previous logger", ex.Message, ex.StackTrace));
                _socket = null;
                return;
            }

            IPEndPoint remoteEndPoint = GetRemoteEndPoint();

            CoreLogger.LogInfo("ServerLoggerProvider", string.Format("server is in {0}", remoteEndPoint));

            try {
                _socket.Connect(remoteEndPoint);
            } catch (Exception ex) {
                CoreLogger.LogWarning("ServerLoggerProvider", "failed to connect to socket: " + ex.Message);
                _socket = null;
                return;
            }

            foreach (string module in CoreLogger.Modules)
            {
                string msg  = string.Format("+node|{0}|TabTaleLog\r\n", module);
                int    sent = _socket.Send(msg.ToByteArray(Encoding.ASCII));
                if (sent != msg.Length)
                {
                    _oldLogWarning("ServerLoggerProvider", "failed to send registraion of module " + module);
                }
            }

            LogDebug("ServerLoggerProvider", "provider set");
        }
        public string GetString(string id, string defaultValue = "")
        {
            GeneralParameterConfigData data = _configs.FirstOrDefault(config => config.id == id) as GeneralParameterConfigData;

            if (data == null)
            {
                CoreLogger.LogWarning(_loggerModule, "GetString: id=\"" + id + "\" not found. Returning default value.");
                return(defaultValue);
            }
            if (data.type != "string")
            {
                CoreLogger.LogWarning(_loggerModule, "GetString: called for id=\"" + id + "\" that stored as type=" + data.type + ". Returning default value.");
                return(defaultValue);
            }
            return(data.value);
        }
        void InsertImage(string prefabPath)
        {
            GameObject imgPrefab = _assetManager.GetResource <GameObject> (prefabPath);

            if (imgPrefab != null)
            {
                for (int i = imageContainer.transform.childCount - 1; i >= 0; i--)
                {
                    Destroy(imageContainer.transform.GetChild(i).gameObject);
                }
                GameObject imgGo = Instantiate(imgPrefab) as GameObject;
                imgGo.transform.SetParent(imageContainer.transform, false);
                imageContainer.SetActive(true);
            }
            else
            {
                CoreLogger.LogWarning("UGuiGeneralDialogController", "InsertImage prefab" + prefabPath + " not found");
                imageContainer.SetActive(false);
            }
            imageContainer.SetActive(true);
        }
Exemple #5
0
        /// <summary>
        /// Adds a managed service to this resolver. If a provider is present, the
        /// resolver will now know how to return it in response to requests for this
        /// service. The service must derive from TBase.
        /// </summary>
        /// <returns><c>true</c>, if service was added, <c>false</c> otherwise. A service will
        /// not be added if it does not derive from TBase</returns>
        /// <param name="serviceType">Service type.</param>
        public bool AddService(Type serviceType)
        {
            //check if service is relevant
            if (!typeof(IService).IsAssignableFrom(serviceType))
            {
                CoreLogger.LogWarning(_loggerModule, string.Format("cannot add incompatible type {0} to loader of {1}", serviceType.Name, typeof(IService).Name));
                return(false);
            }

            //if so, check if it's already here
            if (IsServiceKnown(serviceType))
            {
                CoreLogger.LogDebug(_loggerModule, string.Format("service {0} already handled by this container", serviceType.Name));
                return(true);
            }

            //now add it
            _unprovidedServices.Add(serviceType);

            return(true);
        }
Exemple #6
0
        public void Start()
        {
            if (_started)
            {
                CoreLogger.LogWarning(LoggerModules.GameApplication, "Start called twice!");
                return;
            }

            foreach (IModule module in _modules.Values)
            {
                CoreLogger.LogDebug(LoggerModules.GameApplication, string.Format("starting module {0}", module.GetType().Name));
                try
                {
                    module.StartModule();
                } catch (Exception ex)
                {
                    CoreLogger.LogError(LoggerModules.GameApplication, string.Format("failed to initialize module {0}:{1}", module.GetType().Name, ex));
                }
            }

            _started = true;
        }
        public bool GetBool(string id, bool defaultValue = false)
        {
            GeneralParameterConfigData data = _configs.FirstOrDefault(config => config.id == id) as GeneralParameterConfigData;

            if (data == null)
            {
                CoreLogger.LogWarning(_loggerModule, "GetBool: id=\"" + id + "\" not found. Returning default value.");
                return(defaultValue);
            }
            if (data.type != "bool")
            {
                CoreLogger.LogWarning(_loggerModule, "GetBool: called for id=\"" + id + "\" that stored as type=" + data.type + ". Returning default value.");
                return(defaultValue);
            }
            bool result = defaultValue;

            if (!Boolean.TryParse(data.value, out result))
            {
                return(defaultValue);
            }
            return(result);
        }
        public float GetFloat(string id, float defaultValue = 0f)
        {
            GeneralParameterConfigData data = _configs.FirstOrDefault(config => config.id == id) as GeneralParameterConfigData;

            if (data == null)
            {
                CoreLogger.LogWarning(_loggerModule, "GetFloat: id=\"" + id + "\" not found. Returning default value.");
                return(defaultValue);
            }
            if (data.type != "float")
            {
                CoreLogger.LogWarning(_loggerModule, "GetFloat: called for id=\"" + id + "\" that stored as type=" + data.type + ". Returning default value.");
                return(defaultValue);
            }
            float result = defaultValue;

            if (!float.TryParse(data.value, out result))
            {
                return(defaultValue);
            }
            return(result);
        }
Exemple #9
0
        public void Stop()
        {
            if (!_started)
            {
                CoreLogger.LogWarning(LoggerModules.GameApplication, "Stop called before Start!");
                return;
            }

            if (_stopped)
            {
                CoreLogger.LogWarning(LoggerModules.GameApplication, "Stop called twice!");
                return;
            }

            foreach (IModule module in _modules.Values)
            {
                CoreLogger.LogDebug(LoggerModules.GameApplication, string.Format("stopping and terminating module {0}", module.GetType().Name));
                module.StopModule();
                module.Terminate();
            }

            _stopped = true;
        }
Exemple #10
0
        public IEnumerator Init(bool block)
        {
            if (s_initInProgress)
            {
                CoreLogger.LogError(LoggerModules.GameApplication, "attempt to initialize kernel while already doing so!");
                yield break;
            }

            Application.targetFrameRate = this.targetFrameRate;

            s_instance = this;

            s_initInProgress = true;

            _taskQueue        = gameObject.AddMissingComponent <TaskQueue>();
            _taskQueue.Active = false;

            EnqueueCreateResolvers();

            EnqueueAddProviders();

            EnqueuePreStageServiceResolution(block);
            _taskQueue.Enqueue(() => {
                LoadLoggerConfig();
            });
            EnqueueInitModules(int.MinValue, -1, block);

            EnqueueServiceResolution(block);
            EnqueueInitModules(0, 0, block);

            EnqueuePostStageServiceResolution(block);
            EnqueueInitModules(1, int.MaxValue, block);

            _taskQueue.Enqueue(() => {
                LoadLoggerConfig();
            });

            //register to the event that tells us when the queue is empty,
            //which implies we have finished initializing
            bool initDone = false;

            //when the task queue empties, we will know we are done
            _taskQueue.Enqueue(() => {
                //at this point we can set the static instance safely
                s_earlyAccess = false;

                //init is done
                s_initInProgress = false;
                initDone         = true;
            });

            //now start the actual initialization, by activating the queue
            float initStart = Time.time;

            //start running the init tasks
            _taskQueue.Active = true;

            if (block)
            {
                //the synchronous version:
                _taskQueue.HandleAll();

                //at this point in time, the singleton is ready for use
                _gameModules.Start();

                yield break;
            }
            else
            {
                //the async. version:

                //while(Time.time - initStart < initTimeout)
                while (true)
                {
                    if (Time.time - initStart > initTimeout)
                    {
                        CoreLogger.LogWarning(LoggerModules.GameApplication, "timeout in creating GameApplication object");
                    }

                    if (initDone)
                    {
                        //at this point in time, the singleton is ready for use
                        _gameModules.Start();

                        yield return(StartCoroutine(WaitForStrangeServiceProviderInit()));

                        InitDone();
                        CoreLogger.LogDebug(LoggerModules.GameApplication, "GameApplication succesfully finished Init!");
                        yield break;
                    }

                    yield return(null);
                }
            }
        }