private FSystem createSystemInstance(SystemDescription systemDescription) { System.Type type = System.Type.GetType(systemDescription._typeAssemblyQualifiedName); if (type == null) // modification done between time when you set the system in the mainloop && when you run -> class deleted or renamed ?? // When inspector doesnt work and you set manually { return(null); } FSystem system = (FSystem)System.Activator.CreateInstance(type); system.Pause = systemDescription._pause; return(system); }
// Parse scene and bind all GameObjects to FYFY // Create all systems private void OnEnable() { // if upgrade FYFY, old version instance could be null because Awake is not called again, we set instance reference properly if (instance == null) { instance = this; } if (Application.isPlaying == false) { return; } // Parse scene and bind GameObjects to FYFY List <GameObject> sceneGameObjects = new List <GameObject>(); if (_loadingState == 0) { // Bind all game objects except ones defined in _specialGameObjects GameObject[] roots = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject root in roots) { foreach (Transform childTransform in root.GetComponentsInChildren <Transform>(true)) // include root transform // Check if current game object is not an excluded game object or a child of an excluded game object { bool needToExclude = false; foreach (GameObject excluded in _specialGameObjects) { if (excluded != null) { if (childTransform.IsChildOf(excluded.transform)) // true if childTransform == excluded.transform { needToExclude = true; break; } } } if (!needToExclude) { sceneGameObjects.Add(childTransform.gameObject); } } } } else { // Bind only game objects defined in _specialGameObjects foreach (GameObject included in _specialGameObjects) { if (included != null) { foreach (Transform childTransform in included.GetComponentsInChildren <Transform>(true)) // include itself { sceneGameObjects.Add(childTransform.gameObject); } } } } // Bind all game object tagged as DontDestroyOnLoad foreach (GameObject ddol_go in GameObjectManager._ddolObjects) { if (ddol_go != null) { foreach (Transform childTransform in ddol_go.GetComponentsInChildren <Transform>(true)) // include itself { sceneGameObjects.Add(childTransform.gameObject); } } } foreach (GameObject gameObject in sceneGameObjects) { // In case of GameObject state (enable/disable) is controlled by Unity tools (animators for instance) Fyfy is not notified from this change => solution add a special component that catch Unity events and submit update to FYFY if (!gameObject.GetComponent <FyfyBridge>()) { gameObject.AddComponent <FyfyBridge>(); } // Compute Wrappers HashSet <string> componentTypeNames = new HashSet <string>(); foreach (Component c in gameObject.GetComponents <Component>()) { if (c != null) // it is possible if a GameObject contains a breaked component (Missing script) { System.Type type = c.GetType(); componentTypeNames.Add(type.FullName); } } GameObjectWrapper gameObjectWrapper = new GameObjectWrapper(gameObject, componentTypeNames); if (!GameObjectManager._gameObjectWrappers.ContainsKey(gameObject.GetInstanceID())) { GameObjectManager._gameObjectWrappers.Add(gameObject.GetInstanceID(), gameObjectWrapper); } } // Create all systems for (int i = 0; i < _fixedUpdateSystemDescriptions.Length; ++i) { SystemDescription systemDescription = _fixedUpdateSystemDescriptions[i]; try{ FSystem system = this.createSystemInstance(systemDescription); if (system != null) { FSystemManager._fixedUpdateSystems.Add(system); // set reference of this system in its wrapper string compilableName = systemDescription._typeFullName.Replace('.', '_'); Component wrapper = gameObject.GetComponent(compilableName + "_wrapper"); if (wrapper != null) { (wrapper as BaseWrapper).system = system; } } else { UnityEngine.Debug.LogError(systemDescription._typeFullName + " class doesn't exist, hooking up this FSystem to FixedUpdate context aborted. Check your MainLoop Game Object."); } }catch (System.Exception e) { UnityEngine.Debug.LogException(e); } } for (int i = 0; i < _updateSystemDescriptions.Length; ++i) { SystemDescription systemDescription = _updateSystemDescriptions[i]; try{ FSystem system = this.createSystemInstance(systemDescription); if (system != null) { FSystemManager._updateSystems.Add(system); // set reference of this system in its wrapper string compilableName = systemDescription._typeFullName.Replace('.', '_'); Component wrapper = gameObject.GetComponent(compilableName + "_wrapper"); if (wrapper != null) { (wrapper as BaseWrapper).system = system; } } else { UnityEngine.Debug.LogError(systemDescription._typeFullName + " class doesn't exist, hooking up this FSystem to Update context aborted. Check your MainLoop Game Object."); } } catch (System.Exception e) { UnityEngine.Debug.LogException(e); } } for (int i = 0; i < _lateUpdateSystemDescriptions.Length; ++i) { SystemDescription systemDescription = _lateUpdateSystemDescriptions[i]; try{ FSystem system = this.createSystemInstance(systemDescription); if (system != null) { FSystemManager._lateUpdateSystems.Add(system); // set reference of this system in its wrapper string compilableName = systemDescription._typeFullName.Replace('.', '_'); Component wrapper = gameObject.GetComponent(compilableName + "_wrapper"); if (wrapper != null) { (wrapper as BaseWrapper).system = system; } } else { UnityEngine.Debug.LogError(systemDescription._typeFullName + " class doesn't exist, hooking up this FSystem to LateUpdate context aborted. Check your MainLoop Game Object."); } } catch (System.Exception e) { UnityEngine.Debug.LogException(e); } } _stopwatch = new Stopwatch(); }