Beispiel #1
0
    public TempListElementUI Add()
    {
        TempListElementUI element = InternalAdd();

        m_actualUsedComponents.Add(element);
        element.Show();
        return(element);
    }
Beispiel #2
0
 /// <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);
     }
 }
Beispiel #3
0
 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");
     }
 }
Beispiel #4
0
    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);
        }
    }
Beispiel #5
0
    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]);
            }
        }
    }
Beispiel #6
0
    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);
    }
Beispiel #7
0
    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);
    }
Beispiel #8
0
    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);
    }
Beispiel #9
0
 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);
     }
 }