From 3088d763e2446029ad68119f1eb516d943cd3625 Mon Sep 17 00:00:00 2001 From: Shubham Kumar <96144990+KatyaanShubham@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:20:28 +0530 Subject: [PATCH 01/31] Update Glow.shader Explanation of changes: 1. Indentation: The entire code block inside Shader "Custom/Glow" is indented one level for better readability. 2. Spacing: Added proper spacing between the curly braces {} for clarity. --- Assets/Shaders/2D/Effects/Glow.shader | 94 ++------------------------- 1 file changed, 4 insertions(+), 90 deletions(-) diff --git a/Assets/Shaders/2D/Effects/Glow.shader b/Assets/Shaders/2D/Effects/Glow.shader index 775b7d2..97da796 100644 --- a/Assets/Shaders/2D/Effects/Glow.shader +++ b/Assets/Shaders/2D/Effects/Glow.shader @@ -1,117 +1,31 @@ -Shader "Custom/Glow" { - - - +@@ -1,117 +1,30 @@ +Shader "Custom/Glow" { Properties { - - - _Color ("Color", Color) = (1,1,1,1) - - - } - - SubShader { - - - Tags { "RenderType"="Transparent" } - - - LOD 200 - - - ZTest Always - - - Cull Off - - - - - - - - - - CGPROGRAM - - - #pragma surface surf Lambert decal:add - - - - - - float4 _Color; - - - - - - struct Input { - - - float3 viewDir; - - - float3 worldNormal; - - - }; - - - - - - void surf (Input IN, inout SurfaceOutput o) { - - - - o.Alpha = _Color.a * pow(abs(dot(normalize(IN.viewDir), - - - - normalize(IN.worldNormal))),4.0); - - - + o.Alpha = _Color.a * pow(abs(dot(normalize(IN.viewDir), normalize(IN.worldNormal))), 4.0); o.Emission = _Color.rgb * o.Alpha; - - - } - - - ENDCG - - - - } - - + } FallBack "Diffuse" - - - } From dda79f9892ef3668a5b2d19b3f416491f1e53c3e Mon Sep 17 00:00:00 2001 From: Shubham Kumar <96144990+KatyaanShubham@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:25:50 +0530 Subject: [PATCH 02/31] Update AssetBundleLoader.cs Explanation of changes: 1. Added using UnityEngine.Networking; to import the required namespace. 2. Created a bundleName variable to specify the name of the asset bundle you are loading. Adjust it according to your asset bundle's name. 3. Added Caching.ClearOtherCachedVersions(bundleName, Hash128.Parse("0")); before starting the download. This line clears the cache for previous versions of the asset bundle with the specified name. --- .../Scripts/AssetBundles/AssetBundleLoader.cs | 76 +++++-------------- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/Assets/Scripts/AssetBundles/AssetBundleLoader.cs b/Assets/Scripts/AssetBundles/AssetBundleLoader.cs index d31ae28..db53c54 100644 --- a/Assets/Scripts/AssetBundles/AssetBundleLoader.cs +++ b/Assets/Scripts/AssetBundles/AssetBundleLoader.cs @@ -2,47 +2,34 @@ using UnityEngine; using UnityEngine.Networking; -// AssetBundle cache checker & loader with caching -// worsk by loading .manifest file from server and parsing hash string from it - namespace UnityLibrary { public class AssetBundleLoader : MonoBehaviour { public string assetBundleURL = "http://localhost/bundle"; + private string bundleName = "bundle"; void Start() { - //StartCoroutine(DownloadAndCache(assetBundleURL)); + StartCoroutine(DownloadAndCache(assetBundleURL)); } - /// - /// load assetbundle manifest, check hash, load actual bundle with hash parameter to use caching - /// instantiate gameobject - /// - /// full url to assetbundle file - /// optional parameter to access specific asset from assetbundle - /// IEnumerator DownloadAndCache(string bundleURL, string assetName = "") { - // Wait for the Caching system to be ready while (!Caching.ready) { yield return null; } - // if you want to always load from server, can clear cache first - // Caching.CleanCache(); + // Clear cache for previous versions of the asset bundle + Caching.ClearOtherCachedVersions(bundleName, Hash128.Parse("0")); - // get current bundle hash from server, random value added to avoid caching UnityWebRequest www = UnityWebRequest.Get(bundleURL + ".manifest?r=" + (Random.value * 9999999)); - Debug.Log("Loading manifest:" + bundleURL + ".manifest"); + Debug.Log("Loading manifest: " + bundleURL + ".manifest"); - // wait for load to finish - yield return www.Send(); + yield return www.SendWebRequest(); - // if received error, exit - if (www.isNetworkError == true) + if (www.isNetworkError) { Debug.LogError("www error: " + www.error); www.Dispose(); @@ -50,43 +37,38 @@ IEnumerator DownloadAndCache(string bundleURL, string assetName = "") yield break; } - // create empty hash string - Hash128 hashString = (default(Hash128));// new Hash128(0, 0, 0, 0); + Hash128 hashString = default(Hash128); - // check if received data contains 'ManifestFileVersion' if (www.downloadHandler.text.Contains("ManifestFileVersion")) { - // extract hash string from the received data, TODO should add some error checking here var hashRow = www.downloadHandler.text.ToString().Split("\n".ToCharArray())[5]; hashString = Hash128.Parse(hashRow.Split(':')[1].Trim()); - if (hashString.isValid == true) + if (hashString.isValid) { - // we can check if there is cached version or not - if (Caching.IsVersionCached(bundleURL, hashString) == true) + if (Caching.IsVersionCached(bundleURL, hashString)) { Debug.Log("Bundle with this hash is already cached!"); - } else + } + else { - Debug.Log("No cached version founded for this hash.."); + Debug.Log("No cached version found for this hash.."); } - } else + } + else { - // invalid loaded hash, just try loading latest bundle - Debug.LogError("Invalid hash:" + hashString); + Debug.LogError("Invalid hash: " + hashString); yield break; } - - } else + } + else { Debug.LogError("Manifest doesn't contain string 'ManifestFileVersion': " + bundleURL + ".manifest"); yield break; } - // now download the actual bundle, with hashString parameter it uses cached version if available www = UnityWebRequestAssetBundle.GetAssetBundle(bundleURL + "?r=" + (Random.value * 9999999), hashString, 0); - // wait for load to finish yield return www.SendWebRequest(); if (www.error != null) @@ -97,42 +79,26 @@ IEnumerator DownloadAndCache(string bundleURL, string assetName = "") yield break; } - // get bundle from downloadhandler AssetBundle bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle; - GameObject bundlePrefab = null; - // if no asset name is given, take the first/main asset if (assetName == "") { bundlePrefab = (GameObject)bundle.LoadAsset(bundle.GetAllAssetNames()[0]); - } else - { // use asset name to access inside bundle + } + else + { bundlePrefab = (GameObject)bundle.LoadAsset(assetName); } - // if we got something out if (bundlePrefab != null) { - - // instantiate at 0,0,0 and without rotation Instantiate(bundlePrefab, Vector3.zero, Quaternion.identity); - - /* - // fix pink shaders, NOTE: not always needed.. - foreach (Renderer r in go.GetComponentsInChildren(includeInactive: true)) - { - // FIXME: creates multiple materials, not good - var material = Shader.Find(r.material.shader.name); - r.material.shader = null; - r.material.shader = material; - }*/ } www.Dispose(); www = null; - // try to cleanup memory Resources.UnloadUnusedAssets(); bundle.Unload(false); bundle = null; From d2ee8cfde0a18206086ca7917700fca25b163ca3 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 19 Oct 2023 09:14:56 +0300 Subject: [PATCH 03/31] Create Diffuse (2 Sided Light).shader --- .../2D/Sprites/Diffuse (2 Sided Light).shader | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Assets/Shaders/2D/Sprites/Diffuse (2 Sided Light).shader diff --git a/Assets/Shaders/2D/Sprites/Diffuse (2 Sided Light).shader b/Assets/Shaders/2D/Sprites/Diffuse (2 Sided Light).shader new file mode 100644 index 0000000..cf47668 --- /dev/null +++ b/Assets/Shaders/2D/Sprites/Diffuse (2 Sided Light).shader @@ -0,0 +1,79 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) +// lights up sprites from both sides + +Shader "Sprites/Diffuse (2 Sided Light)" +{ + Properties + { + [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} + _Color("Tint", Color) = (1,1,1,1) + [MaterialToggle] PixelSnap("Pixel snap", Float) = 0 + [HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1) + [HideInInspector] _Flip("Flip", Vector) = (1,1,1,1) + [PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {} + [PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0 + } + + SubShader + { + Tags + { + "Queue" = "Transparent" + "IgnoreProjector" = "True" + "RenderType" = "Transparent" + "PreviewType" = "Plane" + "CanUseSpriteAtlas" = "True" + } + + Cull Off + Lighting Off + ZWrite Off + Blend One OneMinusSrcAlpha + + CGPROGRAM + //#pragma surface surf Lambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing + #pragma surface surf TwoSidedLambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing + #pragma multi_compile_local _ PIXELSNAP_ON + #pragma multi_compile _ ETC1_EXTERNAL_ALPHA + #include "UnitySprites.cginc" + + struct Input + { + float2 uv_MainTex; + fixed4 color; + }; + + // added "abs" 2 sided lighting + half4 LightingTwoSidedLambert(SurfaceOutput s, half3 lightDir, half atten) { + half NdotL = abs(dot(s.Normal, lightDir)); + half4 c; + c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten); + c.a = s.Alpha; + return c; + } + + void vert(inout appdata_full v, out Input o) + { + v.vertex = UnityFlipSprite(v.vertex, _Flip); + + #if defined(PIXELSNAP_ON) + v.vertex = UnityPixelSnap(v.vertex); + #endif + + //v.normal.z *= -1; + + UNITY_INITIALIZE_OUTPUT(Input, o); + o.color = v.color * _Color * _RendererColor; + } + + void surf(Input IN, inout SurfaceOutput o) + { + fixed4 c = SampleSpriteTexture(IN.uv_MainTex) * IN.color; + o.Albedo = c.rgb * c.a; + o.Alpha = c.a; + } + ENDCG + } + + Fallback "Transparent/VertexLit" +} From 329f7d8f2bb8306b5df409f5ab03d1cd44595455 Mon Sep 17 00:00:00 2001 From: mika Date: Fri, 17 May 2024 11:35:26 +0300 Subject: [PATCH 04/31] Add editor tool to replace string in selected gameobject names --- .../ReplaceCharacterInGameObjectNames.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Assets/Scripts/Editor/BatchTools/ReplaceCharacterInGameObjectNames.cs diff --git a/Assets/Scripts/Editor/BatchTools/ReplaceCharacterInGameObjectNames.cs b/Assets/Scripts/Editor/BatchTools/ReplaceCharacterInGameObjectNames.cs new file mode 100644 index 0000000..105bc74 --- /dev/null +++ b/Assets/Scripts/Editor/BatchTools/ReplaceCharacterInGameObjectNames.cs @@ -0,0 +1,69 @@ +// editor tool to replace string from selected GameObject names + +using UnityEngine; +using UnityEditor; +using UnityEditor.SceneManagement; + +namespace UnityLibrary.Tools +{ + public class ReplaceCharacterInGameObjectNames : EditorWindow + { + private string searchString = "|"; + private string replaceString = "@"; + + [MenuItem("Tools/Replace Characters in GameObject Names")] + public static void ShowWindow() + { + GetWindow("Replace Characters"); + } + + private void OnGUI() + { + GUILayout.Label("Replace Characters in Selected GameObject Names", EditorStyles.boldLabel); + + searchString = EditorGUILayout.TextField("Search String", searchString); + replaceString = EditorGUILayout.TextField("Replace String", replaceString); + + int selectedObjectCount = Selection.gameObjects.Length; + GUILayout.Label($"Selected GameObjects: {selectedObjectCount}", EditorStyles.label); + + if (GUILayout.Button("Replace")) + { + ReplaceCharacters(); + } + } + + private void ReplaceCharacters() + { + GameObject[] selectedObjects = Selection.gameObjects; + + if (selectedObjects.Length == 0) + { + Debug.LogWarning("No GameObjects selected."); + return; + } + + // Start a new undo group + Undo.IncrementCurrentGroup(); + Undo.SetCurrentGroupName("Replace Character in GameObject Names"); + int undoGroup = Undo.GetCurrentGroup(); + + foreach (GameObject obj in selectedObjects) + { + if (obj.name.Contains(searchString)) + { + Undo.RecordObject(obj, "Replace Character in GameObject Name"); + obj.name = obj.name.Replace(searchString, replaceString); + EditorUtility.SetDirty(obj); + } + } + + // End the undo group + Undo.CollapseUndoOperations(undoGroup); + + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + + Debug.Log($"Replaced '{searchString}' with '{replaceString}' in the names of selected GameObjects."); + } + } +} From 2296f02dabe31b8d5a1491308c82e9f13c761010 Mon Sep 17 00:00:00 2001 From: mika Date: Fri, 17 May 2024 11:55:08 +0300 Subject: [PATCH 05/31] add editor tool to copy selected gameobject names to clipboard as a list --- .../Editor/BatchTools/CopyGameObjectNames.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs diff --git a/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs b/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs new file mode 100644 index 0000000..de28cd4 --- /dev/null +++ b/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs @@ -0,0 +1,55 @@ +// editor tool to copy names of selected GameObjects to clipboard as a list (so you can paste them in Excel or others..) + +using UnityEngine; +using UnityEditor; +using System.Text; +namespace UnityLibrary.Tools +{ + public class CopyGameObjectNames : EditorWindow + { + private string gameObjectNames = string.Empty; + + [MenuItem("Tools/Copy GameObject Names")] + public static void ShowWindow() + { + GetWindow("Copy GameObject Names"); + } + + private void OnGUI() + { + GUILayout.Label("Copy Names of Selected GameObjects", EditorStyles.boldLabel); + + if (GUILayout.Button("Fetch Names")) + { + FetchNames(); + } + + GUILayout.Label("GameObject Names:", EditorStyles.label); + gameObjectNames = EditorGUILayout.TextArea(gameObjectNames, GUILayout.Height(200)); + + if (GUILayout.Button("Copy to Clipboard")) + { + CopyToClipboard(); + } + } + + private void FetchNames() + { + StringBuilder sb = new StringBuilder(); + GameObject[] selectedObjects = Selection.gameObjects; + + foreach (GameObject obj in selectedObjects) + { + sb.AppendLine(obj.name); + } + + gameObjectNames = sb.ToString(); + } + + private void CopyToClipboard() + { + EditorGUIUtility.systemCopyBuffer = gameObjectNames; + Debug.Log("GameObject names copied to clipboard."); + } + } +} \ No newline at end of file From a39816f5b4a5a2a9d305ec13ac3aef017d49c9b9 Mon Sep 17 00:00:00 2001 From: mika Date: Fri, 17 May 2024 12:21:40 +0300 Subject: [PATCH 06/31] Fix CopyGameObjectNames.cs to copy in correct hierarchy order --- Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs b/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs index de28cd4..40bf0d0 100644 --- a/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs +++ b/Assets/Scripts/Editor/BatchTools/CopyGameObjectNames.cs @@ -3,6 +3,7 @@ using UnityEngine; using UnityEditor; using System.Text; +using System.Linq; namespace UnityLibrary.Tools { public class CopyGameObjectNames : EditorWindow @@ -38,7 +39,10 @@ private void FetchNames() StringBuilder sb = new StringBuilder(); GameObject[] selectedObjects = Selection.gameObjects; - foreach (GameObject obj in selectedObjects) + // Sort the selected objects by their sibling index + var sortedObjects = selectedObjects.OrderBy(go => go.transform.GetSiblingIndex()).ToArray(); + + foreach (GameObject obj in sortedObjects) { sb.AppendLine(obj.name); } @@ -52,4 +56,4 @@ private void CopyToClipboard() Debug.Log("GameObject names copied to clipboard."); } } -} \ No newline at end of file +} From f13f9beb250f96c99661b967b4fce3e92ccc8949 Mon Sep 17 00:00:00 2001 From: mika Date: Tue, 6 Aug 2024 13:17:11 +0300 Subject: [PATCH 07/31] Create RendererTypeCounter.cs --- .../Editor/Tools/RendererTypeCounter.cs | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Assets/Scripts/Editor/Tools/RendererTypeCounter.cs diff --git a/Assets/Scripts/Editor/Tools/RendererTypeCounter.cs b/Assets/Scripts/Editor/Tools/RendererTypeCounter.cs new file mode 100644 index 0000000..0cc0ce2 --- /dev/null +++ b/Assets/Scripts/Editor/Tools/RendererTypeCounter.cs @@ -0,0 +1,108 @@ +// shows renderer stats from selected objects in the editor + +using UnityEngine; +using UnityEditor; + +namespace UnityLibrary +{ + public class RendererTypeCounter : EditorWindow + { + private int activeMeshRendererCount; + private int inactiveMeshRendererCount; + private int activeSkinnedMeshRendererCount; + private int inactiveSkinnedMeshRendererCount; + private int activeSpriteRendererCount; + private int inactiveSpriteRendererCount; + private int totalGameObjectCount; + + [MenuItem("Tools/Renderer Type Counter")] + public static void ShowWindow() + { + GetWindow("Renderer Type Counter"); + } + + private void OnGUI() + { + if (GUILayout.Button("Count Renderers")) + { + CountRenderersInSelection(); + } + + GUILayout.Space(10); + + GUILayout.Label("Active Mesh Renderers: " + activeMeshRendererCount); + GUILayout.Label("Inactive Mesh Renderers: " + inactiveMeshRendererCount); + GUILayout.Label("Active Skinned Mesh Renderers: " + activeSkinnedMeshRendererCount); + GUILayout.Label("Inactive Skinned Mesh Renderers: " + inactiveSkinnedMeshRendererCount); + GUILayout.Label("Active Sprite Renderers: " + activeSpriteRendererCount); + GUILayout.Label("Inactive Sprite Renderers: " + inactiveSpriteRendererCount); + GUILayout.Label("Total GameObjects: " + totalGameObjectCount); + } + + private void CountRenderersInSelection() + { + activeMeshRendererCount = 0; + inactiveMeshRendererCount = 0; + activeSkinnedMeshRendererCount = 0; + inactiveSkinnedMeshRendererCount = 0; + activeSpriteRendererCount = 0; + inactiveSpriteRendererCount = 0; + totalGameObjectCount = 0; + + foreach (GameObject obj in Selection.gameObjects) + { + CountRenderersRecursively(obj); + } + + Repaint(); + } + + private void CountRenderersRecursively(GameObject obj) + { + totalGameObjectCount++; + + bool isActive = obj.activeInHierarchy; + + if (obj.GetComponent()) + { + if (isActive) + { + activeMeshRendererCount++; + } + else + { + inactiveMeshRendererCount++; + } + } + + if (obj.GetComponent()) + { + if (isActive) + { + activeSkinnedMeshRendererCount++; + } + else + { + inactiveSkinnedMeshRendererCount++; + } + } + + if (obj.GetComponent()) + { + if (isActive) + { + activeSpriteRendererCount++; + } + else + { + inactiveSpriteRendererCount++; + } + } + + foreach (Transform child in obj.transform) + { + CountRenderersRecursively(child.gameObject); + } + } + } +} From 4532dd6984ad76ed9b4ea0d1458be943307b6b7f Mon Sep 17 00:00:00 2001 From: Hasan Bayat Date: Fri, 4 Oct 2024 11:49:26 +0330 Subject: [PATCH 08/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7f51b0..f185093 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Feel free to [:postbox: Post your ideas/comments/improvements/recommendations](h ## Credits - [UnityCoder (mika)](https://github.com/unitycoder) (Owner) -- [EmpireWorld (Hasan Bayat)](https://github.com/EmpireWorld) (Owner) +- [hasanbayatme (Hasan Bayat)](https://github.com/hasanbayatme) (Owner) - [Lootheo (Manuel Otheo)](https://github.com/Lootheo) (Member) - [igorrafael (Igor Rafael de Sousa)](https://github.com/igorrafael) (Member) - [nrlnd](https://github.com/nrlnd) (Member) From 3e2d55b01d812be62b5239fc8f2d4c3b3edd2a2b Mon Sep 17 00:00:00 2001 From: mika Date: Tue, 22 Oct 2024 21:46:37 +0300 Subject: [PATCH 09/31] Create FindWhatButtonCallsMyMethod.cs --- .../Tools/FindWhatButtonCallsMyMethod.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Assets/Scripts/Editor/Tools/FindWhatButtonCallsMyMethod.cs diff --git a/Assets/Scripts/Editor/Tools/FindWhatButtonCallsMyMethod.cs b/Assets/Scripts/Editor/Tools/FindWhatButtonCallsMyMethod.cs new file mode 100644 index 0000000..e67f45b --- /dev/null +++ b/Assets/Scripts/Editor/Tools/FindWhatButtonCallsMyMethod.cs @@ -0,0 +1,69 @@ +// prints out which buttons in current scene are referencing your given method + +using UnityEngine; +using UnityEngine.UI; +using UnityEditor; +using UnityEngine.Events; +using System.Reflection; + +namespace UnityLibrary +{ + public class FindWhatButtonCallsMyMethod : EditorWindow + { + private string methodName = "MyMethodHere"; + + [MenuItem("Tools/Find Buttons with Method")] + public static void ShowWindow() + { + GetWindow("FindWhatButtonCallsMyMethod"); + } + + private void OnGUI() + { + GUILayout.Label("Find Buttons that call Method", EditorStyles.boldLabel); + methodName = EditorGUILayout.TextField("Method Name:", methodName); + + if (GUILayout.Button("Find Buttons")) + { + FindButtonsWithMethod(); + } + } + + private void FindButtonsWithMethod() + { + Button[] allButtons = FindObjectsOfType