Example #1
0
        /// <summary>Initialize template.</summary>
        protected virtual void Start()
        {
            // check template
            #if DEBUG
            string message;
            if (!GalleryImageContainer.HasValidTemplate(this, out message))
            {
                Debug.LogError("[mod.io] " + message, this);
                return;
            }
            #endif

            // get template vars
            Transform templateParent         = this.containerTemplate.parent;
            string    templateInstance_name  = this.containerTemplate.gameObject.name + " (Instance)";
            int       templateInstance_index = this.containerTemplate.GetSiblingIndex() + 1;
            this.m_itemTemplate = this.containerTemplate.GetComponentInChildren <GalleryImageDisplay>(true);

            // duplication protection
            bool isInstantiated = (templateParent.childCount > templateInstance_index &&
                                   templateParent.GetChild(templateInstance_index).gameObject.name == templateInstance_name);
            if (isInstantiated)
            {
                this.m_templateClone = templateParent.GetChild(templateInstance_index).gameObject;
                GalleryImageDisplay[] itemInstances = this.m_templateClone.GetComponentsInChildren <GalleryImageDisplay>(true);

                if (itemInstances == null || itemInstances.Length == 0)
                {
                    isInstantiated = false;
                    GameObject.Destroy(this.m_templateClone);
                }
                else
                {
                    this.m_container = (RectTransform)itemInstances[0].transform.parent;

                    foreach (GalleryImageDisplay item in itemInstances)
                    {
                        GameObject.Destroy(item.gameObject);
                    }
                }
            }

            if (!isInstantiated)
            {
                this.m_templateClone = GameObject.Instantiate(this.containerTemplate.gameObject, templateParent);
                this.m_templateClone.transform.SetSiblingIndex(templateInstance_index);
                this.m_templateClone.name = templateInstance_name;

                GalleryImageDisplay itemInstance = this.m_templateClone.GetComponentInChildren <GalleryImageDisplay>(true);
                this.m_container = (RectTransform)itemInstance.transform.parent;
                GameObject.Destroy(itemInstance.gameObject);

                this.m_templateClone.SetActive(true);
            }

            this.DisplayImages(this.m_modId, this.m_locators);
        }
        /// <summary>Copies the data of another component to display.</summary>
        public void DisplayGalleryImage(GalleryImageDisplay display)
        {
            int modId = ModProfile.NULL_ID;
            GalleryImageLocator locator = null;

            if (display != null)
            {
                modId   = display.ModId;
                locator = display.Locator;
            }

            this.DisplayGalleryImage(modId, locator);
        }
Example #3
0
        // ---------[ UTILITY ]---------
        /// <summary>Checks a GalleryImageContainer's template structure.</summary>
        public static bool HasValidTemplate(GalleryImageContainer container, out string helpMessage)
        {
            helpMessage = null;
            bool isValid = true;

            GalleryImageDisplay itemTemplate = null;

            // null check
            if (container.containerTemplate == null)
            {
                helpMessage = ("Invalid template:"
                               + " The container template is unassigned.");
                isValid = false;
            }
            // containerTemplate is child of Component
            else if (!container.containerTemplate.IsChildOf(container.transform) ||
                     container.containerTemplate == container.transform)
            {
                helpMessage = ("Invalid template:"
                               + " The container template must be a child of this object.");
                isValid = false;
            }
            // GalleryImageDisplay is found under containerTemplate
            else if ((itemTemplate = container.containerTemplate.gameObject.GetComponentInChildren <GalleryImageDisplay>()) == null)
            {
                helpMessage = ("Invalid template:"
                               + " No GalleryImageDisplay component found in the children of the container template.");
                isValid = false;
            }
            // GalleryImageDisplay is on same gameObject as containerTemplate
            else if (itemTemplate.transform == container.containerTemplate)
            {
                helpMessage = ("Invalid template:"
                               + " The GalleryImageDisplay component cannot share a GameObject with the container template.");
                isValid = false;
            }

            return(isValid);
        }