diff --git a/CommunityEntity.UI.cs b/CommunityEntity.UI.cs index 05ee240..e08c9ae 100644 --- a/CommunityEntity.UI.cs +++ b/CommunityEntity.UI.cs @@ -295,6 +295,167 @@ private void CreateComponents( GameObject go, JSON.Object obj ) break; } + + case "UnityEngine.UI.VerticalLayoutGroup": + { + var vlg = go.AddComponent(); + var paddingArray = obj.GetString( "padding", "0" ).Split( ' ' ); + RectOffset padding = null; + if ( paddingArray.Length > 0 ) + { + padding = new RectOffset(); + padding.left = int.Parse( paddingArray[0] ); + + if ( paddingArray.Length > 1 ) + { + padding.right = int.Parse( paddingArray[1] ); + + if ( paddingArray.Length > 2 ) + { + padding.top = int.Parse( paddingArray[2] ); + + if ( paddingArray.Length > 3 ) + { + padding.bottom = int.Parse( paddingArray[3] ); + } + } + } + } + + if ( padding != null ) + { + vlg.padding = padding; + } + + vlg.spacing = obj.GetInt( "spacing", 0 ); + vlg.childAlignment = (TextAnchor)System.Enum.Parse( typeof( TextAnchor ), obj.GetString( "childAlignment", "UpperLeft" ) ); + + if ( obj.ContainsKey( "childControlWidth" ) ) + { + vlg.childControlWidth = true; + } + + if ( obj.ContainsKey( "childControlHeight" ) ) + { + vlg.childControlHeight = true; + } + + if ( obj.ContainsKey( "childForceExpandWidth" ) ) + { + vlg.childForceExpandWidth = true; + } + + if ( obj.ContainsKey( "childForceExpandHeight" ) ) + { + vlg.childForceExpandHeight = true; + } + break; + } + + case "UnityEngine.UI.HorizontalLayoutGroup": + { + var hlg = go.AddComponent(); + var paddingArray = obj.GetString( "padding", "0" ).Split( ' ' ); + RectOffset padding = null; + if ( paddingArray.Length > 0 ) + { + padding = new RectOffset(); + padding.left = int.Parse( paddingArray[0] ); + + if ( paddingArray.Length > 1 ) + { + padding.right = int.Parse( paddingArray[1] ); + + if ( paddingArray.Length > 2 ) + { + padding.top = int.Parse( paddingArray[2] ); + + if ( paddingArray.Length > 3 ) + { + padding.bottom = int.Parse( paddingArray[3] ); + } + } + } + } + + if ( padding != null ) + { + hlg.padding = padding; + } + + hlg.spacing = obj.GetInt( "spacing", 0 ); + hlg.childAlignment = (TextAnchor)System.Enum.Parse( typeof( TextAnchor ), obj.GetString( "childAlignment", "UpperLeft" ) ); + + if ( obj.ContainsKey( "childControlWidth" ) ) + { + hlg.childControlWidth = true; + } + + if ( obj.ContainsKey( "childControlHeight" ) ) + { + hlg.childControlHeight = true; + } + + if ( obj.ContainsKey( "childForceExpandWidth" ) ) + { + hlg.childForceExpandWidth = true; + } + + if ( obj.ContainsKey( "childForceExpandHeight" ) ) + { + hlg.childForceExpandHeight = true; + } + break; + } + + case "UnityEngine.UI.LayoutElement": + { + var le = go.AddComponent(); + + if ( obj.ContainsKey( "ignoreLayout" ) ) + { + le.ignoreLayout = true; + break; + } + + if ( obj.ContainsKey( "minWidth" ) ) + { + le.minWidth = obj.GetFloat( "minWidth", 0 ); + } + + if ( obj.ContainsKey( "minHeight" ) ) + { + le.minHeight = obj.GetFloat( "minHeight", 0 ); + } + + if ( obj.ContainsKey( "preferredWidth" ) ) + { + le.preferredWidth = obj.GetFloat( "preferredWidth", 0 ); + } + + if ( obj.ContainsKey( "preferredHeight" ) ) + { + le.preferredHeight = obj.GetFloat( "preferredHeight", 0 ); + } + + if ( obj.ContainsKey( "flexibleWidth" ) ) + { + le.flexibleWidth = obj.GetFloat( "flexibleWidth", 0 ); + } + + if ( obj.ContainsKey( "flexibleHeight" ) ) + { + le.flexibleHeight = obj.GetFloat( "flexibleHeight", 0 ); + } + + if ( obj.ContainsKey( "layoutPriority" ) ) + { + le.layoutPriority = obj.GetInt( "layoutPriority", 1 ); + } + + break; + } + case "NeedsKeyboard": { go.AddComponent();