Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sceneObserver">The observer this was build with.</param>
 public void Initialize(SceneObserver sceneObserver)
 {
     thisIsMe           = (T)this;
     instanceID         = GetInstanceID();
     this.sceneObserver = sceneObserver;
     main = transform.root.GetComponent <IInitializeMain>();
 }
Пример #2
0
    /// <summary>
    /// Use this method to instantiate IInitializeMain Objects
    /// </summary>
    /// <typeparam name="T">Reference to the asset you want instantiated.</typeparam>
    /// <typeparam name="T1">The type of the value to give to the main.</typeparam>
    /// <param name="asset">Reference to the prefab or ScriptableObject to be instantiated.</param>
    /// <param name="args">The value given to the instantiated main.</param>
    /// <param name="observer">Reference to the sceneobserver</param>
    /// <returns></returns>
    internal T Create <T, T1>(T asset, T1 args, SceneObserver observer) where T : UnityEngine.Object
    {
        IInitializeMain mainI = (IInitializeMain)asset;

        if (mainI.Scene == SceneMarker.All || mainI.Scene == observer.Scene)
        {
            T   instance = Instantiate(asset);
            var main     = (IInitializeMain)instance;
            main.Initialize(observer);
            main.Init(args);
            observer.AddMain(main);

            return(instance);
        }
        else
        {
            Debug.LogError("The asset " + asset + " cant be instantiated in this scene because it is Scenebound");
            return(null);
        }
    }
 internal void RemoveMain(IInitializeMain initializeMain)
 {
     mainsInScene.Remove(initializeMain);
 }
 internal void AddMain(IInitializeMain initializeMain)
 {
     mainsInScene.Add(initializeMain);
     initializeMain.BeforeMainDestroyed += RemoveMain;
 }