コード例 #1
0
ファイル: ScenePathProvider.cs プロジェクト: Qmaks/CryoDI
        private bool TryToFindObject(out T value)
        {
            var gameObject = new MaskFinder().Find(_path);

            if (gameObject == null)
            {
                value = default(T);
                return(false);
            }

            if (typeof(T) == typeof(GameObject))
            {
                value = (T)(object)gameObject;
                return(true);
            }

            if (typeof(T) == typeof(Transform))
            {
                value = (T)(object)gameObject.transform;
                return(true);
            }

            var components = gameObject.GetComponents <Component>();
            T   component  = components.OfType <T>().FirstOrDefault();

            if (component != null)
            {
                value = component;
                return(true);
            }

            value = default(T);
            return(false);
        }
コード例 #2
0
ファイル: ScenePathProvider.cs プロジェクト: Qmaks/CryoDI
        private T FindObject()
        {
            var gameObject = new MaskFinder().Find(_path);

            if (gameObject == null)
            {
                throw new ContainerException("Can't find game object \"" + _path + "\"");
            }

            if (typeof(T) == typeof(GameObject))
            {
                return((T)(object)gameObject);
            }

            if (typeof(T) == typeof(Transform))
            {
                return((T)(object)gameObject.transform);
            }

            var components = gameObject.GetComponents <Component>();
            T   component  = components.OfType <T>().FirstOrDefault();

            if (component != null)
            {
                return(component);
            }

            throw new ContainerException("Can't find component \"" + typeof(T).FullName + "\" of game object \"" + _path + "\"");
        }
コード例 #3
0
        public T GetObject(DIContainer container)
        {
            var gameObject = new MaskFinder().Find(_path);

            if (gameObject == null)
            {
                throw new ContainerException("Can't find game object \"" + _path + "\"");
            }

            if (!_inited)
            {
                container.BuildUp(gameObject);
                _inited = true;
            }

            if (typeof(T) == typeof(GameObject))
            {
                return((T)(object)gameObject);
            }

            if (typeof(T) == typeof(Transform))
            {
                return((T)(object)gameObject.transform);
            }

            T component = gameObject.GetComponents <Component>().OfType <T>().FirstOrDefault();

            if (component != null)
            {
                return(component);
            }

            throw new ContainerException("Can't find component \"" + typeof(T).FullName + "\" of game object \"" + _path + "\"");
        }