Exemplo n.º 1
0
    /// <summary>
    /// Initialize the specified instance. All exceptions from the invocation of instance.Initialize() will be swallowed.
    /// </summary>
    /// <param name="instance">Instance to intialize.</param>
    private bool Initialize(IInitializable instance)
    {
        string instanceName = instance.GetType().Name;

        try {
            this.LogTrace("Initializing " + instanceName, LogCategory.INITIALIZATION);
                        #if METRICS_ENABLED && INCLUDE_DEV_METRICS
            Metrics.Start("Initialize:" + instanceName);
                        #endif
            instance.Initialize(InstanceInitialized);
        } catch (Exception e) {
                        #if METRICS_ENABLED && INCLUDE_DEV_METRICS
            Metrics.End("Initialize:" + instanceName);
                        #endif

            // An exception was thrown, so we will never complete. Invoke failedCallback.
            this.LogError("Exception initializing " + (instance != null ? instance.ToString() : "null instance") + ": " + e.ToString());

            Failure(e.ToString());

            // Stop initialization of any future instances
            return(false);
        }

        // Continue initialization
        return(true);
    }
Exemplo n.º 2
0
        internal static void RegisterComponent(Component cmp)
        {
            LifecycleEvent(cmp, "Consider for awake");

            if (cmp is IInitializable)
            {
                IInitializable init = cmp as IInitializable;
                if (!cmp.isPrefab || (cmp.isPrefab && init.ShouldPrefabsBeInitialized()))
                {
                    init.Initialize(assetHelper);
                }
            }

            if (cmp.gameObject != null && !cmp.isPrefab)
            {
                LifecycleEvent(cmp, "Add to objects");
                objects.Add(cmp.GetInstanceID(), cmp);
                if (!cmp.isPrefab)
                {
                    LifecycleEvent(cmp, "Add to start");
                    componentsToStart.Enqueue(cmp);
                }
                if (!objects.ContainsKey(cmp.gameObject.GetInstanceID()))
                {
                    objects.Add(cmp.gameObject.GetInstanceID(), cmp.gameObject);
                }
                if (!cmp.isPrefab && typeCaps.HasCaps(cmp.GetType(), TypeSet.TypeCapabilities.Awake))
                {
                    componentsToAwake.Enqueue(cmp);
                }
            }
        }
Exemplo n.º 3
0
        private void InitializeTask(Task task)
        {
            RuntimeTask rt = null;

            if (task is Wait)
            {
                rt = Initialize_Wait(task);
            }
            else
            {
                rt = new RuntimeTask(task, task.targetMethod);
                MonoBehaviour comp = GetEqualTypeComponent(task.targetScript.GetType()) as MonoBehaviour;
                if (comp == null)
                {
                    comp = gameObject.AddComponent(task.targetScript.GetType()) as MonoBehaviour;
                    IInitializable initializable = comp as IInitializable;
                    initializable.Initialize();
                }

                if (task.isCoroutine)
                {
                    rt.comp = comp;
                }
                else
                {
                    Func <IDisposable> tempFunc = Delegate.CreateDelegate(typeof(Func <IDisposable>), comp, task.targetMethod) as Func <IDisposable>;
                    rt.taskFunc = tempFunc;
                }
            }

            _runtimeTasks.Add(task, rt);
        }
        internal static void TryInitialize(this object obj, object application)
        {
            IInitializable initializable = obj as IInitializable;

            if (initializable != null)
            {
                initializable.Initialize(application);
            }
        }
Exemplo n.º 5
0
 public static bool InitializeDefStat(IInitializable i)
 {
     if (i != null)
     {
         if (!i.Initialize())
         {
             Log.Warning("Failed to initialize DefStat " + i.Label);
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 6
0
 private void InitializeListeners(Configuration cfg, object[] list)
 {
     initializedListeners.AddRange(list);
     foreach (object i in list)
     {
         IInitializable initializable = i as IInitializable;
         if (initializable != null)
         {
             initializable.Initialize(cfg);
         }
     }
 }
Exemplo n.º 7
0
 public void LoadOrUpdate()
 {
     // Update Method
     if (objectsToLoad.Count > 0)
     {
         IInitializable obj = objectsToLoad.Dequeue();
         obj.Initialize();
     }
     else
     {
         // Loading complete.
     }
 }
Exemplo n.º 8
0
        private void BroadcastDependencyInitialization(object dependency)
        {
            IInitializable iInitializable = dependency as IInitializable;

            if (iInitializable != null)
            {
                iInitializable.Initialize();
            }

            if (OnInitializeDependency != null)
            {
                OnInitializeDependency(dependency);
            }
        }
        /// <summary>
        /// Initializes the global objects.
        /// </summary>
        /// <param name="dependencyInjectionContainer">The dependency injection container.</param>
        public void InitializeGlobalObjects(DependencyInjectionContainer dependencyInjectionContainer)
        {
            ExceptionUtilities.CheckArgumentNotNull(dependencyInjectionContainer, "dependencyInjectionContainer");

            // pre-resolve global objects
            foreach (var globalObject in this.implementations.Where(c => c.IsGlobal))
            {
                var            result = dependencyInjectionContainer.Resolve(globalObject.ContractType);
                IInitializable init   = result as IInitializable;
                if (init != null)
                {
                    init.Initialize();
                }
            }
        }
Exemplo n.º 10
0
 private void SetScriptConnections(GameObject character, List <MonoBehaviour> scripts)
 {
     for (int i = 0; i < scripts.Count; i++)
     {
         IInitializable initializable = scripts[i] as IInitializable;
         if (initializable != null)
         {
             initializable.Initialize(character);
         }
         else
         {
             Debug.LogError("The script is not initializable!");
         }
     }
 }
Exemplo n.º 11
0
        private void Initialize()
        {
            bool canLogin = TryLogin();

            EventProcessor.OnMessageRecv += OnMessageRecv;

            for (int i = 0; i < PluginManager.inits.Count; i++)
            {
                IInitializable init = PluginManager.inits[i];
                if (init.Initialize())
                {
                    Debug.Log("Loaded " + init.initHandle + " successfully");
                }
                else
                {
                    Debug.LogError("Loaded " + init.initHandle + " unsuccessfully");
                }
            }
        }
Exemplo n.º 12
0
 private void InitializeService(Composite composite)
 {
     if (composite.services.Length > 0)
     {
         for (int i = 0; i < composite.services.Length; i++)
         {
             Service        sv   = composite.services[i];
             RuntimeService rs   = new RuntimeService(composite, sv.tick);
             MonoBehaviour  comp = GetEqualTypeComponent(sv.targetScript.GetType()) as MonoBehaviour;
             if (comp == null)
             {
                 comp = gameObject.AddComponent(sv.targetScript.GetType()) as MonoBehaviour;
                 IInitializable initializable = comp as IInitializable;
                 initializable.Initialize();
             }
             rs.serviceAction = Delegate.CreateDelegate(typeof(Action), comp, sv.targetMethod) as Action;
             _runtimeServices.Add(rs);
         }
     }
 }
Exemplo n.º 13
0
 private void InitializeDecorator(Node node)
 {
     if (node.decorators.Length > 0)
     {
         for (int i = 0; i < node.decorators.Length; i++)
         {
             Decorator        dc   = node.decorators[i];
             RuntimeDecorator rd   = new RuntimeDecorator(node, dc, dc.observerAbortsType, dc.tick, dc.inversed);
             MonoBehaviour    comp = GetEqualTypeComponent(dc.targetScript.GetType()) as MonoBehaviour;
             if (comp == null)
             {
                 comp = gameObject.AddComponent(dc.targetScript.GetType()) as MonoBehaviour;
                 IInitializable initializable = comp as IInitializable;
                 initializable.Initialize();
             }
             rd.decoratorFunc = Delegate.CreateDelegate(typeof(Func <bool>), comp, dc.targetMethod) as Func <bool>;
             _runtimeDecorators.Add(rd);
         }
     }
 }
Exemplo n.º 14
0
        public static void LoadPlugins(Assembly assembly)
        {
            Type initType = typeof(IInitializable);

            List <Type> initializables = assembly.GetTypes().Where(x => initType.IsAssignableFrom(x)).ToList();

            inits = new List <IInitializable>();

            foreach (Type iType in initializables)
            {
                IInitializable init       = (IInitializable)Activator.CreateInstance(iType);
                string         pluginPath = runningPath + "\\" + init.initHandle + "\\";

                if (!Directory.Exists(pluginPath))
                {
                    Directory.CreateDirectory(pluginPath);
                }

                init.basePath = pluginPath;
                inits.Add(init);
            }

            inits.Sort((i1, i2) => i1.priority.CompareTo(i2.priority));
            for (int i = 0; i < inits.Count; i++)
            {
                IInitializable init    = inits[i];
                bool           didInit = init.Initialize();

                if (didInit)
                {
                    Debug.Log("Initialized " + init.initHandle + " successfully.");
                }
                else
                {
                    Debug.LogError("Initialization of " + init.initHandle + " failed.");
                }
            }
        }
Exemplo n.º 15
0
 IEnumerator ExecutionProcess()
 {
     for (int i = 0; i < preInitializers.Count; i++)
     {
         IPreInitializable preInitializable = preInitializers[i].GetComponent <IPreInitializable>();
         yield return(preInitializable.PreInitialize());
     }
     for (int i = 0; i < loadersExecutionOrder.Count; i++)
     {
         ILoadable loadable = loadersExecutionOrder[i].GetComponent <ILoadable>();
         yield return(loadable.Load());
     }
     for (int i = 0; i < initializersExecutionOrder.Count; i++)
     {
         IInitializable initializable = initializersExecutionOrder[i].GetComponent <IInitializable>();
         yield return(initializable.Initialize());
     }
     for (int i = 0; i < savablesExecutionOrder.Count; i++)
     {
         ISavable savable = savablesExecutionOrder[i].GetComponent <ISavable>();
         savable.PropertyChanged += OnSaveRequired;
     }
 }
Exemplo n.º 16
0
 private void ProcessState(IInitializable step)
 {
     Debug.Log($"[{nameof(GameStateController)}] {nameof(ProcessState)} {step.GetType().Name}");
     new EventCommand(GameEvents.StateMachineEvents.Start, step.GetType().Name).Execute();
     step.Initialize(OnStepComplete);
 }
Exemplo n.º 17
0
 public void Initialize(IInitializable initializable)
 {
     initializable.Initialize(_database);
 }
Exemplo n.º 18
0
 public void Initialize(IInitializable initializable)
 {
     initializable.Initialize(_database);
 }
Exemplo n.º 19
0
        public async Task Run()
        {
            await _initializer.Initialize();

            await _runnable.Run();
        }