public override void Render(GameObjectElementBuilder builder, PropCollection props) { var rectTransform = builder.AddComponent <RectTransform>(); var canvasRenderer = builder.AddComponent <CanvasRenderer>(); var mouseOverDetector = builder.AddComponent <MouseOverDetector>(); var width = props.GetInt("width", 100); var height = props.GetInt("height", 100); var x = props.GetInt("x", 0); var y = props.GetInt("y", 0); var onEnter = props.GetCallbackAction("onEnter"); var onLeave = props.GetCallbackAction("onLeave"); if (onEnter != null) { mouseOverDetector.SetProperty(OnEnter, new UnityAction(onEnter)); } if (onLeave != null) { mouseOverDetector.SetProperty(OnLeave, new UnityAction(onLeave)); } rectTransform.SetProperty(AnchorMin, Vector2.zero); rectTransform.SetProperty(AnchorMax, Vector2.zero); rectTransform.SetProperty(Pivot, new Vector2(0, 1)); rectTransform.SetProperty(OffsetMax, new Vector2(x + width, y + height)); rectTransform.SetProperty(OffsetMin, new Vector2(x, y)); }
public override void Render(GameObjectElementBuilder builder, PropCollection props) { base.Render(builder, props); var image = builder.AddComponent <Image>(); var button = builder.AddComponent <Button>(); var onClick = props.GetCallbackAction("onClick"); if (onClick != null) { var buttonClickedEvent = new Button.ButtonClickedEvent(); buttonClickedEvent.AddListener(new UnityAction(onClick)); button.SetProperty(OnClick, buttonClickedEvent); } var imageResource = props.GetString("image", null); if (imageResource != null) { image.SetProperty(Sprite, ComponentResources.Get(imageResource) as Sprite); } image.SetProperty(Type, Image.Type.Sliced); }
public override void Render(GameObjectElementBuilder builder, PropCollection props) { base.Render(builder, props); var image = builder.AddComponent <Image>(); var button = builder.AddComponent <Button>(); var onClick = props.GetCallbackAction("onClick"); var buttonClickedEvent = new Button.ButtonClickedEvent(); buttonClickedEvent.AddListener(new UnityAction(onClick)); button.SetProperty(e => e.onClick, buttonClickedEvent); image.SetProperty(e => e.color, Color.blue); }