Example #1
0
        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);
        }
Example #2
0
        private void playingModeDrawElementCallBack(FYFY.FSystem system, Rect rect)
        {
            float buttonSize = EditorGUIUtility.singleLineHeight;

            Color baseColor = GUI.color;

            GUI.color = (system.Pause == true) ? Color.red : Color.green;
            if (GUI.Button(new Rect(rect.x, rect.y + 1.35f, buttonSize, buttonSize), ""))
            {
                system.Pause = !system.Pause;
            }
            GUI.color = baseColor;

            string typeFullName = system.GetType().FullName + string.Format(" avg: {0:00.000}", system.avgExecDuration / 1000) + string.Format(" max: {0:00.000}", system.maxExecDuration / 1000);
            Rect   textArea     = new Rect(rect.x + buttonSize + 5, rect.y + 1.35f, rect.width - (buttonSize + 5), buttonSize);

            EditorGUI.LabelField(textArea, findFittableString(typeFullName, textArea));
        }
Example #3
0
 /// <summary>Set field "fieldName" defined inside "system" system with "parameter" parameter </summary>
 public static void initAppropriateSystemField(FSystem system, string fieldName, object parameter)
 {
     if (system != null)
     {
         Type systemType = system.GetType();
         // We found the system, now found the target field
         FieldInfo fieldInfo = systemType.GetField(fieldName);
         if (fieldInfo != null)
         {
             fieldInfo.SetValue(system, parameter);
         }
         else
         {
             UnityEngine.Debug.LogError(fieldName + " is not available in " + systemType.FullName);
         }
     }
     else
     {
         UnityEngine.Debug.LogError("initAppropriateSystemField aborted because first parameter is null");
     }
 }
Example #4
0
 /// <summary>Call function "functionName" defined inside "system" system with "parameter" parameter </summary>
 public static void callAppropriateSystemMethod(FSystem system, string functionName, object parameter)
 {
     if (system != null)
     {
         Type systemType = system.GetType();
         // Found the target funcion
         MethodInfo systemMethod;
         if (parameter != null)
         {
             systemMethod = systemType.GetMethod(functionName, new Type[] { parameter.GetType() });
         }
         else
         {
             systemMethod = systemType.GetMethod(functionName, new Type[] { });
         }
         if (systemMethod != null)
         {
             // We found the function, then we invoke it
             if (parameter != null)
             {
                 systemMethod.Invoke(system, new object[] { parameter });
             }
             else
             {
                 systemMethod.Invoke(system, new object[] { });
             }
         }
         else
         {
             UnityEngine.Debug.LogError(functionName + " is not available in " + systemType.FullName);
         }
     }
     else
     {
         UnityEngine.Debug.LogError("callAppropriateSystemMethod aborted because first parameter is null");
     }
 }
Example #5
0
        // 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();
        }