Ejemplo n.º 1
0
 private void CleanUsedByInScene()
 {
     if (UsedByInScene.Count > 0)
     {
         for (int i = UsedByInScene.Count - 1; i >= 0; i--)
         {
             if (!UsedByInScene[i])
             {
                 UsedByInScene.RemoveAt(i);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void OnGUI()
        {
            if (m_Targets == null || m_Targets.Length == 0)
            {
                return;
            }

            float width       = AssetUsageWindow.Instance.position.width - 10;
            int   columns     = Mathf.Clamp((int)(width / 100), 1, m_Targets.Length);
            float columnWidth = (width + 8) / columns;

            GUILayout.Label(m_Guids.Length != 1 ? "Selected Assets x" + m_Guids.Length.ToString("N0") : "Selected Asset", EditorStyles.boldLabel);

            GUILayout.BeginHorizontal();

            for (int i = 0; i < Targets.Length; i++)
            {
                Object target = Targets[i];
                Object obj    = EditorGUILayout.ObjectField(target, typeof(Object), false, GUILayout.Width(columnWidth - 4));

                if (obj != target)
                {
                    Object[] copy = Targets.ToArray();
                    copy[i]           = obj;
                    Selection.objects = copy;
                }

                if (i % columns == columns - 1)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
            }

            GUILayout.EndHorizontal();

            if (m_Guids.Length == 0)
            {
                GUILayout.Label("Nothing selected.", EditorStyles.boldLabel);
                return;
            }

            if (m_Guids.Length > 997)
            {
                GUILayout.Label("Too many file IDs selected. (" + m_Guids.Length.ToString("N0") + "/900 max)", EditorStyles.boldLabel);
                return;
            }

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(GUILayout.Width(width / 2));

            GUILayout.Label("Referenced by " + UsedBy.Count.ToString("N0") + (UsedBy.Count != 1 ? " assets:" : " asset:"));
            m_UsedByScroll = GUILayout.BeginScrollView(m_UsedByScroll, GUIStyle.none);
            UsedBy.ForEach(OnAssetButtonGUI);

            CleanUsedByInScene();

            if (UsedByInScene.Count > 0)
            {
                EditorGUILayout.Space();
                GUILayout.Label("References in Hierarchy:");
                UsedByInScene.ForEach(OnHierarchyObjectButtonGUI);
            }

            GUILayout.EndScrollView();

            if (GUILayout.Button("Select all"))
            {
                Object[] selection = new Object[UsedBy.Count];

                for (int index = 0; index < selection.Length; index++)
                {
                    selection[index] = AssetDatabase.LoadAssetAtPath <Object>(UsedBy[index].Path);
                }

                Selection.objects = selection;
                EditorGUIUtility.PingObject(Selection.activeObject);
            }

            GUILayout.EndVertical();

            GUILayout.BeginVertical(GUILayout.Width(width / 2));
            GUILayout.Label("Referencing " + Using.Count.ToString("N0") + (Using.Count != 1 ? " assets:" : " asset:"));
            m_UsesScroll = GUILayout.BeginScrollView(m_UsesScroll, GUIStyle.none);
            Using.ForEach(OnAssetButtonGUI);
            GUILayout.EndScrollView();

            if (GUILayout.Button("Select all"))
            {
                Object[] selection = new Object[Using.Count];

                for (int index = 0; index < selection.Length; index++)
                {
                    selection[index] = AssetDatabase.LoadAssetAtPath <Object>(Using[index].Path);
                }

                Selection.objects = selection;
                EditorGUIUtility.PingObject(Selection.activeObject);
            }
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }