public IActionResult EditMaterialVendors([FromBody] MaterialVendorsEditForm form) { var error = new Error(); if (form.MaterialVendors.Count <= 0) { return(BadRequest("No material vendors were provided")); } var materials = new List <MaterialVendor>(); foreach (var materialVendor in form.MaterialVendors) { materials.Add(materialVendor.MapToCore()); } foreach (var materialVendor in materials) { _materialManager.ValidateMaterial(materialVendor, ref error); if (error.ErrorCode != ErrorCode.OKAY) { return(BadRequest(error.Message)); } } foreach (var materialVendor in materials) { _materialManager.UpdateMaterialVendor(materialVendor); } var material = _materialManager.GetMaterial(form.MaterialVendors[0].MaterialId); var response = MaterialDetails.MapFromObject(material); return(Ok(response)); }
public async Task <IActionResult> Edit(int id, [Bind("MaterialDetailsId,Name,ShortName,ProductCode,AvgWeighTime,AvgWaitTime,CostPerTon,IncludeInMatVar,ParallelWeighGroup,ParallelGroupOrder,IsActive,NeedsDetailsInput,StartDate,EndDate")] MaterialDetails materialDetails) { if (id != materialDetails.MaterialDetailsId) { return(NotFound()); } if (ModelState.IsValid) { try { _materialDetailsRepository.Update(materialDetails); await _materialDetailsRepository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MaterialDetailsExists(materialDetails.MaterialDetailsId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(materialDetails)); }
// Load attachment from embedded resource. private Attachment CreateMaterialsAttachment(MaterialDetails matDeets) { List <string> jumperList = new List <string>() { "jumper", "sweater", "hoodie", "oodie", "jersey" }; //To Do: Add logic for different fixes... call IFitIt api? var cardResourcePath = "FixerBot.Cards.welcomeCard.json"; if (jumperList.Contains(matDeets.Item.Split(" ").Last().ToLower())) { cardResourcePath = "FixerBot.Cards.buyThreadCard.json"; } using (var stream = GetType().Assembly.GetManifestResourceStream(cardResourcePath)) { using (var reader = new StreamReader(stream)) { var adaptiveCard = reader.ReadToEnd(); return(new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(adaptiveCard), }); } } }
private async Task <DialogTurnResult> ResolveMendingChoiceAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var result = ((FoundChoice)stepContext.Result).Value; var fixDetails = (FixDetails)stepContext.Options; switch (result) { case "I Can't Do This": var postingDetails = new PostingDetails { Posting = Posting.GetPerson, Item = fixDetails.Item, Problem = fixDetails.Problem }; return(await stepContext.BeginDialogAsync(nameof(CreatePostingDialog), postingDetails, cancellationToken)); case "I Need Materials": MaterialDetails matDeets = new MaterialDetails(fixDetails); return(await stepContext.BeginDialogAsync(nameof(GetMaterialsDialog), matDeets, cancellationToken)); case "Mending Complete": // TO DO: Give Feedback and level up! return(await stepContext.NextAsync(null, cancellationToken)); default: return(await stepContext.NextAsync(null, cancellationToken)); } }
public IActionResult GetMaterial(int materialId) { var material = _materialManager.GetMaterial(materialId); var response = MaterialDetails.MapFromObject(material); return(Ok(response)); }
public MaterialDetails AddNewFoundMaterial(MaterialDetails newMaterial) { newMaterial.NeedsDetailsInput = true; newMaterial.IsActive = true; _context.MaterialDetails.Add(newMaterial); _context.SaveChanges(); return(newMaterial); }
protected override void Awake() { details = gameObject.GetComponent <MaterialDetails>(); if (disableWhenIdle && enabled && IsIdle()) { startDisabled = true; enabled = false; } }
public IActionResult EditMaterial([FromBody] MaterialEditForm form) { var error = new Error(); var material = _materialManager.UpdateMaterial(form.MapToCore(), ref error); if (error.ErrorCode != ErrorCode.OKAY) { return(BadRequest(error.Message)); } var response = MaterialDetails.MapFromObject(material); return(Ok(response)); }
MaterialDetails TryAddActiveMaterial(Material mat) { if (mat != null) { MaterialDetails details = FindMaterialDetails(mat); if (details == null) { details = new MaterialDetails(mat); ActiveMaterials.Add(details); } return(details); } return(null); }
private TextureDetails GetTextureDetail(Texture tTexture, Material tMaterial, MaterialDetails tMaterialDetails) { TextureDetails tTextureDetails = GetTextureDetail(tTexture); tTextureDetails.FoundInMaterials.Add(tMaterial); foreach (Renderer renderer in tMaterialDetails.FoundInRenderers) { if (!tTextureDetails.FoundInRenderers.Contains(renderer)) { tTextureDetails.FoundInRenderers.Add(renderer); } } return(tTextureDetails); }
void AddToActiveMaterail(MaterialDetails td) { bool find = false; foreach (MaterialDetails t in ActiveMaterials) { if (t == td) { find = true; break; } } if (find == false) { ActiveMaterials.Add(td); } }
public IActionResult MaterialUsageSingle(string name, DateSelectorModal dateSelectorModal) { List <BatchReport> reports = new List <BatchReport>(); MaterialDetails details = _materialDetailsRepository.GetSingleMaterial(name); MaterialUsageViewModel materialUsageViewModel = new MaterialUsageViewModel(); materialUsageViewModel.Name = details.Name; materialUsageViewModel.ProductCode = details.ProductCode; materialUsageViewModel.ShortName = details.ShortName; materialUsageViewModel.CostPerTon = details.CostPerTon; materialUsageViewModel.DateSelectorModal = dateSelectorModal; reports = helper.GetBatchReportsForDateSelector(materialUsageViewModel.DateSelectorModal); materialUsageViewModel.streamInfo = GetStreamMatVarBreakdown(reports, details.Name); CalculateWeeklyUsageForSetTimePeriod(materialUsageViewModel, reports, details); materialUsageViewModel.WeeklyUsage = materialUsageViewModel.WeeklyUsage.OrderBy(x => x.Year).ThenBy(x => x.WeekNo).ToList(); return(View("MaterialUsageSingle", materialUsageViewModel)); }
public ActionResult Details(string id) { try { //SetUp _Layout e check permições do urilizador setNavbar(); setUserContext(); if ((int)utilizadorATrabalhar._prefil == 0) { return(RedirectToAction("Login", "Utilizador")); } Material_Helper objetoHelper = new Material_Helper(Program._conect); MaterialDetails objetoM = objetoHelper.ler(id); return(View(objetoM)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { menssagem = e.Message })); } }
/// <summary> /// Sort by RenderQueue /// </summary> static int MaterialSorter(MaterialDetails first, MaterialDetails second) { var firstIsNull = first.material == null; var secondIsNull = second.material == null; if (firstIsNull && secondIsNull) { return(0); } if (firstIsNull) { return(int.MaxValue); } if (secondIsNull) { return(int.MinValue); } return(first.material.renderQueue - second.material.renderQueue); }
private TextureDetails GetTextureDetail(Texture tTexture, Material tMaterial, MaterialDetails tMaterialDetails) { TextureDetails tTextureDetails = FindTextureDetails(tTexture); if (tTextureDetails == null) { tTextureDetails = new TextureDetails(); tTextureDetails.texture = tTexture; tTextureDetails.isCubeMap = tTexture is Cubemap; int memSize = CalculateTextureSizeBytes(tTexture); tTextureDetails.memSizeKB = memSize / 1024; TextureFormat tFormat = TextureFormat.RGBA32; int tMipMapCount = 1; if (tTexture is Texture2D) { tFormat = (tTexture as Texture2D).format; tMipMapCount = (tTexture as Texture2D).mipmapCount; } if (tTexture is Cubemap) { tFormat = (tTexture as Cubemap).format; } tTextureDetails.format = tFormat; tTextureDetails.mipMapCount = tMipMapCount; } tTextureDetails.FoundInMaterials.Add(tMaterial); foreach (Renderer renderer in tMaterialDetails.FoundInRenderers) { if (!tTextureDetails.FoundInRenderers.Contains(renderer)) { tTextureDetails.FoundInRenderers.Add(renderer); } } return(tTextureDetails); }
void CheckResources() { ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); Renderer[] renderers = (Renderer[])FindObjectsOfType(typeof(Renderer)); //Debug.Log("Total renderers "+renderers.Length); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails = FindMaterialDetails(material); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = material; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInRenderers.Add(renderer); } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial = tMaterialDetails.material; foreach (Object obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial })) { if (obj is Texture) { Texture tTexture = obj as Texture; TextureDetails tTextureDetails = FindTextureDetails(tTexture); if (tTextureDetails == null) { tTextureDetails = new TextureDetails(); tTextureDetails.texture = tTexture; tTextureDetails.isCubeMap = tTexture is Cubemap; int memSize = CalculateTextureSizeBytes(tTexture); tTextureDetails.memSizeKB = memSize / 1024; TextureFormat tFormat = TextureFormat.RGBA32; int tMipMapCount = 1; if (tTexture is Texture2D) { tFormat = (tTexture as Texture2D).format; tMipMapCount = (tTexture as Texture2D).mipmapCount; } if (tTexture is Cubemap) { tFormat = (tTexture as Cubemap).format; } tTextureDetails.format = tFormat; tTextureDetails.mipMapCount = tMipMapCount; ActiveTextures.Add(tTextureDetails); } tTextureDetails.FoundInMaterials.Add(tMaterial); foreach (Renderer renderer in tMaterialDetails.FoundInRenderers) { if (!tTextureDetails.FoundInRenderers.Contains(renderer)) { tTextureDetails.FoundInRenderers.Add(renderer); } } } } } MeshFilter[] meshFilters = (MeshFilter[])FindObjectsOfType(typeof(MeshFilter)); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh = tMeshFilter.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInMeshFilters.Add(tMeshFilter); } } SkinnedMeshRenderer[] skinnedMeshRenderers = (SkinnedMeshRenderer[])FindObjectsOfType(typeof(SkinnedMeshRenderer)); foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers) { Mesh tMesh = tSkinnedMeshRenderer.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer); } } TotalTextureMemory = 0; foreach (TextureDetails tTextureDetails in ActiveTextures) { TotalTextureMemory += tTextureDetails.memSizeKB; } TotalMeshVertices = 0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { TotalMeshVertices += tMeshDetails.mesh.vertexCount; } // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); }); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); }); }
private BatchIssue CheckWeighTimeAgainstLastMaterialInParallelWeighGroup(BatchReport report, Material material, MaterialDetails materialInfo) { BatchIssue issue = null; Material lastMaterialInGroup = GetSingleMaterialFromVessel(report, GetLastMaterialNameFromGroup(materialInfo.ParallelWeighGroup)); double timeLost = GetTimeLost(report, material, materialInfo.AvgWeighTime); if (timeLost > WeighTimeLossThreshold && lastMaterialInGroup != null) { issue = new BatchIssue() { FaultType = BatchIssue.FaultTypes.WeighTime, MaterialName = material.Name, MaterialShortName = _materialDetailsRepository.GetSingleMaterial(material.Name).ShortName ?? material.Name, TimeLost = timeLost, WeightDiffference = 0, Message = $"{material.Name} took {material.WeighTime} minutes to weigh. " + $"However it weighs in parallel with other materials. The last material " + $"to weigh in the group is {lastMaterialInGroup.Name} which did not weigh " + $"until {lastMaterialInGroup.StartTime.ToShortTimeString()} meaning the time lost was {timeLost} minutes.", IssueCreatedBy = IssueDescriptor }; } return(issue); }
private BatchIssue CheckWeighTimeAgainstAverageTime(BatchReport report, Material material, MaterialDetails materialInfo) { BatchIssue issue = null; if (material.WeighTime > materialInfo.AvgWeighTime) { double timeLost = GetTimeLost(report, material, materialInfo.AvgWeighTime); issue = new BatchIssue() { FaultType = BatchIssue.FaultTypes.WeighTime, MaterialShortName = _materialDetailsRepository.GetSingleMaterial(material.Name).ShortName ?? material.Name, MaterialName = material.Name, TimeLost = timeLost, WeightDiffference = 0, Message = $"{material.Name} took {material.WeighTime} minutes to weigh. " + $"The average weigh time is {materialInfo.AvgWeighTime} minutes giving " + $"a loss of {timeLost} minutes", IssueCreatedBy = IssueDescriptor }; } return(issue); }
public EntityEntry <MaterialDetails> Update(MaterialDetails materialDetails) { return(_context.Update(materialDetails)); }
void CheckResources() { ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); Renderer[] renderers = FindObjects <Renderer>(); //Debug.Log("Total renderers "+renderers.Length); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails = FindMaterialDetails(material); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = material; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInRenderers.Add(renderer); } if (renderer is SpriteRenderer) { SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer; if (tSpriteRenderer.sprite != null) { var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } } } if (IncludeGuiElements) { Graphic[] graphics = FindObjects <Graphic>(); foreach (Graphic graphic in graphics) { if (graphic.mainTexture) { var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } if (graphic.materialForRendering) { MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = graphic.materialForRendering; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInGraphics.Add(graphic); } } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial = tMaterialDetails.material; if (tMaterial != null) { var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial }); foreach (Object obj in dependencies) { if (obj is Texture) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails); ActiveTextures.Add(tTextureDetail); } } //if the texture was downloaded, it won't be included in the editor dependencies if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture)) { var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails); ActiveTextures.Add(tTextureDetail); } } } MeshFilter[] meshFilters = FindObjects <MeshFilter>(); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh = tMeshFilter.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInMeshFilters.Add(tMeshFilter); } } SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers) { Mesh tMesh = tSkinnedMeshRenderer.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer); } } if (IncludeSpriteAnimations) { Animator[] animators = FindObjects <Animator>(); foreach (Animator anim in animators) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController; #elif UNITY_5 UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; #endif //Skip animators without layers, this can happen if they don't have an animator controller. if (!ac || ac.layers == null || ac.layers.Length == 0) { continue; } for (int x = 0; x < anim.layerCount; x++) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.StateMachine sm = ac.GetLayer(x).stateMachine; int cnt = sm.stateCount; #elif UNITY_5 UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine; int cnt = sm.states.Length; #endif for (int i = 0; i < cnt; i++) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.State state = sm.GetState(i); Motion m = state.GetMotion(); #elif UNITY_5 UnityEditor.Animations.AnimatorState state = sm.states[i].state; Motion m = state.motion; #endif if (m != null) { AnimationClip clip = m as AnimationClip; EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip); foreach (EditorCurveBinding ecb in ecbs) { if (ecb.propertyName == "m_Sprite") { foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb)) { Sprite tSprite = keyframe.value as Sprite; if (tSprite != null) { var tTextureDetail = GetTextureDetail(tSprite.texture, anim); if (!ActiveTextures.Contains(tTextureDetail)) { ActiveTextures.Add(tTextureDetail); } } } } } } } } } } if (IncludeScriptReferences) { MonoBehaviour[] scripts = FindObjects <MonoBehaviour>(); foreach (MonoBehaviour script in scripts) { BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; // only public non-static fields are bound to by Unity. FieldInfo[] fields = script.GetType().GetFields(flags); foreach (FieldInfo field in fields) { System.Type fieldType = field.FieldType; if (fieldType == typeof(Sprite)) { Sprite tSprite = field.GetValue(script) as Sprite; if (tSprite != null) { var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } } } } } TotalTextureMemory = 0; foreach (TextureDetails tTextureDetails in ActiveTextures) { TotalTextureMemory += tTextureDetails.memSizeKB; } TotalMeshVertices = 0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { TotalMeshVertices += tMeshDetails.mesh.vertexCount; } // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); }); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); }); collectedInPlayingMode = Application.isPlaying; }
void CheckForSpriteTextures( MaterialDetails tMaterialDetails ) { foreach ( Renderer renderer in tMaterialDetails.FoundInRenderers ) { SpriteRenderer spriteRenderer = renderer as SpriteRenderer; if ( spriteRenderer != null ) { if ( spriteRenderer.sprite != null ) { Texture tTexture = spriteRenderer.sprite.texture; var tTextureDetail = GetTextureDetail ( tTexture, tMaterialDetails.material, tMaterialDetails ); if ( ! ActiveTextures.Contains ( tTextureDetail ) ) ActiveTextures.Add ( tTextureDetail ); if ( !tTextureDetail.FoundInRenderers.Contains ( spriteRenderer ) ) tTextureDetail.FoundInRenderers.Add ( spriteRenderer ); } } } }
void CheckResources() { //Debug.Log("CheckResources"); ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); ActiveShaderDetails.Clear(); ActiveSoundDetails.Clear(); foreach (LightmapData lightmap in LightmapSettings.lightmaps) { TryAddActiveTextures(lightmap.lightmapNear); TryAddActiveTextures(lightmap.lightmapFar); } Renderer[] renderers = (Renderer[])FindObjectsOfType(typeof(Renderer)); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails = TryAddActiveMaterial(material); if (tMaterialDetails != null) { tMaterialDetails.FoundInGameObjects.Add(renderer.gameObject); } ShaderDetails tShaderDetails = TryAddActiveShader(material.shader); if (tShaderDetails != null) { if (!tShaderDetails.FoundInGameObjects.Contains(renderer.gameObject)) { tShaderDetails.FoundInGameObjects.Add(renderer.gameObject); } } } // add the lightmap reference to the renderer if (renderer.lightmapIndex >= 0 && renderer.lightmapIndex < LightmapSettings.lightmaps.Length) { LightmapData lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex]; TextureDetails lmNear = FindTextureDetails(lightmap.lightmapNear); if (lmNear != null && !lmNear.FoundInRenderers.Contains(renderer)) { lmNear.FoundInRenderers.Add(renderer); } TextureDetails lmFar = FindTextureDetails(lightmap.lightmapFar); if (lmFar != null && !lmFar.FoundInRenderers.Contains(renderer)) { lmFar.FoundInRenderers.Add(renderer); } } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial = tMaterialDetails.material; foreach (Object obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial })) { if (obj is Texture) { Texture tTexture = obj as Texture; TextureDetails tTextureDetails = TryAddActiveTextures(tTexture); tTextureDetails.FoundInMaterials.Add(tMaterial); } if (obj is Shader) { Shader shader = obj as Shader; ShaderDetails shaderDetails = TryAddActiveShader(shader); if (!shaderDetails.FoundInMaterials.Contains(tMaterial)) { shaderDetails.FoundInMaterials.Add(tMaterial); } } } } MeshFilter[] meshFilters = (MeshFilter[])FindObjectsOfType(typeof(MeshFilter)); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh = tMeshFilter.sharedMesh; if (tMesh != null) { MeshDetails details = TryAddActiveMesh(tMesh); if (!details.FoundInGameObjects.Contains(tMeshFilter.gameObject)) { details.FoundInGameObjects.Add(tMeshFilter.gameObject); } } } Light[] lights = (Light[])FindObjectsOfType(typeof(Light)); foreach (Light light in lights) { if (light.cookie) { TextureDetails details = TryAddActiveTextures(light.cookie); if (!details.FoundInLights.Contains(light)) { details.FoundInLights.Add(light); } } } GameObject[] gameObjs = (GameObject[])FindObjectsOfType(typeof(GameObject)); foreach (GameObject obj in gameObjs) { foreach (Object o in EditorUtility.CollectDependencies(new UnityEngine.Object[] { obj })) { if (o is AudioClip) { AudioClip clip = o as AudioClip; SoundDetails details = TryAddAudioClip(clip); if (!details.FoundInGameObjects.Contains(obj)) { details.FoundInGameObjects.Add(obj); } } if (o is MonoScript) { MonoScript script = o as MonoScript; ScriptDetails details = TryAddScript(script); if (!details.FoundInGameObjects.Contains(obj)) { details.FoundInGameObjects.Add(obj); } } } } TotalTextureMemory = 0; foreach (TextureDetails tTextureDetails in ActiveTextures) { TotalTextureMemory += tTextureDetails.memSizeBytes; } TotalMeshVertices = 0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { TotalMeshVertices += tMeshDetails.mesh.vertexCount; } // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeBytes - details1.memSizeBytes); }); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); }); }
private double GetMaxMinTemp(bool overMax, MaterialDetails material) { return(overMax ? material.MaxRawTemp : material.MinRawTemp); }
MaterialDetails TryAddActiveMaterial( Material mat ) { if ( mat != null ) { MaterialDetails details = FindMaterialDetails( mat ); if ( details == null ) { details = new MaterialDetails( mat ); ActiveMaterials.Add( details ); } return details; } return null; }
void ListTextures() { textureListScrollPos = EditorGUILayout.BeginScrollView(textureListScrollPos); foreach (TextureDetails tDetails in ActiveTextures) { GUILayout.BeginHorizontal(); Texture tex = new Texture(); tex = tDetails.texture; #if !UNITY_EDITOR_OSX if (tDetails.texture.GetType() == typeof(Texture2DArray) || tDetails.texture.GetType() == typeof(Cubemap)) { #else if (tDetails.texture.GetType() == typeof(Cubemap)) { #endif tex = AssetPreview.GetMiniThumbnail(tDetails.texture); } GUILayout.Box(tex, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight)); if (tDetails.instance == true) { GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f); } if (tDetails.isgui == true) { GUI.color = new Color(defColor.r, 0.95f, 0.8f, 1.0f); } if (tDetails.isSky) { GUI.color = new Color(0.9f, defColor.g, defColor.b, 1.0f); } if (GUILayout.Button(tDetails.texture.name, GUILayout.Width(150))) { SelectObject(tDetails.texture, ctrlPressed); } GUI.color = defColor; string sizeLabel = "" + tDetails.texture.width + "x" + tDetails.texture.height; if (tDetails.isCubeMap) { sizeLabel += "x6"; } #if !UNITY_EDITOR_OSX if (tDetails.texture.GetType() == typeof(Texture2DArray)) { sizeLabel += "[]\n" + ((Texture2DArray)tDetails.texture).depth + "depths"; } #endif sizeLabel += " - " + tDetails.mipMapCount + "mip\n" + FormatSizeString(tDetails.memSizeKB) + " - " + tDetails.format; GUILayout.Label(sizeLabel, GUILayout.Width(120)); if (GUILayout.Button(tDetails.FoundInMaterials.Count + " Mat", GUILayout.Width(50))) { SelectObjects(tDetails.FoundInMaterials, ctrlPressed); } HashSet <Object> FoundObjects = new HashSet <Object>(); foreach (Renderer renderer in tDetails.FoundInRenderers) { FoundObjects.Add(renderer.gameObject); } foreach (Animator animator in tDetails.FoundInAnimators) { FoundObjects.Add(animator.gameObject); } foreach (Graphic graphic in tDetails.FoundInGraphics) { FoundObjects.Add(graphic.gameObject); } foreach (MonoBehaviour script in tDetails.FoundInScripts) { FoundObjects.Add(script.gameObject); } if (GUILayout.Button(FoundObjects.Count + " GO", GUILayout.Width(50))) { SelectObjects(new List <Object>(FoundObjects), ctrlPressed); } GUILayout.EndHorizontal(); } if (ActiveTextures.Count > 0) { EditorGUILayout.Space(); GUILayout.BeginHorizontal(); //GUILayout.Box(" ",GUILayout.Width(ThumbnailWidth),GUILayout.Height(ThumbnailHeight)); if (GUILayout.Button("Select \n All", GUILayout.Width(ThumbnailWidth * 2))) { List <Object> AllTextures = new List <Object>(); foreach (TextureDetails tDetails in ActiveTextures) { AllTextures.Add(tDetails.texture); } SelectObjects(AllTextures, ctrlPressed); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); } void ListMaterials() { materialListScrollPos = EditorGUILayout.BeginScrollView(materialListScrollPos); foreach (MaterialDetails tDetails in ActiveMaterials) { if (tDetails.material != null) { GUILayout.BeginHorizontal(); GUILayout.Box(AssetPreview.GetAssetPreview(tDetails.material), GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight)); if (tDetails.instance == true) { GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f); } if (tDetails.isgui == true) { GUI.color = new Color(defColor.r, 0.95f, 0.8f, 1.0f); } if (tDetails.isSky) { GUI.color = new Color(0.9f, defColor.g, defColor.b, 1.0f); } if (GUILayout.Button(tDetails.material.name, GUILayout.Width(150))) { SelectObject(tDetails.material, ctrlPressed); } GUI.color = defColor; string shaderLabel = tDetails.material.shader != null ? tDetails.material.shader.name : "no shader"; GUILayout.Label(shaderLabel, GUILayout.Width(200)); if (GUILayout.Button((tDetails.FoundInRenderers.Count + tDetails.FoundInGraphics.Count) + " GO", GUILayout.Width(50))) { List <Object> FoundObjects = new List <Object>(); foreach (Renderer renderer in tDetails.FoundInRenderers) { FoundObjects.Add(renderer.gameObject); } foreach (Graphic graphic in tDetails.FoundInGraphics) { FoundObjects.Add(graphic.gameObject); } SelectObjects(FoundObjects, ctrlPressed); } GUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } void ListMeshes() { meshListScrollPos = EditorGUILayout.BeginScrollView(meshListScrollPos); foreach (MeshDetails tDetails in ActiveMeshDetails) { if (tDetails.mesh != null) { GUILayout.BeginHorizontal(); string name = tDetails.mesh.name; if (name == null || name.Count() < 1) { name = tDetails.FoundInMeshFilters[0].gameObject.name; } if (tDetails.instance == true) { GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f); } if (GUILayout.Button(name, GUILayout.Width(150))) { SelectObject(tDetails.mesh, ctrlPressed); } GUI.color = defColor; string sizeLabel = "" + tDetails.mesh.vertexCount + " vert"; GUILayout.Label(sizeLabel, GUILayout.Width(100)); if (GUILayout.Button(tDetails.FoundInMeshFilters.Count + " GO", GUILayout.Width(50))) { List <Object> FoundObjects = new List <Object>(); foreach (MeshFilter meshFilter in tDetails.FoundInMeshFilters) { FoundObjects.Add(meshFilter.gameObject); } SelectObjects(FoundObjects, ctrlPressed); } if (tDetails.FoundInSkinnedMeshRenderer.Count > 0) { if (GUILayout.Button(tDetails.FoundInSkinnedMeshRenderer.Count + " skinned mesh GO", GUILayout.Width(140))) { List <Object> FoundObjects = new List <Object> (); foreach (SkinnedMeshRenderer skinnedMeshRenderer in tDetails.FoundInSkinnedMeshRenderer) { FoundObjects.Add(skinnedMeshRenderer.gameObject); } SelectObjects(FoundObjects, ctrlPressed); } } else { GUI.color = new Color(defColor.r, defColor.g, defColor.b, 0.5f); GUILayout.Label(" 0 skinned mesh"); GUI.color = defColor; } GUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } void ListMissing() { missingListScrollPos = EditorGUILayout.BeginScrollView(missingListScrollPos); foreach (MissingGraphic dMissing in MissingObjects) { GUILayout.BeginHorizontal(); if (GUILayout.Button(dMissing.name, GUILayout.Width(150))) { SelectObject(dMissing.Object, ctrlPressed); } GUILayout.Label("missing ", GUILayout.Width(48)); switch (dMissing.type) { case "mesh": GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f); break; case "sprite": GUI.color = new Color(defColor.r, 0.8f, 0.8f, 1.0f); break; case "material": GUI.color = new Color(0.8f, defColor.g, 0.8f, 1.0f); break; } GUILayout.Label(dMissing.type); GUI.color = defColor; GUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); } string FormatSizeString(int memSizeKB) { if (memSizeKB < 1024) { return("" + memSizeKB + "k"); } else { float memSizeMB = ((float)memSizeKB) / 1024.0f; return(memSizeMB.ToString("0.00") + "Mb"); } } TextureDetails FindTextureDetails(Texture tTexture) { foreach (TextureDetails tTextureDetails in ActiveTextures) { if (tTextureDetails.texture == tTexture) { return(tTextureDetails); } } return(null); } MaterialDetails FindMaterialDetails(Material tMaterial) { foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { if (tMaterialDetails.material == tMaterial) { return(tMaterialDetails); } } return(null); } MeshDetails FindMeshDetails(Mesh tMesh) { foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { if (tMeshDetails.mesh == tMesh) { return(tMeshDetails); } } return(null); } void CheckResources() { ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); MissingObjects.Clear(); thingsMissing = false; Renderer[] renderers = FindObjects <Renderer>(); MaterialDetails skyMat = new MaterialDetails(); skyMat.material = RenderSettings.skybox; skyMat.isSky = true; ActiveMaterials.Add(skyMat); //Debug.Log("Total renderers "+renderers.Length); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails = FindMaterialDetails(material); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = material; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInRenderers.Add(renderer); } if (renderer is SpriteRenderer) { SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer; if (tSpriteRenderer.sprite != null) { var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } else if (tSpriteRenderer.sprite == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tSpriteRenderer.transform; tMissing.type = "sprite"; tMissing.name = tSpriteRenderer.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } } } if (IncludeGuiElements) { Graphic[] graphics = FindObjects <Graphic>(); foreach (Graphic graphic in graphics) { if (graphic.mainTexture) { var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } if (graphic.materialForRendering) { MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = graphic.materialForRendering; tMaterialDetails.isgui = true; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInGraphics.Add(graphic); } } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial = tMaterialDetails.material; if (tMaterial != null) { var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial }); foreach (Object obj in dependencies) { if (obj is Texture) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails); tTextureDetail.isSky = tMaterialDetails.isSky; tTextureDetail.instance = tMaterialDetails.instance; tTextureDetail.isgui = tMaterialDetails.isgui; ActiveTextures.Add(tTextureDetail); } } //if the texture was downloaded, it won't be included in the editor dependencies if (tMaterial.HasProperty("_MainTex")) { if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture)) { var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails); ActiveTextures.Add(tTextureDetail); } } } } MeshFilter[] meshFilters = FindObjects <MeshFilter>(); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh = tMeshFilter.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInMeshFilters.Add(tMeshFilter); } else if (tMesh == null && tMeshFilter.transform.GetComponent("TextContainer") == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tMeshFilter.transform; tMissing.type = "mesh"; tMissing.name = tMeshFilter.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } if (tMeshFilter.transform.GetComponent <MeshRenderer>().sharedMaterial == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tMeshFilter.transform; tMissing.type = "material"; tMissing.name = tMeshFilter.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } } SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers) { Mesh tMesh = tSkinnedMeshRenderer.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer); } else if (tMesh == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tSkinnedMeshRenderer.transform; tMissing.type = "mesh"; tMissing.name = tSkinnedMeshRenderer.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } if (tSkinnedMeshRenderer.sharedMaterial == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tSkinnedMeshRenderer.transform; tMissing.type = "material"; tMissing.name = tSkinnedMeshRenderer.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } } if (IncludeSpriteAnimations) { Animator[] animators = FindObjects <Animator>(); foreach (Animator anim in animators) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController; #elif UNITY_5 UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; #endif //Skip animators without layers, this can happen if they don't have an animator controller. if (!ac || ac.layers == null || ac.layers.Length == 0) { continue; } for (int x = 0; x < anim.layerCount; x++) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.StateMachine sm = ac.GetLayer(x).stateMachine; int cnt = sm.stateCount; #elif UNITY_5 UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine; int cnt = sm.states.Length; #endif for (int i = 0; i < cnt; i++) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.State state = sm.GetState(i); Motion m = state.GetMotion(); #elif UNITY_5 UnityEditor.Animations.AnimatorState state = sm.states[i].state; Motion m = state.motion; #endif if (m != null) { AnimationClip clip = m as AnimationClip; if (clip != null) { EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip); foreach (EditorCurveBinding ecb in ecbs) { if (ecb.propertyName == "m_Sprite") { foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb)) { Sprite tSprite = keyframe.value as Sprite; if (tSprite != null) { var tTextureDetail = GetTextureDetail(tSprite.texture, anim); if (!ActiveTextures.Contains(tTextureDetail)) { ActiveTextures.Add(tTextureDetail); } } } } } } } } } } } if (IncludeScriptReferences) { MonoBehaviour[] scripts = FindObjects <MonoBehaviour>(); foreach (MonoBehaviour script in scripts) { BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; // only public non-static fields are bound to by Unity. FieldInfo[] fields = script.GetType().GetFields(flags); foreach (FieldInfo field in fields) { System.Type fieldType = field.FieldType; if (fieldType == typeof(Sprite)) { Sprite tSprite = field.GetValue(script) as Sprite; if (tSprite != null) { var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } } if (fieldType == typeof(Mesh)) { Mesh tMesh = field.GetValue(script) as Mesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; tMeshDetails.instance = true; ActiveMeshDetails.Add(tMeshDetails); } } } if (fieldType == typeof(Material)) { Material tMaterial = field.GetValue(script) as Material; if (tMaterial != null) { MaterialDetails tMatDetails = FindMaterialDetails(tMaterial); if (tMatDetails == null) { tMatDetails = new MaterialDetails(); tMatDetails.instance = true; tMatDetails.material = tMaterial; if (!ActiveMaterials.Contains(tMatDetails)) { ActiveMaterials.Add(tMatDetails); } } if (tMaterial.mainTexture) { var tSpriteTextureDetail = GetTextureDetail(tMaterial.mainTexture); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial }); foreach (Object obj in dependencies) { if (obj is Texture) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMatDetails); if (!ActiveTextures.Contains(tTextureDetail)) { ActiveTextures.Add(tTextureDetail); } } } } } } } } TotalTextureMemory = 0; foreach (TextureDetails tTextureDetails in ActiveTextures) { TotalTextureMemory += tTextureDetails.memSizeKB; } TotalMeshVertices = 0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { TotalMeshVertices += tMeshDetails.mesh.vertexCount; } // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); }); ActiveTextures = ActiveTextures.Distinct().ToList(); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); }); collectedInPlayingMode = Application.isPlaying; }
void CheckResources() { ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); Renderer[] renderers = (Renderer[])FindObjectsOfType(typeof(Renderer)); //Debug.Log("Total renderers "+renderers.Length); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails = FindMaterialDetails(material); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = material; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInRenderers.Add(renderer); } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial = tMaterialDetails.material; var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial }); foreach (Object obj in dependencies) { if (obj is Texture) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails); ActiveTextures.Add(tTextureDetail); } } //if the texture was downloaded, it won't be included in the editor dependencies if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture)) { var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails); ActiveTextures.Add(tTextureDetail); } } MeshFilter[] meshFilters = (MeshFilter[])FindObjectsOfType(typeof(MeshFilter)); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh = tMeshFilter.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInMeshFilters.Add(tMeshFilter); } } SkinnedMeshRenderer[] skinnedMeshRenderers = (SkinnedMeshRenderer[])FindObjectsOfType(typeof(SkinnedMeshRenderer)); foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers) { Mesh tMesh = tSkinnedMeshRenderer.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer); } } TotalTextureMemory = 0; foreach (TextureDetails tTextureDetails in ActiveTextures) { TotalTextureMemory += tTextureDetails.memSizeKB; } TotalMeshVertices = 0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { TotalMeshVertices += tMeshDetails.mesh.vertexCount; } // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); }); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); }); }
void CheckResources() { ActiveTextures.Clear (); ActiveMaterials.Clear (); ActiveMeshDetails.Clear (); Renderer[] renderers = (Renderer[])FindObjectsOfType ( typeof ( Renderer ) ); //Debug.Log("Total renderers "+renderers.Length); foreach ( Renderer renderer in renderers ) { //Debug.Log("Renderer is "+renderer.name); foreach ( Material material in renderer.sharedMaterials ) { MaterialDetails tMaterialDetails = FindMaterialDetails ( material ); if ( tMaterialDetails == null ) { tMaterialDetails = new MaterialDetails (); tMaterialDetails.material = material; ActiveMaterials.Add ( tMaterialDetails ); } tMaterialDetails.FoundInRenderers.Add ( renderer ); } } foreach ( MaterialDetails tMaterialDetails in ActiveMaterials ) { Material tMaterial = tMaterialDetails.material; var dependencies = EditorUtility.CollectDependencies ( new UnityEngine.Object[] { tMaterial } ); foreach ( Object obj in dependencies ) { if ( obj is Texture ) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail ( tTexture, tMaterial, tMaterialDetails ); ActiveTextures.Add ( tTextureDetail ); } } //if the texture was downloaded, it won't be included in the editor dependencies if ( tMaterial.mainTexture != null && !dependencies.Contains ( tMaterial.mainTexture ) ) { var tTextureDetail = GetTextureDetail ( tMaterial.mainTexture, tMaterial, tMaterialDetails ); ActiveTextures.Add ( tTextureDetail ); } CheckForSpriteTextures ( tMaterialDetails ); } MeshFilter[] meshFilters = (MeshFilter[])FindObjectsOfType ( typeof ( MeshFilter ) ); foreach ( MeshFilter tMeshFilter in meshFilters ) { Mesh tMesh = tMeshFilter.sharedMesh; if ( tMesh != null ) { MeshDetails tMeshDetails = FindMeshDetails ( tMesh ); if ( tMeshDetails == null ) { tMeshDetails = new MeshDetails (); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add ( tMeshDetails ); } tMeshDetails.FoundInMeshFilters.Add ( tMeshFilter ); } } SkinnedMeshRenderer[] skinnedMeshRenderers = (SkinnedMeshRenderer[])FindObjectsOfType ( typeof ( SkinnedMeshRenderer ) ); foreach ( SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers ) { Mesh tMesh = tSkinnedMeshRenderer.sharedMesh; if ( tMesh != null ) { MeshDetails tMeshDetails = FindMeshDetails ( tMesh ); if ( tMeshDetails == null ) { tMeshDetails = new MeshDetails (); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add ( tMeshDetails ); } tMeshDetails.FoundInSkinnedMeshRenderer.Add ( tSkinnedMeshRenderer ); } } TotalTextureMemory = 0; foreach ( TextureDetails tTextureDetails in ActiveTextures ) TotalTextureMemory += tTextureDetails.memSizeKB; TotalMeshVertices = 0; foreach ( MeshDetails tMeshDetails in ActiveMeshDetails ) TotalMeshVertices += tMeshDetails.mesh.vertexCount; // Sort by size, descending ActiveTextures.Sort ( delegate ( TextureDetails details1, TextureDetails details2 ) { return details2.memSizeKB - details1.memSizeKB; } ); ActiveMeshDetails.Sort ( delegate ( MeshDetails details1, MeshDetails details2 ) { return details2.mesh.vertexCount - details1.mesh.vertexCount; } ); }
private TextureDetails GetTextureDetail( Texture tTexture, Material tMaterial, MaterialDetails tMaterialDetails ) { TextureDetails tTextureDetails = FindTextureDetails ( tTexture ); if ( tTextureDetails == null ) { tTextureDetails = new TextureDetails (); tTextureDetails.texture = tTexture; tTextureDetails.isCubeMap = tTexture is Cubemap; int memSize = CalculateTextureSizeBytes ( tTexture ); tTextureDetails.memSizeKB = memSize / 1024; TextureFormat tFormat = TextureFormat.RGBA32; int tMipMapCount = 1; if ( tTexture is Texture2D ) { tFormat = ( tTexture as Texture2D ).format; tMipMapCount = ( tTexture as Texture2D ).mipmapCount; } if ( tTexture is Cubemap ) { tFormat = ( tTexture as Cubemap ).format; } tTextureDetails.format = tFormat; tTextureDetails.mipMapCount = tMipMapCount; } if ( ! tTextureDetails.FoundInMaterials.Contains ( tMaterial ) ) tTextureDetails.FoundInMaterials.Add ( tMaterial ); foreach ( Renderer renderer in tMaterialDetails.FoundInRenderers ) if ( ! ( renderer is SpriteRenderer ) ) if ( ! tTextureDetails.FoundInRenderers.Contains ( renderer ) ) tTextureDetails.FoundInRenderers.Add ( renderer ); return tTextureDetails; }
void CheckResources() { ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); MissingObjects.Clear(); thingsMissing = false; Renderer[] renderers = FindObjects <Renderer>(); MaterialDetails skyMat = new MaterialDetails(); skyMat.material = RenderSettings.skybox; skyMat.isSky = true; ActiveMaterials.Add(skyMat); //Debug.Log("Total renderers "+renderers.Length); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails = FindMaterialDetails(material); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = material; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInRenderers.Add(renderer); } if (renderer is SpriteRenderer) { SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer; if (tSpriteRenderer.sprite != null) { var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } else if (tSpriteRenderer.sprite == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tSpriteRenderer.transform; tMissing.type = "sprite"; tMissing.name = tSpriteRenderer.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } } } if (IncludeLightmapTextures) { LightmapData[] lightmapTextures = LightmapSettings.lightmaps; // Unity lightmaps foreach (LightmapData lightmapData in lightmapTextures) { if (lightmapData.lightmapColor != null) { var textureDetail = GetTextureDetail(lightmapData.lightmapColor); if (!ActiveTextures.Contains(textureDetail)) { ActiveTextures.Add(textureDetail); } } if (lightmapData.lightmapDir != null) { var textureDetail = GetTextureDetail(lightmapData.lightmapColor); if (!ActiveTextures.Contains(textureDetail)) { ActiveTextures.Add(textureDetail); } } if (lightmapData.shadowMask != null) { var textureDetail = GetTextureDetail(lightmapData.shadowMask); if (!ActiveTextures.Contains(textureDetail)) { ActiveTextures.Add(textureDetail); } } } } if (IncludeGuiElements) { Graphic[] graphics = FindObjects <Graphic>(); foreach (Graphic graphic in graphics) { if (graphic.mainTexture) { var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } if (graphic.materialForRendering) { MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering); if (tMaterialDetails == null) { tMaterialDetails = new MaterialDetails(); tMaterialDetails.material = graphic.materialForRendering; tMaterialDetails.isgui = true; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInGraphics.Add(graphic); } } Button[] buttons = FindObjects <Button>(); foreach (Button button in buttons) { CheckButtonSpriteState(button, button.spriteState.disabledSprite); CheckButtonSpriteState(button, button.spriteState.highlightedSprite); CheckButtonSpriteState(button, button.spriteState.pressedSprite); } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial = tMaterialDetails.material; if (tMaterial != null) { var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial }); foreach (Object obj in dependencies) { if (obj is Texture) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails); tTextureDetail.isSky = tMaterialDetails.isSky; tTextureDetail.instance = tMaterialDetails.instance; tTextureDetail.isgui = tMaterialDetails.isgui; ActiveTextures.Add(tTextureDetail); } } //if the texture was downloaded, it won't be included in the editor dependencies if (tMaterial.HasProperty("_MainTex")) { if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture)) { var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails); ActiveTextures.Add(tTextureDetail); } } } } MeshFilter[] meshFilters = FindObjects <MeshFilter>(); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh = tMeshFilter.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInMeshFilters.Add(tMeshFilter); if (GameObjectUtility.AreStaticEditorFlagsSet(tMeshFilter.gameObject, StaticEditorFlags.BatchingStatic)) { tMeshDetails.StaticBatchingEnabled.Add(tMeshFilter.gameObject); } } else if (tMesh == null && tMeshFilter.transform.GetComponent("TextContainer") == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tMeshFilter.transform; tMissing.type = "mesh"; tMissing.name = tMeshFilter.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } var meshRenderrer = tMeshFilter.transform.GetComponent <MeshRenderer>(); if (meshRenderrer == null || meshRenderrer.sharedMaterial == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tMeshFilter.transform; tMissing.type = "material"; tMissing.name = tMeshFilter.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } } SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers) { Mesh tMesh = tSkinnedMeshRenderer.sharedMesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer); } else if (tMesh == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tSkinnedMeshRenderer.transform; tMissing.type = "mesh"; tMissing.name = tSkinnedMeshRenderer.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } if (tSkinnedMeshRenderer.sharedMaterial == null) { MissingGraphic tMissing = new MissingGraphic(); tMissing.Object = tSkinnedMeshRenderer.transform; tMissing.type = "material"; tMissing.name = tSkinnedMeshRenderer.transform.name; MissingObjects.Add(tMissing); thingsMissing = true; } } if (IncludeSpriteAnimations) { Animator[] animators = FindObjects <Animator>(); foreach (Animator anim in animators) { #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3 UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController; #elif UNITY_5 || UNITY_5_3_OR_NEWER UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; #endif //Skip animators without layers, this can happen if they don't have an animator controller. if (!ac || ac.layers == null || ac.layers.Length == 0) { continue; } for (int x = 0; x < anim.layerCount; x++) { UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine; int cnt = sm.states.Length; for (int i = 0; i < cnt; i++) { UnityEditor.Animations.AnimatorState state = sm.states[i].state; Motion m = state.motion; if (m != null) { AnimationClip clip = m as AnimationClip; if (clip != null) { EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip); foreach (EditorCurveBinding ecb in ecbs) { if (ecb.propertyName == "m_Sprite") { foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb)) { Sprite tSprite = keyframe.value as Sprite; if (tSprite != null) { var tTextureDetail = GetTextureDetail(tSprite.texture, anim); if (!ActiveTextures.Contains(tTextureDetail)) { ActiveTextures.Add(tTextureDetail); } } } } } } } } } } } if (IncludeScriptReferences) { MonoBehaviour[] scripts = FindObjects <MonoBehaviour>(); foreach (MonoBehaviour script in scripts) { BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; // only public non-static fields are bound to by Unity. FieldInfo[] fields = script.GetType().GetFields(flags); foreach (FieldInfo field in fields) { System.Type fieldType = field.FieldType; if (fieldType == typeof(Sprite)) { Sprite tSprite = field.GetValue(script) as Sprite; if (tSprite != null) { var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } } if (fieldType == typeof(Mesh)) { Mesh tMesh = field.GetValue(script) as Mesh; if (tMesh != null) { MeshDetails tMeshDetails = FindMeshDetails(tMesh); if (tMeshDetails == null) { tMeshDetails = new MeshDetails(); tMeshDetails.mesh = tMesh; tMeshDetails.instance = true; ActiveMeshDetails.Add(tMeshDetails); } } } if (fieldType == typeof(Material)) { Material tMaterial = field.GetValue(script) as Material; if (tMaterial != null) { MaterialDetails tMatDetails = FindMaterialDetails(tMaterial); if (tMatDetails == null) { tMatDetails = new MaterialDetails(); tMatDetails.instance = true; tMatDetails.material = tMaterial; if (!ActiveMaterials.Contains(tMatDetails)) { ActiveMaterials.Add(tMatDetails); } } if (tMaterial.mainTexture) { var tSpriteTextureDetail = GetTextureDetail(tMaterial.mainTexture); if (!ActiveTextures.Contains(tSpriteTextureDetail)) { ActiveTextures.Add(tSpriteTextureDetail); } } var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial }); foreach (Object obj in dependencies) { if (obj is Texture) { Texture tTexture = obj as Texture; var tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMatDetails); if (!ActiveTextures.Contains(tTextureDetail)) { ActiveTextures.Add(tTextureDetail); } } } } } } } } TotalTextureMemory = 0; foreach (TextureDetails tTextureDetails in ActiveTextures) { TotalTextureMemory += tTextureDetails.memSizeKB; } TotalMeshVertices = 0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) { TotalMeshVertices += tMeshDetails.mesh.vertexCount; } // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); }); ActiveTextures = ActiveTextures.Distinct().ToList(); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); }); collectedInPlayingMode = Application.isPlaying; // Sort by render queue ActiveMaterials.Sort(MaterialSorter); }
void CheckResources() { ActiveTextures.Clear(); ActiveMaterials.Clear(); ActiveMeshDetails.Clear(); Renderer[] renderers = (Renderer[]) FindObjectsOfType(typeof(Renderer)); //Debug.Log("Total renderers "+renderers.Length); foreach (Renderer renderer in renderers) { //Debug.Log("Renderer is "+renderer.name); foreach (Material material in renderer.sharedMaterials) { MaterialDetails tMaterialDetails=FindMaterialDetails(material); if (tMaterialDetails==null) { tMaterialDetails=new MaterialDetails(); tMaterialDetails.material=material; ActiveMaterials.Add(tMaterialDetails); } tMaterialDetails.FoundInRenderers.Add(renderer); } } foreach (MaterialDetails tMaterialDetails in ActiveMaterials) { Material tMaterial=tMaterialDetails.material; foreach (Object obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] {tMaterial})) { if (obj is Texture) { Texture tTexture=obj as Texture; TextureDetails tTextureDetails=FindTextureDetails(tTexture); if (tTextureDetails==null) { tTextureDetails=new TextureDetails(); tTextureDetails.texture=tTexture; tTextureDetails.isCubeMap=tTexture is Cubemap; int memSize=CalculateTextureSizeBytes(tTexture); tTextureDetails.memSizeKB=memSize/1024; TextureFormat tFormat=TextureFormat.RGBA32; int tMipMapCount=1; if (tTexture is Texture2D) { tFormat=(tTexture as Texture2D).format; tMipMapCount=(tTexture as Texture2D).mipmapCount; } if (tTexture is Cubemap) { tFormat=(tTexture as Cubemap).format; } tTextureDetails.format=tFormat; tTextureDetails.mipMapCount=tMipMapCount; ActiveTextures.Add(tTextureDetails); } tTextureDetails.FoundInMaterials.Add(tMaterial); foreach (Renderer renderer in tMaterialDetails.FoundInRenderers) { if (!tTextureDetails.FoundInRenderers.Contains( renderer)) tTextureDetails.FoundInRenderers.Add(renderer); } } } } MeshFilter[] meshFilters = (MeshFilter[]) FindObjectsOfType(typeof(MeshFilter)); foreach (MeshFilter tMeshFilter in meshFilters) { Mesh tMesh=tMeshFilter.sharedMesh; if (tMesh!=null) { MeshDetails tMeshDetails=FindMeshDetails(tMesh); if (tMeshDetails==null) { tMeshDetails=new MeshDetails(); tMeshDetails.mesh=tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInMeshFilters.Add(tMeshFilter); } } SkinnedMeshRenderer[] skinnedMeshRenderers = (SkinnedMeshRenderer[]) FindObjectsOfType(typeof(SkinnedMeshRenderer)); foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers) { Mesh tMesh=tSkinnedMeshRenderer.sharedMesh; if (tMesh!=null) { MeshDetails tMeshDetails=FindMeshDetails(tMesh); if (tMeshDetails==null) { tMeshDetails=new MeshDetails(); tMeshDetails.mesh=tMesh; ActiveMeshDetails.Add(tMeshDetails); } tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer); } } TotalTextureMemory=0; foreach (TextureDetails tTextureDetails in ActiveTextures) TotalTextureMemory+=tTextureDetails.memSizeKB; TotalMeshVertices=0; foreach (MeshDetails tMeshDetails in ActiveMeshDetails) TotalMeshVertices+=tMeshDetails.mesh.vertexCount; // Sort by size, descending ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) {return details2.memSizeKB-details1.memSizeKB;}); ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) {return details2.mesh.vertexCount-details1.mesh.vertexCount;}); }
// 调用时机:目录列表改变,检索模式改变 void checkResources() { string[] paths = null; // TODO: inputPathList从未被使用,一直使用的是当前的inputPath paths = GetFilePaths <Material>(inputPath, searchOption); //目前只会找到有Material引用的自定义Texture和Shader //对于被引用的默认Texture和Shader也进行显示 //找到material使用的texture和shader foreach (string path in paths) { Material material = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material)); if (material != null) { MaterialDetails tMaterialDetails = new MaterialDetails(); tMaterialDetails.FoundInGameObjects = new List <string>(); tMaterialDetails.name = material.name; tMaterialDetails.path = path; // 对于缩略图进行深拷贝 Texture2D preview = AssetPreview.GetAssetPreview(material); tMaterialDetails.preview = new Texture2D(preview.width, preview.height); tMaterialDetails.preview.SetPixels32(preview.GetPixels32()); tMaterialDetails.preview.Apply(); AllMaterials.Add(tMaterialDetails); foreach (Object obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] { material })) { string p = AssetDatabase.GetAssetPath(obj); if (p == defaultPath) { p = defaultPath + "::" + obj.name; } if (obj is Texture) { Texture tTexture = (Texture)obj; int check = 0; foreach (TextureDetails details in AllTextures) { if (details.path == p) { check = 1; details.FoundInMaterials.Add(path); break; } } if (check == 0) { TextureDetails tTextureDetails = new TextureDetails(); tTextureDetails.FoundInMaterials = new List <string>(); tTextureDetails.name = tTexture.name; tTextureDetails.path = p; tTextureDetails.preview = AssetPreview.GetMiniThumbnail(tTexture); tTextureDetails.memSizeBytes = TextureDetails.CalculateTextureSizeBytes(tTexture); tTextureDetails.width = tTexture.width; tTextureDetails.height = tTexture.height; tTextureDetails.FoundInMaterials.Add(path); AllTextures.Add(tTextureDetails); } } else if (obj is Shader) { Shader tShader = (Shader)obj; int check = 0; foreach (ShaderDetails details in AllShaders) { if (details.path == p) { check = 1; details.FoundInMaterials.Add(path); break; } } if (check == 0) { ShaderDetails tShaderDetails = new ShaderDetails(); tShaderDetails.FoundInMaterials = new List <string>(); tShaderDetails.FoundInGameObjects = new List <string>(); tShaderDetails.name = tShader.name; tShaderDetails.path = p; tShaderDetails.FoundInMaterials.Add(path); AllShaders.Add(tShaderDetails); } } } } } paths = GetFilePaths <Mesh>(inputPath, searchOption); foreach (string path in paths) { Mesh mesh = (Mesh)AssetDatabase.LoadAssetAtPath(path, typeof(Mesh)); if (mesh != null) { MeshDetails tMeshDetails = new MeshDetails(); tMeshDetails.FoundInGameObjects = new List <string>(); tMeshDetails.name = mesh.name; tMeshDetails.path = path; tMeshDetails.preview = AssetPreview.GetAssetPreview(mesh); tMeshDetails.vertexCount = mesh.vertexCount; tMeshDetails.triangles = mesh.triangles.Length; AllMeshes.Add(tMeshDetails); } } paths = GetFilePaths <AudioClip>(inputPath, searchOption); foreach (string path in paths) { AudioClip clip = (AudioClip)AssetDatabase.LoadAssetAtPath(path, typeof(AudioClip)); if (clip != null) { SoundDetails tSoundDetails = new SoundDetails(); tSoundDetails.FoundInGameObjects = new List <string>(); tSoundDetails.name = clip.name; tSoundDetails.path = path; tSoundDetails.preview = AssetPreview.GetAssetPreview(clip); AllSounds.Add(tSoundDetails); } } paths = GetFilePaths <MonoScript>(inputPath, searchOption); foreach (string path in paths) { MonoScript script = (MonoScript)AssetDatabase.LoadAssetAtPath(path, typeof(MonoScript)); if (script != null) { ScriptDetails tScriptDetails = new ScriptDetails(); tScriptDetails.FoundInGameObjects = new List <string>(); tScriptDetails.name = script.name; tScriptDetails.path = path; AllScripts.Add(tScriptDetails); } } // TODO: 优化查重算法 // TODO: 目前只能找到存为prefab的GameObject // 找到GameObject引用的内建资源也能找到 paths = GetFilePaths <GameObject>(inputPath, searchOption); foreach (string path in paths) { GameObject gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)); if (gameObject != null) { foreach (Object obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] { gameObject })) { string p = AssetDatabase.GetAssetPath(obj); if (p == defaultPath) { p = defaultPath + "::" + obj.name; } if (obj is Material) { Material material = (Material)obj; int check = 1; foreach (MaterialDetails details in AllMaterials) { if (details.path == p) { check = 0; details.FoundInGameObjects.Add(path); break; } } if (check == 1) { MaterialDetails tMaterialDetails = new MaterialDetails(); tMaterialDetails.FoundInGameObjects = new List <string>(); tMaterialDetails.name = material.name; tMaterialDetails.path = path; // 对于material的缩略图进行深拷贝 Texture2D preview = AssetPreview.GetAssetPreview(material); tMaterialDetails.preview = new Texture2D(preview.width, preview.height); tMaterialDetails.preview.SetPixels32(preview.GetPixels32()); tMaterialDetails.preview.Apply(); tMaterialDetails.FoundInGameObjects.Add(path); AllMaterials.Add(tMaterialDetails); } } else if (obj is Mesh) { Mesh mesh = (Mesh)obj; int check = 1; foreach (MeshDetails details in AllMeshes) { if (details.path == p) { check = 0; details.FoundInGameObjects.Add(path); break; } } if (check == 1) { MeshDetails tMeshDetails = new MeshDetails(); tMeshDetails.FoundInGameObjects = new List <string>(); tMeshDetails.name = mesh.name; tMeshDetails.path = path; tMeshDetails.preview = AssetPreview.GetAssetPreview(mesh); tMeshDetails.vertexCount = mesh.vertexCount; tMeshDetails.triangles = mesh.triangles.Length; tMeshDetails.FoundInGameObjects.Add(path); AllMeshes.Add(tMeshDetails); } } else if (obj is AudioClip) { AudioClip clip = (AudioClip)obj; int check = 1; foreach (SoundDetails details in AllSounds) { if (details.path == p) { check = 0; details.FoundInGameObjects.Add(path); break; } } if (check == 1) { SoundDetails tSoundDetails = new SoundDetails(); tSoundDetails.FoundInGameObjects = new List <string>(); tSoundDetails.name = clip.name; tSoundDetails.path = p; tSoundDetails.preview = AssetPreview.GetAssetPreview(clip); tSoundDetails.FoundInGameObjects.Add(path); AllSounds.Add(tSoundDetails); } } else if (obj is MonoScript) { MonoScript script = (MonoScript)obj; int check = 1; foreach (ScriptDetails details in AllScripts) { if (details.path == p) { check = 0; details.FoundInGameObjects.Add(path); break; } } if (check == 1) { ScriptDetails tScriptDetails = new ScriptDetails(); tScriptDetails.FoundInGameObjects = new List <string>(); tScriptDetails.name = script.name; tScriptDetails.path = p; tScriptDetails.FoundInGameObjects.Add(path); AllScripts.Add(tScriptDetails); } } } } } foreach (TextureDetails tTextureDetails in AllTextures) { TotalTextureMemory += tTextureDetails.memSizeBytes; } foreach (MeshDetails tMeshDetails in AllMeshes) { TotalMeshVertices += tMeshDetails.vertexCount; } }
private void CalculateWeeklyUsageForSetTimePeriod(MaterialUsageViewModel materialUsageViewModel, List <BatchReport> reports, MaterialDetails details) { foreach (var report in reports) { foreach (var vessel in report.AllVessels) { foreach (var material in vessel.Materials) { if (material.Name == details.Name) { double target = material.TargetWeight; double actual = material.ActualWeight; if (material.Name.Contains("DYE")) { target = helper.CalculateDyeAmountInSolution(material.Name, material.TargetWeight); actual = helper.CalculateDyeAmountInSolution(material.Name, material.ActualWeight); } if (materialUsageViewModel.WeeklyUsage.Any(x => x.WeekNo == report.WeekNo && x.Year == report.StartTime.Year)) { materialUsageViewModel.WeeklyUsage.Find(x => x.WeekNo == report.WeekNo && x.Year == report.StartTime.Year).Target += target; materialUsageViewModel.WeeklyUsage.Find(x => x.WeekNo == report.WeekNo && x.Year == report.StartTime.Year).Actual += actual; } else { materialUsageViewModel.WeeklyUsage.Add( new SingleMaterialWeeklyUsage(report.WeekNo, report.StartTime.Year, target, actual, materialUsageViewModel.CostPerTon)); } materialUsageViewModel.TotalBatchesMadeWithMaterial++; } } } } materialUsageViewModel.CalculateTotals(); }