コード例 #1
0
        public static DataElement GetConfiguration(string id = "")
        {
            char   pathSaparator = '/';           // Path.DirectorySeparatorChar
            string configName    = "Config" + pathSaparator + (id == "" ? s_defaultConfigName : id);

            DataElement config;

            if (s_config.TryGetValue(configName, out config))
            {
                return(config);
            }

            IList <TextAsset> cascadingConfig = GameApplication.LoadCascadingFrameworkResource <TextAsset>(configName);

            if (cascadingConfig.Count < 1)
            {
                return(DataElement.Null);
            }

            config = DataElement.Parse(cascadingConfig[0].text);
            for (int i = 1; i < cascadingConfig.Count; i++)
            {
                config.Merge(DataElement.Parse(cascadingConfig[i].text));
            }

            s_config[configName] = config;

            return(config);
        }
コード例 #2
0
        public void Init()
        {
            Debug.Log("SocialSync.Init");

            _coroutineFactory  = GameApplication.Instance.CoroutineFactory;
            _connectionHandler = new ConnectionHandler();
            _connectionHandler.Init(gameDB, _coroutineFactory);
            _loggerModule = CoreLogger.RegisterModule(GetType().Name);

            SocialStateData socialData = socialStateModel.GetState();

            _socialConnectionStatus = new Dictionary <SocialNetwork, bool>();
            _socialConnectionStatus.Add(SocialNetwork.Facebook, (socialData.facebookId != ""));
            _socialConnectionStatus.Add(SocialNetwork.GameCenter, (socialData.gameCenterId != ""));
            _socialConnectionStatus.Add(SocialNetwork.PlayServices, (socialData.googlePlayId != ""));
            _socialUserId = new Dictionary <SocialNetwork, string>();
            _socialUserId.Add(SocialNetwork.Facebook, socialData.facebookId);
            _socialUserId.Add(SocialNetwork.GameCenter, socialData.gameCenterId);
            _socialUserId.Add(SocialNetwork.PlayServices, socialData.googlePlayId);

            Data.DataElement connConfig = GameApplication.GetConfiguration("connection");
            if (!connConfig.IsNull)
            {
                _fakeFacebookId     = (!connConfig.ContainsKey(_configKeyFakeFacebookId)) ? "0" : (string)connConfig[_configKeyFakeFacebookId];
                _fakeGameCenterId   = (!connConfig.ContainsKey(_configKeyFakeGameCenterId)) ? "0" : (string)connConfig[_configKeyFakeGameCenterId];
                _fakePlayServicesId = (!connConfig.ContainsKey(_configKeyFakePlayServicesId)) ? "0" : (string)connConfig[_configKeyFakePlayServicesId];
            }
        }
コード例 #3
0
 public ApplicaitonEvents(GameApplication gameApplication)
 {
     gameApplication.GainedFocus += () => GainedFocus();
     gameApplication.LostFocus   += () => LostFocus();
     gameApplication.Paused      += () => Paused();
     gameApplication.Resumed     += t => Resumed(t);
     gameApplication.Quit        += () => Quit();
     gameApplication.LevelLoaded += level => LevelLoaded(level);
 }
コード例 #4
0
        /// <summary>
        /// This initializes the GameApplication singleton as a blocking call - it means
        /// that access to Instance is valied immediately as this method returns.
        /// </summary>
        public static GameApplication CreateInstanceSync()
        {
#if UNITY_EDITOR
            s_requestingScene = "";
#endif

            if (s_instance != null)
            {
                CoreLogger.LogError(LoggerModules.GameApplication, "calling GameApplication sync init while in async init - this is a serious error, unless in a special debug mode!!");
                return(s_instance);
            }

            CoreLogger.LogDebug(LoggerModules.GameApplication, "creating GameApplication instance synchronously");

            GameApplication instance = CreateOrGet();
            if (instance == null)
            {
                CoreLogger.LogCritical(LoggerModules.GameApplication, "unable to obtain kernel instance!");
                return(null);
            }

            if (!instance.AllowSynchronousCreation)
            {
                if (instance.synchronousCreationFallbackScene != null && instance.synchronousCreationFallbackScene != "")
                {
                    CoreLogger.LogDebug(LoggerModules.GameApplication, string.Format("synchronous creation not allowed in this game - " +
                                                                                     "reverting to scene {0}", instance.synchronousCreationFallbackScene));
                    string scene = instance.synchronousCreationFallbackScene;
                    DestroyObject(instance.gameObject);
#if UNITY_EDITOR
                    GameApplication.Init(scene);
#endif
                    return(null);
                }

                CoreLogger.LogCritical(LoggerModules.GameApplication, "synchrnous creation not allowed in this Game!!!");
                return(null);
            }

            IEnumerator steps = instance.Init(true);
            while (steps.MoveNext())
            {
            }

            return(instance);
        }
コード例 #5
0
        void Awake()
        {
            _layers           = new Dictionary <SoundLayer, List <SoundManagerClip> >();
            _continuosLooping = new Dictionary <string, SoundManagerClip>();

            foreach (SoundLayer layer in Enum.GetValues(typeof(SoundLayer)))
            {
                _layers.Add(layer, new List <SoundManagerClip>());
            }

            //masterMixer = Resources.Load<AudioMixer>("TTMasterMixer") as AudioMixer;
            masterMixer = GameApplication.LoadFrameworkResource <AudioMixer> ("TTMasterMixer");
            if (masterMixer == null)
            {
                masterMixer = Resources.Load <AudioMixer>("TTMasterMixer");
            }
        }
コード例 #6
0
        public void Init(IGameDB gameDB, ICoroutineFactory coroutineFactory)
        {
            _gameDB           = gameDB;
            _coroutineFactory = coroutineFactory;

            _emptyBody = _encoding.GetBytes(" ");

            Data.DataElement connConfig = GameApplication.GetConfiguration("connection");
            _url = (connConfig.IsNull || !connConfig.ContainsKey(_configKeyURL)) ? _defaultUrl : (string)connConfig[_configKeyURL];

            // TODO - replace this with real versioning mechanism TBD
            string clientVersion = (connConfig.IsNull || !connConfig.ContainsKey(_configKeyClientVersion)) ? "1.0" :
                                   (string)connConfig[_configKeyClientVersion];

            string clientConfigVersion = (connConfig.IsNull || !connConfig.ContainsKey(_configKeyClientConfigVersion)) ? "1.0" :
                                         (string)connConfig[_configKeyClientConfigVersion];

            _headers = new Dictionary <string, string>();
            _headers.Add(_keyToken, "");
            _headers.Add(_keyClientVersion, clientVersion);
            _headers.Add(_keyClientConfigVersion, clientConfigVersion);
            _headers.Add("Content-Length", "1");
        }
コード例 #7
0
        public ServerAddress GetServerAddress()
        {
            if (HasSavedServerAddress())
            {
                return new ServerAddress()
                       {
                           ip = PlayerPrefs.GetString(IP_KEY), port = PlayerPrefs.GetInt(PORT_KEY)
                       }
            }
            ;

            DataElement logServerConfig = GameApplication.GetConfiguration("serverLogger");

            if (logServerConfig != null)
            {
                return new ServerAddress()
                       {
                           ip = logServerConfig["ip"], port = logServerConfig["port"]
                       }
            }
            ;

            return(defaultServer);
        }
コード例 #8
0
 public DataElement GetConfiguration(string id = "")
 {
     return(GameApplication.GetConfiguration(id));
 }
コード例 #9
0
 public void Init()
 {
     _connConfig = GameApplication.GetConfiguration("connection");
 }
コード例 #10
0
        void Awake()
        {
            //At this point we want to initialize the SDK's
            //FIXME: we may want to reconsider this method - right now the concept
            //is to have the GameApplication object initialize what it can, and then
            //have the GameApplication object initialized through this object when running
            //in full "game" mode, and on its own automatically when running in "scene" mode
            // - that is, a single scene called from the unity editor
            //the downside to this is that we have to re-init all the services again and again
            //when debugging - it may be benefitial to create an "external" singleton to retain
            //this object - one that "lives" through unity editor run sessions (its lifecycle
            //is an editor session, not a game session)
            //note that it's possible to do that later on, but the downside to that is that
            //we will need some method to "reset" it from the editor
            string nextScene = openingScene;

#if UNITY_EDITOR
            SceneController.s_jumpToInitOnTestScenes = false;

            if (GameApplication.RequestingScene != "")
            {
                nextScene = GameApplication.RequestingScene;
            }
            else
            {
                GameApplication.RequestingScene = nextScene;
            }
#endif

            //find the SplashScreen, so we can signal it off later
            SplashScreen       splashScreen       = gameObject.GetComponentInChildren <SplashScreen>();
            GameApplication    gameApplication    = GameApplication.CreateOrGet();
            ServiceInitializer serviceInitializer = new ServiceInitializer();
            if (splashScreen == null)
            {
                GameApplication.InitDone += () => {
                    GameApplication.Instance.SceneManager.SwitchScene(nextScene);
                };

                //iff we finish the pre-init phase, we can start the kernel
                serviceInitializer.Run(GetComponentsInChildren(typeof(IApplicationPreInit)).Cast <IApplicationPreInit>(), result => {
                    if (result)
                    {
                        StartCoroutine(gameApplication.Init(false));
                    }
                    else
                    {
                        CoreLogger.LogError("Init", "failed to start the application");
                        Application.Quit();
                    }
                });
            }
            else
            {
                serviceInitializer.Run(GetComponentsInChildren(typeof(IApplicationPreInit)).Cast <IApplicationPreInit>(), result => {
                    //iff we finish the pre-init phase, we can ask the splash screen to start the kernel
                    if (result)
                    {
                        splashScreen.Enqueue(() => gameApplication.Init(false), "Build Game Application");

                        splashScreen.Done += () => {
                            CoreLogger.LogDebug("GameApplication.Instance == " + GameApplication.Instance);
                            CoreLogger.LogDebug("GameApplication.Instance.SceneManager ==" + GameApplication.Instance.SceneManager);

                            GameApplication.Instance.SceneManager.SwitchScene(nextScene);
                        };
                    }
                    else
                    {
                        CoreLogger.LogError("Init", "failed to start the application");
                        Application.Quit();
                    }
                });
            }


#if UNITY_EDITOR
#else
            Debugger.Assert(GameApplication.Instance == null, "GameApplication initialization called twice!");
#endif
        }
コード例 #11
0
        public IPromise TryConnectToServer()
        {
            if (!initialized)
            {
                promise.Dispatch();
                return(promise);
            }

            // Avoid running model sync when uploading gld
            if (IsUploadScene())
            {
                logger.Log(Tag, "Running in upload mode - skipping connection with the server...");
                promise.Dispatch();
                return(promise);
            }


            if (Application.isEditor && !GsdkSettingsData.Instance.IsConnectionEnabled)
            {
                logger.Log(Tag, "Editor Connection is disabled in gsdk settings - will not fetch GLD from the server");
                promise.Dispatch();
                return(promise);
            }

            syncType = SyncType.OnDemand;

            //Load configs
            Data.DataElement connConfig = GameApplication.GetConfiguration("connection");
            string           sType      = (connConfig.IsNull || !connConfig.ContainsKey(SYNC_TYPE_KEY)) ? "Continuous" : (string)connConfig[SYNC_TYPE_KEY];

            syncLoopLength = (connConfig.IsNull || !connConfig.ContainsKey(SYNC_LOOP_KEY)) ? syncLoopLength : (float)connConfig[SYNC_LOOP_KEY];
            bool sEnabled = (connConfig.IsNull || !connConfig.ContainsKey(SYNC_ENABLED_KEY)) ? true : (bool)connConfig[SYNC_ENABLED_KEY];

            if (!sEnabled)
            {
                _dataSyncEnabled = false;
            }

            try
            {
                syncType = (SyncType)Enum.Parse(typeof(SyncType), sType, true);
            } catch (Exception ex)
            {
                logger.LogError(Tag, string.Format("Wrong configuraton in connection config file, the {0} key is not of the type SyncType \n Message received:{1}", SYNC_TYPE_KEY, ex.Message));
            }

            if (syncType != SyncType.Off)
            {
                _coroutineFactory.StartCoroutine(() => WaitForState(SyncLoopState.Connected));
            }

            switch (syncType)
            {
            case SyncType.OnDemand:
                _coroutineFactory.StartCoroutine(() => StartOnDemandMode(false));
                break;

            case SyncType.Continuous:
                _coroutineFactory.StartCoroutine(AsyncLoop);
                break;

            case SyncType.Off:
                promise.Dispatch();
                break;

            default:
                break;
            }

            return(promise);
        }
コード例 #12
0
        public void Init()
        {
            Data.DataElement connConfig = GameApplication.GetConfiguration("connection");

            _bucketId = (connConfig.IsNull || !connConfig.ContainsKey(_configBucketId)) ? "" : (string)connConfig[_configBucketId];
        }