public void onSelectChange(SpriteAtlasManagerWindow.AtlasListView view, SpriteAtlasData data, SpriteAtlasData.SpriteInfo si, Sprite s) { if (s == null && si != null) { s = si.packed; } string key = GetSpriteKey(s); List <SpriteReferenceInfo.GameObjectInfo> list; if (refInfo.TryGetValue(key, out list)) { m_refList.refs = list; } else { m_refList.refs = new List <SpriteReferenceInfo.GameObjectInfo>(); } m_refList.Reload(); m_refList.ExpandAll(); return; }
void OnGUI() { List <GameObject> newObjectList = new List <GameObject>(); bool pack = false; bool reload = false; bool update_sprite = false; if (m_AssetList == null) { m_AssetList = new SpriteAtlasManagerWindow.AtlasListView(this); m_AssetList.select_origin_with_pack = true; m_AssetList.multiSelectEnable = true; ReloadTreeView(); } /* * if (m_ReferenceListView == null) { * m_ReferenceListView = new ReferenceListView(); * m_ReferenceListView.refs = single_sprites; * } */ if (m_refList == null) { m_refList = new SpriteAtlasManagerWindow.ReferenceListView(); m_refList.Reload(); } GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { targetTexture = (Texture2D)EditorGUILayout.ObjectField(targetTexture, typeof(Texture2D), false); if (GUILayout.Button("Reload")) { reload = true; } if (GUILayout.Button("Update Atlas")) { pack = true; } if (GUILayout.Button("Update Sprite")) { update_sprite = true; } if (GUILayout.Toggle(__debug, "debug") != __debug) { __debug = !__debug; Reload(); } } GUILayout.EndHorizontal(); GUILayout.Space(20); GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); for (int i = 0; i < targetGameObjects.Count; i++) { newObjectList.Add((GameObject)EditorGUILayout.ObjectField(targetGameObjects[i], typeof(GameObject), true)); } GameObject obj = (GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), true); if (obj != null) { newObjectList.Add(obj); } GUILayout.EndVertical(); GUILayout.Space(position.width - 120); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); Rect r = new Rect( 150, 40, (position.width - 150) / 2, (position.height - 40)); m_AssetList.OnGUI(r); /* * Rect s = r; * s.y = s.yMax; * m_ReferenceListView.OnGUI(s); * r.height = position.height - 40; */ r.x = r.xMax + 10; m_refList.OnGUI(r); bool changed = false; for (int i = 0; i < newObjectList.Count; i++) { if (i < targetGameObjects.Count) { if (newObjectList[i] != targetGameObjects[i]) { if (newObjectList[i] != null) { if (!targetGameObjects.Contains(newObjectList[i])) { ScanGameObject(newObjectList[i]); } } changed = true; } targetGameObjects[i] = newObjectList[i]; } else if (newObjectList[i] != null) { targetGameObjects.Add(newObjectList[i]); ScanGameObject(newObjectList[i]); changed = true; } } if (changed) { ReloadTreeView(); } else if (pack) { List <SpriteAtlasData> data = m_AssetList.GetSpriteAtlasDatasList(); List <SpriteAtlasData.SpriteInfo> list = new List <SpriteAtlasData.SpriteInfo>(); foreach (var d in data) { list.AddRange(d.sprites); } Pack(list.ToArray(), targetTexture); } else if (reload) { Reload(); } if (update_sprite) { List <SpriteAtlasData> data = m_AssetList.GetSpriteAtlasDatasList(); foreach (GameObject o in targetGameObjects) { if (o != null) { foreach (SpriteAtlasData d in data) { foreach (SpriteAtlasData.SpriteInfo info in d.sprites) { if (info.packed != null && info.origin != null && info.origin != info.packed) { SpriteReferenceInfo.ScanGameObject(o, (c, p) => SpriteReferenceInfo.ReplaceSprite(c, info.origin, info.packed)); } } } EditorUtility.SetDirty(o); } } Reload(); } }