public TempListElementUI Add() { TempListElementUI element = InternalAdd(); m_actualUsedComponents.Add(element); element.Show(); return(element); }
/// <summary> /// /// </summary> /// <returns>-1 means element is not in the list</returns> public int IndexOf(TempListElementUI instance) { try { return(m_actualUsedComponents.IndexOf(instance)); } catch (ArgumentOutOfRangeException) { return(-1); } }
public void Remove(TempListElementUI instance) { if (m_actualUsedComponents.Remove(instance)) { instance.Hide(); } else { Debug.LogError($"listview_{this.gameObject.name} does not contains {instance.ElementRectTransform.name}, remove failed"); } }
public void Clear() { TempListElementUI element = null; while (m_actualUsedComponents.Count > 0) { element = m_actualUsedComponents[m_actualUsedComponents.Count - 1]; m_actualUsedComponents.RemoveAt(m_actualUsedComponents.Count - 1); InternalRemove(element); } }
private void FindPrefabInstances() { bool hasPrefab = !(m_elementPrefab == null); TempListElementUI elementPrefab = m_elementPrefab.GetComponent <TempListElementUI>(); m_actualUsedComponents.Clear(); List <GameObject> toDeleteObjectList = new List <GameObject>(); foreach (Transform child in Container) { TempListElementUI childElement = child.GetComponent <TempListElementUI>(); if (childElement == null) { toDeleteObjectList.Add(child.gameObject); continue; } if (hasPrefab) { GameObject detectPrefabGo = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(child.gameObject); TempListElementUI detectPrefab = (detectPrefabGo == null) ? null : detectPrefabGo.GetComponent <TempListElementUI>(); if (elementPrefab == detectPrefab) { // same source prefab m_actualUsedComponents.Add(childElement); } else { // different source prefab, delete this one toDeleteObjectList.Add(child.gameObject); } } else if (UnityEditor.PrefabUtility.IsAnyPrefabInstanceRoot(child.gameObject)) { // find the first prefab GameObject prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(child.gameObject); m_elementPrefab = prefab.GetComponent <TempListElementUI>(); m_actualUsedComponents.Add(childElement); hasPrefab = true; } } for (int i = 0; i < toDeleteObjectList.Count; i++) { if (Application.isPlaying) { GameObject.Destroy(toDeleteObjectList[i]); } else { GameObject.DestroyImmediate(toDeleteObjectList[i]); } } }
public void RemoveAt(int index) { if (index < 0 || index >= m_actualUsedComponents.Count) { Debug.LogError($"{index} is invalid for SimpleListView", this.gameObject); return; } TempListElementUI toRemove = m_actualUsedComponents[index]; m_actualUsedComponents.RemoveAt(index); InternalRemove(toRemove); }
private void EditorTimeAdd() { if (Application.isPlaying) { return; } if (m_elementPrefab == null) { Debug.LogError("listview is missing element prefab"); return; } TempListElementUI spawnObject = (TempListElementUI)UnityEditor.PrefabUtility.InstantiatePrefab(m_elementPrefab, Container); m_actualUsedComponents.Add(spawnObject); }
public void InnerSwap(int indexA, int indexB) { if (indexA < 0 || indexA > m_actualUsedComponents.Count - 1 || indexB < 0 || indexB > m_actualUsedComponents.Count - 1) { return; } TempListElementUI temp = m_actualUsedComponents[indexA]; int transformIndexA = temp.ElementRectTransform.GetSiblingIndex(); int transformIndexB = m_actualUsedComponents[indexB].ElementRectTransform.GetSiblingIndex(); m_actualUsedComponents[indexA] = m_actualUsedComponents[indexB]; m_actualUsedComponents[indexB] = temp; m_actualUsedComponents[indexA].ElementRectTransform.SetSiblingIndex(transformIndexA); m_actualUsedComponents[indexB].ElementRectTransform.SetSiblingIndex(transformIndexB); }
protected virtual void InternalRemove(TempListElementUI element) { if (element == null) { return; } element.Hide(); if (Application.isEditor && !Application.isPlaying) { GameObject.DestroyImmediate(element.ElementRectTransform.gameObject); } else { GameObject.Destroy(element.ElementRectTransform.gameObject); } }