Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple script that check if exist some conflict with all Resources folders in project. For use it just go to ' Window/ResourcesCheckConflict '
//This script put inside a Folder with the name 'Editor'
//Developer by ARKMs , use it with total liberty
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections.Generic;
public class ResourcesCheckConflict
{
[MenuItem( "Window/ResourcesCheckConflict" )]
static void ResourcesCheckConflictCall()
{
CheckResourcesConflict();
}
class RESOURCESDATA
{
public string name;
public string path;
public RESOURCESDATA( string path )
{
string fullAssetsPath = Path.GetFullPath("Assets").Replace('\\', '/');
path = path.Replace('\\', '/');
path = path.Replace(fullAssetsPath, "");
this.path = path;
var parts = path.Split( new string[] { "Resources/" }, StringSplitOptions.RemoveEmptyEntries );
this.name = parts[1];
}
}
static void CheckResourcesConflict()
{
// find all Resources folders
string[] dirs = Directory.GetDirectories( Application.dataPath, "Resources", SearchOption.AllDirectories );
List<RESOURCESDATA> resources = new List<RESOURCESDATA>();
//Get all files
for(int i=0; i<dirs.Length; i++)
{
resources.AddRange( getAllResourcesAtPath( dirs[i] ) );
}
//Check if exist a conflict
List<string> resourceNames = new List<string>();
List<string> resourcePath = new List<string>(); //This only helps show the path in conflict
for (int i=0; i<resources.Count; i++)
{
if(resourceNames.Contains( resources[i].name ) )
{
Debug.LogError ( "Conflict: " + resources[i].name + " path " + resources[i].path + " with: " + resourcePath[resourceNames.IndexOf(resources[i].name)]);
continue;
}
resourceNames.Add( resources[i].name );
resourcePath.Add(resources[i].path);
}
Debug.Log ("--finish check Resources conflict--");
}
//This function return all files inside a Resources folder
static List<RESOURCESDATA> getAllResourcesAtPath( string path )
{
List<RESOURCESDATA> resources = new List<RESOURCESDATA>();
string[] files = Directory.GetFiles( path, "*", SearchOption.AllDirectories );
for(int i=0; i<files.Length; i++)
{
if( files[i].EndsWith( ".meta" ) || files[i].EndsWith( ".db" ) || files[i].EndsWith( ".DS_Store" ) )
continue;
resources.Add( new RESOURCESDATA(files[i]) );
}
return resources;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment