Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions CommunityEntity.UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,167 @@ private void CreateComponents( GameObject go, JSON.Object obj )

break;
}

case "UnityEngine.UI.VerticalLayoutGroup":
{
var vlg = go.AddComponent<VerticalLayoutGroup>();
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<HorizontalLayoutGroup>();
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<LayoutElement>();

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<NeedsKeyboard>();
Expand Down