Skip to content

Commit c6f7889

Browse files
committed
Fix LayoutGroup Bug
When adjusting position with LayoutGroup, the position of each UI object will reset to zero. This has been fixed by adding a function that will reset LayoutGroup
1 parent 0c742e4 commit c6f7889

14 files changed

+365
-73
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
If you don't know how to use this plugin, I highly recommend watching this short 5 minutes video here: https://youtu.be/QUbW6me4D1w
2+
3+
If you want to modify this plugin, all of the codes inside are commented and explained properly (I hope). Let me know if you need help!
4+
5+
You can contact me through our Discord server: https://discord.com/invite/aDMGjpFeBX
6+
Or by opening an issue in my github page: https://github.com/FFaUniHan/Unity_UI_AutoAnimation

UI Auto Animation/Assets/UI Auto Animation/Readme.txt.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UI Auto Animation/Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class UIAutoAnimation : MonoBehaviour
1212

1313
private List<Component> componentList;
1414
private RectTransform[] rectTransformList;
15+
private HorizontalOrVerticalLayoutGroup[] layoutGroupList;
1516
private float[] originalAlpha;
1617
private Vector2[] originalPosition;
1718
private Vector3[] originalScale;
@@ -218,13 +219,16 @@ private IEnumerator EntrancePositionEnumeration()
218219

219220
elapsedTime[i] += Time.deltaTime;
220221
}
222+
223+
ResetAllLayoutGroup();
221224
yield return null;
222225
}
223226
}
224227

225228
//There are always inaccuracies when dealing with float values
226229
//So to keep it safe, when the final loop is done, set everything to its final state.
227230
SetAllPosition_Original();
231+
ResetAllLayoutGroup();
228232
}
229233

230234
private IEnumerator ExitPositionEnumeration()
@@ -279,12 +283,15 @@ private IEnumerator ExitPositionEnumeration()
279283

280284
elapsedTime[i] += Time.deltaTime;
281285
}
286+
287+
ResetAllLayoutGroup();
282288
yield return null;
283289
}
284290

285291
//There are always inaccuracies when dealing with float values
286292
//So to keep it safe, when the final loop is done, set everything to its final state.
287293
SetAllPosition_Offset(animationExitPresets);
294+
ResetAllLayoutGroup();
288295
}
289296
}
290297

@@ -341,6 +348,7 @@ private IEnumerator EntranceScaleEnumeration()
341348

342349
elapsedTime[i] += Time.deltaTime;
343350
}
351+
344352
yield return null;
345353
}
346354
}
@@ -402,6 +410,7 @@ private IEnumerator ExitScaleEnumeration()
402410

403411
elapsedTime[i] += Time.deltaTime;
404412
}
413+
405414
yield return null;
406415
}
407416

@@ -464,6 +473,7 @@ private IEnumerator EntranceRotationEnumeration()
464473

465474
elapsedTime[i] += Time.deltaTime;
466475
}
476+
467477
yield return null;
468478
}
469479
}
@@ -526,6 +536,7 @@ private IEnumerator ExitRotationEnumeration()
526536

527537
elapsedTime[i] += Time.deltaTime;
528538
}
539+
529540
yield return null;
530541
}
531542

@@ -643,6 +654,11 @@ private void GetComponentsList()
643654
Vector3 rotation = rect.localRotation.eulerAngles;
644655
originalRotation[i] = rotation;
645656
}
657+
658+
//Get the Vertical Layout Group if it exists.
659+
//If we set the position of the child object in the Layout Group,
660+
//their position will reset to zero. So we need to recalculate them.
661+
layoutGroupList = GetComponentsInChildren<HorizontalOrVerticalLayoutGroup>();
646662
}
647663

648664
/// <summary>
@@ -924,6 +940,26 @@ private Vector3[] CreateOffsetRotationList(SOAnimationPresets animationPresets)
924940
}
925941
return offsetRotationList;
926942
}
943+
944+
/// <summary>
945+
/// Reset the layout group position.
946+
/// If we set the position of the child object in the Layout Group through script,
947+
/// their position will reset to zero. So we need to recalculate them.
948+
/// </summary>
949+
private void ResetAllLayoutGroup()
950+
{
951+
if (layoutGroupList.Length > 0)
952+
{
953+
for (int i = 0; i < layoutGroupList.Length; i++)
954+
{
955+
layoutGroupList[i].CalculateLayoutInputVertical();
956+
layoutGroupList[i].SetLayoutVertical();
957+
958+
layoutGroupList[i].CalculateLayoutInputHorizontal();
959+
layoutGroupList[i].SetLayoutHorizontal();
960+
}
961+
}
962+
}
927963
#endregion
928964

929965

UI Auto Animation/Logs/AssetImportWorker0-prev.log

Lines changed: 50 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ C:/SSD Projects/Unity_UI_AutoAnimation/UI Auto Animation
1515
-logFile
1616
Logs/AssetImportWorker0.log
1717
-srvPort
18-
49291
18+
50449
1919
Successfully changed project path to: C:/SSD Projects/Unity_UI_AutoAnimation/UI Auto Animation
2020
C:/SSD Projects/Unity_UI_AutoAnimation/UI Auto Animation
2121
[UnityMemory] Configuration Parameters - Can be set up in boot.config
@@ -47,11 +47,11 @@ C:/SSD Projects/Unity_UI_AutoAnimation/UI Auto Animation
4747
"memorysetup-temp-allocator-size-cloud-worker=32768"
4848
"memorysetup-temp-allocator-size-gi-baking-worker=262144"
4949
"memorysetup-temp-allocator-size-gfx=262144"
50-
Player connection [892] Host "[IP] 192.168.18.16 [Port] 0 [Flags] 2 [Guid] 2337635719 [EditorId] 2337635719 [Version] 1048832 [Id] WindowsEditor(7,FFAUNIHAN) [Debug] 1 [PackageName] WindowsEditor [ProjectName] Editor" joined multi-casting on [225.0.0.222:54997]...
50+
Player connection [9272] Host "[IP] 192.168.18.16 [Port] 0 [Flags] 2 [Guid] 1018422997 [EditorId] 1018422997 [Version] 1048832 [Id] WindowsEditor(7,FFAUNIHAN) [Debug] 1 [PackageName] WindowsEditor [ProjectName] Editor" joined multi-casting on [225.0.0.222:54997]...
5151

52-
Player connection [892] Host "[IP] 192.168.18.16 [Port] 0 [Flags] 2 [Guid] 2337635719 [EditorId] 2337635719 [Version] 1048832 [Id] WindowsEditor(7,FFAUNIHAN) [Debug] 1 [PackageName] WindowsEditor [ProjectName] Editor" joined alternative multi-casting on [225.0.0.222:34997]...
52+
Player connection [9272] Host "[IP] 192.168.18.16 [Port] 0 [Flags] 2 [Guid] 1018422997 [EditorId] 1018422997 [Version] 1048832 [Id] WindowsEditor(7,FFAUNIHAN) [Debug] 1 [PackageName] WindowsEditor [ProjectName] Editor" joined alternative multi-casting on [225.0.0.222:34997]...
5353

54-
Refreshing native plugins compatible for Editor in 79.82 ms, found 3 plugins.
54+
Refreshing native plugins compatible for Editor in 27.37 ms, found 3 plugins.
5555
Preloading 0 native plugins for Editor in 0.00 ms.
5656
Initialize engine version: 2022.2.17f1 (54cb9bda89c4)
5757
[Subsystems] Discovering subsystems at path C:/Program Files/Unity/Hub/Editor/2022.2.17f1/Editor/Data/Resources/UnitySubsystems
@@ -67,106 +67,96 @@ Initialize mono
6767
Mono path[0] = 'C:/Program Files/Unity/Hub/Editor/2022.2.17f1/Editor/Data/Managed'
6868
Mono path[1] = 'C:/Program Files/Unity/Hub/Editor/2022.2.17f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit-win32'
6969
Mono config path = 'C:/Program Files/Unity/Hub/Editor/2022.2.17f1/Editor/Data/MonoBleedingEdge/etc'
70-
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=127.0.0.1:56176
70+
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=127.0.0.1:56768
7171
Begin MonoManager ReloadAssembly
7272
Registering precompiled unity dll's ...
7373
Register platform support module: C:/Program Files/Unity/Hub/Editor/2022.2.17f1/Editor/Data/PlaybackEngines/AndroidPlayer/UnityEditor.Android.Extensions.dll
7474
Register platform support module: C:/Program Files/Unity/Hub/Editor/2022.2.17f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/UnityEditor.WindowsStandalone.Extensions.dll
75-
Registered in 0.063045 seconds.
76-
- Loaded All Assemblies, in 2.027 seconds
75+
Registered in 0.022818 seconds.
76+
- Loaded All Assemblies, in 1.109 seconds
7777
Native extension for WindowsStandalone target not found
7878
Native extension for Android target not found
79-
InvalidOperationException: Cannot process request because the process (3808) has exited.
80-
at System.Diagnostics.Process.GetProcessHandle (System.Int32 access, System.Boolean throwIfExited) [0x0004e] in <1843c052da054b31a104425a8da029fc>:0
81-
at System.Diagnostics.Process.GetProcessHandle (System.Int32 access) [0x00000] in <1843c052da054b31a104425a8da029fc>:0
82-
at System.Diagnostics.Process.Kill () [0x00002] in <1843c052da054b31a104425a8da029fc>:0
83-
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Kill()
84-
at UnityEditor.Android.AndroidDeploymentTargetsExtension.GetKnownTargets (UnityEditor.DeploymentTargets.IDeploymentTargetsMainThreadContext context, UnityEditor.ProgressHandler progressHandler) [0x0014a] in <966827195df443f8a1081ee07ce3e766>:0
85-
at UnityEditor.Android.TargetScanWorker.ScanSync () [0x00039] in <966827195df443f8a1081ee07ce3e766>:0
86-
at UnityEditor.Android.TargetExtension.OnUsbDevicesChanged (UnityEditor.Hardware.UsbDevice[] usbDevices) [0x00081] in <966827195df443f8a1081ee07ce3e766>:0
87-
at UnityEditor.Android.TargetExtension.OnLoad () [0x000ad] in <966827195df443f8a1081ee07ce3e766>:0
88-
at UnityEditor.Modules.ModuleManager.InitializePlatformSupportModules () [0x0009d] in <88872b21b1e746a7ad699974a2be8304>:0
89-
79+
Android Extension - Scanning For ADB Devices 966 ms
9080
Mono: successfully reloaded assembly
91-
- Finished resetting the current domain, in 6.543 seconds
81+
- Finished resetting the current domain, in 2.220 seconds
9282
Domain Reload Profiling:
93-
ReloadAssembly (1108ms)
94-
BeginReloadAssembly (476ms)
83+
ReloadAssembly (520ms)
84+
BeginReloadAssembly (250ms)
9585
ExecutionOrderSort (0ms)
9686
DisableScriptedObjects (0ms)
9787
BackupInstance (0ms)
9888
ReleaseScriptingObjects (0ms)
99-
CreateAndSetChildDomain (4ms)
89+
CreateAndSetChildDomain (3ms)
10090
LoadAllAssembliesAndSetupDomain (0ms)
101-
LoadAssemblies (472ms)
91+
LoadAssemblies (244ms)
10292
RebuildTransferFunctionScriptingTraits (0ms)
103-
SetupTypeCache (870ms)
104-
TypeCache.Initialize (868ms)
105-
TypeCache.ScanAssembly (856ms)
106-
ResolveRequiredComponents (2ms)
93+
SetupTypeCache (555ms)
94+
TypeCache.Initialize (550ms)
95+
TypeCache.ScanAssembly (548ms)
96+
ResolveRequiredComponents (4ms)
10797
FinalizeReload (0ms)
10898
ReleaseScriptCaches (0ms)
10999
RebuildScriptCaches (0ms)
110-
SetupLoadedEditorAssemblies (6159ms)
100+
SetupLoadedEditorAssemblies (1962ms)
111101
LogAssemblyErrors (0ms)
112-
InitializePlatformSupportModulesInManaged (4730ms)
113-
SetLoadedEditorAssemblies (26ms)
102+
InitializePlatformSupportModulesInManaged (1333ms)
103+
SetLoadedEditorAssemblies (13ms)
114104
RefreshPlugins (0ms)
115-
BeforeProcessingInitializeOnLoad (11ms)
116-
ProcessInitializeOnLoadAttributes (992ms)
117-
ProcessInitializeOnLoadMethodAttributes (400ms)
118-
AfterProcessingInitializeOnLoad (1ms)
119-
EditorAssembliesLoaded (0ms)
105+
BeforeProcessingInitializeOnLoad (4ms)
106+
ProcessInitializeOnLoadAttributes (418ms)
107+
ProcessInitializeOnLoadMethodAttributes (193ms)
108+
AfterProcessingInitializeOnLoad (0ms)
109+
EditorAssembliesLoaded (1ms)
120110
ExecutionOrderSort2 (0ms)
121111
AwakeInstancesAfterBackupRestoration (0ms)
122112
========================================================================
123113
Worker process is ready to serve import requests
124114
Begin MonoManager ReloadAssembly
125115
Symbol file LoadedFromMemory doesn't match image C:\SSD Projects\Unity_UI_AutoAnimation\UI Auto Animation\Library\PackageCache\com.unity.visualscripting@1.8.0\Editor\VisualScripting.Core\Dependencies\YamlDotNet\Unity.VisualScripting.YamlDotNet.dll
126116
Symbol file LoadedFromMemory doesn't match image C:\SSD Projects\Unity_UI_AutoAnimation\UI Auto Animation\Library\PackageCache\com.unity.visualscripting@1.8.0\Editor\VisualScripting.Core\Dependencies\DotNetZip\Unity.VisualScripting.IonicZip.dll
127-
- Loaded All Assemblies, in 3.936 seconds
128-
Refreshing native plugins compatible for Editor in 43.43 ms, found 3 plugins.
117+
- Loaded All Assemblies, in 3.114 seconds
118+
Refreshing native plugins compatible for Editor in 7.43 ms, found 3 plugins.
129119
Native extension for WindowsStandalone target not found
130120
Native extension for Android target not found
131121
Mono: successfully reloaded assembly
132-
- Finished resetting the current domain, in 2.967 seconds
122+
- Finished resetting the current domain, in 1.211 seconds
133123
Domain Reload Profiling:
134-
ReloadAssembly (781ms)
135-
BeginReloadAssembly (478ms)
124+
ReloadAssembly (787ms)
125+
BeginReloadAssembly (474ms)
136126
ExecutionOrderSort (0ms)
137-
DisableScriptedObjects (15ms)
127+
DisableScriptedObjects (26ms)
138128
BackupInstance (0ms)
139129
ReleaseScriptingObjects (0ms)
140-
CreateAndSetChildDomain (44ms)
141-
LoadAllAssembliesAndSetupDomain (3149ms)
142-
LoadAssemblies (2052ms)
130+
CreateAndSetChildDomain (63ms)
131+
LoadAllAssembliesAndSetupDomain (2316ms)
132+
LoadAssemblies (1210ms)
143133
RebuildTransferFunctionScriptingTraits (0ms)
144-
SetupTypeCache (1403ms)
145-
TypeCache.Initialize (1272ms)
146-
TypeCache.ScanAssembly (1255ms)
147-
ResolveRequiredComponents (47ms)
134+
SetupTypeCache (1349ms)
135+
TypeCache.Initialize (1309ms)
136+
TypeCache.ScanAssembly (1301ms)
137+
ResolveRequiredComponents (9ms)
148138
FinalizeReload (0ms)
149139
ReleaseScriptCaches (0ms)
150140
RebuildScriptCaches (0ms)
151-
SetupLoadedEditorAssemblies (1493ms)
141+
SetupLoadedEditorAssemblies (842ms)
152142
LogAssemblyErrors (0ms)
153-
InitializePlatformSupportModulesInManaged (87ms)
143+
InitializePlatformSupportModulesInManaged (51ms)
154144
SetLoadedEditorAssemblies (9ms)
155145
RefreshPlugins (0ms)
156-
BeforeProcessingInitializeOnLoad (314ms)
157-
ProcessInitializeOnLoadAttributes (971ms)
158-
ProcessInitializeOnLoadMethodAttributes (82ms)
159-
AfterProcessingInitializeOnLoad (30ms)
146+
BeforeProcessingInitializeOnLoad (131ms)
147+
ProcessInitializeOnLoadAttributes (582ms)
148+
ProcessInitializeOnLoadMethodAttributes (47ms)
149+
AfterProcessingInitializeOnLoad (20ms)
160150
EditorAssembliesLoaded (0ms)
161151
ExecutionOrderSort2 (0ms)
162-
AwakeInstancesAfterBackupRestoration (42ms)
163-
Launched and connected shader compiler UnityShaderCompiler.exe after 0.15 seconds
164-
Refreshing native plugins compatible for Editor in 15.08 ms, found 3 plugins.
152+
AwakeInstancesAfterBackupRestoration (15ms)
153+
Launched and connected shader compiler UnityShaderCompiler.exe after 0.08 seconds
154+
Refreshing native plugins compatible for Editor in 7.50 ms, found 3 plugins.
165155
Preloading 0 native plugins for Editor in 0.00 ms.
166156
Unloading 3084 Unused Serialized files (Serialized files now loaded: 0)
167157
Unloading 31 unused Assets / (66.4 KB). Loaded Objects now: 3551.
168158
Memory consumption went from 113.4 MB to 113.3 MB.
169-
Total: 26.178700 ms (FindLiveObjects: 3.364900 ms CreateObjectMapping: 0.722800 ms MarkObjects: 18.326700 ms DeleteObjects: 1.222000 ms)
159+
Total: 6.904300 ms (FindLiveObjects: 0.298100 ms CreateObjectMapping: 0.148300 ms MarkObjects: 6.300800 ms DeleteObjects: 0.155600 ms)
170160

171161
AssetImportParameters requested are different than current active one (requested -> active):
172162
custom:container-demuxer-ogg: 62fdf1f143b41e24485cea50d1cbac27 ->
@@ -181,9 +171,9 @@ AssetImportParameters requested are different than current active one (requested
181171
custom:audio-encoder-webm-vorbis: bf7c407c2cedff20999df2af8eb42d56 ->
182172
========================================================================
183173
Received Import Request.
184-
Time since last request: 270577.740261 seconds.
174+
Time since last request: 334546.564642 seconds.
185175
path: Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs
186176
artifactKey: Guid(f7ffeee45352e4843b7e1df525780522) Importer(815301076,1909f56bfc062723c751e8b465ee728b)
187-
Start importing Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs using Guid(f7ffeee45352e4843b7e1df525780522) Importer(815301076,1909f56bfc062723c751e8b465ee728b) -> (artifact id: 'fe0b061155e64c5ce7c18c9d07da5f3a') in 0.016336 seconds
177+
Start importing Assets/UI Auto Animation/Scripts/UIAutoAnimation.cs using Guid(f7ffeee45352e4843b7e1df525780522) Importer(815301076,1909f56bfc062723c751e8b465ee728b) -> (artifact id: 'b7b480f51bd780b7aaa5f4fc9b7681b0') in 0.004622 seconds
188178
Number of updated asset objects reloaded before import = 0
189179
Number of asset objects unloaded after import = 0

0 commit comments

Comments
 (0)