Created
May 10, 2017 18:59
-
-
Save arkms/ef2d76f2784e3d0424e7171d98297279 to your computer and use it in GitHub Desktop.
A simple script that check if exist some conflict with all Resources folders in project. For use it just go to ' Window/ResourcesCheckConflict '
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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