public static List <List <GameObject> > LoadAssetOnScenes(ResearcheType thisType, Object objComp, string thisStringSearch, bool getChildren, int diffComp = 2) { GameObject[] objectList = UnityEngine.SceneManagement.SceneManager.GetActiveScene( ).GetRootGameObjects( ); List <List <GameObject> > getAllObj = new List <List <GameObject> > ( ); List <GameObject> getObj; if (getChildren) { for (int a = 0; a < objectList.Length; a++) { getObj = returnCurrObj(GetComponentsInChildrenOfAsset(objectList [a]), thisType, objComp, thisStringSearch, diffComp); if (getObj.Count > 0) { getAllObj.Add(getObj); } } } else { getObj = returnCurrObj(objectList, thisType, objComp, thisStringSearch); if (getObj.Count > 0) { getAllObj.Add(getObj); } } return(getAllObj); }
public static List <List <GameObject> > LoadOnPrefab(ResearcheType thisType, Object objComp, List <GameObject> thisPref, string thisStringSearch, bool getChildren, int diffComp = 2) { List <List <GameObject> > objectList = new List <List <GameObject> > ( ); List <GameObject> getObj; int a; if (getChildren) { for (a = 0; a < thisPref.Count; a++) { getObj = returnCurrObj(GetComponentsInChildrenOfAsset(thisPref [a]), thisType, objComp, thisStringSearch, diffComp); if (getObj.Count > 0) { objectList.Add(getObj); } } } else { getObj = returnCurrObj(thisPref.ToArray( ), thisType, objComp, thisStringSearch); if (getObj.Count > 0) { objectList.Add(getObj); } } return(objectList); }
public static List <List <GameObject> > LoadAssetsInProject(ResearcheType thisType, Object objComp, string thisStringSearch, bool getChildren, string optionalPath = "", int diffComp = 2) { string currTag = thisStringSearch; string[] GUIDs; if (optionalPath != "") { if (optionalPath.EndsWith("/")) { optionalPath = optionalPath.TrimEnd('/'); } GUIDs = AssetDatabase.FindAssets("t:GameObject", new string[] { optionalPath }); } else { GUIDs = AssetDatabase.FindAssets("t:GameObject"); } List <List <GameObject> > objectList = new List <List <GameObject> > ( ); List <GameObject> asset = new List <GameObject> ( ); List <GameObject> getObj; string guid; string assetPath; int a; for (a = 0; a < GUIDs.Length; a++) { guid = GUIDs [a]; assetPath = AssetDatabase.GUIDToAssetPath(guid); asset.Add(AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject); } if (getChildren) { for (a = 0; a < asset.Count; a++) { getObj = returnCurrObj(GetComponentsInChildrenOfAsset(asset [a]), thisType, objComp, thisStringSearch, diffComp); if (getObj.Count > 0) { objectList.Add(getObj); } } } else { getObj = returnCurrObj(asset.ToArray( ), thisType, objComp, thisStringSearch); if (getObj.Count > 0) { objectList.Add(getObj); } } return(objectList); }
void OnEnable() { thisType = ResearcheType.Tag; thisStringSearch = string.Empty; SpecificPath = string.Empty; objComp = null; thisNbr = 0; getChildren = true; childProj = true; childScene = true; childPref = true; foldListPref = true; foldComp = false; apply = false; aPageProj = 0; aPageScene = 0; aPagePref = 0; compDiff = 2; scrollPosProj = Vector2.zero; scrollPosScene = Vector2.zero; scrollPosPref = Vector2.zero; bPageProj = new List <int> ( ); bPageScene = new List <int> ( ); bPagePref = new List <int> ( ); foldoutProj = new List <bool> ( ); foldoutScene = new List <bool> ( ); foldoutPref = new List <bool> ( ); AllObjectProject = new List <List <GameObject> > ( ); AllObjectScene = new List <List <GameObject> > ( ); InfoOnPrefab = new List <List <GameObject> > ( ); thispref = new List <GameObject> ( ); CompInfo = new List <Component> ( ); }
static List <GameObject> returnCurrObj(GameObject[] objectList, ResearcheType thisType, Object objComp, string thisStringSearch, int diffComp = 2) { List <GameObject> objTagList = new List <GameObject> ( ); Component [] components; Component [] componentsPref; GameObject getPref; if (thisType == ResearcheType.SamePref) { if (objComp == null) { return(new List <GameObject> ( )); } getPref = ( GameObject )objComp; componentsPref = getPref.GetComponents <Component> ( ); } else { getPref = objectList [0]; componentsPref = getPref.GetComponents <Component> ( ); } string getSearch = thisStringSearch; int a; int b; for (a = 0; a < objectList.Length; a++) { if (objectList [a] == null) { continue; } switch (thisType) { case ResearcheType.Tag: if (getSearch == string.Empty || objectList[a].tag == getSearch) { objTagList.Add(objectList [a]); } break; case ResearcheType.Name: if (objectList[a].name == getSearch) { objTagList.Add(objectList [a]); } break; case ResearcheType.Layer: if (objectList[a].layer == int.Parse(getSearch)) { objTagList.Add(objectList [a]); } break; case ResearcheType.Component: components = objectList[a].GetComponents <Component> ( ); if (objComp == null) { return(new List <GameObject> ( )); } for (b = 0; b < components.Length; b++) { if (components [b] != null && components [b].GetType( ) == objComp.GetType( )) { objTagList.Add(objectList[a]); break; } } break; case ResearcheType.MissingComp: components = objectList[a].GetComponents <Component> ( ); for (b = 0; b < components.Length; b++) { if (!components [b]) { objTagList.Add(objectList[a]); break; } } break; case ResearcheType.SamePref: components = objectList [a].GetComponents <Component> ( ); if ((componentsPref.Length - components.Length <= diffComp) && objectList [a].name.Length >= getPref.name.Length && objectList [a].name.Substring(0, getPref.name.Length) == getPref.name) { objTagList.Add(objectList [a]); } break; } } return(objTagList); }
void OnGUI() { List <List <GameObject> > getAllOnProj = AllObjectProject; List <List <GameObject> > getAllOnScene = AllObjectScene; List <List <GameObject> > getAllOnPrefab = InfoOnPrefab; List <int> bProj = bPageProj; List <int> bScene = bPageScene; List <int> bPref = bPagePref; List <bool> fPref = foldoutPref; List <bool> fScene = foldoutScene; List <bool> fProj = foldoutProj; int a; GUILayout.Label("Get Specific object", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck( ); thisType = (ResearcheType)EditorGUILayout.EnumPopup("Research Type:", thisType); if (EditorGUI.EndChangeCheck( )) { AllObjectScene = new List <List <GameObject> > ( ); AllObjectProject = new List <List <GameObject> > ( ); InfoOnPrefab = new List <List <GameObject> > ( ); objComp = null; thisStringSearch = string.Empty; thisNbr = 0; compDiff = 2; apply = false; } switch (thisType) { case ResearcheType.Tag: thisStringSearch = EditorGUILayout.TagField("Search This Tag :", thisStringSearch); break; case ResearcheType.Layer: thisNbr = EditorGUILayout.LayerField("Search This Number Layer :", thisNbr); thisStringSearch = thisNbr.ToString( ); break; case ResearcheType.Name: thisStringSearch = EditorGUILayout.TextField("Search This Name :", thisStringSearch); break; case ResearcheType.Component: objComp = EditorGUILayout.ObjectField("This component", objComp, typeof(Object), true); break; case ResearcheType.SamePref: EditorGUILayout.BeginVertical( ); EditorGUI.BeginChangeCheck( ); objComp = EditorGUILayout.ObjectField("This Object", objComp, typeof(Object), true); if (EditorGUI.EndChangeCheck( )) { apply = false; CompInfo = new List <Component> ( ); if (objComp != null) { GameObject getObj = ( GameObject )objComp; foreach (Component thisComp in getObj.GetComponents <Component> ( )) { CompInfo.Add(thisComp); } } } compDiff = (int)EditorGUILayout.Slider("Max Number Component Different", compDiff, 0, 10); EditorGUILayout.EndVertical( ); break; } var buttonStyle = new GUIStyle(EditorStyles.miniButton); if (getChildren) { buttonStyle.normal.textColor = Color.green; } else { buttonStyle.normal.textColor = Color.red; } if (GUILayout.Button("Search On Children", buttonStyle)) { getChildren = !getChildren; } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Object On Scene")) { aPageScene = 0; bPageScene = new List <int> ( ); bScene = bPageScene; fScene = foldoutScene; childScene = getChildren; AllObjectScene = SearchObject.LoadAssetOnScenes(thisType, objComp, thisStringSearch, getChildren, compDiff); getAllOnScene = AllObjectScene; for (a = 0; a < getAllOnScene.Count; a++) { bScene.Add(0); fScene.Add(false); } } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Object On Object")) { bPageProj = new List <int> ( ); foldoutProj = new List <bool> ( ); fProj = foldoutProj; bProj = bPageProj; aPageProj = 0; childProj = getChildren; AllObjectProject = SearchObject.LoadAssetsInProject(thisType, objComp, thisStringSearch, getChildren, SpecificPath, compDiff); getAllOnProj = AllObjectProject; for (a = 0; a < getAllOnProj.Count; a++) { bProj.Add(0); fProj.Add(false); } } SpecificPath = EditorGUILayout.TextField("On Specific folder :", SpecificPath); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Object On Prefabs") && thispref != null) { aPagePref = 0; bPagePref = new List <int> ( ); bPref = bPagePref; fPref = foldoutPref; childPref = getChildren; InfoOnPrefab = SearchObject.LoadOnPrefab(thisType, objComp, thispref, thisStringSearch, getChildren, compDiff); getAllOnPrefab = InfoOnPrefab; for (a = 0; a < getAllOnPrefab.Count; a++) { bPref.Add(0); fPref.Add(false); } } var list = thispref; int newCount = Mathf.Max(0, EditorGUILayout.IntField("Number Ref", list.Count)); while (newCount < list.Count) { list.RemoveAt(list.Count - 1); } while (newCount > list.Count) { list.Add(null); } EditorGUILayout.BeginVertical( ); if (thispref.Count > 0) { foldListPref = EditorGUILayout.Foldout(foldListPref, "Object List"); } if (foldListPref) { for (a = 0; a < thispref.Count; a++) { thispref [a] = ( GameObject )EditorGUILayout.ObjectField("This component", thispref [a], typeof(GameObject), true); } } EditorGUILayout.EndVertical( ); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space( ); EditorGUILayout.Space( ); if (thisType == ResearcheType.SamePref) { if (apply) { EditorGUILayout.BeginHorizontal( ); if (GUILayout.Button("Confirm", EditorStyles.miniButton)) { modifPref(getAllOnScene); modifPref(getAllOnProj); modifPref(getAllOnPrefab); apply = false; } if (GUILayout.Button("Cancel", EditorStyles.miniButton)) { apply = false; } EditorGUILayout.EndHorizontal( ); } else { EditorGUILayout.BeginHorizontal( ); if ((getAllOnScene.Count > 0 || getAllOnProj.Count > 0 || getAllOnPrefab.Count > 0) && CompInfo.Count > 0 && GUILayout.Button("Apply Update", EditorStyles.miniButton)) { apply = true; } EditorGUILayout.BeginVertical( ); EditorGUI.indentLevel = 2; if (CompInfo.Count > 0) { foldComp = EditorGUILayout.Foldout(foldComp, "Component List"); } if (foldComp) { for (a = 0; a < CompInfo.Count; a++) { EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel(CompInfo [a].GetType( ).ToString( )); if (GUILayout.Button("Remove From Update", EditorStyles.miniButton)) { CompInfo.RemoveAt(a); a--; } EditorGUILayout.EndHorizontal( ); } } EditorGUI.indentLevel = 0; EditorGUILayout.EndVertical( ); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal( ); #region Scene Layout if (getAllOnScene.Count > 0) { scrollPosScene = EditorGUILayout.BeginScrollView(scrollPosScene); if (GUILayout.Button("Clear Scene", EditorStyles.miniButton)) { AllObjectScene = new List <List <GameObject> > ( ); } aPageScene = LayoutSearch(getAllOnScene, bScene, fScene, aPageScene, childScene); EditorGUILayout.EndScrollView( ); } #endregion #region Project layout if (getAllOnProj.Count > 0) { scrollPosProj = EditorGUILayout.BeginScrollView(scrollPosProj); if (GUILayout.Button("Clear Project", EditorStyles.miniButton)) { AllObjectProject = new List <List <GameObject> > ( ); } aPageProj = LayoutSearch(getAllOnProj, bProj, fProj, aPageProj, childProj); EditorGUILayout.EndScrollView( ); } #endregion #region Pref Layout if (getAllOnPrefab.Count > 0) { scrollPosPref = EditorGUILayout.BeginScrollView(scrollPosPref); if (GUILayout.Button("Clear Pref", EditorStyles.miniButton)) { InfoOnPrefab = new List <List <GameObject> > ( ); } aPagePref = LayoutSearch(getAllOnPrefab, bPref, fPref, aPagePref, childPref); EditorGUILayout.EndScrollView( ); } #endregion EditorGUILayout.EndHorizontal(); }