예제 #1
0
        /// <summary>
        /// Verifies if the containerDescriptor referenced by this script is the first one on the game object at the source of the interaction.
        /// </summary>
        private bool IsFirstContainerOpenable(IGameObjectProvider target)
        {
            // Only accept the first Openable container on the GameObject.
            // Note: if you want separately functioning doors etc, they must be on different GameObjects.
            ContainerDescriptor[] containerDescriptors = target.GameObject.GetComponents <ContainerDescriptor>();
            for (int i = 0; i < containerDescriptors.Length; i++)
            {
                if (containerDescriptor != containerDescriptors[i] && containerDescriptors[i].isOpenable)
                {
                    return(false);
                }

                if (containerDescriptor == containerDescriptors[i])
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        public static T GetComponentInTree <T>(this IInteractionSource source, out IGameObjectProvider provider) where T : class
        {
            IInteractionSource current = source;

            while (current != null)
            {
                if (current is IGameObjectProvider gameObjectProvider)
                {
                    T component = gameObjectProvider.GameObject.GetComponent <T>();
                    if (component != null)
                    {
                        provider = gameObjectProvider;
                        return(component);
                    }
                }
                current = current.Parent;
            }

            provider = null;
            return(null);
        }