Esempio n. 1
0
        private static void Update()
        {
            CheckGameObjectsPresetInScene <SingletonObject> singleton = new CheckGameObjectsPresetInScene <SingletonObject>();
            GameObjectSerachResult result = singleton.CheckForGameObject();

            if (result.numberOfObjects > 1)
            {
                List <GameObject> gObjs = result.foundGameObjects;

                int index = 0;
                for (int i = 0; i < gObjs.Count; i++)
                {
                    SingletonTypes t = gObjs[i].GetComponent <SingletonObject>().type;
                    if (allSingletonTypes.ContainsKey(t))
                    {
                        duplicateObjects.Add(gObjs[i]);
                        index++;
                    }
                    else
                    {
                        allSingletonTypes.Add(t, gObjs[i]);
                    }
                }
            }

            for (int i = 0; i < duplicateObjects.Count; i++)
            {
                DestroyImmediate(duplicateObjects[i]);
            }
            duplicateObjects.Clear();
            allSingletonTypes = new Dictionary <SingletonTypes, GameObject>();
        }
Esempio n. 2
0
        protected static void Set(T value, SingletonTypes sType)
        {
            if (null == value)
            {
                if (_me && _me.gameObject)
                {
                    Destroy(_me.gameObject);
                }
                _me = null;
            }
            else
            {
                _me = value;
            }

            //MyDebug.Log("Getting Persitatn info");
            PersitantInfo mePi = IsPersitant();

            if (mePi.isDontDestroy && !mePi.changeHierarchy)
            {
                SetPersitant(_me.gameObject, true);
            }
            if (mePi.changeHierarchy)
            {
                SetParentHer(_me.gameObject);
            }
        }
Esempio n. 3
0
 public View()
     : base()
 {
     IsSingleton   = true;
     NeedAccess    = true;
     SingletonType = SingletonTypes.Page;
 }
Esempio n. 4
0
        protected static T Get(SingletonTypes sType)
        {
            if (applicationIsQuitting)
            {
                MyDebug.Warning("[Singleton] Me of '" + typeof(T) +
                                "' already destroyed on application quit." +
                                " Won't create again - returning null.");
                return(null);
            }

            lock (locked) {
                type = typeof(T);
                if (null == _me)
                {
                    T t;
                    switch (sType)
                    {
                    case SingletonTypes.AutoCraete:
                        t = FindSingleton();
                        if (null != t)
                        {
                            _me = t;
                        }
                        else
                        {
                            AutoCreateMe();
                        }

                        break;

                    case SingletonTypes.AutoCreateWithPrefab:
                        t = FindSingleton();
                        if (null != t)
                        {
                            _me = t;
                        }
                        else
                        {
                            AutoCreateFromPrefab();
                        }
                        break;

                    case SingletonTypes.Precreated:
                        throw new System.NullReferenceException("[Singleton] " + type.ToString() + " not present in scene");
                        break;
                    }
                    PersitantInfo mePi = IsPersitant();
                    if (mePi.isDontDestroy && !mePi.changeHierarchy)
                    {
                        SetPersitant(_me.gameObject, true);
                    }
                    if (mePi.changeHierarchy)
                    {
                        SetParentHer(_me.gameObject);
                    }
                }
            }
            return(_me);
        }
 public StandardSingletonDeclaration(
     Type concreteType, object concreteIdentifier, List <TypeValuePair> args,
     SingletonTypes type, object singletonSpecificId)
     : this(
         new SingletonId(concreteType, concreteIdentifier), args,
         type, singletonSpecificId)
 {
 }
 public StandardSingletonDeclaration(
     SingletonId id, List <TypeValuePair> args, SingletonTypes type, object singletonSpecificId)
 {
     Id         = id;
     Type       = type;
     SpecificId = singletonSpecificId;
     Arguments  = args;
 }
 public StandardSingletonDeclaration(
     Type concreteType, string concreteIdentifier, List<TypeValuePair> args,
     SingletonTypes type, object singletonSpecificId)
     : this(
         new SingletonId(concreteType, concreteIdentifier), args,
         type, singletonSpecificId)
 {
 }
 public StandardSingletonDeclaration(
     SingletonId id, List<TypeValuePair> args, SingletonTypes type, object singletonSpecificId)
 {
     Id = id;
     Type = type;
     SpecificId = singletonSpecificId;
     Arguments = args;
 }
Esempio n. 9
0
 public ViewInfo(string viewName, Type viewType, IModuleInfo module, bool isSingleton, bool needAccess, SingletonTypes type)
 {
     m_viewType      = viewType;
     m_viewName      = viewName;
     m_module        = module;
     m_isSingleton   = isSingleton;
     m_needAccess    = needAccess;
     m_singletonType = type;
 }
Esempio n. 10
0
 public ScopableBindingFinalizer(
     BindInfo bindInfo,
     SingletonTypes singletonType, object singletonSpecificId,
     Func<DiContainer, Type, IProvider> providerFactory)
     : base(bindInfo)
 {
     _singletonType = singletonType;
     _providerFactory = providerFactory;
     _singletonSpecificId = singletonSpecificId;
 }
Esempio n. 11
0
 public ScopableBindingFinalizer(
     BindInfo bindInfo,
     SingletonTypes singletonType, object singletonSpecificId,
     Func <DiContainer, Type, IProvider> providerFactory)
     : base(bindInfo)
 {
     _singletonType       = singletonType;
     _providerFactory     = providerFactory;
     _singletonSpecificId = singletonSpecificId;
 }
 public ProviderInfo(
     SingletonTypes type,
     CachedProvider provider,
     object singletonSpecificId,
     List<TypeValuePair> arguments)
 {
     Type = type;
     Provider = provider;
     SingletonSpecificId = singletonSpecificId;
     Arguments = arguments;
 }
 public ProviderInfo(
     SingletonTypes type,
     CachedProvider provider,
     object singletonSpecificId,
     List <TypeValuePair> arguments)
 {
     Type                = type;
     Provider            = provider;
     SingletonSpecificId = singletonSpecificId;
     Arguments           = arguments;
 }
        protected static T Get(SingletonTypes sType)
        {
            if (applicationIsQuitting)
            {
                MyDebug.Warning("[Singleton] Me of '" + typeof(T) +
                                "' already destroyed on application quit." +
                                " Won't create again - returning null.");
                return(null);
            }

            lock (locked) {
                type = typeof(T);
                if (_me == null)
                {
                    T t;
                    switch (sType)
                    {
                    case SingletonTypes.AutoCraete:
                        t = FindSingleton();
                        if (null != t)
                        {
                            _me = t;
                        }
                        else
                        {
                            AutoCreateMe();
                        }
                        break;

                    case SingletonTypes.AutoCreateWithPrefab:
                        t = FindSingleton();
                        if (null != t)
                        {
                            _me = t;
                        }
                        else
                        {
                            AutoCreateFromPrefab();
                        }
                        break;

                    case SingletonTypes.Precreated:
                        throw new System.NullReferenceException("[Singleton] " + type.ToString() + " not present in scene");
                        break;
                    }
                }
            }
            return(_me);
        }
Esempio n. 15
0
        public void UnmarkSingleton(SingletonId id, SingletonTypes type)
        {
            Assert.That(_singletonInfos.ContainsKey(id));

            var info = _singletonInfos[id];

            Assert.IsEqual(type, info.Type);

            info.RefCount -= 1;

            if (info.RefCount == 0)
            {
                _singletonInfos.RemoveWithConfirm(id);
            }
        }
Esempio n. 16
0
        public void MarkSingleton(SingletonId id, SingletonTypes type)
        {
            SingletonTypes existingType;

            if (_singletonTypes.TryGetValue(id, out existingType))
            {
                if (existingType != type)
                {
                    throw Assert.CreateException(
                              "Cannot use both '{0}' and '{1}' for the same type/concreteIdentifier!", existingType, type);
                }
            }
            else
            {
                _singletonTypes.Add(id, type);
            }
        }
Esempio n. 17
0
        public void MarkSingleton(SingletonId id, SingletonTypes type)
        {
            SingletonInfo info;

            if (!_singletonInfos.TryGetValue(id, out info))
            {
                info = new SingletonInfo()
                {
                    Type = type,
                };

                _singletonInfos.Add(id, info);
            }

            if (info.Type != type)
            {
                throw new ZenjectBindException(
                          "Cannot use both '{0}' and '{1}' for the same type/concreteIdentifier!".Fmt(info.Type, type));
            }

            info.RefCount += 1;
        }
Esempio n. 18
0
 public void UnmarkSingleton(
     Type type, string concreteIdentifier, SingletonTypes singletonTyp)
 {
     UnmarkSingleton(
         new SingletonId(type, concreteIdentifier), singletonTyp);
 }
Esempio n. 19
0
 public View(string viewName, bool isSingleton, bool needAccess, SingletonTypes singletonType)
 {
     this.SingletonType = singletonType;
 }
Esempio n. 20
0
 public void MarkSingleton(
     Type type, object concreteIdentifier, SingletonTypes singletonType)
 {
     MarkSingleton(new SingletonId(type, concreteIdentifier), singletonType);
 }