This commit is contained in:
admin committed 2026-07-03 10:12:02 +02:00
1 parent 26f2a00726
commit f8b6524515
39 files changed
+16974

No files matched your search

File diff suppressed because it is too large. Load diff
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a01905a4456bdae4ab3f6c123fd56003
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b7595d854267e4647b870b897feaa766
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7f1ed5d1134de134a9e052ef368e3a84
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+298
View File
@@ -0,0 +1,298 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class AssetType
{
// ------------------------------- STATIC -----------------------------
internal static readonly AssetType[] FILTERS =
{
new AssetType("Scene", ".unity"),
new AssetType("Prefab", ".prefab"),
new AssetType("Model", ".3df", ".3dm", ".3dmf", ".3dv", ".3dx", ".c5d", ".lwo", ".lws", ".ma", ".mb",
".mesh", ".vrl", ".wrl", ".wrz", ".fbx", ".dae", ".3ds", ".dxf", ".obj", ".skp", ".max", ".blend"),
new AssetType("Material", ".mat", ".cubemap", ".physicsmaterial"),
new AssetType("Texture", ".ai", ".apng", ".png", ".bmp", ".cdr", ".dib", ".eps", ".exif", ".ico", ".icon",
".j", ".j2c", ".j2k", ".jas", ".jiff", ".jng", ".jp2", ".jpc", ".jpe", ".jpeg", ".jpf", ".jpg", "jpw",
"jpx", "jtf", ".mac", ".omf", ".qif", ".qti", "qtif", ".tex", ".tfw", ".tga", ".tif", ".tiff", ".wmf",
".psd", ".exr", ".rendertexture"),
new AssetType("Video", ".asf", ".asx", ".avi", ".dat", ".divx", ".dvx", ".mlv", ".m2l", ".m2t", ".m2ts",
".m2v", ".m4e", ".m4v", "mjp", ".mov", ".movie", ".mp21", ".mp4", ".mpe", ".mpeg", ".mpg", ".mpv2",
".ogm", ".qt", ".rm", ".rmvb", ".wmv", ".xvid", ".flv"),
new AssetType("Audio", ".mp3", ".wav", ".ogg", ".aif", ".aiff", ".mod", ".it", ".s3m", ".xm"),
new AssetType("Script", ".cs", ".js", ".boo", ".h"),
new AssetType("Text", ".txt", ".json", ".xml", ".bytes", ".sql"),
new AssetType("Shader", ".shader", ".cginc"),
new AssetType("Animation", ".anim", ".controller", ".overridecontroller", ".mask"),
new AssetType("Unity Asset", ".asset", ".guiskin", ".flare", ".fontsettings", ".prefs"),
new AssetType("Others") //
};
private static FR2_Ignore _ignore;
public HashSet<string> extension;
public string name;
public AssetType(string name, params string[] exts)
{
this.name = name;
extension = new HashSet<string>();
for (var i = 0; i < exts.Length; i++)
{
extension.Add(exts[i]);
}
}
private static FR2_Ignore ignore
{
get
{
if (_ignore == null)
{
_ignore = new FR2_Ignore();
}
return _ignore;
}
}
public static int GetIndex(string ext)
{
for (var i = 0; i < FILTERS.Length - 1; i++)
{
if (FILTERS[i].extension.Contains(ext))
{
return i;
}
}
return FILTERS.Length - 1; //Others
}
public static bool DrawSearchFilter()
{
int n = FILTERS.Length;
var nCols = 4;
int nRows = Mathf.CeilToInt(n / (float) nCols);
var result = false;
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
{
if (GUILayout.Button("All", EditorStyles.toolbarButton) && !FR2_Setting.IsIncludeAllType())
{
FR2_Setting.IncludeAllType();
result = true;
}
if (GUILayout.Button("None", EditorStyles.toolbarButton) && FR2_Setting.GetExcludeType() != -1)
{
FR2_Setting.ExcludeAllType();
result = true;
}
}
EditorGUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
for (var i = 0; i < nCols; i++)
{
GUILayout.BeginVertical();
for (var j = 0; j < nRows; j++)
{
int idx = i * nCols + j;
if (idx >= n)
{
break;
}
bool s = !FR2_Setting.IsTypeExcluded(idx);
bool s1 = GUILayout.Toggle(s, FILTERS[idx].name);
if (s1 != s)
{
result = true;
FR2_Setting.ToggleTypeExclude(idx);
}
}
GUILayout.EndVertical();
if ((i + 1) * nCols >= n)
{
break;
}
}
GUILayout.EndHorizontal();
return result;
}
public static void SetDirtyIgnore()
{
ignore.SetDirty();
}
public static bool DrawIgnoreFolder()
{
var change = false;
ignore.Draw();
// FR2_Helper.GuiLine();
// List<string> lst = FR2_Setting.IgnoreFolder.ToList();
// bool change = false;
// pos = EditorGUILayout.BeginScrollView(pos);
// for(int i =0; i < lst.Count; i++)
// {
// GUILayout.BeginHorizontal();
// {
// if(GUILayout.Button("X", GUILayout.Width(30)))
// {
// change = true;
// FR2_Setting.RemoveIgnore(lst[i]);
// }
// GUILayout.Label(lst[i]);
// }GUILayout.EndHorizontal();
// }
// EditorGUILayout.EndScrollView();
return change;
}
private class FR2_Ignore
{
public readonly FR2_TreeUI2.GroupDrawer groupIgnore;
private bool dirty;
private Dictionary<string, FR2_Ref> refs;
public FR2_Ignore()
{
groupIgnore = new FR2_TreeUI2.GroupDrawer(DrawGroup, DrawItem);
ApplyFiter();
}
private void DrawItem(Rect r, string guid)
{
FR2_Ref rf;
if (!refs.TryGetValue(guid, out rf))
{
return;
}
if (rf.depth == 1) //mode != Mode.Dependency &&
{
Color c = GUI.color;
GUI.color = Color.blue;
GUI.DrawTexture(new Rect(r.x - 4f, r.y + 2f, 2f, 2f), EditorGUIUtility.whiteTexture);
GUI.color = c;
}
rf.asset.Draw(r, false, FR2_Setting.GroupMode != FR2_RefDrawer.Mode.Folder, null);
Rect drawR = r;
drawR.x = drawR.x + drawR.width - 50f; // (groupDrawer.TreeNoScroll() ? 60f : 70f) ;
drawR.width = 30;
drawR.y += 1;
drawR.height -= 2;
if (GUI.Button(drawR, "X", EditorStyles.miniButton))
{
FR2_Setting.RemoveIgnore(rf.asset.assetPath);
}
}
private void DrawGroup(Rect r, string id, int childCound)
{
GUI.Label(r, id, EditorStyles.boldLabel);
if (childCound <= 1)
{
return;
}
Rect drawR = r;
drawR.x = drawR.x + drawR.width - 50f; // (groupDrawer.TreeNoScroll() ? 60f : 70f) ;
drawR.width = 30;
drawR.y += 1;
drawR.height -= 2;
if (GUI.Button(drawR, "*X", EditorStyles.miniButton))
{
List<FR2_Ref> lst = refs.Values.Where(x => x.group == id).ToList();
for (var i = 0; i < lst.Count; i++)
{
FR2_Setting.RemoveIgnore(lst[i].asset.assetPath);
}
}
}
public void SetDirty()
{
dirty = true;
}
//private float sizeRatio {
// get{
// if(FR2_Window.window != null)
// return FR2_Window.window.sizeRatio;
// return .3f;
// }
//}
public void Draw()
{
if (dirty)
{
ApplyFiter();
}
if (refs == null)
{
return;
}
// Rect rect = FR2_Window.window == null ? new Rect(): FR2_Window.window.GetBotPanelRect();
// GUILayout.BeginArea(rect);
groupIgnore.Draw();
// GUILayout.EndArea();
}
private void ApplyFiter()
{
dirty = false;
refs = new Dictionary<string, FR2_Ref>();
foreach (KeyValuePair<string, List<string>> item in FR2_Setting.IgnoreFiltered)
foreach (string item2 in item.Value)
{
string guid = AssetDatabase.AssetPathToGUID(item2);
if (string.IsNullOrEmpty(guid))
{
continue;
}
FR2_Asset asset = FR2_Cache.Api.Get(guid, true);
var r = new FR2_Ref(0, 0, asset, null, item.Key);
refs.Add(guid, r);
}
groupIgnore.Reset
(
refs.Values.ToList(),
rf => rf.asset != null ? rf.asset.guid : "",
GetGroup,
SortGroup
);
}
private string GetGroup(FR2_Ref rf)
{
return rf.group;
}
private void SortGroup(List<string> groups) { }
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: af50e16ff6b530b4b808183a3ae0722b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 933e0cc22e789714c87e348a699023d7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,46 @@
using UnityEditor;
using UnityEngine;
using vietlabs.fr2;
[CustomEditor(typeof(FR2_Cache))]
internal class FR2_CacheEditor : Editor
{
private static string inspectGUID;
private static int index;
public override void OnInspectorGUI()
{
var c = (FR2_Cache) target;
GUILayout.Label("Total : " + c.AssetList.Count);
c.priority = EditorGUILayout.IntSlider("Priority", c.priority, 0, 5);
Object s = Selection.activeObject;
if (s == null)
{
return;
}
string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(s));
if (inspectGUID != guid)
{
inspectGUID = guid;
index = c.AssetList.FindIndex(item => item.guid == guid);
}
if (index != -1)
{
if (index >= c.AssetList.Count)
{
index = 0;
}
serializedObject.Update();
SerializedProperty prop = serializedObject.FindProperty("AssetList").GetArrayElementAtIndex(index);
EditorGUILayout.PropertyField(prop, true);
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f9b9c04ea6b703343b8aff08a26cf9aa
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+912
View File
@@ -0,0 +1,912 @@
//#define FR2_DEBUG
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
using CBParams = System.Collections.Generic.List<System.Collections.Generic.List<string>>;
using Object = UnityEngine.Object;
namespace vietlabs.fr2
{
//internal class FR2_DuplicateAsset : FR2_TreeItemUI
//{
// public FR2_Asset asset;
// public FR2_DuplicateAsset(FR2_Asset asset)
// {
// this.asset = asset;
// }
// protected override void Draw(Rect r)
// {
// var drawR = r;
// drawR.xMin -= 16f;
// asset.Draw(drawR, false, true, window);
// var bRect = r;
// bRect.xMin += bRect.width - 50f;
// if (GUI.Button(bRect, "Use", EditorStyles.miniButton))
// {
// EditorGUIUtility.systemCopyBuffer = asset.guid;
// Debug.Log("guid: " + asset.guid + " systemCopyBuffer " + EditorGUIUtility.systemCopyBuffer);
// Selection.objects = (parent as FR2_DuplicateFolder).children.Select(
// a => FR2_Unity.LoadAssetAtPath<Object>(((FR2_DuplicateAsset) a).asset.assetPath)
// ).ToArray();
// FR2_Export.MergeDuplicate();
// }
// //if (GUI.Button(bRect, "Remove Others", EditorStyles.miniButton))
// //{
// // EditorGUIUtility.systemCopyBuffer = asset.guid;
// // Selection.objects = (parent as FR2_DuplicateFolder).children.Select(
// // a => FR2_Unity.LoadAssetAtPath<Object>(((FR2_DuplicateAsset)a).asset.assetPath)
// // ).ToArray();
// // FR2_Export.MergeDuplicate();
// //}
// }
//}
//internal class FR2_DuplicateFolder : FR2_TreeItemUI
//{
// private static FR2_FileCompare comparer;
// public string assetPath;
// public string count;
// public string filesize;
// public string label;
// public FR2_DuplicateFolder(List<string> list)
// {
// list.Sort((item1, item2) => { return item1.CompareTo(item2); });
// var first = true;
// for (var i = 0; i < list.Count; i++)
// {
// var item = list[i];
// var asset = FR2_Cache.Api.Get(AssetDatabase.AssetPathToGUID(item));
// if (asset == null)
// {
// Debug.LogWarning("Something wrong, asset not found <" + item + ">");
// continue;
// }
// if (first)
// {
// first = false;
// label = asset.assetName;
// count = list.Count.ToString();
// filesize = GetfileSizeString(asset.fileSize);
// assetPath = item;
// }
// AddChild(new FR2_DuplicateAsset(asset));
// }
// }
// private string GetfileSizeString(long fileSize)
// {
// return fileSize <= 1024
// ? fileSize + " B"
// : fileSize <= 1024*1024
// ? Mathf.RoundToInt(fileSize/1024f) + " KB"
// : Mathf.RoundToInt(fileSize/1024f/1024f) + " MB";
// }
// protected override void Draw(Rect r)
// {
// var tex = AssetDatabase.GetCachedIcon(assetPath);
// var rect = r;
// if (tex != null)
// {
// rect.width = 16f;
// GUI.DrawTexture(rect, tex);
// }
// rect = r;
// rect.xMin += 16f;
// GUI.Label(rect, label, EditorStyles.boldLabel);
// rect = r;
// rect.xMin += rect.width - 50f;
// GUI.Label(rect, filesize, EditorStyles.miniLabel);
// rect = r;
// rect.xMin += rect.width - 70f;
// GUI.Label(rect, count, EditorStyles.miniLabel);
// rect = r;
// rect.xMin += rect.width - 70f;
// }
//}
internal class FR2_DuplicateTree2 : IRefDraw
{
private const float TimeDelayDelete = .5f;
private static readonly FR2_FileCompare fc = new FR2_FileCompare();
private readonly FR2_TreeUI2.GroupDrawer groupDrawer;
private CBParams cacheAssetList;
private bool caseSensitive;
private Dictionary<string, List<FR2_Ref>> dicIndex; //index, list
private bool dirty;
private int excludeCount;
private string guidPressDelete;
private List<FR2_Ref> list;
private Dictionary<string, FR2_Ref> refs;
public int scanExcludeByIgnoreCount;
public int scanExcludeByTypeCount;
private string searchTerm = "";
private bool showFilter;
private bool showIgnore;
private float TimePressDelete;
public FR2_DuplicateTree2(IWindow window)
{
this.window = window;
groupDrawer = new FR2_TreeUI2.GroupDrawer(DrawGroup, DrawAsset);
}
public IWindow window { get; set; }
public bool Draw()
{
if (dirty)
{
RefreshView(cacheAssetList);
}
if (fc.nChunks2 > 0 && fc.nScaned < fc.nChunks2)
{
FR2_Cache api = FR2_Cache.Api;
float w = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 70f;
api.priority = EditorGUILayout.IntSlider("Priority", api.priority, 0, 5);
EditorGUIUtility.labelWidth = w;
Rect rect = GUILayoutUtility.GetRect(1, Screen.width, 18f, 18f);
float p = fc.nScaned / (float) fc.nChunks2;
EditorGUI.ProgressBar(rect, p, string.Format("Scanning {0} / {1}", fc.nScaned, fc.nChunks2));
GUILayout.FlexibleSpace();
return true;
}
DrawHeader();
groupDrawer.Draw();
return false;
}
public int ElementCount()
{
return list == null ? 0 : list.Count;
}
private void DrawAsset(Rect r, string guid)
{
FR2_Ref rf;
if (!refs.TryGetValue(guid, out rf))
{
return;
}
if (rf.depth == 1) //mode != Mode.Dependency &&
{
Color c = GUI.color;
GUI.color = Color.blue;
GUI.DrawTexture(new Rect(r.x - 4f, r.y + 2f, 2f, 2f), EditorGUIUtility.whiteTexture);
GUI.color = c;
}
rf.asset.Draw(r, false, FR2_Setting.GroupMode != FR2_RefDrawer.Mode.Folder, window, false);
Texture tex = AssetDatabase.GetCachedIcon(rf.asset.assetPath);
if (tex == null)
{
return;
}
Rect drawR = r;
drawR.x = drawR.x + drawR.width - 60f; // (groupDrawer.TreeNoScroll() ? 60f : 70f) ;
drawR.width = 40f;
drawR.y += 1;
drawR.height -= 2;
if (GUI.Button(drawR, "Use", EditorStyles.miniButton))
{
if (FR2_Export.IsMergeProcessing)
{
Debug.LogWarning("Previous merge is processing");
}
else
{
AssetDatabase.SaveAssets();
EditorGUIUtility.systemCopyBuffer = rf.asset.guid;
EditorGUIUtility.systemCopyBuffer = rf.asset.guid;
// Debug.Log("guid: " + rf.asset.guid + " systemCopyBuffer " + EditorGUIUtility.systemCopyBuffer);
int index = rf.index;
Selection.objects = list.Where(x => x.index == index)
.Select(x => FR2_Unity.LoadAssetAtPath<Object>(x.asset.assetPath)).ToArray();
FR2_Export.MergeDuplicate();
}
}
if (rf.asset.UsageCount() > 0)
{
return;
}
drawR.x -= 25;
drawR.width = 20;
if (wasPreDelete(guid))
{
Color col = GUI.color;
GUI.color = Color.red;
if (GUI.Button(drawR, "X", EditorStyles.miniButton))
{
guidPressDelete = null;
AssetDatabase.DeleteAsset(rf.asset.assetPath);
}
GUI.color = col;
window.WillRepaint = true;
}
else
{
if (GUI.Button(drawR, "X", EditorStyles.miniButton))
{
guidPressDelete = guid;
TimePressDelete = Time.realtimeSinceStartup;
window.WillRepaint = true;
}
}
}
private bool wasPreDelete(string guid)
{
if (guidPressDelete == null || guid != guidPressDelete)
{
return false;
}
if (Time.realtimeSinceStartup - TimePressDelete < TimeDelayDelete)
{
return true;
}
guidPressDelete = null;
return false;
}
private void DrawGroup(Rect r, string label, int childCount)
{
// GUI.Label(r, label + " (" + childCount + ")", EditorStyles.boldLabel);
FR2_Asset asset = dicIndex[label][0].asset;
Texture tex = AssetDatabase.GetCachedIcon(asset.assetPath);
Rect rect = r;
if (tex != null)
{
rect.width = 16f;
GUI.DrawTexture(rect, tex);
}
rect = r;
rect.xMin += 16f;
GUI.Label(rect, asset.assetName, EditorStyles.boldLabel);
rect = r;
rect.xMin += rect.width - 50f;
GUI.Label(rect, FR2_Helper.GetfileSizeString(asset.fileSize), EditorStyles.miniLabel);
rect = r;
rect.xMin += rect.width - 70f;
GUI.Label(rect, childCount.ToString(), EditorStyles.miniLabel);
rect = r;
rect.xMin += rect.width - 70f;
}
// private List<FR2_DuplicateFolder> duplicated;
public void Reset(CBParams assetList)
{
fc.Reset(assetList, OnUpdateView, RefreshView);
}
private void OnUpdateView(CBParams assetList) { }
public bool isExclueAnyItem()
{
return excludeCount > 0 || scanExcludeByTypeCount > 0;
}
public bool isExclueAnyItemByIgnoreFolder()
{
return scanExcludeByIgnoreCount > 0;
}
// void OnActive
private void RefreshView(CBParams assetList)
{
cacheAssetList = assetList;
dirty = false;
list = new List<FR2_Ref>();
refs = new Dictionary<string, FR2_Ref>();
dicIndex = new Dictionary<string, List<FR2_Ref>>();
if (assetList == null)
{
return;
}
int minScore = searchTerm.Length;
string term1 = searchTerm;
if (!caseSensitive)
{
term1 = term1.ToLower();
}
string term2 = term1.Replace(" ", string.Empty);
excludeCount = 0;
for (var i = 0; i < assetList.Count; i++)
{
var lst = new List<FR2_Ref>();
for (var j = 0; j < assetList[i].Count; j++)
{
string guid = AssetDatabase.AssetPathToGUID(assetList[i][j]);
if (string.IsNullOrEmpty(guid))
{
continue;
}
if (refs.ContainsKey(guid))
{
continue;
}
FR2_Asset asset = FR2_Cache.Api.Get(guid);
if (asset == null)
{
continue;
}
var fr2 = new FR2_Ref(i, 0, asset, null);
if (FR2_Setting.IsTypeExcluded(fr2.type))
{
excludeCount++;
continue; //skip this one
}
if (string.IsNullOrEmpty(searchTerm))
{
fr2.matchingScore = 0;
list.Add(fr2);
lst.Add(fr2);
refs.Add(guid, fr2);
continue;
}
//calculate matching score
string name1 = fr2.asset.assetName;
if (!caseSensitive)
{
name1 = name1.ToLower();
}
string name2 = name1.Replace(" ", string.Empty);
int score1 = FR2_Unity.StringMatch(term1, name1);
int score2 = FR2_Unity.StringMatch(term2, name2);
fr2.matchingScore = Mathf.Max(score1, score2);
if (fr2.matchingScore > minScore)
{
list.Add(fr2);
lst.Add(fr2);
refs.Add(guid, fr2);
}
}
dicIndex.Add(i.ToString(), lst);
}
ResetGroup();
}
private void ResetGroup()
{
//folderDrawer.GroupByAssetType(list);
groupDrawer.Reset(list,
rf => rf.asset.guid
, GetGroup, SortGroup);
if (window != null)
{
window.Repaint();
}
}
private string GetGroup(FR2_Ref rf)
{
return rf.index.ToString();
}
private void SortGroup(List<string> groups)
{
// groups.Sort( (item1, item2) =>
// {
// if (item1 == "Others" || item2 == "Selection") return 1;
// if (item2 == "Others" || item1 == "Selection") return -1;
// return item1.CompareTo(item2);
// });
}
public void SetDirty()
{
dirty = true;
}
public void RefreshSort() { }
private void DrawHeader()
{
//draw filter
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
{
DrawSearch();
GUILayout.Space(5);
Color col = GUI.color;
GUI.color = FR2_Cache.Api.setting.ScanColor;
if (GUILayout.Button("Scan", EditorStyles.toolbarButton, GUILayout.Width(60)))
{
FR2_Cache.onReady -= OnCacheReady;
FR2_Cache.onReady += OnCacheReady;
FR2_Cache.Api.Check4Changes(true, true);
}
GUI.color = col;
}
EditorGUILayout.EndHorizontal();
}
private void OnCacheReady()
{
scanExcludeByTypeCount = 0;
Reset(FR2_Cache.Api.ScanSimilar(IgnoreTypeWhenScan, IgnoreFolderWhenScan));
FR2_Cache.onReady -= OnCacheReady;
}
private void IgnoreTypeWhenScan()
{
scanExcludeByTypeCount++;
}
private void IgnoreFolderWhenScan()
{
scanExcludeByIgnoreCount++;
}
private void DrawSearch(string searchLable = "")
{
if (FR2_RefDrawer.toolbarSearchField == null)
{
FR2_RefDrawer.InitSearchStyle();
}
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
bool v = GUILayout.Toggle(caseSensitive, "Aa", EditorStyles.toolbarButton, GUILayout.Width(24f));
if (v != caseSensitive)
{
caseSensitive = v;
dirty = true;
}
GUILayout.Space(2f);
string value = GUILayout.TextField(searchTerm, FR2_RefDrawer.toolbarSearchField);
if (searchTerm != value)
{
searchTerm = value;
dirty = true;
}
GUIStyle style = string.IsNullOrEmpty(searchTerm)
? FR2_RefDrawer.toolbarSearchFieldCancelButtonEmpty
: FR2_RefDrawer.toolbarSearchFieldCancelButton;
if (GUILayout.Button("Cancel", style))
{
searchTerm = string.Empty;
dirty = true;
}
GUILayout.Space(2f);
}
GUILayout.EndHorizontal();
}
}
internal class FR2_FileCompare
{
public static HashSet<FR2_Chunk> HashChunksNotComplete;
internal static int streamClosedCount;
private CBParams cacheList;
public List<FR2_Head> deads = new List<FR2_Head>();
public List<FR2_Head> heads = new List<FR2_Head>();
public int nChunks;
public int nChunks2;
public int nScaned;
public Action<CBParams> OnCompareComplete;
public Action<CBParams> OnCompareUpdate;
private int streamCount;
public void Reset(CBParams list, Action<CBParams> onUpdate, Action<CBParams> onComplete)
{
nChunks = 0;
nScaned = 0;
nChunks2 = 0;
streamCount = streamClosedCount = 0;
HashChunksNotComplete = new HashSet<FR2_Chunk>();
if (heads.Count > 0)
{
for (var i = 0; i < heads.Count; i++)
{
heads[i].CloseChunk();
}
}
deads.Clear();
heads.Clear();
OnCompareUpdate = onUpdate;
OnCompareComplete = onComplete;
if (list.Count <= 0)
{
OnCompareComplete(new CBParams());
return;
}
cacheList = list;
for (var i = 0; i < list.Count; i++)
{
var file = new FileInfo(list[i][0]);
int nChunk = Mathf.CeilToInt(file.Length / (float) FR2_Head.chunkSize);
nChunks2 += nChunk;
}
// for(int i =0;i< list.Count;i++)
// {
// AddHead(list[i]);
// }
AddHead(cacheList[cacheList.Count - 1]);
cacheList.RemoveAt(cacheList.Count - 1);
EditorApplication.update -= ReadChunkAsync;
EditorApplication.update += ReadChunkAsync;
}
public FR2_FileCompare AddHead(List<string> files)
{
if (files.Count < 2)
{
Debug.LogWarning("Something wrong ! head should not contains < 2 elements");
}
var chunkList = new List<FR2_Chunk>();
for (var i = 0; i < files.Count; i++)
{
streamCount++;
// Debug.Log("new stream " + files[i]);
chunkList.Add(new FR2_Chunk
{
file = files[i],
stream = new FileStream(files[i], FileMode.Open, FileAccess.Read),
buffer = new byte[FR2_Head.chunkSize]
});
}
var file = new FileInfo(files[0]);
int nChunk = Mathf.CeilToInt(file.Length / (float) FR2_Head.chunkSize);
heads.Add(new FR2_Head
{
fileSize = file.Length,
currentChunk = 0,
nChunk = nChunk,
chunkList = chunkList
});
nChunks += nChunk;
return this;
}
private bool checkCompleteAllCurFile()
{
return streamClosedCount + HashChunksNotComplete.Count >= streamCount; //-1 for safe
}
private void ReadChunkAsync()
{
bool alive = ReadChunk();
HashChunksNotComplete.RemoveWhere(x => x.stream == null || !x.stream.CanRead);
if (cacheList.Count > 0 && checkCompleteAllCurFile()) //complete all chunk
{
int numCall = FR2_Cache.Api.priority; // - 2;
if (numCall <= 0)
{
numCall = 1;
}
for (var i = 0; i < numCall; i++)
{
if (cacheList.Count <= 0)
{
break;
}
AddHead(cacheList[cacheList.Count - 1]);
cacheList.RemoveAt(cacheList.Count - 1);
}
}
var update = false;
for (int i = heads.Count - 1; i >= 0; i--)
{
FR2_Head h = heads[i];
if (h.isDead)
{
h.CloseChunk();
heads.RemoveAt(i);
if (h.chunkList.Count > 1)
{
update = true;
deads.Add(h);
}
}
}
if (update)
{
Trigger(OnCompareUpdate);
}
if (!alive && cacheList.Count <= 0 && checkCompleteAllCurFile()
) //&& cacheList.Count <= 0 complete all chunk and cache list empty
{
foreach (FR2_Chunk item in HashChunksNotComplete)
{
if (item.stream != null && item.stream.CanRead)
{
item.stream.Close();
item.stream = null;
}
}
HashChunksNotComplete.Clear();
// Debug.Log("complete ");
nScaned = nChunks;
EditorApplication.update -= ReadChunkAsync;
Trigger(OnCompareComplete);
}
}
private void Trigger(Action<CBParams> cb)
{
if (cb == null)
{
return;
}
CBParams list = deads.Select(item => item.GetFiles()).ToList();
//#if FR2_DEBUG
// Debug.Log("Callback ! " + deads.Count + ":" + heads.Count);
//#endif
cb(list);
}
private bool ReadChunk()
{
var alive = false;
for (var i = 0; i < heads.Count; i++)
{
FR2_Head h = heads[i];
if (h.isDead)
{
Debug.LogWarning("Should never be here : " + h.chunkList[0].file);
continue;
}
nScaned++;
alive = true;
h.ReadChunk();
h.CompareChunk(heads);
break;
}
//if (!alive) return false;
//alive = false;
//for (var i = 0; i < heads.Count; i++)
//{
// var h = heads[i];
// if (h.isDead) continue;
// h.CompareChunk(heads);
// alive |= !h.isDead;
//}
return alive;
}
}
internal class FR2_Head
{
public const int chunkSize = 10240;
public List<FR2_Chunk> chunkList;
public int currentChunk;
public long fileSize;
public int nChunk;
public int size; //last stream read size
public bool isDead
{
get { return currentChunk == nChunk || chunkList.Count == 1; }
}
public List<string> GetFiles()
{
return chunkList.Select(item => item.file).ToList();
}
public void AddToDict(byte b, FR2_Chunk chunk, Dictionary<byte, List<FR2_Chunk>> dict)
{
List<FR2_Chunk> list;
if (!dict.TryGetValue(b, out list))
{
list = new List<FR2_Chunk>();
dict.Add(b, list);
}
list.Add(chunk);
}
public void CloseChunk()
{
for (var i = 0; i < chunkList.Count; i++)
{
// Debug.Log("stream close");
FR2_FileCompare.streamClosedCount++;
chunkList[i].stream.Close();
chunkList[i].stream = null;
}
}
public void ReadChunk()
{
#if FR2_DEBUG
if (currentChunk == 0) Debug.LogWarning("Read <" + chunkList[0].file + "> " + currentChunk + ":" + nChunk);
#endif
if (currentChunk == nChunk)
{
Debug.LogWarning("Something wrong, should dead <" + isDead + ">");
return;
}
int from = currentChunk * chunkSize;
size = (int) Mathf.Min(fileSize - from, chunkSize);
for (var i = 0; i < chunkList.Count; i++)
{
FR2_Chunk chunk = chunkList[i];
chunk.size = size;
chunk.stream.Read(chunk.buffer, 0, size);
}
currentChunk++;
}
public void CompareChunk(List<FR2_Head> heads)
{
int idx = chunkList.Count;
byte[] buffer = chunkList[idx - 1].buffer;
while (--idx >= 0)
{
FR2_Chunk chunk = chunkList[idx];
int diff = FirstDifferentIndex(buffer, chunk.buffer, size);
if (diff == -1)
{
continue;
}
#if FR2_DEBUG
Debug.Log(string.Format(
" --> Different found at : idx={0} diff={1} size={2} chunk={3}",
idx, diff, size, currentChunk));
#endif
byte v = buffer[diff];
var d = new Dictionary<byte, List<FR2_Chunk>>(); //new heads
chunkList.RemoveAt(idx);
FR2_FileCompare.HashChunksNotComplete.Add(chunk);
AddToDict(chunk.buffer[diff], chunk, d);
for (int j = idx - 1; j >= 0; j--)
{
FR2_Chunk tChunk = chunkList[j];
byte tValue = tChunk.buffer[diff];
if (tValue == v)
{
continue;
}
idx--;
FR2_FileCompare.HashChunksNotComplete.Add(tChunk);
chunkList.RemoveAt(j);
AddToDict(tChunk.buffer[diff], tChunk, d);
}
foreach (KeyValuePair<byte, List<FR2_Chunk>> item in d)
{
List<FR2_Chunk> list = item.Value;
if (list.Count == 1)
{
#if FR2_DEBUG
Debug.Log(" --> Dead head found for : " + list[0].file);
#endif
}
else if (list.Count > 1) // 1 : dead head
{
#if FR2_DEBUG
Debug.Log(" --> NEW HEAD : " + list[0].file);
#endif
heads.Add(new FR2_Head
{
nChunk = nChunk,
fileSize = fileSize,
currentChunk = currentChunk - 1,
chunkList = list
});
}
}
}
}
internal static int FirstDifferentIndex(byte[] arr1, byte[] arr2, int maxIndex)
{
for (var i = 0; i < maxIndex; i++)
{
if (arr1[i] != arr2[i])
{
return i;
}
}
return -1;
}
}
internal class FR2_Chunk
{
public byte[] buffer;
public string file;
public long size;
public FileStream stream;
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d5c2f1d0a3c6acc4a9cf0d8f013f14d3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+442
View File
@@ -0,0 +1,442 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class FR2_Export
{
// private static int processIndex;
private const int maxThread = 5;
//[MenuItem("Assets/FR2/Tools/Merge Duplicates")]
private static Dictionary<string, ProcessReplaceData> listReplace;
private static List<Thread> lstThreads;
public static bool IsMergeProcessing { get; private set; }
[MenuItem("Assets/FR2/Toggle Ignore", false, 19)]
private static void Ignore()
{
Object[] actives = Selection.objects;
for (var i = 0; i < actives.Length; i++)
{
string path = AssetDatabase.GetAssetPath(actives[i]);
if (path.Equals(FR2_Cache.DEFAULT_CACHE_PATH))
{
continue;
}
if (FR2_Setting.IgnoreAsset.Contains(path))
{
FR2_Setting.RemoveIgnore(path);
}
else
{
FR2_Setting.AddIgnore(path);
}
}
}
[MenuItem("Assets/FR2/Copy GUID", false, 20)]
private static void CopyGUID()
{
EditorGUIUtility.systemCopyBuffer = AssetDatabase.AssetPathToGUID(
AssetDatabase.GetAssetPath(Selection.activeObject)
);
}
[MenuItem("Assets/FR2/Export Selection", false, 21)]
private static void ExportSelection()
{
FR2_Unity.ExportSelection();
}
[MenuItem("Assets/FR2/Select Dependencies (assets I use)", false, 22)]
private static void SelectDependencies_wtme()
{
SelectDependencies(false);
}
[MenuItem("Assets/FR2/Select Dependencies included me", false, 23)]
private static void SelectDependencies_wme()
{
SelectDependencies(true);
}
//[MenuItem("Assets/FR2/Select")]
[MenuItem("Assets/FR2/Select Used (assets used me)", false, 24)]
private static void SelectUsed_wtme()
{
SelectUsed(false);
}
[MenuItem("Assets/FR2/Select Used included me", false, 25)]
private static void SelectUsed_wme()
{
SelectUsed(true);
}
[MenuItem("Assets/FR2/Export Dependencies", false, 40)]
private static void ExportDependencies()
{
Selection.objects = GetSelectionDependencies().ToArray();
FR2_Unity.ExportSelection();
}
[MenuItem("Assets/FR2/Export Assets (no scripts)", false, 41)]
private static void ExportAsset()
{
List<Object> list = GetSelectionDependencies();
for (int i = list.Count - 1; i >= 0; i--)
{
if (list[i] is MonoScript)
{
list.RemoveAt(i);
}
}
//Debug.Log(i + ":" + list[i] + ":" + list[i].GetType());
Selection.objects = list.ToArray();
FR2_Unity.ExportSelection();
}
public static void MergeDuplicate()
{
// for (int i = 0; i < Selection.objects.Length; i++)
// {
// Object item = Selection.objects[i];
// Debug.Log(item.name);
// }
string guid = EditorGUIUtility.systemCopyBuffer;
// var wat = new System.Diagnostics.Stopwatch();
// wat.Start();
//validate clipboard guid
string gPath = AssetDatabase.GUIDToAssetPath(guid);
if (string.IsNullOrEmpty(gPath) || !gPath.StartsWith("Assets/"))
{
Debug.LogWarning("Invalid guid <" + guid + "> in clipboard, can not replace !");
return;
}
List<string> guids = FR2_Unity.Selection_AssetGUIDs.ToList();
if (!guids.Contains(guid))
{
Debug.LogWarning("Clipboard guid <" + guid +
"> not found in Selection, you may not intentionally replace selection assets by clipboard guid");
return;
}
guids.Remove(guid);
if (guids.Count == 0)
{
Debug.LogWarning("No new asset selected to replace, must select all duplications to replace");
return;
}
List<FR2_Asset> assetList = FR2_Cache.Api.FindAssets(guids.ToArray(), false);
// var dictAsset = new Dictionary<string, int>();
//replace one by one
listReplace = new Dictionary<string, ProcessReplaceData>();
lstThreads = new List<Thread>();
for (int i = assetList.Count - 1; i >= 0; i--)
{
// Debug.Log("FR2 Replace GUID : " + assetList[i].guid + " ---> " + guid + " : " + assetList[i].UsedByMap.Count + " assets updated");
string fromId = assetList[i].guid;
List<FR2_Asset> arr = assetList[i].UsedByMap.Values.ToList();
for (var j = 0; j < arr.Count; j++)
{
FR2_Asset a = arr[j];
if (!listReplace.ContainsKey(a.assetPath))
{
listReplace.Add(a.assetPath, new ProcessReplaceData());
}
listReplace[a.assetPath].datas.Add(new ReplaceData
{
from = fromId,
to = guid,
asset = a
});
}
}
foreach (KeyValuePair<string, ProcessReplaceData> item in listReplace)
{
item.Value.processIndex = item.Value.datas.Count - 1;
}
IsMergeProcessing = true;
EditorApplication.update -= ApplicationUpdate;
EditorApplication.update += ApplicationUpdate;
// for (var i = assetList.Count - 1; i >= 0; i--)
// {
// // Debug.Log("FR2 Replace GUID : " + assetList[i].guid + " ---> " + guid + " : " + assetList[i].UsedByMap.Count + " assets updated");
// var from = assetList[i].guid;
// var arr = assetList[i].UsedByMap.Values.ToList();
// for (var j = 0; j < arr.Count; j ++)
// {
// var a = arr[j];
// var result = a.ReplaceReference(from, guid);
// if (result && !dictAsset.ContainsKey(a.guid))
// {
// dictAsset.Add(a.guid, 1);
// }
// }
// }
// Debug.Log("Time replace guid " + wat.ElapsedMilliseconds);
// wat = new System.Diagnostics.Stopwatch();
// wat.Start();
// var listRefresh = dictAsset.Keys.ToList();
// for (var i = 0; i < listRefresh.Count; i++)
// {
// FR2_Cache.Api.RefreshAsset(listRefresh[i], true);
// }
// FR2_Cache.Api.RefreshSelection();
// FR2_Cache.Api.Check4Usage();
// AssetDatabase.Refresh();
// Debug.Log("Time replace guid " + wat.ElapsedMilliseconds);
}
private static void ApplicationUpdate()
{
bool notComplete = listReplace.Where(x => x.Value.processIndex >= 0).Count() > 0;
if (lstThreads.Count <= 0 && notComplete)
{
foreach (KeyValuePair<string, ProcessReplaceData> item in listReplace)
{
if (item.Value.processIndex >= 0)
{
ReplaceData a = item.Value.datas[item.Value.processIndex--];
a.isTerrian = a.asset.type == FR2_AssetType.TERRAIN;
if (a.isTerrian)
{
a.terrainData =
AssetDatabase.LoadAssetAtPath(a.asset.assetPath, typeof(Object)) as TerrainData;
}
var thread = new Thread(
delegate()
{
lock (a)
{
a.isSucess = a.asset.ReplaceReference(a.from, a.to, a.terrainData);
// Debug.Log(a.asset.assetPath+" "+ a.isSucess);
}
});
lstThreads.Add(thread);
thread.Start();
}
}
}
for (int i = lstThreads.Count - 1; i >= 0; i--)
{
if (!lstThreads[i].IsAlive)
{
lstThreads.RemoveAt(i);
}
}
foreach (KeyValuePair<string, ProcessReplaceData> item in listReplace)
{
List<ReplaceData> lst = item.Value.datas;
for (var i = 0; i < lst.Count; i++)
{
ReplaceData data = lst[i];
if (!data.isUpdated && data.isSucess)
{
data.isUpdated = true;
if (data.isTerrian)
{
EditorUtility.SetDirty(data.terrainData);
AssetDatabase.SaveAssets();
data.terrainData = null;
FR2_Unity.UnloadUnusedAssets();
}
else
{
AssetDatabase.ImportAsset(data.asset.assetPath, ImportAssetOptions.Default);
}
}
}
}
if (lstThreads.Count <= 0 && !notComplete) //complete
{
var guidsRefreshed = new HashSet<string>();
EditorApplication.update -= ApplicationUpdate;
foreach (KeyValuePair<string, ProcessReplaceData> item in listReplace)
{
List<ReplaceData> lst = item.Value.datas;
for (var i = 0; i < lst.Count; i++)
{
ReplaceData data = lst[i];
if (data.isSucess && !guidsRefreshed.Contains(data.asset.guid))
{
guidsRefreshed.Add(data.asset.guid);
FR2_Cache.Api.RefreshAsset(data.asset.guid, true);
}
}
}
lstThreads = null;
listReplace = null;
FR2_Cache.Api.RefreshSelection();
FR2_Cache.Api.Check4Usage();
// EditorUtility.SetDirty(FR2_Cache.Api);
AssetDatabase.Refresh();
IsMergeProcessing = false;
}
}
//[MenuItem("Assets/FR2/Tools/Fix Model Import Material")]
//public static void FixModelImportMaterial(){
// if (Selection.activeObject == null) return;
// CreatePrefabReplaceModel((GameObject)Selection.activeObject);
//}
//[MenuItem("GameObject/FR2/Paste Materials", false, 10)]
//public static void PasteMaterials(){
// if (Selection.activeObject == null) return;
// var r = Selection.activeGameObject.GetComponent<Renderer>();
// Undo.RecordObject(r, "Replace Materials");
// r.materials = model_materials;
// EditorUtility.SetDirty(r);
//}
//[MenuItem("GameObject/FR2/Copy Materials", false, 10)]
//public static void CopyMaterials(){
// if (Selection.activeObject == null) return;
// var r = Selection.activeGameObject.GetComponent<Renderer>();
// if (r == null) return;
// model_materials = r.sharedMaterials;
//}
//-------------------------- APIs ----------------------
private static void SelectDependencies(bool includeMe)
{
List<FR2_Asset> list = FR2_Cache.Api.FindAssets(FR2_Unity.Selection_AssetGUIDs, false);
var dict = new Dictionary<string, Object>();
if (includeMe)
{
AddToDict(dict, list.ToArray());
}
for (var i = 0; i < list.Count; i++)
{
AddToDict(dict, FR2_Asset.FindUsage(list[i]).ToArray());
}
Selection.objects = dict.Values.ToArray();
}
private static void SelectUsed(bool includeMe)
{
List<FR2_Asset> list = FR2_Cache.Api.FindAssets(FR2_Unity.Selection_AssetGUIDs, false);
var dict = new Dictionary<string, Object>();
if (includeMe)
{
AddToDict(dict, list.ToArray());
}
for (var i = 0; i < list.Count; i++)
{
AddToDict(dict, list[i].UsedByMap.Values.ToArray());
}
Selection.objects = dict.Values.ToArray();
}
//-------------------------- UTILS ---------------------
internal static void AddToDict(Dictionary<string, Object> dict, params FR2_Asset[] list)
{
for (var j = 0; j < list.Length; j++)
{
string guid = list[j].guid;
if (!dict.ContainsKey(guid))
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
dict.Add(guid, FR2_Unity.LoadAssetAtPath<Object>(assetPath));
}
}
}
private static List<Object> GetSelectionDependencies()
{
if (!FR2_Cache.isReady)
{
Debug.LogWarning("FR2 cache not yet ready, please open Window > FR2_Window !");
return null;
}
return FR2_Cache.FindUsage(FR2_Unity.Selection_AssetGUIDs).Select(
guid =>
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
return FR2_Unity.LoadAssetAtPath<Object>(assetPath);
}
).ToList();
}
private class ProcessReplaceData
{
public readonly List<ReplaceData> datas = new List<ReplaceData>();
public int processIndex;
}
private class ReplaceData
{
public FR2_Asset asset;
public string from;
public bool isSucess;
public bool isTerrian;
public bool isUpdated;
public TerrainData terrainData;
public string to;
}
// AssetDatabase.ImportAsset(oAssetPath, ImportAssetOptions.Default);
// importer.importMaterials = false;
// var importer = AssetImporter.GetAtPath(oAssetPath) as ModelImporter;
// var nModel = AssetDatabase.LoadAssetAtPath<GameObject>(oAssetPath);
// // Reimport model with importMaterial = false
// var extension = Path.GetExtension(oAssetPath);
// model_materials = model.GetComponent<Renderer>().sharedMaterials;
// var oGUID = AssetDatabase.AssetPathToGUID(oAssetPath);
// var oAssetPath = AssetDatabase.GetAssetPath(model);
// if (model == null) return;
//{
//static void CreatePrefabReplaceModel(GameObject model)
//static Material[] model_materials;
// //create prefab from new model
// var prefabPath = oAssetPath.Replace(extension, ".prefab");
// var clone = (GameObject)Object.Instantiate(nModel);
// clone.GetComponent<Renderer>().sharedMaterials = model_materials;
// PrefabUtility.CreatePrefab(prefabPath, clone, ReplacePrefabOptions.ReplaceNameBased);
// AssetDatabase.SaveAssets();
// GameObject.DestroyImmediate(clone);
//}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b543c2ce7dc56c2418505cbb6cb7852d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+211
View File
@@ -0,0 +1,211 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace vietlabs.fr2
{
public class FR2_Helper
{
internal static readonly AssetType[] FILTERS =
{
new AssetType("Scene", ".unity"),
new AssetType("Prefab", ".prefab"),
new AssetType("Model", ".3df", ".3dm", ".3dmf", ".3dv", ".3dx", ".c5d", ".lwo", ".lws", ".ma", ".mb",
".mesh", ".vrl", ".wrl", ".wrz", ".fbx", ".dae", ".3ds", ".dxf", ".obj", ".skp", ".max", ".blend"),
new AssetType("Material", ".mat", ".cubemap", ".physicsmaterial"),
new AssetType("Texture", ".ai", ".apng", ".png", ".bmp", ".cdr", ".dib", ".eps", ".exif", ".ico", ".icon",
".j", ".j2c", ".j2k", ".jas", ".jiff", ".jng", ".jp2", ".jpc", ".jpe", ".jpeg", ".jpf", ".jpg", "jpw",
"jpx", "jtf", ".mac", ".omf", ".qif", ".qti", "qtif", ".tex", ".tfw", ".tga", ".tif", ".tiff", ".wmf",
".psd", ".exr", ".rendertexture"),
new AssetType("Video", ".asf", ".asx", ".avi", ".dat", ".divx", ".dvx", ".mlv", ".m2l", ".m2t", ".m2ts",
".m2v", ".m4e", ".m4v", "mjp", ".mov", ".movie", ".mp21", ".mp4", ".mpe", ".mpeg", ".mpg", ".mpv2",
".ogm", ".qt", ".rm", ".rmvb", ".wmv", ".xvid", ".flv"),
new AssetType("Audio", ".mp3", ".wav", ".ogg", ".aif", ".aiff", ".mod", ".it", ".s3m", ".xm"),
new AssetType("Script", ".cs", ".js", ".boo"),
new AssetType("Text", ".txt", ".json", ".xml", ".bytes", ".sql"),
new AssetType("Shader", ".shader", ".cginc"),
new AssetType("Animation", ".anim", ".controller", ".overridecontroller", ".mask"),
new AssetType("Unity Asset", ".asset", ".guiskin", ".flare", ".fontsettings", ".prefs"),
new AssetType("Others") //
};
public static IEnumerable<GameObject> getAllObjsInCurScene()
{
// foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
// {
// yield return obj;
// }
for (var j = 0; j < SceneManager.sceneCount; j++)
{
Scene scene = SceneManager.GetSceneAt(j);
foreach (GameObject item in GetGameObjectsInScene(scene))
{
yield return item;
}
}
if (EditorApplication.isPlaying)
{
//dont destroy scene
GameObject temp = null;
try
{
temp = new GameObject();
Object.DontDestroyOnLoad(temp);
Scene dontDestroyOnLoad = temp.scene;
Object.DestroyImmediate(temp);
temp = null;
foreach (GameObject item in GetGameObjectsInScene(dontDestroyOnLoad))
{
yield return item;
}
}
finally
{
if (temp != null)
{
Object.DestroyImmediate(temp);
}
}
}
}
private static IEnumerable<GameObject> GetGameObjectsInScene(Scene scene)
{
var rootObjects = new List<GameObject>();
scene.GetRootGameObjects(rootObjects);
// iterate root objects and do something
for (var i = 0; i < rootObjects.Count; ++i)
{
GameObject gameObject = rootObjects[i];
foreach (GameObject item in getAllChild(gameObject))
{
yield return item;
}
yield return gameObject;
}
}
public static IEnumerable<GameObject> getAllChild(GameObject target)
{
if (target.transform.childCount > 0)
{
for (var i = 0; i < target.transform.childCount; i++)
{
yield return target.transform.GetChild(i).gameObject;
foreach (GameObject item in getAllChild(target.transform.GetChild(i).gameObject))
{
yield return item;
}
}
}
}
public static IEnumerable<Object> GetAllRefObjects(GameObject obj)
{
Component[] components = obj.GetComponents<Component>();
foreach (Component com in components)
{
if (com == null)
{
continue;
}
var serialized = new SerializedObject(com);
SerializedProperty it = serialized.GetIterator().Copy();
while (it.NextVisible(true))
{
if (it.propertyType != SerializedPropertyType.ObjectReference)
{
continue;
}
if (it.objectReferenceValue == null)
{
continue;
}
yield return it.objectReferenceValue;
}
}
}
public static int StringMatch(string pattern, string input)
{
if (input == pattern)
{
return int.MaxValue;
}
if (input.Contains(pattern))
{
return int.MaxValue - 1;
}
var pidx = 0;
var score = 0;
var tokenScore = 0;
for (var i = 0; i < input.Length; i++)
{
char ch = input[i];
if (ch == pattern[pidx])
{
tokenScore += tokenScore + 1; //increasing score for continuos token
pidx++;
if (pidx >= pattern.Length)
{
break;
}
}
else
{
tokenScore = 0;
}
score += tokenScore;
}
return score;
}
public static int GetIndex(string ext)
{
for (var i = 0; i < FILTERS.Length - 1; i++)
{
if (FILTERS[i].extension.Contains(ext))
{
return i;
}
}
return FILTERS.Length - 1; //Others
}
public static void GuiLine(int i_height = 1)
{
Rect rect = EditorGUILayout.GetControlRect(false, i_height);
rect.height = i_height;
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 1));
}
public static string GetfileSizeString(long fileSize)
{
return fileSize <= 1024
? fileSize + " B"
: fileSize <= 1024 * 1024
? Mathf.RoundToInt(fileSize / 1024f) + " KB"
: Mathf.RoundToInt(fileSize / 1024f / 1024f) + " MB";
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3ba0d9bfe79ff94ca52a3bd6b6870d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
+10
View File
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6db5b6c2e2bbb4f2093a7cd892ececca
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+384
View File
@@ -0,0 +1,384 @@
#if UNITY_2018_3_OR_NEWER
#define SUPPORT_NESTED_PREFAB
#endif
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_2017_1_OR_NEWER
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
#endif
#if SUPPORT_NESTED_PREFAB
using UnityEditor.Experimental.SceneManagement;
#endif
namespace vietlabs.fr2
{
public class FR2_SceneCache
{
private static FR2_SceneCache _api;
public static Action onReady;
public static bool ready = true;
private Dictionary<Component, HashSet<HashValue>> _cache = new Dictionary<Component, HashSet<HashValue>>();
public int current;
public Dictionary<string, HashSet<Component>> folderCache = new Dictionary<string, HashSet<Component>>();
private List<GameObject> listGO;
//public HashSet<string> prefabDependencies = new HashSet<string>();
public Dictionary<GameObject, HashSet<string>> prefabDependencies =
new Dictionary<GameObject, HashSet<string>>();
public int total;
private IWindow window;
public FR2_SceneCache()
{
#if UNITY_2018_1_OR_NEWER
EditorApplication.hierarchyChanged -= OnSceneChanged;
EditorApplication.hierarchyChanged += OnSceneChanged;
#else
EditorApplication.hierarchyWindowChanged -= OnSceneChanged;
EditorApplication.hierarchyWindowChanged += OnSceneChanged;
#endif
#if UNITY_2018_2_OR_NEWER
EditorSceneManager.activeSceneChangedInEditMode -= OnSceneChanged;
EditorSceneManager.activeSceneChangedInEditMode += OnSceneChanged;
#endif
#if UNITY_2017_1_OR_NEWER
SceneManager.activeSceneChanged -= OnSceneChanged;
SceneManager.activeSceneChanged += OnSceneChanged;
SceneManager.sceneLoaded -= OnSceneChanged;
SceneManager.sceneLoaded += OnSceneChanged;
Undo.postprocessModifications -= OnModify;
Undo.postprocessModifications += OnModify;
#endif
#if SUPPORT_NESTED_PREFAB
PrefabStage.prefabStageOpened -= prefabOnpen;
PrefabStage.prefabStageClosing += prefabClose;
PrefabStage.prefabStageOpened -= prefabOnpen;
PrefabStage.prefabStageClosing += prefabClose;
#endif
}
public static FR2_SceneCache Api
{
get
{
if (_api == null)
{
_api = new FR2_SceneCache();
}
return _api;
}
}
public bool Dirty { get; private set; } = true;
public Dictionary<Component, HashSet<HashValue>> cache
{
get
{
if (_cache == null)
{
refreshCache(window);
}
return _cache;
}
}
public void refreshCache(IWindow window)
{
if (window == null)
{
return;
}
// if(!ready) return;
this.window = window;
_cache = new Dictionary<Component, HashSet<HashValue>>();
folderCache = new Dictionary<string, HashSet<Component>>();
prefabDependencies = new Dictionary<GameObject, HashSet<string>>();
ready = false;
List<GameObject> listRootGO = null;
#if SUPPORT_NESTED_PREFAB
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
{
GameObject rootPrefab = PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot;
if (rootPrefab != null)
{
listRootGO = new List<GameObject> {rootPrefab};
}
}
#else
#endif
if (listRootGO == null)
{
listGO = FR2_Unity.getAllObjsInCurScene().ToList();
}
else
{
listGO = new List<GameObject>();
foreach (GameObject item in listRootGO)
{
listGO.AddRange(FR2_Unity.getAllChild(item, true));
}
}
total = listGO.Count;
current = 0;
// Debug.Log("refresh cache total " + total);
EditorApplication.update -= OnUpdate;
EditorApplication.update += OnUpdate;
// foreach (var item in FR2_Helper.getAllObjsInCurScene())
// {
// // Debug.Log("object in scene: " + item.name);
// Component[] components = item.GetComponents<Component>();
// foreach (var com in components)
// {
// if(com == null) continue;
// SerializedObject serialized = new SerializedObject(com);
// SerializedProperty it = serialized.GetIterator().Copy();
// while (it.NextVisible(true))
// {
// if (it.propertyType != SerializedPropertyType.ObjectReference) continue;
// if (it.objectReferenceValue == null) continue;
// if(!_cache.ContainsKey(com)) _cache.Add(com, new HashSet<SerializedProperty>());
// if(!_cache[com].Contains(it))
// _cache[com].Add(it.Copy());
// }
// }
// }
Dirty = false;
}
private void OnUpdate()
{
for (var i = 0; i < 5 * FR2_Cache.Api.priority; i++)
{
if (listGO == null || listGO.Count <= 0)
{
//done
// Debug.Log("done");
EditorApplication.update -= OnUpdate;
ready = true;
Dirty = false;
listGO = null;
if (onReady != null)
{
onReady();
}
if (window != null)
{
window.OnSelectionChange();
}
return;
}
int index = listGO.Count - 1;
GameObject go = listGO[index];
if (go == null)
{
continue;
}
string prefabGUID = FR2_Unity.GetPrefabParent(go);
if (!string.IsNullOrEmpty(prefabGUID))
{
Transform parent = go.transform.parent;
while (parent != null)
{
GameObject g = parent.gameObject;
if (!prefabDependencies.ContainsKey(g))
{
prefabDependencies.Add(g, new HashSet<string>());
}
prefabDependencies[g].Add(prefabGUID);
parent = parent.parent;
}
}
Component[] components = go.GetComponents<Component>();
foreach (Component com in components)
{
if (com == null)
{
continue;
}
var serialized = new SerializedObject(com);
SerializedProperty it = serialized.GetIterator().Copy();
while (it.NextVisible(true))
{
if (it.propertyType != SerializedPropertyType.ObjectReference)
{
continue;
}
if (it.objectReferenceValue == null)
{
continue;
}
var isSceneObject = true;
string path = AssetDatabase.GetAssetPath(it.objectReferenceValue);
if (!string.IsNullOrEmpty(path))
{
string dir = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(dir))
{
isSceneObject = false;
if (!folderCache.ContainsKey(dir))
{
folderCache.Add(dir, new HashSet<Component>());
}
if (!folderCache[dir].Contains(com))
{
folderCache[dir].Add(com);
}
}
}
if (!_cache.ContainsKey(com))
{
_cache.Add(com, new HashSet<HashValue>());
}
_cache[com].Add(new HashValue
{target = it.objectReferenceValue, isSceneObject = isSceneObject});
// if (!_cache.ContainsKey(com)) _cache.Add(com, new HashSet<SerializedProperty>());
// if (!_cache[com].Contains(it))
// _cache[com].Add(it.Copy());
// string path = AssetDatabase.GetAssetPath(it.objectReferenceValue);
// if (string.IsNullOrEmpty(path)) continue;
// string dir = System.IO.Path.GetDirectoryName(path);
// if (string.IsNullOrEmpty(dir)) continue;
// if (!folderCache.ContainsKey(dir)) folderCache.Add(dir, new HashSet<Component>());
// if (!folderCache[dir].Contains(com))
// folderCache[dir].Add(com);
}
}
listGO.RemoveAt(index);
current++;
}
}
private void OnSceneChanged()
{
if (!Application.isPlaying)
{
Api.refreshCache(window);
return;
}
SetDirty();
}
#if UNITY_2017_1_OR_NEWER
private UndoPropertyModification[] OnModify(UndoPropertyModification[] modifications)
{
for (var i = 0; i < modifications.Length; i++)
{
if (modifications[i].currentValue.objectReference != null)
{
SetDirty();
break;
}
}
return modifications;
}
#endif
public void SetDirty()
{
Dirty = true;
}
public class HashValue
{
public bool isSceneObject;
public Object target;
//public SerializedProperty pro;
// public HashValue(SerializedProperty pro, bool isSceneObject)
// {
// //this.pro = pro;
// this.isSceneObject = isSceneObject;
// }
}
#if SUPPORT_NESTED_PREFAB
private void prefabClose(PrefabStage obj)
{
if (!Application.isPlaying)
{
Api.refreshCache(window);
return;
}
SetDirty();
}
private void prefabOnpen(PrefabStage obj)
{
if (!Application.isPlaying)
{
Api.refreshCache(window);
return;
}
SetDirty();
}
#endif
#if UNITY_2017_1_OR_NEWER
private void OnSceneChanged(Scene scene, LoadSceneMode mode)
{
OnSceneChanged();
}
private void OnSceneChanged(Scene arg0, Scene arg1)
{
OnSceneChanged();
}
#endif
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 658977c5b6e84344581803c8025947d3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,237 @@
using System;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_5_3_OR_NEWER
#endif
namespace vietlabs.fr2
{
public class FR2_SceneWindow : FR2_WindowBase, IHasCustomMenu
{
public override bool ShowScene
{
get { return true; }
}
//[MenuItem("Window/Find Reference 2/Scene")]
private static void ShowWindow()
{
var _window = CreateInstance<FR2_SceneWindow>();
_window.InitIfNeeded();
FR2_Unity.SetWindowTitle(_window, "FR2 Scene");
_window.Show();
}
[NonSerialized] internal FR2_RefDrawer RefInScene;
[NonSerialized] internal FR2_RefDrawer RefSceneInScene;
internal int level;
private Vector2 scrollPos;
private string tempGUID;
private Object tempObject;
[NonSerialized] internal FR2_RefDrawer SceneUsesDrawer; //scene use another scene objects
private void OnEnable()
{
resizerStyle = new GUIStyle();
resizerStyle.normal.background = EditorGUIUtility.Load("icons/d_AvatarBlendBackground.png") as Texture2D;
}
protected override void InitIfNeeded()
{
if (SceneUsesDrawer != null)
{
return;
}
SceneUsesDrawer = new FR2_RefDrawer(this)
{
Lable = "Scene Objects",
isDrawRefreshSceneCache = true
};
RefInScene = new FR2_RefDrawer(this)
{
Lable = "Scene Objects",
isDrawRefreshSceneCache = true
};
RefSceneInScene = new FR2_RefDrawer(this)
{
Lable = "Scene Objects",
isDrawRefreshSceneCache = true
};
FR2_Cache.onReady -= OnReady;
FR2_Cache.onReady += OnReady;
FR2_Setting.OnIgnoreChange -= OnSelectionChange;
FR2_Setting.OnIgnoreChange += OnSelectionChange;
#if UNITY_2018_OR_NEWER
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChangedInEditMode -= OnSceneChanged;
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChangedInEditMode += OnSceneChanged;
#elif UNITY_2017_OR_NEWER
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChanged -= OnSceneChanged;
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChanged += OnSceneChanged;
#endif
//Debug.Log(" FR2_Window ---> Init");
}
#if UNITY_2018_OR_NEWER
private void OnSceneChanged(Scene arg0, Scene arg1)
{
if (IsFocusingFindInScene || IsFocusingSceneToAsset || IsFocusingSceneInScene)
{
OnSelectionChange();
}
}
#endif
protected override void OnReady()
{
OnSelectionChange();
}
public override void OnSelectionChange()
{
isNoticeIgnore = false;
if (!FR2_Cache.isReady)
{
return;
}
if (lockSelection)
{
return;
}
if (focusedWindow == null)
{
return;
}
if (SceneUsesDrawer == null)
{
InitIfNeeded();
}
ids = FR2_Unity.Selection_AssetGUIDs;
//ignore selection on asset when selected any object in scene
if (Selection.gameObjects.Length > 0 && !FR2_Unity.IsInAsset(Selection.gameObjects[0]))
{
ids = new string[0];
}
if (IsFocusingSceneInScene)
{
RefSceneInScene.ResetSceneInScene(Selection.gameObjects);
}
if (IsFocusingUses)
{
SceneUsesDrawer.ResetSceneUseSceneObjects(Selection.gameObjects);
}
if (IsFocusingFindInScene)
{
RefInScene.Reset(ids, this as IWindow);
}
level = 0;
EditorApplication.delayCall += Repaint;
}
protected override void OnGUI()
{
if (!CheckDrawHeader())
{
return;
}
Rect rectTop = GetTopPanelRect();
Rect rectBot = GetBotPanelRect();
RefDrawConfig config1 = null, config2 = null, config3 = null;
var drawTool = false;
var drawCount = 0;
if (IsFocusingUses || IsFocusingSceneToAsset)
{
drawTool = GetDrawConfig(SceneUsesDrawer, out config1);
}
else if (IsFocusingSceneInScene || IsFocusingFindInScene || IsFocusingUsedBy)
{
if (RefSceneInScene.ElementCount() <= 0)
{
drawTool = GetDrawConfig(RefInScene, out config1);
}
else
{
drawTool = GetDrawConfig(RefSceneInScene, out config2);
}
}
if (!IsFocusingGUIDs && !IsFocusingUnused)
{
drawCount += DrawConfig(config1, rectTop, rectBot, ref willRepaint);
drawCount += DrawConfig(config2, rectTop, rectBot, ref willRepaint);
drawCount += DrawConfig(config3, rectTop, rectBot, ref willRepaint);
}
if (drawTool)
{
drawCount++;
GUILayout.BeginArea(rectBot);
DrawTool();
GUILayout.EndArea();
}
DrawFooter();
OnAfterGUI(drawCount);
}
protected override void maskDirty()
{
RefInScene.SetDirty();
RefSceneInScene.SetDirty();
SceneUsesDrawer.SetDirty();
}
protected override void RefreshSort()
{
RefInScene.RefreshSort();
RefSceneInScene.RefreshSort();
SceneUsesDrawer.RefreshSort();
}
protected override bool checkNoticeFilter()
{
var rsl = false;
if (IsFocusingFindInScene && !rsl)
{
rsl = RefInScene.isExclueAnyItem();
}
if (IsFocusingSceneInScene && !rsl)
{
rsl = RefSceneInScene.isExclueAnyItem();
}
return rsl;
}
protected override bool checkNoticeIgnore()
{
bool rsl = isNoticeIgnore;
return rsl;
}
private string[] ids;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 026fd8cec188743acb7e03ee6101aab9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+131
View File
@@ -0,0 +1,131 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class FR2_Selection
{
public static HashSet<string> h = new HashSet<string>();
public static HashSet<Object> HScene = new HashSet<Object>();
private static bool dirty;
private static HashSet<string> __cache;
private static HashSet<string> cache
{
get
{
if (__cache == null || dirty)
{
dirty = false;
__cache = new HashSet<string>();
foreach (string item in h)
{
__cache.Add(item);
}
foreach (Object item in HScene)
{
__cache.Add(item.GetInstanceID().ToString());
}
}
return __cache;
}
}
public static int SelectionCount
{
get { return h.Count + HScene.Count; }
}
public static void Commit()
{
var list = new List<Object>();
foreach (string guid in h)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
// var obj = AssetDatabase.LoadAssetAtPath<Object>(path);
Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
list.Add(obj);
}
foreach (Object obj in HScene)
{
list.Add(obj);
}
Selection.objects = list.ToArray();
}
public static bool IsSelect(string guid)
{
return cache.Contains(guid);
//return h.Contains(guid);
}
public static void RemoveSelection(string guid)
{
if (!h.Remove(guid))
{
dirty = true;
HScene.RemoveWhere(x => x.GetInstanceID().ToString() == guid);
}
}
private static bool IsSelect(Object obj)
{
return HScene.Contains(obj);
}
public static void ClearSelection()
{
dirty = true;
h.Clear();
HScene.Clear();
}
public static void AppendSelection(string guid)
{
if (IsSelect(guid))
{
return;
}
dirty = true;
h.Add(guid);
}
public static void AppendSelection(FR2_Ref rf)
{
if (rf.isSceneRef)
{
HScene.Add(rf.component);
}
else
{
h.Add(rf.asset.guid);
}
dirty = true;
}
public static void RemoveSelection(FR2_Ref rf)
{
if (rf.isSceneRef)
{
HScene.Remove(rf.component);
}
else
{
h.Remove(rf.asset.guid);
}
dirty = true;
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6b62a2942a0a19948b601dc0be99a527
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+405
View File
@@ -0,0 +1,405 @@
#define DEV_MODE
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class FR2_TreeUI
{
public float itemH = 16f;
private Vector2 position;
private FR2_TreeItemUI root;
public int selected;
public Color selectedColor = new Color32(0, 0, 255, 100);
private Rect visibleRect;
public void Draw(FR2_TreeItemUI root, bool drawRoot = true)
{
EventType evtType = Event.current.type;
Rect r = GUILayoutUtility.GetRect(1f, Screen.width, itemH, Screen.height);
if (evtType != EventType.Layout)
{
visibleRect = r;
}
int n = root.GetNVisible(Mathf.Max(root._treeStamp, 1));
var contentRect = new Rect(0f, 0f, 1f, n * itemH);
int nVisible = Mathf.RoundToInt(visibleRect.height / itemH) + 1;
int min = Mathf.Max(0, Mathf.FloorToInt(position.y / itemH));
int max = Mathf.Min(min + nVisible, n);
bool noScroll = contentRect.height < visibleRect.height;
//Debug.Log("Drawing :: " + min + ":" + max + ":" + n);
if (noScroll)
{
position = Vector2.zero;
}
position = GUI.BeginScrollView(visibleRect, position, contentRect);
{
var rect = new Rect(0, 0, r.width - (noScroll ? 4f : itemH), itemH);
var current = 0;
if (drawRoot)
{
root.Draw(min, max, ref rect, ref current);
}
else
{
root.DrawChildren(min, max, ref rect, ref current);
}
}
GUI.EndScrollView();
}
public void Draw<T>(List<T> list) where T : FR2_TreeItemUI
{
if (root == null)
{
root = new FR2_TreeItemUI();
for (var i = 0; i < list.Count; i++)
{
root.AddChild(list[i]);
}
}
Draw(root, false);
}
public void Draw<T>(List<T> objList, Action<int, Rect, T> itemDrawer)
{
Draw(objList.Count, (idx, r, hasMouse) => { itemDrawer(idx, r, objList[idx]); });
//var evtType = Event.current.type;
//Rect r = GUILayoutUtility.GetRect(1f, Screen.width, 16f, Screen.height);
//if (evtType != EventType.layout){
// visibleRect = r;
//}
//var n = objList.Count;
//var contentRect = new Rect(0f, 0f, 1f, n * itemH);
//var nVisible = Mathf.RoundToInt(visibleRect.height/itemH) + 1;
//var min = Mathf.Max(0, Mathf.FloorToInt(position.y / itemH));
//var max = Mathf.Min(min + nVisible, n);
//var noScroll = contentRect.height < visibleRect.height;
//if (noScroll) position = Vector2.zero;
//position = GUI.BeginScrollView(visibleRect, position, contentRect);
//{
// var rect = new Rect (0, 0, r.width - (noScroll ? 4f : 16f), itemH);
// for (var i = min; i<max; i++){
// rect.y = i * itemH;
// itemDrawer(i, rect, objList[i]);
// }
//}
//GUI.EndScrollView();
}
public void Draw(int n, Action<int, Rect, bool> drawer, bool repaintOnly = false)
{
EventType evtType = Event.current.type;
Rect r = GUILayoutUtility.GetRect(1f, Screen.width, itemH, Screen.height);
if (evtType != EventType.Layout)
{
visibleRect = r;
}
if (!repaintOnly || evtType == EventType.Repaint)
{
var contentRect = new Rect(0f, 0f, 1f, n * itemH);
int nVisible = Mathf.RoundToInt(visibleRect.height / itemH) + 1;
int min = Mathf.Max(0, Mathf.FloorToInt(position.y / itemH));
int max = Mathf.Min(min + nVisible, n);
bool noScroll = contentRect.height < visibleRect.height;
if (noScroll)
{
position = Vector2.zero;
}
position = GUI.BeginScrollView(visibleRect, position, contentRect);
//Debug.Log(min + ":" + max + ":" + n);
for (int i = min; i < max; i++)
{
var rr = new Rect(0, itemH * i, Screen.width, itemH);
if (i == selected)
{
Color c = GUI.color;
GUI.color = selectedColor;
{
GUI.DrawTexture(rr, EditorGUIUtility.whiteTexture);
}
GUI.color = c;
}
bool containsMouse = rr.Contains(Event.current.mousePosition);
bool hasMouse = Event.current.type == EventType.MouseDown && containsMouse;
drawer(i, rr, hasMouse);
if (Event.current.type == EventType.MouseUp && containsMouse)
{
selected = i;
Event.current.Use();
}
}
GUI.EndScrollView();
}
}
}
public class FR2_TreeItemUI
{
private const float arrowWidth = 14f;
// -------------------------- DRAWER ----------------------------
private static GUIStyle foldStyle;
// -------------------------- PARENT / CHILDREN ----------------------------
protected bool _expand = true;
protected int _itemHeight = 16;
protected int _nFakeSize;
protected int _nVisible;
internal int _treeStamp;
internal List<FR2_TreeItemUI> children = new List<FR2_TreeItemUI>();
// -------------------------- PARENT / CHILDREN ----------------------------
internal FR2_TreeItemUI parent;
public virtual int GetNVisible(int stamp)
{
if (!_expand)
{
return 1 + _nFakeSize;
}
if (_treeStamp == stamp)
{
return _nVisible + _nFakeSize;
}
RefreshVisibleCount(stamp);
return _nVisible + _nFakeSize;
}
public void ToggleExpand()
{
int delta = _nVisible - 1;
_expand = !_expand;
SetDeltaVisible(_expand ? delta : -delta, _treeStamp);
}
private void RefreshVisibleCount(int stamp)
{
_treeStamp = stamp;
_nVisible = 1;
for (var i = 0; i < children.Count; i++)
{
FR2_TreeItemUI c = children[i];
_nVisible += c.GetNVisible(stamp);
}
}
private void SetDeltaVisible(int delta, int stamp)
{
_treeStamp = stamp;
_nVisible += delta;
if (parent != null)
{
parent.SetDeltaVisible(delta, stamp);
}
else
{
GetNVisible(++stamp);
}
}
public FR2_TreeItemUI AddChild(FR2_TreeItemUI child)
{
#if DEV_MODE
{
if (!IsValidChild(child))
{
return this;
}
if (child.parent == this)
{
Debug.LogWarning("Child.parent already == this");
return this;
}
if (children.Contains(child))
{
Debug.LogWarning("Something broken, child already in this.children list <" + child +
"> but its parent not set to this");
return this;
}
}
#endif
if (child.parent != null)
{
child.parent.RemoveChild(child);
}
child.parent = this;
children.Add(child);
int delta = child.GetNVisible(_treeStamp);
SetDeltaVisible(delta, _treeStamp);
return this;
}
public FR2_TreeItemUI RemoveChild(FR2_TreeItemUI child)
{
#if DEV_MODE
{
if (!IsValidChild(child))
{
return this;
}
if (child.parent != this)
{
Debug.LogWarning("child.parent != this, can not remove");
return this;
}
if (!children.Contains(child))
{
Debug.LogWarning(
"Something broken, child.parent == this but this.children does not contains child");
return this;
}
}
#endif
child.parent = null;
children.Remove(child);
//Recursive update nVIsible items up the tree
int delta = child.GetNVisible(_treeStamp);
SetDeltaVisible(-delta, _treeStamp);
return this;
}
#if DEV_MODE
private bool IsValidChild(FR2_TreeItemUI child)
{
if (child == null)
{
Debug.LogWarning("Child should not be null <" + child + ">");
return false;
}
//if (child.target == null){
// Debug.LogWarning("Child's target should not be null <" + child + ">");
// return false;
//}
return true;
}
#endif
public virtual void DrawChildren(int from, int to, ref Rect r, ref int current)
{
for (var i = 0; i < children.Count; i++)
{
children[i].Draw(from, to, ref r, ref current);
if (current >= to)
{
return;
}
}
}
public virtual void Draw(int from, int to, ref Rect r, ref int current)
{
if (current >= to)
{
Debug.LogWarning("Out of view " + current + ":" + from + ":" + to + ":" + this);
return; //finish drawing
}
int n = _nFakeSize + 1;
int h = _itemHeight * n;
if (current + n >= from)
{
//partially / fully visible ? just draw
if (children.Count > 0)
{
// DrawTexture expand / collapse arrow
Rect arrowRect = r;
arrowRect.width = arrowWidth;
EditorGUI.BeginChangeCheck();
if (foldStyle == null)
{
foldStyle = "IN Foldout";
}
GUI.Toggle(arrowRect, _expand, GUIContent.none, foldStyle);
if (EditorGUI.EndChangeCheck())
{
ToggleExpand();
}
}
Rect drawRect = r;
drawRect.x += arrowWidth;
drawRect.width -= arrowWidth;
drawRect.height = h;
Draw(drawRect);
}
current += n;
r.y += h;
if (!_expand || current >= to)
{
return;
}
r.x += arrowWidth;
r.width -= arrowWidth;
for (var i = 0; i < children.Count; i++)
{
children[i].Draw(from, to, ref r, ref current);
if (current >= to)
{
return;
}
}
r.x -= arrowWidth;
r.width += arrowWidth;
}
protected virtual void Draw(Rect r) { }
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6c8689dad9c3ed341b7088135cb83be6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+385
View File
@@ -0,0 +1,385 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class FR2_TreeUI2
{
internal Drawer drawer;
private Vector2 position;
private TreeItem rootItem;
internal Rect visibleRect;
public FR2_TreeUI2(Drawer drawer)
{
this.drawer = drawer;
}
public void Reset(params string[] root)
{
position = Vector2.zero;
rootItem = new TreeItem
{
tree = this,
id = "$root",
height = 0,
depth = -1,
_isOpen = true,
highlight = false,
childCount = root.Length
};
rootItem.RefreshChildren(root);
rootItem.DeepOpen();
}
public void Draw()
{
EventType evtType = Event.current.type;
Rect r = GUILayoutUtility.GetRect(1f, Screen.width, 16f, Screen.height);
if (evtType != EventType.Layout)
{
visibleRect = r;
}
var contentRect = new Rect(0f, 0f, 1f, rootItem.childrenHeight);
bool noScroll = contentRect.height < visibleRect.height;
if (noScroll)
{
position = Vector2.zero;
}
var minY = (int) position.y;
var maxY = (int) (position.y + visibleRect.height);
contentRect.x -= FR2_Setting.TreeIndent;
TreeItem.DrawCall = 0;
TreeItem.DrawRender = 0;
position = GUI.BeginScrollView(visibleRect, position, contentRect);
{
var rect = new Rect(0, 0, r.width - (noScroll ? 4f : 16f), 16f);
var index = 0;
rootItem.Draw(ref index, ref rect, minY, maxY);
}
GUI.EndScrollView();
}
public bool NoScroll()
{
return rootItem.childrenHeight < visibleRect.height;
}
// ------------------------ DELEGATE --------------
public class Drawer
{
public virtual int GetHeight(string id)
{
return 16;
}
public virtual int GetChildCount(string id)
{
return 0;
}
public virtual string[] GetChildren(string id)
{
return null;
}
public virtual void Draw(Rect r, TreeItem item)
{
GUI.Label(r, item.id);
}
}
public class GroupDrawer : Drawer
{
public Action<Rect, string, int> drawGroup;
public Action<Rect, string> drawItem;
private Dictionary<string, List<string>> groupDict;
private FR2_TreeUI2 tree;
public GroupDrawer(Action<Rect, string, int> drawGroup, Action<Rect, string> drawItem)
{
this.drawItem = drawItem;
this.drawGroup = drawGroup;
}
// ----------------- TREE WRAPPER ------------------
public bool TreeNoScroll()
{
return tree.NoScroll();
}
public void Reset<T>(List<T> items, Func<T, string> idFunc, Func<T, string> groupFunc,
Action<List<string>> customGroupSort = null)
{
groupDict = new Dictionary<string, List<string>>();
for (var i = 0; i < items.Count; i++)
{
List<string> list;
string groupName = groupFunc(items[i]);
string itemId = idFunc(items[i]);
if (!groupDict.TryGetValue(groupName, out list))
{
list = new List<string>();
groupDict.Add(groupName, list);
}
list.Add(itemId);
}
if (tree == null)
{
tree = new FR2_TreeUI2(this);
}
List<string> groups = groupDict.Keys.ToList();
//if (groups.Count == 1) //single group : Flat list
//{
// var v = groupDict[groups[0]];
// tree.Reset(v.ToArray());
// groupDict.Clear();
//} else
{ //multiple groups
if (customGroupSort != null)
{
customGroupSort(groups);
}
else
{
groups.Sort();
}
tree.Reset(groups.ToArray());
}
}
public void Draw()
{
if (tree != null)
{
tree.Draw();
}
}
// ----------------- DRAWER WRAPPER ------------------
public override int GetChildCount(string id)
{
List<string> group;
if (groupDict.TryGetValue(id, out group))
{
return group.Count;
}
return 0;
}
public override string[] GetChildren(string id)
{
List<string> group;
if (groupDict.TryGetValue(id, out group))
{
return group.ToArray();
}
return null;
}
public override void Draw(Rect r, TreeItem item)
{
List<string> group;
if (groupDict.TryGetValue(item.id, out group))
{
drawGroup(r, item.id, item.childCount);
return;
}
drawItem(r, item.id);
}
}
// ------------------------ TreeItem2 --------------
public class TreeItem
{
public static int DrawCall;
public static int DrawRender;
internal bool _isOpen;
public int childCount;
public List<TreeItem> children;
public int childrenHeight;
public int depth; // item depth
public int height;
public bool highlight;
public string id; // item id
internal TreeItem parent;
//static Color COLOR = new Color(0f, 0f, 0f, 0.05f);
internal FR2_TreeUI2 tree;
public bool IsOpen
{
get { return _isOpen; }
set
{
if (_isOpen == value || childCount == 0)
{
return;
}
_isOpen = value;
if (_isOpen)
{
if (children == null)
{
RefreshChildren(tree.drawer.GetChildren(id));
}
//Update height for all parents
TreeItem p = parent;
while (p != null)
{
p.childrenHeight += childrenHeight;
p = p.parent;
}
}
else
{
//Update height for all parents
TreeItem p = parent;
while (p != null)
{
p.childrenHeight -= childrenHeight;
p = p.parent;
}
}
}
}
internal void DeepOpen()
{
IsOpen = true;
if (children == null)
{
return;
}
for (var i = 0; i < children.Count; i++)
{
children[i].DeepOpen();
}
}
internal void Draw(ref int index, ref Rect rect, int minY, int maxY)
{
DrawCall++;
// if (DrawCall < 10)
// {
// Debug.Log(index + ":" + rect + ":" + minY + ":" + maxY + ":" + height + ":" + childrenHeight);
// }
//var skipDraw = (rect.y >= maxY) || (height <=0);
float min = rect.y;
float max = rect.y + height;
bool interMin = min >= minY && min <= maxY;
bool interMax = max >= minY && max <= maxY;
if (height > 0 && (interMin || interMax))
{
DrawRender++;
rect.height = height;
if (index % 2 == 1 && FR2_Setting.AlternateRowColor)
{
Color o = GUI.color;
GUI.color = FR2_Setting.RowColor;
// GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture);
GUI.DrawTexture(new Rect(rect.x - FR2_Setting.TreeIndent, rect.y, rect.width, rect.height),
EditorGUIUtility.whiteTexture);
GUI.color = o;
}
float x = (depth + 1) * 16f;
tree.drawer.Draw(new Rect(x, rect.y, rect.width - x, rect.height), this);
if (childCount > 0)
{
IsOpen = GUI.Toggle(new Rect(rect.x + x - 16f, rect.y, 16f, 16f), IsOpen, string.Empty,
EditorStyles.foldout);
}
index++;
rect.y += height;
}
else
{
rect.y += height;
}
if (_isOpen && rect.y <= maxY) //draw children
{
for (var i = 0; i < children.Count; i++)
{
children[i].Draw(ref index, ref rect, minY, maxY);
if (rect.y > maxY)
{
break;
}
}
}
}
internal void RefreshChildren(string[] childrenIDs)
{
childCount = childrenIDs.Length;
childrenHeight = 0;
children = new List<TreeItem>();
for (var i = 0; i < childCount; i++)
{
string itemId = childrenIDs[i];
var item = new TreeItem
{
tree = tree,
parent = this,
id = itemId,
depth = depth + 1,
highlight = false,
height = tree.drawer.GetHeight(itemId),
childCount = tree.drawer.GetChildCount(itemId)
};
childrenHeight += item.height;
children.Add(item);
}
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c0367155479c84189ad956f35f707b7c
timeCreated: 1493613697
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+724
View File
@@ -0,0 +1,724 @@
#if UNITY_5_3_OR_NEWER
#define UNITY_4_3_OR_NEWER
#define UNITY_4_4_OR_NEWER
#define UNITY_4_5_OR_NEWER
#define UNITY_4_6_OR_NEWER
#define UNITY_4_7_OR_NEWER
#define UNITY_5_0_OR_NEWER
#define UNITY_5_1_OR_NEWER
#define UNITY_5_2_OR_NEWER
#else
#if UNITY_5
#define UNITY_4_3_OR_NEWER
#define UNITY_4_4_OR_NEWER
#define UNITY_4_5_OR_NEWER
#define UNITY_4_6_OR_NEWER
#define UNITY_4_7_OR_NEWER
#if UNITY_5_0
#define UNITY_5_0_OR_NEWER
#elif UNITY_5_1
#define UNITY_5_0_OR_NEWER
#define UNITY_5_1_OR_NEWER
#elif UNITY_5_2
#define UNITY_5_0_OR_NEWER
#define UNITY_5_1_OR_NEWER
#define UNITY_5_2_OR_NEWER
#endif
#else
#if UNITY_4_3
#define UNITY_4_3_OR_NEWER
#elif UNITY_4_4
#define UNITY_4_3_OR_NEWER
#define UNITY_4_4_OR_NEWER
#elif UNITY_4_5
#define UNITY_4_3_OR_NEWER
#define UNITY_4_4_OR_NEWER
#define UNITY_4_5_OR_NEWER
#elif UNITY_4_6
#define UNITY_4_3_OR_NEWER
#define UNITY_4_4_OR_NEWER
#define UNITY_4_5_OR_NEWER
#define UNITY_4_6_OR_NEWER
#elif UNITY_4_7
#define UNITY_4_3_OR_NEWER
#define UNITY_4_4_OR_NEWER
#define UNITY_4_5_OR_NEWER
#define UNITY_4_6_OR_NEWER
#define UNITY_4_7_OR_NEWER
#endif
#endif
#endif
#if UNITY_5_3_OR_NEWER
#define UNITY_SCENE_MANAGER
#endif
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_SCENE_MANAGER
using UnityEngine.SceneManagement;
#endif
namespace vietlabs.fr2
{
public class FR2_Unity
{
internal static readonly AssetType[] FILTERS =
{
new AssetType("Scene", ".unity"),
new AssetType("Prefab", ".prefab"),
new AssetType("Model", ".3df", ".3dm", ".3dmf", ".3dv", ".3dx", ".c5d", ".lwo", ".lws", ".ma", ".mb",
".mesh", ".vrl", ".wrl", ".wrz", ".fbx", ".dae", ".3ds", ".dxf", ".obj", ".skp", ".max", ".blend"),
new AssetType("Material", ".mat", ".cubemap", ".physicsmaterial"),
new AssetType("Texture", ".ai", ".apng", ".png", ".bmp", ".cdr", ".dib", ".eps", ".exif", ".ico", ".icon",
".j", ".j2c", ".j2k", ".jas", ".jiff", ".jng", ".jp2", ".jpc", ".jpe", ".jpeg", ".jpf", ".jpg", "jpw",
"jpx", "jtf", ".mac", ".omf", ".qif", ".qti", "qtif", ".tex", ".tfw", ".tga", ".tif", ".tiff", ".wmf",
".psd", ".exr", ".rendertexture"),
new AssetType("Video", ".asf", ".asx", ".avi", ".dat", ".divx", ".dvx", ".mlv", ".m2l", ".m2t", ".m2ts",
".m2v", ".m4e", ".m4v", "mjp", ".mov", ".movie", ".mp21", ".mp4", ".mpe", ".mpeg", ".mpg", ".mpv2",
".ogm", ".qt", ".rm", ".rmvb", ".wmv", ".xvid", ".flv"),
new AssetType("Audio", ".mp3", ".wav", ".ogg", ".aif", ".aiff", ".mod", ".it", ".s3m", ".xm"),
new AssetType("Script", ".cs", ".js", ".boo"),
new AssetType("Text", ".txt", ".json", ".xml", ".bytes", ".sql"),
new AssetType("Shader", ".shader", ".cginc"),
new AssetType("Animation", ".anim", ".controller", ".overridecontroller", ".mask"),
new AssetType("Unity Asset", ".asset", ".guiskin", ".flare", ".fontsettings", ".prefs"),
new AssetType("Others") //
};
public static string[] Selection_AssetGUIDs
{
get
{
#if UNITY_5_0_OR_NEWER
return Selection.assetGUIDs;
#else
var mInfo =
typeof(Selection).GetProperty("assetGUIDs", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (mInfo != null){
return (string[]) mInfo.GetValue(null, null);
}
Debug.LogWarning("Unity changed ! Selection.assetGUIDs not found !");
return new string[0];
#endif
}
}
//private static Texture2D _whiteTexture;
//public static Texture2D whiteTexture {
// get {
// return EditorGUIUtility.whiteTexture;
// #if UNITY_5_0_OR_NEWER
// return EditorGUIUtility.whiteTexture;
// #else
// if (_whiteTexture != null) return _whiteTexture;
// _whiteTexture = new Texture2D(1,1, TextureFormat.RGBA32, false);
// _whiteTexture.SetPixel(0, 0, Color.white);
// _whiteTexture.hideFlags = HideFlags.DontSave;
// return _whiteTexture;
// #endif
// }
//}
public static T LoadAssetAtPath<T>(string path) where T : Object
{
#if UNITY_5_1_OR_NEWER
return AssetDatabase.LoadAssetAtPath<T>(path);
#else
return (T)AssetDatabase.LoadAssetAtPath(path, typeof(T));
#endif
}
public static void SetWindowTitle(EditorWindow window, string title)
{
#if UNITY_5_1_OR_NEWER
window.titleContent = new GUIContent(title);
#else
window.title = title;
#endif
}
public static void GetCompilingPhase(string path, out bool isPlugin, out bool isEditor)
{
#if (UNITY_5_2_0 || UNITY_5_2_1) && !UNITY_5_2_OR_NEWER
bool oldSystem = true;
#else
var oldSystem = false;
#endif
// ---- Old system: Editor for the plugin should be Plugins/Editor
if (oldSystem)
{
bool isPluginEditor = path.StartsWith("Assets/Plugins/Editor/", StringComparison.Ordinal)
|| path.StartsWith("Assets/Standard Assets/Editor/", StringComparison.Ordinal)
|| path.StartsWith("Assets/Pro Standard Assets/Editor/",
StringComparison.Ordinal);
if (isPluginEditor)
{
isPlugin = true;
isEditor = true;
return;
}
}
isPlugin = path.StartsWith("Assets/Plugins/", StringComparison.Ordinal)
|| path.StartsWith("Assets/Standard Assets/", StringComparison.Ordinal)
|| path.StartsWith("Assets/Pro Standard Assets/", StringComparison.Ordinal);
isEditor = oldSystem && isPlugin ? false : path.Contains("/Editor/");
}
public static T LoadAssetWithGUID<T>(string guid) where T : Object
{
if (string.IsNullOrEmpty(guid))
{
return null;
}
string path = AssetDatabase.GUIDToAssetPath(guid);
if (string.IsNullOrEmpty(path))
{
return null;
}
#if UNITY_5_1_OR_NEWER
return AssetDatabase.LoadAssetAtPath<T>(path);
#else
return (T)AssetDatabase.LoadAssetAtPath(path, typeof(T));
#endif
}
public static void UnloadUnusedAssets()
{
#if UNITY_5_0_OR_NEWER
EditorUtility.UnloadUnusedAssetsImmediate();
#else
EditorUtility.UnloadUnusedAssets();
#endif
Resources.UnloadUnusedAssets();
}
internal static int Epoch(DateTime time)
{
return (int) (time.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}
internal static bool DrawToggle(ref bool v, string label)
{
bool v1 = GUILayout.Toggle(v, label);
if (v1 != v)
{
v = v1;
return true;
}
return false;
}
internal static bool DrawToggleToolbar(ref bool v, string label, float width)
{
bool v1 = GUILayout.Toggle(v, label, EditorStyles.toolbarButton, GUILayout.Width(width));
if (v1 != v)
{
v = v1;
return true;
}
return false;
}
internal static bool DrawToggleToolbar(ref bool v, GUIContent icon, float width)
{
bool v1 = GUILayout.Toggle(v, icon, EditorStyles.toolbarButton, GUILayout.Width(width));
if (v1 != v)
{
v = v1;
return true;
}
return false;
}
internal static bool DrawToggle(bool v, string label, Action<bool> setter)
{
bool v1 = GUILayout.Toggle(v, label);
if (v1 != v)
{
if (setter != null)
{
setter(v1);
}
return true;
}
return false;
}
internal static EditorWindow FindEditor(string className)
{
EditorWindow[] list = Resources.FindObjectsOfTypeAll<EditorWindow>();
foreach (EditorWindow item in list)
{
if (item.GetType().FullName == className)
{
return item;
}
}
return null;
}
internal static void RepaintAllEditor(string className)
{
EditorWindow[] list = Resources.FindObjectsOfTypeAll<EditorWindow>();
foreach (EditorWindow item in list)
{
#if FR2_DEV
Debug.Log(item.GetType().FullName);
#endif
if (item.GetType().FullName != className)
{
continue;
}
item.Repaint();
}
}
internal static void RepaintProjectWindows()
{
RepaintAllEditor("UnityEditor.ProjectBrowser");
}
internal static void RepaintFR2Windows()
{
RepaintAllEditor("vietlabs.fr2.FR2_Window");
}
internal static void ExportSelection()
{
Type packageExportT = null;
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
packageExportT = assembly.GetType("UnityEditor.PackageExport");
if (packageExportT != null)
{
break;
}
}
if (packageExportT == null)
{
Debug.LogWarning("Export Package Error : UnityEditor.PackageExport not found !");
return;
}
EditorWindow panel = EditorWindow.GetWindow(packageExportT, true, "Exporting package");
#if UNITY_5_2_OR_NEWER
var prop = "m_IncludeDependencies";
#else
var prop = "m_bIncludeDependencies";
#endif
FieldInfo fieldInfo = packageExportT.GetField(prop, BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo == null)
{
Debug.LogWarning("Export Package error : " + prop + " not found !");
return;
}
MethodInfo methodInfo =
packageExportT.GetMethod("BuildAssetList", BindingFlags.NonPublic | BindingFlags.Instance);
if (methodInfo == null)
{
Debug.LogWarning("Export Package error : BuildAssetList method not found !");
return;
}
fieldInfo.SetValue(panel, false);
methodInfo.Invoke(panel, null);
panel.Repaint();
}
public static Type GetType(string typeName)
{
Type type = Type.GetType(typeName);
if (type != null)
{
return type;
}
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
type = a.GetType(typeName);
if (type != null)
{
return type;
}
}
return null;
}
public static IEnumerable<Transform> GetAllChild(Transform root)
{
yield return root;
if (root.childCount <= 0)
{
yield break;
}
for (var i = 0; i < root.childCount; i++)
{
foreach (Transform item in GetAllChild(root.GetChild(i)))
{
yield return item;
}
}
}
public static IEnumerable<GameObject> getAllObjsInCurScene()
{
#if UNITY_SCENE_MANAGER
for (var j = 0; j < SceneManager.sceneCount; j++)
{
Scene scene = SceneManager.GetSceneAt(j);
foreach (GameObject item in GetGameObjectsInScene(scene))
{
yield return item;
}
}
if (EditorApplication.isPlaying)
{
//dont destroy scene
GameObject temp = null;
try
{
temp = new GameObject();
Object.DontDestroyOnLoad(temp);
Scene dontDestroyOnLoad = temp.scene;
Object.DestroyImmediate(temp);
temp = null;
foreach (GameObject item in GetGameObjectsInScene(dontDestroyOnLoad))
{
yield return item;
}
}
finally
{
if (temp != null)
{
Object.DestroyImmediate(temp);
}
}
}
#else
foreach (Transform obj in Resources.FindObjectsOfTypeAll(typeof(Transform)))
{
GameObject o = obj.gameObject;
yield return o;
}
#endif
}
#if UNITY_SCENE_MANAGER
private static IEnumerable<GameObject> GetGameObjectsInScene(Scene scene)
{
var rootObjects = new List<GameObject>();
if (!scene.isLoaded)
{
yield break;
}
scene.GetRootGameObjects(rootObjects);
// iterate root objects and do something
for (var i = 0; i < rootObjects.Count; ++i)
{
GameObject gameObject = rootObjects[i];
foreach (GameObject item in getAllChild(gameObject))
{
yield return item;
}
yield return gameObject;
}
}
#endif
public static IEnumerable<GameObject> getAllChild(GameObject target, bool returnMe = false)
{
if (returnMe)
{
yield return target;
}
if (target.transform.childCount > 0)
{
for (var i = 0; i < target.transform.childCount; i++)
{
yield return target.transform.GetChild(i).gameObject;
foreach (GameObject item in getAllChild(target.transform.GetChild(i).gameObject, false))
{
yield return item;
}
}
}
}
public static IEnumerable<Object> GetAllRefObjects(GameObject obj)
{
Component[] components = obj.GetComponents<Component>();
foreach (Component com in components)
{
if (com == null)
{
continue;
}
var serialized = new SerializedObject(com);
SerializedProperty it = serialized.GetIterator().Copy();
while (it.NextVisible(true))
{
if (it.propertyType != SerializedPropertyType.ObjectReference)
{
continue;
}
if (it.objectReferenceValue == null)
{
continue;
}
yield return it.objectReferenceValue;
}
}
}
public static int StringMatch(string pattern, string input)
{
if (input == pattern)
{
return int.MaxValue;
}
if (input.Contains(pattern))
{
return int.MaxValue - 1;
}
var pidx = 0;
var score = 0;
var tokenScore = 0;
for (var i = 0; i < input.Length; i++)
{
char ch = input[i];
if (ch == pattern[pidx])
{
tokenScore += tokenScore + 1; //increasing score for continuos token
pidx++;
if (pidx >= pattern.Length)
{
break;
}
}
else
{
tokenScore = 0;
}
score += tokenScore;
}
return score;
}
public static int GetIndex(string ext)
{
for (var i = 0; i < FILTERS.Length - 1; i++)
{
if (FILTERS[i].extension.Contains(ext))
{
return i;
}
}
return FILTERS.Length - 1; //Others
}
public static void GuiLine(int i_height = 1)
{
Rect rect = EditorGUILayout.GetControlRect(false, i_height);
rect.height = i_height;
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 1));
}
public static bool IsInAsset(GameObject obj)
{
//#if UNITY_5_3_OR_NEWER
// this not working in new empty created scene
//return string.IsNullOrEmpty(obj.scene.name);
//#else
return !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(obj));
//#endif
}
public static string GetPrefabParent(Object obj)
{
#if UNITY_2018_2_OR_NEWER
string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(obj);
return AssetDatabase.AssetPathToGUID(prefabPath);
#else
var prefab = PrefabUtility.GetPrefabParent(obj);
return AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(prefab));
#endif
}
public static string GetGameObjectPath(GameObject obj, bool includeMe = true)
{
if (obj == null)
{
return string.Empty;
}
string path = includeMe ? "/" + obj.name : "/";
while (obj.transform.parent != null)
{
obj = obj.transform.parent.gameObject;
path = "/" + obj.name + path;
}
path = path.TrimStart('/');
return path;
}
public static bool CheckIsPrefab(GameObject obj)
{
#if UNITY_2018_3_OR_NEWER
// var t = PrefabUtility.GetPrefabAssetType(obj);
// var isPrefab = (t != PrefabAssetType.NotAPrefab) && (t != PrefabAssetType.MissingAsset);
return PrefabUtility.IsAnyPrefabInstanceRoot(obj);
#else
return PrefabUtility.GetPrefabType(obj) != PrefabType.None;
#endif
}
public static TerrainTextureData[] GetTerrainTextureDatas(TerrainData data)
{
#if UNITY_2018_3_OR_NEWER
var arr = new TerrainTextureData[data.terrainLayers.Length];
for (var i = 0; i < data.terrainLayers.Length; i++)
{
TerrainLayer layer = data.terrainLayers[i];
arr[i] = new TerrainTextureData
(
layer.normalMapTexture,
layer.maskMapTexture,
layer.diffuseTexture
);
}
return arr;
#else
var arr = new TerrainTextureData[data.splatPrototypes.Length];
for(int i = 0; i < data.splatPrototypes.Length; i++)
{
var layer = data.splatPrototypes[i];
arr[i] = new TerrainTextureData
(
layer.normalMap,
layer.texture
);
}
return arr;
#endif
}
public static int ReplaceTerrainTextureDatas(TerrainData terrain, Texture2D fromObj, Texture2D toObj)
{
var found = 0;
#if UNITY_2018_3_OR_NEWER
TerrainLayer[] arr3 = terrain.terrainLayers;
for (var i = 0; i < arr3.Length; i++)
{
if (arr3[i].normalMapTexture == fromObj)
{
found++;
arr3[i].normalMapTexture = toObj;
}
if (arr3[i].maskMapTexture == fromObj)
{
found++;
arr3[i].maskMapTexture = toObj;
}
if (arr3[i].diffuseTexture == fromObj)
{
found++;
arr3[i].diffuseTexture = toObj;
}
}
terrain.terrainLayers = arr3;
#else
var arr3 = terrain.splatPrototypes;
for (var i = 0; i < arr3.Length; i++)
{
if (arr3[i].texture == fromObj)
{
found++;
arr3[i].texture = toObj;
}
if (arr3[i].normalMap == fromObj)
{
found++;
arr3[i].normalMap = toObj;
}
}
terrain.splatPrototypes = arr3;
#endif
return found;
}
public class TerrainTextureData
{
public Texture2D[] textures;
public TerrainTextureData(params Texture2D[] param)
{
var count = 0;
if (param != null)
{
count = param.Length;
}
textures = new Texture2D[count];
for (var i = 0; i < count; i++)
{
textures[i] = param[i];
}
}
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7d62736a417e747e481e3aa85951cd18
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,121 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class FR2_UsedInBuild : IRefDraw
{
private readonly FR2_TreeUI2.GroupDrawer groupDrawer;
private bool dirty;
private readonly FR2_RefDrawer drawer;
private Dictionary<string, FR2_Ref> refs;
public FR2_UsedInBuild(IWindow window)
{
this.window = window;
drawer = new FR2_RefDrawer(window);
dirty = true;
drawer.displayFileSize = true;
drawer.SetDirty();
}
public IWindow window { get; set; }
public int ElementCount()
{
return refs == null ? 0 : refs.Count;
}
public bool Draw()
{
//Debug.Log("draw");
if (dirty)
{
RefreshView();
}
return drawer.Draw();
}
public void SetDirty()
{
drawer.SetDirty();
}
public void RefreshView()
{
var scenes = new HashSet<string>();
// string[] scenes = new string[sceneCount];
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
if (scene == null)
{
continue;
}
if (scene.enabled == false)
{
continue;
}
string sce = AssetDatabase.AssetPathToGUID(scene.path);
if (scenes.Contains(sce))
{
continue;
}
scenes.Add(sce);
}
refs = FR2_Ref.FindUsage(scenes.ToArray());
foreach (string VARIABLE in scenes)
{
FR2_Ref asset = null;
if (!refs.TryGetValue(VARIABLE, out asset))
{
continue;
}
asset.depth = 1;
}
List<FR2_Asset> list = FR2_Cache.Api.AssetList;
int count = list.Count;
for (var i = 0; i < count; i++)
{
FR2_Asset item = list[i];
if (item.inEditor) continue;
if (item.inPlugins)
{
if (item.type == FR2_AssetType.SCENE) continue;
}
if (item.inResources || item.inStreamingAsset || item.inPlugins)
{
if (refs.ContainsKey(item.guid))
{
continue;
}
refs.Add(item.guid, new FR2_Ref(0, 1, item, null));
}
}
drawer.SetRefs(refs);
dirty = false;
}
internal void RefreshSort()
{
drawer.RefreshSort();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e0eebac9e6cbe431ca16d9cb27500785
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+406
View File
@@ -0,0 +1,406 @@
using System;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_5_3_OR_NEWER
#endif
namespace vietlabs.fr2
{
// filter, ignore anh huong ket qua thi hien mau do
// optimize lag duplicate khi use
public class FR2_Window : FR2_WindowBase, IHasCustomMenu
{
[NonSerialized] internal FR2_DuplicateTree2 Duplicated;
private string[] ids;
internal int level;
private Object[] objs;
[NonSerialized] internal FR2_RefDrawer RefUnUse;
[NonSerialized] internal FR2_RefDrawer SceneToAssetDrawer;
private Vector2 scrollPos;
private string tempGUID;
private Object tempObject;
[NonSerialized] internal FR2_RefDrawer UsedByDrawer;
[NonSerialized] internal FR2_UsedInBuild UsedInBuild;
[NonSerialized] internal FR2_RefDrawer UsesDrawer;
public override bool ShowScene
{
get { return false; }
}
//[MenuItem("Window/Find Reference 2/Assets")]
private static void ShowWindow()
{
var _window = CreateInstance<FR2_Window>();
_window.InitIfNeeded();
FR2_Unity.SetWindowTitle(_window, "FR2 Assets");
_window.Show();
}
private void OnEnable()
{
resizerStyle = new GUIStyle();
resizerStyle.normal.background = EditorGUIUtility.Load("icons/d_AvatarBlendBackground.png") as Texture2D;
}
protected override void InitIfNeeded()
{
{
if (UsesDrawer != null)
{
return;
}
UsesDrawer = new FR2_RefDrawer(this)
{
Lable = "Assets"
};
UsedByDrawer = new FR2_RefDrawer(this)
{
Lable = "Assets"
};
Duplicated = new FR2_DuplicateTree2(this);
SceneToAssetDrawer = new FR2_RefDrawer(this)
{
Lable = "Assets",
isDrawRefreshSceneCache = true
};
RefUnUse = new FR2_RefDrawer(this)
{
Lable = "Unsed Asset",
isDrawRefreshSceneCache = false
};
UsedInBuild = new FR2_UsedInBuild(this);
}
FR2_Cache.onReady -= OnReady;
FR2_Cache.onReady += OnReady;
FR2_Setting.OnIgnoreChange -= OnSelectionChange;
FR2_Setting.OnIgnoreChange += OnSelectionChange;
//Debug.Log(" FR2_Window ---> Init");
}
protected override void OnReady()
{
OnSelectionChange();
if (IsFocusingUnused)
{
RefUnUse.ResetUnusedAsset();
}
}
public override void OnSelectionChange()
{
isNoticeIgnore = false;
if (!FR2_Cache.isReady)
{
return;
}
if (lockSelection)
{
return;
}
if (focusedWindow == null)
{
return;
}
if (UsesDrawer == null)
{
InitIfNeeded();
}
ids = FR2_Unity.Selection_AssetGUIDs;
//ignore selection on asset when selected any object in scene
if (Selection.gameObjects.Length > 0 && !FR2_Unity.IsInAsset(Selection.gameObjects[0]))
{
ids = new string[0];
}
level = 0;
if (IsFocusingSceneToAsset)
{
SceneToAssetDrawer.Reset(Selection.gameObjects, true, true);
}
if (IsFocusingUses)
{
UsesDrawer.Reset(ids, true);
}
if (IsFocusingUsedBy)
{
UsedByDrawer.Reset(ids, false);
}
if (IsFocusingGUIDs)
{
objs = new Object[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
objs[i] = FR2_Unity.LoadAssetAtPath<Object>
(
AssetDatabase.GUIDToAssetPath(ids[i])
);
}
}
if (IsFocusingUsedInBuild) { }
EditorApplication.delayCall += Repaint;
}
// public static Rect windowRect;
//return true if draw tool along
protected override void OnGUI()
{
if (!CheckDrawHeader())
{
Debug.Log("return");
return;
}
//if (Selected.Count == 0){
// GUILayout.Label("Nothing selected");
//}
Rect rectTop = GetTopPanelRect();
Rect rectBot = GetBotPanelRect();
RefDrawConfig config1 = null, config2 = null, config3 = null;
var drawTool = false;
var drawCount = 0;
if (IsFocusingUses || IsFocusingSceneToAsset)
{
Debug.Log("draw 1");
drawTool = GetDrawConfig(UsesDrawer, SceneToAssetDrawer, out config1, out config2);
//drawTool = GetDrawConfig(UsesDrawer, SceneToAssetDrawer, out config1, out config2);
}
else if (IsFocusingSceneInScene || IsFocusingFindInScene || IsFocusingUsedBy)
{
Debug.Log("draw 2");
drawTool = GetDrawConfig(UsedByDrawer, out config2);
}
else if (IsFocusingDuplicate)
{
Debug.Log("draw 3");
drawTool = GetDrawConfig(Duplicated, out config1);
}
else if (IsFocusingGUIDs)
{
Debug.Log("draw 4");
drawCount++;
if (AnyToolInBot)
{
GUILayout.BeginArea(rectTop);
DrawGUIDs();
GUILayout.EndArea();
drawTool = true;
}
else
{
DrawGUIDs();
drawTool = false;
}
}
else if (IsFocusingUnused)
{
Debug.Log("draw 5");
drawCount++;
if (AnyToolInBot)
{
GUILayout.BeginArea(rectTop);
RefUnUse.Draw();
GUILayout.EndArea();
drawTool = true;
}
else
{
RefUnUse.Draw();
drawTool = false;
}
}
else if (IsFocusingUsedInBuild)
{
Debug.Log("draw :" + IsFocusingUsedInBuild);
drawTool = GetDrawConfig(UsedInBuild, out config1);
}
if (!IsFocusingGUIDs && !IsFocusingUnused)
{
Debug.Log("!IsFocusingGUIDs");
drawCount += DrawConfig(config1, rectTop, rectBot, ref willRepaint);
drawCount += DrawConfig(config2, rectTop, rectBot, ref willRepaint);
drawCount += DrawConfig(config3, rectTop, rectBot, ref willRepaint);
}
if (drawTool)
{
drawCount++;
GUILayout.BeginArea(rectBot);
DrawTool();
GUILayout.EndArea();
}
DrawFooter();
OnAfterGUI(drawCount);
}
protected override void maskDirty()
{
UsedByDrawer.SetDirty();
UsesDrawer.SetDirty();
Duplicated.SetDirty();
SceneToAssetDrawer.SetDirty();
RefUnUse.SetDirty();
UsedInBuild.SetDirty();
}
protected override void RefreshSort()
{
UsedByDrawer.RefreshSort();
UsesDrawer.RefreshSort();
Duplicated.RefreshSort();
SceneToAssetDrawer.RefreshSort();
RefUnUse.RefreshSort();
UsedInBuild.RefreshSort();
}
// public bool isExcludeByFilter;
protected override bool checkNoticeFilter()
{
var rsl = false;
if (IsFocusingUsedBy && !rsl)
{
rsl = UsedByDrawer.isExclueAnyItem();
}
if (IsFocusingDuplicate)
{
return Duplicated.isExclueAnyItem();
}
if (IsFocusingUses && rsl == false)
{
rsl = UsesDrawer.isExclueAnyItem();
}
if (IsFocusingSceneToAsset && rsl == false)
{
rsl = SceneToAssetDrawer.isExclueAnyItem();
}
//tab use by
return rsl;
}
protected override bool checkNoticeIgnore()
{
bool rsl = isNoticeIgnore;
return rsl;
}
private void DrawGUIDs()
{
GUILayout.Label("GUID to Object", EditorStyles.boldLabel);
GUILayout.BeginHorizontal();
{
string guid = EditorGUILayout.TextField(tempGUID ?? string.Empty);
EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f));
if (GUILayout.Button("Paste", EditorStyles.miniButton, GUILayout.Width(70f)))
{
guid = EditorGUIUtility.systemCopyBuffer;
}
if (guid != tempGUID && !string.IsNullOrEmpty(guid))
{
tempGUID = guid;
tempObject = FR2_Unity.LoadAssetAtPath<Object>
(
AssetDatabase.GUIDToAssetPath(tempGUID)
);
}
}
GUILayout.EndHorizontal();
GUILayout.Space(10f);
if (objs == null || ids == null)
{
return;
}
//GUILayout.Label("Selection", EditorStyles.boldLabel);
if (ids.Length == objs.Length)
{
scrollPos = GUILayout.BeginScrollView(scrollPos);
{
for (var i = 0; i < ids.Length; i++)
{
GUILayout.BeginHorizontal();
{
EditorGUILayout.ObjectField(objs[i], typeof(Object), false);
string idi = ids[i];
GUILayout.TextField(idi, GUILayout.Width(240f));
if (GUILayout.Button("Copy", EditorStyles.miniButton, GUILayout.Width(50f)))
{
EditorGUIUtility.systemCopyBuffer = tempGUID = idi;
if (!string.IsNullOrEmpty(tempGUID))
{
tempObject = FR2_Unity.LoadAssetAtPath<Object>
(
AssetDatabase.GUIDToAssetPath(tempGUID)
);
}
//Debug.Log(EditorGUIUtility.systemCopyBuffer);
}
}
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView();
}
// GUILayout.FlexibleSpace();
// GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Merge Selection To"))
{
FR2_Export.MergeDuplicate();
}
EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f));
GUILayout.EndHorizontal();
GUILayout.Space(5f);
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 29dffe27204f9d5459147d239a58a521
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+500
View File
@@ -0,0 +1,500 @@
using System;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_5_3_OR_NEWER
#endif
namespace vietlabs.fr2
{
// filter, ignore anh huong ket qua thi hien mau do
// optimize lag duplicate khi use
public class FR2_WindowAll : FR2_WindowBase, IHasCustomMenu
{
public override bool ShowScene
{
get { return false; }
}
[MenuItem("Window/Find Reference 2")]
private static void ShowWindow()
{
var _window = CreateInstance<FR2_WindowAll>();
_window.InitIfNeeded();
FR2_Unity.SetWindowTitle(_window, "FR2");
_window.Show();
}
[NonSerialized] internal FR2_UsedInBuild UsedInBuild;
[NonSerialized] internal FR2_DuplicateTree2 Duplicated;
[NonSerialized] internal FR2_RefDrawer RefUnUse;
[NonSerialized] internal FR2_RefDrawer UsesDrawer;
[NonSerialized] internal FR2_RefDrawer UsedByDrawer;
[NonSerialized] internal FR2_RefDrawer SceneToAssetDrawer;
[NonSerialized] internal FR2_RefDrawer RefInScene;
[NonSerialized] internal FR2_RefDrawer SceneUsesDrawer; //scene use another scene objects
[NonSerialized] internal FR2_RefDrawer RefSceneInScene;
internal int level;
private Vector2 scrollPos;
private string tempGUID;
private Object tempObject;
private void OnEnable()
{
resizerStyle = new GUIStyle();
resizerStyle.normal.background = EditorGUIUtility.Load("icons/d_AvatarBlendBackground.png") as Texture2D;
Repaint();
}
protected override void InitIfNeeded()
{
{
if (UsesDrawer != null)
{
return;
}
UsesDrawer = new FR2_RefDrawer(this)
{
Lable = "Assets"
};
UsedByDrawer = new FR2_RefDrawer(this)
{
Lable = "Assets"
};
Duplicated = new FR2_DuplicateTree2(this);
SceneToAssetDrawer = new FR2_RefDrawer(this)
{
Lable = "Assets",
isDrawRefreshSceneCache = false
};
RefUnUse = new FR2_RefDrawer(this)
{
Lable = "Unsed Asset",
isDrawRefreshSceneCache = false
};
UsedInBuild = new FR2_UsedInBuild(this);
}
if (SceneUsesDrawer != null)
{
return;
}
SceneUsesDrawer = new FR2_RefDrawer(this)
{
Lable = "Scene Objects",
isDrawRefreshSceneCache = true
};
RefInScene = new FR2_RefDrawer(this)
{
Lable = "Scene Objects",
isDrawRefreshSceneCache = true
};
RefSceneInScene = new FR2_RefDrawer(this)
{
Lable = "Scene Objects",
isDrawRefreshSceneCache = true
};
lockSelection = false;
#if UNITY_2018_OR_NEWER
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChangedInEditMode -= OnSceneChanged;
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChangedInEditMode += OnSceneChanged;
#elif UNITY_2017_OR_NEWER
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChanged -= OnSceneChanged;
UnityEditor.SceneManagement.EditorSceneManager.activeSceneChanged += OnSceneChanged;
#endif
FR2_Cache.onReady -= OnReady;
FR2_Cache.onReady += OnReady;
FR2_Setting.OnIgnoreChange -= OnSelectionChange;
FR2_Setting.OnIgnoreChange += OnSelectionChange;
Repaint();
}
#if UNITY_2018_OR_NEWER
private void OnSceneChanged(Scene arg0, Scene arg1)
{
if (IsFocusingFindInScene || IsFocusingSceneToAsset || IsFocusingSceneInScene)
{
OnSelectionChange();
}
}
#endif
protected override void OnReady()
{
OnSelectionChange();
if (IsFocusingUnused)
{
RefUnUse.ResetUnusedAsset();
}
}
public override void OnSelectionChange()
{
Repaint();
isNoticeIgnore = false;
if (!FR2_Cache.isReady)
{
return;
}
if (lockSelection)
{
return;
}
if (focusedWindow == null)
{
return;
}
if (SceneUsesDrawer == null)
{
InitIfNeeded();
}
if (UsesDrawer == null)
{
InitIfNeeded();
}
ids = FR2_Unity.Selection_AssetGUIDs;
//ignore selection on asset when selected any object in scene
if (Selection.gameObjects.Length > 0 && !FR2_Unity.IsInAsset(Selection.gameObjects[0]))
{
ids = new string[0];
}
level = 0;
if (IsFocusingSceneToAsset)
{
SceneToAssetDrawer.Reset(Selection.gameObjects, true, true);
}
if (IsFocusingUses)
{
UsesDrawer.Reset(ids, true);
}
if (IsFocusingUsedBy)
{
UsedByDrawer.Reset(ids, false);
}
if (IsFocusingSceneInScene)
{
RefSceneInScene.ResetSceneInScene(Selection.gameObjects);
}
if (IsFocusingUses)
{
SceneUsesDrawer.ResetSceneUseSceneObjects(Selection.gameObjects);
}
if (IsFocusingFindInScene)
{
RefInScene.Reset(ids, this as IWindow);
}
if (IsFocusingGUIDs)
{
objs = new Object[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
objs[i] = FR2_Unity.LoadAssetAtPath<Object>
(
AssetDatabase.GUIDToAssetPath(ids[i])
);
}
}
if (FR2_SceneCache.Api.Dirty && !Application.isPlaying)
{
FR2_SceneCache.Api.refreshCache(this);
}
EditorApplication.delayCall -= Repaint;
EditorApplication.delayCall += Repaint;
}
// public static Rect windowRect;
//return true if draw tool along
protected override void OnGUI()
{
if (!CheckDrawHeader())
{
return;
}
//if (Selected.Count == 0){
// GUILayout.Label("Nothing selected");
//}
Rect rectTop = GetTopPanelRect();
Rect rectBot = GetBotPanelRect();
RefDrawConfig config1 = null, config2 = null, config3 = null;
var drawTool = false;
var drawCount = 0;
if (IsFocusingUses || IsFocusingSceneToAsset)
{
if (UsesDrawer.ElementCount() <= 0)
{
drawTool = GetDrawConfig(SceneUsesDrawer, SceneToAssetDrawer, out config1, out config2);
}
else
{
drawTool = GetDrawConfig(UsesDrawer, out config3);
}
}
else if (IsFocusingSceneInScene || IsFocusingFindInScene || IsFocusingUsedBy)
{
if (RefSceneInScene.ElementCount() <= 0)
{
drawTool = GetDrawConfig(RefInScene, UsedByDrawer, out config1, out config2);
}
else
{
drawTool = GetDrawConfig(RefSceneInScene, out config3);
}
}
else if (IsFocusingDuplicate)
{
drawTool = GetDrawConfig(Duplicated, out config1);
}
else if (IsFocusingGUIDs)
{
drawCount++;
if (AnyToolInBot)
{
GUILayout.BeginArea(rectTop);
DrawGUIDs();
GUILayout.EndArea();
drawTool = true;
}
else
{
DrawGUIDs();
drawTool = false;
}
}
else if (IsFocusingUnused)
{
drawCount++;
if (AnyToolInBot)
{
GUILayout.BeginArea(rectTop);
RefUnUse.Draw();
GUILayout.EndArea();
drawTool = true;
}
else
{
RefUnUse.Draw();
drawTool = false;
}
}
else if (IsFocusingUsedInBuild)
{
//Debug.Log("draw :" + IsFocusingUsedInBuild);
//drawTool = GetDrawConfig(UsedInBuild, out config1);
UsedInBuild.Draw();
}
if (!IsFocusingGUIDs && !IsFocusingUnused)
{
drawCount += DrawConfig(config1, rectTop, rectBot, ref willRepaint);
drawCount += DrawConfig(config2, rectTop, rectBot, ref willRepaint);
drawCount += DrawConfig(config3, rectTop, rectBot, ref willRepaint);
}
if (drawTool)
{
drawCount++;
GUILayout.BeginArea(rectBot);
DrawTool();
GUILayout.EndArea();
}
DrawFooter();
OnAfterGUI(drawCount);
}
protected override void OnTabChanged()
{
if (IsFocusingUsedInBuild)
{
UsedInBuild.RefreshView();
}
}
protected override void maskDirty()
{
UsedByDrawer.SetDirty();
UsesDrawer.SetDirty();
Duplicated.SetDirty();
SceneToAssetDrawer.SetDirty();
RefUnUse.SetDirty();
RefInScene.SetDirty();
RefSceneInScene.SetDirty();
SceneUsesDrawer.SetDirty();
UsedInBuild.SetDirty();
}
protected override void RefreshSort()
{
UsedByDrawer.RefreshSort();
UsesDrawer.RefreshSort();
Duplicated.RefreshSort();
SceneToAssetDrawer.RefreshSort();
RefUnUse.RefreshSort();
UsedInBuild.RefreshSort();
}
// public bool isExcludeByFilter;
protected override bool checkNoticeFilter()
{
var rsl = false;
if (IsFocusingUsedBy && !rsl)
{
rsl = UsedByDrawer.isExclueAnyItem();
}
if (IsFocusingDuplicate)
{
return Duplicated.isExclueAnyItem();
}
if (IsFocusingUses && rsl == false)
{
rsl = UsesDrawer.isExclueAnyItem();
}
if (IsFocusingSceneToAsset && rsl == false)
{
rsl = SceneToAssetDrawer.isExclueAnyItem();
}
if (IsFocusingFindInScene && !rsl)
{
rsl = RefInScene.isExclueAnyItem();
}
if (IsFocusingSceneInScene && !rsl)
{
rsl = RefSceneInScene.isExclueAnyItem();
}
//tab use by
return rsl;
}
protected override bool checkNoticeIgnore()
{
bool rsl = isNoticeIgnore;
return rsl;
}
private Object[] objs;
private string[] ids;
private void DrawGUIDs()
{
GUILayout.Label("GUID to Object", EditorStyles.boldLabel);
GUILayout.BeginHorizontal();
{
string guid = EditorGUILayout.TextField(tempGUID ?? string.Empty);
EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f));
if (GUILayout.Button("Paste", EditorStyles.miniButton, GUILayout.Width(70f)))
{
guid = EditorGUIUtility.systemCopyBuffer;
}
if (guid != tempGUID && !string.IsNullOrEmpty(guid))
{
tempGUID = guid;
tempObject = FR2_Unity.LoadAssetAtPath<Object>
(
AssetDatabase.GUIDToAssetPath(tempGUID)
);
}
}
GUILayout.EndHorizontal();
GUILayout.Space(10f);
if (objs == null || ids == null)
{
return;
}
//GUILayout.Label("Selection", EditorStyles.boldLabel);
if (ids.Length == objs.Length)
{
scrollPos = GUILayout.BeginScrollView(scrollPos);
{
for (var i = 0; i < ids.Length; i++)
{
GUILayout.BeginHorizontal();
{
EditorGUILayout.ObjectField(objs[i], typeof(Object), false);
string idi = ids[i];
GUILayout.TextField(idi, GUILayout.Width(240f));
if (GUILayout.Button("Copy", EditorStyles.miniButton, GUILayout.Width(50f)))
{
EditorGUIUtility.systemCopyBuffer = tempGUID = idi;
if (!string.IsNullOrEmpty(tempGUID))
{
tempObject = FR2_Unity.LoadAssetAtPath<Object>
(
AssetDatabase.GUIDToAssetPath(tempGUID)
);
}
//Debug.Log(EditorGUIUtility.systemCopyBuffer);
}
}
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView();
}
// GUILayout.FlexibleSpace();
// GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Merge Selection To"))
{
FR2_Export.MergeDuplicate();
}
EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f));
GUILayout.EndHorizontal();
GUILayout.Space(5f);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59de5c9b86a054d2bba67e3b35d00a6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+735
View File
@@ -0,0 +1,735 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public interface IWindow
{
bool IsFocusingDuplicate { get; }
bool WillRepaint { get; set; }
void Repaint();
void OnSelectionChange();
Dictionary<string, FR2_Ref> GetUsedByRefs();
}
internal interface IRefDraw
{
IWindow window { get; }
int ElementCount();
bool Draw();
}
internal class RefDrawConfig
{
public bool drawGlobal;
public bool drawInTop;
public bool isDraw;
public bool isDrawTool;
public IRefDraw refDrawer;
public RefDrawConfig(IRefDraw drawer)
{
refDrawer = drawer;
}
}
// internal class ShareData
// {
// //internal static Dictionary<string, FR2_Ref> UsedBy;
// }
public abstract class FR2_WindowBase : EditorWindow, IWindow
{
public virtual bool ShowScene { get; }
internal class Icon
{
static Icon _icon;
public GUIContent Refresh;
public GUIContent Lock;
public GUIContent LockOn;
public GUIContent Setting;
public static Icon icons => _icon ??= new Icon
{
Refresh = EditorGUIUtility.IconContent("d_Refresh"),
Lock = EditorGUIUtility.IconContent("LockIcon"),
LockOn = EditorGUIUtility.IconContent("LockIcon-On"),
Setting = EditorGUIUtility.IconContent("d_SettingsIcon", "Settings")
};
}
protected int selectedTab;
protected bool IsFocusingUses
{
get { return selectedTab == 0; }
}
protected bool IsFocusingUsedBy
{
get { return selectedTab == 1; }
}
public bool IsFocusingDuplicate
{
get { return selectedTab == 2; }
}
protected bool IsFocusingUnused
{
get { return selectedTab == 4; }
}
protected bool IsFocusingGUIDs
{
get { return selectedTab == 3; }
}
protected bool IsFocusingUsedInBuild
{
get { return selectedTab == 5; }
}
protected bool IsFocusingFindInScene
{
get { return selectedTab == 1; }
}
protected bool IsFocusingSceneToAsset
{
get { return selectedTab == 0; }
}
protected bool IsFocusingSceneInScene
{
get { return selectedTab == 1; }
}
public bool WillRepaint { get; set; }
protected bool showFilter, showSetting, showIgnore;
protected static GUIContent[] TOOLBARS =
{
new GUIContent("Uses"),
new GUIContent("Used By"),
new GUIContent("Duplicate"),
new GUIContent("GUIDs"),
new GUIContent("Unused Assets"),
new GUIContent("Uses In Build")
};
[NonSerialized] protected bool lockSelection;
[NonSerialized] internal List<FR2_Asset> Selected;
public float sizeRatio = 0.5f;
protected Rect resizer;
protected bool isResizing;
protected GUIStyle resizerStyle;
public static bool isNoticeIgnore;
public void AddItemsToMenu(GenericMenu menu)
{
FR2_Cache api = FR2_Cache.Api;
if (api == null)
{
return;
}
menu.AddDisabledItem(new GUIContent("FR2 - v2.4.3"));
menu.AddSeparator(string.Empty);
menu.AddItem(new GUIContent("Enable"), !api.disabled, () => { api.disabled = !api.disabled; });
menu.AddItem(new GUIContent("Clear Selection"), false, () => { FR2_Selection.ClearSelection(); });
menu.AddItem(new GUIContent("Commit Selection (" + FR2_Selection.SelectionCount + ")"), false,
FR2_Selection.Commit);
menu.AddItem(new GUIContent("Refresh"), false, () =>
{
FR2_Asset.lastRefreshTS = Time.realtimeSinceStartup;
FR2_Cache.Api.Check4Changes(true, true);
FR2_SceneCache.Api.SetDirty();
});
#if FR2_DEV
menu.AddItem(new GUIContent("Refresh Usage"), false, () => FR2_Cache.Api.Check4Usage());
menu.AddItem(new GUIContent("Refresh Selected"), false, ()=> FR2_Cache.Api.RefreshSelection());
menu.AddItem(new GUIContent("Clear Cache"), false, () => FR2_Cache.Api.Clear());
#endif
}
protected virtual void OnTabChanged() { }
protected abstract void InitIfNeeded();
public abstract void OnSelectionChange();
protected abstract void OnGUI();
protected abstract void RefreshSort();
protected abstract void maskDirty();
protected abstract bool checkNoticeFilter();
protected abstract bool checkNoticeIgnore();
protected abstract void OnReady();
#if UNITY_2018_OR_NEWER
protected void OnSceneChanged(Scene arg0, Scene arg1)
{
if (IsFocusingFindInScene || IsFocusingSceneToAsset || IsFocusingSceneInScene)
{
OnSelectionChange();
}
}
#endif
protected bool willRepaint;
protected bool CheckDrawHeader()
{
if (EditorApplication.isCompiling)
{
EditorGUILayout.HelpBox("Compiling scripts, please wait!", MessageType.Warning);
Repaint();
return false;
}
if (EditorApplication.isUpdating)
{
EditorGUILayout.HelpBox("Importing assets, please wait!", MessageType.Warning);
Repaint();
return false;
}
InitIfNeeded();
if (EditorSettings.serializationMode != SerializationMode.ForceText)
{
EditorGUILayout.HelpBox("FR2 requires serialization mode set to FORCE TEXT!", MessageType.Warning);
if (GUILayout.Button("FORCE TEXT"))
{
EditorSettings.serializationMode = SerializationMode.ForceText;
}
return false;
}
if (FR2_Cache.hasCache && !FR2_Cache.CheckSameVersion())
{
EditorGUILayout.HelpBox("Incompatible cache version found, need a full refresh may take time!",
MessageType.Warning);
if (GUILayout.Button("Scan project"))
{
FR2_Cache.DeleteCache();
FR2_Cache.CreateCache();
}
return false;
}
if (!FR2_Cache.isReady)
{
if (!FR2_Cache.hasCache)
{
EditorGUILayout.HelpBox(
"FR2 cache not found!\nFirst scan may takes quite some time to finish but you would be able to work normally while the scan works in background...",
MessageType.Warning);
if (GUILayout.Button("Scan project"))
{
FR2_Cache.CreateCache();
}
return false;
}
if (!DrawEnable())
{
return false;
}
FR2_Cache api = FR2_Cache.Api;
string text = "Refreshing ... " + (int) (api.progress * api.workCount) + " / " + api.workCount;
Rect rect = GUILayoutUtility.GetRect(1f, Screen.width, 18f, 18f);
EditorGUI.ProgressBar(rect, api.progress, text);
Repaint();
return false;
}
if (!DrawEnable())
{
return false;
}
willRepaint = Event.current.type == EventType.ScrollWheel;
int newTab = selectedTab;
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
Color color = GUI.contentColor;
GUI.contentColor = EditorGUIUtility.isProSkin
? new Color(0.9f, 0.9f, 0.9f, 1f)
: new Color(0.1f, 0.1f, 0.1f, 1f);
GUIContent icon = Icon.icons.Lock;
if (lockSelection)
{
icon = Icon.icons.LockOn;
}
bool v = GUILayout.Toggle(lockSelection, icon, EditorStyles.toolbarButton, GUILayout.Width(21f));
GUI.contentColor = color;
if (v != lockSelection)
{
lockSelection = v;
if (lockSelection == false)
{
OnSelectionChange();
}
willRepaint = true;
}
for (var i = 0; i < TOOLBARS.Length; i++)
{
if (ShowScene && i > 1)
{
break;
}
bool isSelected = selectedTab == i;
bool b = GUILayout.Toggle(isSelected, TOOLBARS[i], EditorStyles.toolbarButton);
if (b != isSelected)
{
newTab = i;
}
}
// newTab = GUILayout.Toolbar(selectedTab, TOOLBARS);
}
GUILayout.EndHorizontal();
if (newTab != selectedTab)
{
selectedTab = newTab;
OnTabChanged();
// Check4Changes means delay calls to OnReady :: Refresh !
//if (FR2_Cache.Api.isReady) FR2_Cache.Api.Check4Changes();
OnReady();
}
if (Selected == null)
{
Selected = new List<FR2_Asset>();
}
return true;
}
protected void OnAfterGUI(int drawCount)
{
if (willRepaint || WillRepaint || !FR2_SceneCache.ready)
{
WillRepaint = false;
Repaint();
}
if (drawCount > 1)
{
DrawResizer();
ProcessEvents(Event.current);
}
if (GUI.changed)
{
Repaint();
}
}
protected bool DrawEnable()
{
FR2_Cache api = FR2_Cache.Api;
if (api == null)
{
return false;
}
bool v = api.disabled;
if (v)
{
EditorGUILayout.HelpBox("Find References 2 is disabled!", MessageType.Warning);
if (GUILayout.Button("Enable"))
{
api.disabled = !api.disabled;
Repaint();
}
return !api.disabled;
}
if (!api.ready)
{
float w = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 70f;
api.priority = EditorGUILayout.IntSlider("Priority", api.priority, 0, 5);
EditorGUIUtility.labelWidth = w;
}
return !api.disabled;
}
protected bool AnyToolInBot
{
get { return FR2_Setting.showSettings || showIgnore || showFilter; }
}
internal bool GetDrawConfig(IRefDraw refDrawer, out RefDrawConfig config)
{
bool drawTool = AnyToolInBot;
config = new RefDrawConfig(refDrawer);
config.drawGlobal = !drawTool;
config.drawInTop = drawTool;
config.isDraw = true;
return drawTool;
}
internal bool GetDrawConfig(IRefDraw refTop, IRefDraw refBot, out RefDrawConfig config1,
out RefDrawConfig config2)
{
var drawTool = true;
config1 = new RefDrawConfig(refTop);
config2 = new RefDrawConfig(refBot);
config1.isDraw = config1.refDrawer.ElementCount() > 0;
config2.isDraw = config2.refDrawer.ElementCount() > 0;
if (AnyToolInBot)
{
if (refTop.ElementCount() > 0)
{
config1.drawInTop = true;
if (refBot.ElementCount() > 0)
{
drawTool = false;
config2.isDrawTool = true;
}
}
else
{
config2.drawInTop = true;
}
}
else
{
drawTool = false;
if (refTop.ElementCount() > 0)
{
config1.drawInTop = true;
if (refBot.ElementCount() > 0)
{
config2.drawInTop = false;
}
else
{
config1.drawGlobal = true;
}
}
else
{
// config2.drawInTop = true;
config2.drawGlobal = true;
}
}
return drawTool;
}
internal int DrawConfig(RefDrawConfig config, Rect rectTop, Rect rectBot, ref bool WillRepaint)
{
if (config == null)
{
return 0;
}
if (config.refDrawer == null)
{
return 0;
}
if (!config.isDraw)
{
return 0;
}
var willRepaint = false;
if (config.drawGlobal)
{
willRepaint = config.refDrawer.Draw();
}
else
{
if (config.drawInTop)
{
GUILayout.BeginArea(rectTop);
willRepaint = config.refDrawer.Draw();
GUILayout.EndArea();
}
else if (config.isDrawTool)
{
GUILayout.BeginArea(rectBot);
willRepaint = config.refDrawer.Draw();
DrawTool();
GUILayout.EndArea();
}
else
{
GUILayout.BeginArea(rectBot);
willRepaint = config.refDrawer.Draw();
GUILayout.EndArea();
}
}
if (willRepaint)
{
WillRepaint = true;
}
return 1;
}
protected void DrawTool()
{
if (showFilter)
{
if (AssetType.DrawSearchFilter())
{
maskDirty();
}
}
else if (showIgnore)
{
GUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.Label("Ignores");
// showContent = EditorGUILayout.Foldout(showContent, searchLable);
GUILayout.EndHorizontal();
if (AssetType.DrawIgnoreFolder())
{
maskDirty();
}
}
else if (FR2_Setting.showSettings)
{
FR2_Setting.s.DrawSettings();
}
}
public Rect GetTopPanelRect()
{
return new Rect(0, 17, position.width, position.height * sizeRatio - 20);
}
public Rect GetBotPanelRect()
{
return new Rect(0, position.height * sizeRatio + 5, position.width,
position.height * (1 - sizeRatio) - 5 - paddingBot);
}
private void DrawResizer()
{
resizer = new Rect(0, position.height * sizeRatio - 5f, position.width, 10f);
Vector2 a = resizer.position + Vector2.up * 5f;
GUILayout.BeginArea(new Rect(a.x, a.y, position.width, 1), resizerStyle);
// GUILayout.BeginArea(new Rect(resizer.position + (Vector2.up * 5f), new Vector2(position.width, 1)), resizerStyle);
GUILayout.EndArea();
EditorGUIUtility.AddCursorRect(resizer, MouseCursor.ResizeVertical);
}
protected void ProcessEvents(Event e)
{
switch (e.type)
{
case EventType.MouseDown:
if (e.button == 0 && resizer.Contains(e.mousePosition))
{
isResizing = true;
}
break;
#if UNITY_5_3_OR_NEWER
case EventType.MouseLeaveWindow:
#endif
case EventType.MouseUp:
isResizing = false;
break;
}
Resize(e);
}
private void Resize(Event e)
{
if (isResizing)
{
sizeRatio = e.mousePosition.y / position.height;
normalizeSize();
Repaint();
}
}
private void normalizeSize()
{
if (sizeRatio * position.height < paddingTop)
{
sizeRatio = paddingTop / position.height;
}
if (position.height - sizeRatio * position.height < paddingBot)
{
sizeRatio = (position.height - paddingBot) * 1f / position.height;
}
}
private const float paddingTop = 70;
private const float paddingBot = 25;
protected void DrawFooter()
{
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
Color color = GUI.contentColor;
GUI.contentColor = EditorGUIUtility.isProSkin
? new Color(0.9f, 0.9f, 0.9f, 1f)
: new Color(0.1f, 0.1f, 0.1f, 1f);
if (FR2_Unity.DrawToggleToolbar(ref FR2_Setting.showSettings, Icon.icons.Setting, 21f))
{
maskDirty();
if (FR2_Setting.showSettings)
{
showFilter = showIgnore = false;
}
}
GUI.contentColor = color;
bool v = checkNoticeFilter();
string content = !FR2_Setting.IsIncludeAllType() ? "*Filter" : "Filter";
if (v)
{
Color oc = GUI.backgroundColor;
GUI.backgroundColor = Color.red;
v = GUILayout.Toggle(showFilter, content, EditorStyles.toolbarButton, GUILayout.Width(50f));
GUI.backgroundColor = oc;
}
else
{
v = GUILayout.Toggle(showFilter, content, EditorStyles.toolbarButton, GUILayout.Width(50f));
}
if (v != showFilter)
{
showFilter = v;
if (showFilter)
{
FR2_Setting.showSettings = showIgnore = false;
}
}
v = checkNoticeIgnore();
content = FR2_Setting.IgnoreAsset.Count > 0 ? "*Ignore" : "Ignore";
if (v)
{
Color oc = GUI.backgroundColor;
GUI.backgroundColor = Color.red;
v = GUILayout.Toggle(showIgnore, content, EditorStyles.toolbarButton, GUILayout.Width(50f));
GUI.backgroundColor = oc;
}
else
{
v = GUILayout.Toggle(showIgnore, content, EditorStyles.toolbarButton, GUILayout.Width(50f));
}
// var i = GUILayout.Toggle(showIgnore, content, EditorStyles.toolbarButton, GUILayout.Width(50f));
if (v != showIgnore)
{
showIgnore = v;
if (v)
{
showFilter = FR2_Setting.showSettings = false;
}
}
bool ss = FR2_Setting.ShowSelection;
v = GUILayout.Toggle(ss, "Selection", EditorStyles.toolbarButton, GUILayout.Width(60f));
if (v != ss)
{
FR2_Setting.ShowSelection = v;
maskDirty();
}
if (FR2_Selection.SelectionCount > 0)
{
if (GUILayout.Button("Commit Selection [" + FR2_Selection.SelectionCount + "]",
EditorStyles.toolbarButton))
{
FR2_Selection.Commit();
}
if (GUILayout.Button("Clear Selection", EditorStyles.toolbarButton))
{
FR2_Selection.ClearSelection();
}
}
GUILayout.FlexibleSpace();
if (!IsFocusingDuplicate && !IsFocusingGUIDs)
{
float o = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 42f;
FR2_RefDrawer.Mode ov = FR2_Setting.GroupMode;
var vv = (FR2_RefDrawer.Mode) EditorGUILayout.EnumPopup("Group", ov, GUILayout.Width(122f));
if (vv != ov)
{
FR2_Setting.GroupMode = vv;
maskDirty();
}
GUILayout.Space(4f);
EditorGUIUtility.labelWidth = 30f;
FR2_RefDrawer.Sort s = FR2_Setting.SortMode;
var vvv = (FR2_RefDrawer.Sort) EditorGUILayout.EnumPopup("Sort", s, GUILayout.Width(100f));
if (vvv != s)
{
FR2_Setting.SortMode = vvv;
RefreshSort();
}
EditorGUIUtility.labelWidth = o;
}
}
GUILayout.EndHorizontal();
}
public Dictionary<string, FR2_Ref> GetUsedByRefs()
{
return null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 846de4aca6426f74c8cacda9de44511f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: