/// <summary> /// Adds page the component. /// </summary> /// <param name="page">Page.</param> protected virtual void AddComponent(int page) { ScrollRectPage component; if (DefaultPagesCache.Count > 0) { component = DefaultPagesCache[DefaultPagesCache.Count - 1]; DefaultPagesCache.RemoveAt(DefaultPagesCache.Count - 1); } else { component = Compatibility.Instantiate(SRDefaultPage); component.transform.SetParent(SRDefaultPage.transform.parent, false); component.OnPageSelect.AddListener(GoToPage); Utilites.FixInstantiated(SRDefaultPage, component); } component.transform.SetAsLastSibling(); component.gameObject.SetActive(true); component.SetPage(page); DefaultPages.Add(component); }
/// <summary> /// Creates the buttons. /// </summary> protected virtual void CreateButtons() { DefaultButtons.ForEach(x => x.interactable = true); ActiveButtons.ForEach(x => x.interactable = true); if (tabObjects.Length > DefaultButtons.Count) { for (var i = DefaultButtons.Count; i < tabObjects.Length; i++) { var defaultButton = Compatibility.Instantiate(DefaultTabButton); defaultButton.transform.SetParent(Container, false); DefaultButtons.Add(defaultButton); var activeButton = Compatibility.Instantiate(ActiveTabButton); activeButton.transform.SetParent(Container, false); ActiveButtons.Add(activeButton); } } // del existing ui elements if necessary if (tabObjects.Length < DefaultButtons.Count) { for (var i = DefaultButtons.Count - 1; i > tabObjects.Length - 1; i--) { Destroy(DefaultButtons[i].gameObject); Destroy(ActiveButtons[i].gameObject); DefaultButtons.RemoveAt(i); ActiveButtons.RemoveAt(i); } } DefaultButtons.ForEach(SetButtonName); ActiveButtons.ForEach(SetButtonName); }
/// <summary> /// Create component instance. /// </summary> /// <returns>Component instance.</returns> protected TComponent CreateComponent() { TComponent component; if (ComponentsCache.Count > 0) { component = ComponentsCache[ComponentsCache.Count - 1]; ComponentsCache.RemoveAt(ComponentsCache.Count - 1); } else { component = Compatibility.Instantiate(template); component.transform.SetParent(Container, false); Utilites.FixInstantiated(template, component); component.Owner = Owner; } component.Index = -2; component.transform.SetAsLastSibling(); component.gameObject.SetActive(true); CallbackAdd(component); return(component); }
/// <summary> /// Gets the button. /// </summary> /// <returns>The button.</returns> protected virtual Button GetButton() { if (buttonsCache.Count > 0) { return(buttonsCache.Pop()); } var button = Compatibility.Instantiate(DefaultButton); button.transform.SetParent(DefaultButton.transform.parent, false); return(button); }
/// <summary> /// Get instance. /// </summary> /// <returns>Instance.</returns> public TComponent GetInstance() { TComponent instance; if (cache.Count > 0) { instance = cache.Pop(); } else { instance = Compatibility.Instantiate(DefaultItem); Utilites.FixInstantiated(DefaultItem, instance); instance.transform.SetParent(parent, false); } instance.gameObject.SetActive(true); active.Add(instance); return(instance); }
/// <summary> /// Create header from day of week template. /// </summary> protected virtual void GenerateHeader() { if (CalendarDayOfWeekTemplate == null) { return; } for (int i = Header.Count; i < DaysInWeek; i++) { var day_of_week = Compatibility.Instantiate(CalendarDayOfWeekTemplate); day_of_week.transform.SetParent(HeaderContainer, false); Utilites.FixInstantiated(CalendarDayOfWeekTemplate, day_of_week); day_of_week.Calendar = this; day_of_week.gameObject.SetActive(true); Header.Add(day_of_week); } }
/// <summary> /// Return instance by the specified template name. /// </summary> /// <param name="name">Template name.</param> /// <returns>New template instance.</returns> public T Instance(string name) { if (!findTemplatesCalled) { FindTemplates(); } if (!Exists(name)) { throw new ArgumentException("Not found template with name '" + name + "'"); } if (templates[name] == null) { templates.Clear(); FindTemplates(); } T template; if (cache.ContainsKey(name) && (cache[name].Count > 0)) { template = cache[name].Pop(); } else { template = Compatibility.Instantiate(templates[name]); template.TemplateName = name; template.IsTemplate = false; if (onCreateCallback != null) { onCreateCallback(template); } } template.transform.SetParent(templates[name].transform.parent, false); return(template); }
/// <summary> /// Get new component instance. /// </summary> /// <returns>Component instance.</returns> protected TComponent GetComponentInstance() { TComponent component; if (Cache.Count > 0) { component = Cache.Pop(); } else { component = Compatibility.Instantiate(defaultItem); component.transform.SetParent(container, false); Utilites.FixInstantiated(defaultItem, component); } component.gameObject.SetActive(true); Used.Add(component); return(component); }
/// <summary> /// Create component instance. /// </summary> /// <returns>Component instance.</returns> protected ScrollerItem CreateComponent() { ScrollerItem component; if (ComponentsCache.Count > 0) { component = ComponentsCache[ComponentsCache.Count - 1]; ComponentsCache.RemoveAt(ComponentsCache.Count - 1); } else { component = Compatibility.Instantiate(DefaultItem); component.transform.SetParent(transform, false); Utilites.FixInstantiated(DefaultItem, component); component.Owner = this; } component.gameObject.SetActive(true); return(component); }
/// <summary> /// Create the button instance. /// </summary> /// <param name="templateIndex">Index of the button template.</param> /// <param name="label">Button label.</param> /// <param name="action">Action on button click.</param> /// <returns>Button.</returns> protected Button Instantiate(int templateIndex, string label, UnityAction action) { Button button; if (Cache[templateIndex].Count > 0) { button = Cache[templateIndex].Pop(); } else { var template = Templates[templateIndex]; button = Compatibility.Instantiate(template); button.transform.SetParent(template.transform.parent, false); } button.onClick.AddListener(action); button.gameObject.SetActive(true); button.transform.SetAsLastSibling(); var dialog_button = button.GetComponentInChildren <DialogButtonComponentBase>(); if (dialog_button != null) { dialog_button.SetButtonName(label); } else { var text = button.GetComponentInChildren <Text>(); if (text != null) { text.text = label; } } Active[templateIndex].Add(button); return(button); }
/// <summary> /// Instantiated date component from template. /// </summary> /// <returns>Date component.</returns> protected virtual CalendarDateBase GenerateDay() { CalendarDateBase day; if (Cache.Count > 0) { day = Cache.Pop(); } else { day = Compatibility.Instantiate(CalendarDateTemplate); day.transform.SetParent(Container, false); Utilites.FixInstantiated(CalendarDateTemplate, day); day.Calendar = this; } day.gameObject.SetActive(true); day.transform.SetAsLastSibling(); return(day); }
/// <summary> /// Creates the object by path to asset prefab. /// </summary> /// <returns>The created object.</returns> /// <param name="path">Path.</param> /// <param name="parent">Parent.</param> /// <param name="setParent">Set parent for the created gameobject.</param> static GameObject CreateObject(string path, Transform parent = null, bool setParent = true) { var prefab = Compatibility.LoadAssetAtPath <GameObject>(path); if (prefab == null) { throw new ArgumentException(string.Format("Prefab not found at path {0}.", path)); } var go = Compatibility.Instantiate(prefab); if (setParent) { var go_parent = (parent != null) ? parent : Selection.activeTransform; if ((go_parent == null) || ((go_parent.gameObject.transform as RectTransform) == null)) { go_parent = GetCanvasTransform(); } if (go_parent != null) { go.transform.SetParent(go_parent, false); } } go.name = prefab.name; var rectTransform = go.transform as RectTransform; if (rectTransform != null) { rectTransform.anchoredPosition = new Vector2(0, 0); FixInstantiated(prefab, go); } return(go); }
/// <summary> /// Adds the component. /// </summary> protected virtual void AddComponent() { TComponent component; if (componentsCache.Count > 0) { component = componentsCache[componentsCache.Count - 1]; componentsCache.RemoveAt(componentsCache.Count - 1); } else { component = Compatibility.Instantiate(current); component.transform.SetParent(current.transform.parent, false); Utilites.FixInstantiated(current, component); } component.Index = -2; component.Owner = ListView; component.transform.SetAsLastSibling(); component.gameObject.SetActive(true); components.Add(component); }