Beispiel #1
0
        public static void RefreshViewController(HotReloadableViewController viewController, bool forceReload = false)
        {
            if (viewController == null)
            {
#if HRVC_DEBUG
                Logger.log.Warn($"Trying to refresh a HotReloadableViewController when it doesn't exist.");
#endif
                return;
            }
            if (!viewController.isActiveAndEnabled)
            {
#if HRVC_DEBUG
                Logger.log.Warn($"Trying to refresh {viewController.GetInstanceID()}:{viewController.name} when it isn't ActiveAndEnabled.");
#endif
                return;
            }
            if (viewController.ContentChanged || forceReload)
            {
                try
                {
                    viewController.__Deactivate(ViewController.DeactivationType.NotRemovedFromHierarchy, false);
                    for (int i = 0; i < viewController.transform.childCount; i++)
                    {
                        GameObject.Destroy(viewController.transform.GetChild(i).gameObject);
                    }
                    viewController.__Activate(ViewController.ActivationType.NotAddedToHierarchy);
                }
                catch (Exception ex)
                {
                    Logger.log?.Error(ex);
                }
            }
        }
Beispiel #2
0
        public static bool UnregisterViewController(HotReloadableViewController controller)
        {
            string contentFile = controller.ContentFilePath;

            if (string.IsNullOrEmpty(contentFile))
            {
#if HRVC_DEBUG
                Logger.log.Critical($"Skipping registration for {controller.GetInstanceID()}:{controller.name}, it has not content file defined.");
#endif
                return(false);
            }
            bool   successful       = false;
            string contentDirectory = Path.GetDirectoryName(contentFile);
            if (WatcherDictionary.TryGetValue(contentDirectory, out WatcherGroup watcherGroup))
            {
                successful = watcherGroup.UnbindController(controller);
            }
#if HRVC_DEBUG
            else
            {
                Logger.log.Warn($"Unable to get WatcherGroup for {contentDirectory}");
            }
            if (successful)
            {
                Logger.log.Info($"Successfully unregistered {controller.GetInstanceID()}:{controller.name}");
            }
            else
            {
                Logger.log.Warn($"Failed to Unregister {controller.GetInstanceID()}:{controller.name}");
            }
#endif
            return(successful);
        }
Beispiel #3
0
        public static bool RegisterViewController(HotReloadableViewController controller)
        {
            string contentFile = controller.ContentFilePath;

            if (string.IsNullOrEmpty(contentFile))
            {
                return(false);
            }
            string contentDirectory = Path.GetDirectoryName(contentFile);

            if (!Directory.Exists(contentDirectory))
            {
                return(false);
            }
            WatcherGroup watcherGroup;

            if (!WatcherDictionary.TryGetValue(contentDirectory, out watcherGroup))
            {
                watcherGroup = new WatcherGroup(contentDirectory);
                WatcherDictionary.Add(contentDirectory, watcherGroup);
            }
            watcherGroup.BindController(controller);

            return(true);
        }
Beispiel #4
0
            internal bool UnbindController(HotReloadableViewController controller)
            {
                if (controller == null)
                {
#if HRVC_DEBUG
                    Logger.log.Critical($"Unable to unbind controller, it is null.");
#endif
                    return(false);
                }
                return(UnbindController(controller.GetInstanceID()));
            }
Beispiel #5
0
            internal bool BindController(HotReloadableViewController controller)
            {
                if (BoundControllers.ContainsKey(controller.GetInstanceID()))
                {
#if HRVC_DEBUG
                    Logger.log.Critical($"Failed to register controller, already exists. {controller.GetInstanceID()}:{controller.name}");
#endif
                    return(false);
                }
                BoundControllers.Add(controller.GetInstanceID(), new WeakReference <HotReloadableViewController>(controller));
                CreateWatcher();
                Watcher.EnableRaisingEvents = true;
#if HRVC_DEBUG
                Logger.log.Info($"Registering controller {controller.GetInstanceID()}:{controller.name}");
#endif
                return(true);
            }