Exemple #1
0
        public ScrollComponent(UnityUGUIContext Context) : base(Context, "scroll")
        {
            ScrollRect = AddComponent <ScrollRect>();

            var viewport = new GameObject("[Scroll Viewport]").AddComponent <RectTransform>();

            viewport.gameObject.AddComponent <RectMask2D>();
            viewport.SetParent(RectTransform, false);

            viewport.anchorMin = Vector2.zero;
            viewport.anchorMax = Vector2.one;
            viewport.sizeDelta = Vector2.zero;
            viewport.pivot     = Vector2.up;

            var content = new GameObject("[Scroll Container]").AddComponent <RectTransform>();

            Container = content;
            content.SetParent(viewport, false);

            content.anchorMin = Vector2.zero;
            content.anchorMax = Vector2.one;
            content.pivot     = Vector2.up;
            content.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
            content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0);
            content.gameObject.AddComponent <CalculateSizeFromContents>().Layout = Layout;

            ScrollRect.horizontalScrollbar           = CreateScrollbar(false, viewport);
            ScrollRect.verticalScrollbar             = CreateScrollbar(true, viewport);
            ScrollRect.viewport                      = viewport;
            ScrollRect.content                       = content;
            ScrollRect.scrollSensitivity             = 50;
            ScrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
            ScrollRect.verticalScrollbarVisibility   = ScrollRect.ScrollbarVisibility.AutoHide;
            ScrollRect.movementType                  = ScrollRect.MovementType.Clamped;
        }
Exemple #2
0
        public void Get(UnityUGUIContext context, System.Action <AssetType> callback)
        {
            if (IsCached)
            {
                callback(CachedValue);
                return;
            }


            var realType  = type;
            var realValue = value;

            if (realType == AssetReferenceType.Auto)
            {
                var path = context.ResolvePath(realValue as string);
                if (HttpRegex.IsMatch(path))
                {
                    realType  = AssetReferenceType.Url;
                    realValue = path;
                }
                else
                {
                    realType  = AssetReferenceType.Resource;
                    realValue = path;
                }
            }


            Get(context, realType, realValue, (val) =>
            {
                IsCached    = true;
                CachedValue = val;
                callback(val);
            });
        }
Exemple #3
0
        protected virtual void Get(UnityUGUIContext context, AssetReferenceType realType, object realValue, Action <AssetType> callback)
        {
            switch (realType)
            {
            case AssetReferenceType.Resource:
                callback(Resources.Load(realValue as string, typeof(AssetType)) as AssetType);
                break;

            case AssetReferenceType.Global:
                callback(context.Globals.GetValueOrDefault(realValue as string) as AssetType);
                break;

            case AssetReferenceType.Object:
                callback(realValue as AssetType);
                break;

            case AssetReferenceType.File:
            case AssetReferenceType.Url:
            case AssetReferenceType.None:
            case AssetReferenceType.Procedural:
            case AssetReferenceType.Data:
            default:
                callback(null);
                break;
            }
        }
Exemple #4
0
        public VideoComponent(UnityUGUIContext context) : base(context, "video")
        {
            VideoPlayer               = AddComponent <VideoPlayer>();
            VideoPlayer.renderMode    = VideoRenderMode.RenderTexture;
            VideoPlayer.targetTexture = RenderTexture;

            VideoPlayer.prepareCompleted += PrepareCompleted;
        }
Exemple #5
0
 public DocumentProxy(UnityUGUIContext context, ReactUnity root, string origin)
 {
     head         = new HeadProxy();
     execute      = root.ExecuteScript;
     this.origin  = origin;
     this.context = context;
     this.root    = root;
 }
        protected UnityComponent(RectTransform existing, UnityUGUIContext context)
        {
            Context       = context;
            GameObject    = existing.gameObject;
            RectTransform = existing;

            Style  = new NodeStyle();
            Layout = new YogaNode(DefaultLayout);
        }
Exemple #7
0
        public HostComponent(RectTransform host, UnityUGUIContext context) : base(host, context)
        {
            Layout.Width  = Width;
            Layout.Height = Height;

            var responsive = GetOrAddComponent <ResponsiveElement>();

            responsive.Layout  = Layout;
            responsive.Context = context;
        }
Exemple #8
0
        public HostComponent(RectTransform host, UnityUGUIContext context) : base(host, context)
        {
            Layout.Width  = Width;
            Layout.Height = Height;

            var responsive = GameObject.GetComponent <ResponsiveElement>() ?? GameObject.AddComponent <ResponsiveElement>();

            responsive.Layout  = Layout;
            responsive.Context = context;

            ResolveStyle();
        }
Exemple #9
0
        public ImageComponent(UnityUGUIContext context) : base(context)
        {
            ImageContainer = new ContainerComponent(context);
            ImageContainer.GameObject.name = "[ImageContent]";
            Image = ImageContainer.GameObject.AddComponent <Image>();
            var measure = ImageContainer.GameObject.AddComponent <ImageNodeMeasure>();

            ImageContainer.Layout.SetMeasureFunction(measure.Measure);
            measure.Context   = context;
            measure.Layout    = ImageContainer.Layout;
            measure.Component = this;

            ImageContainer.SetParent(this);
        }
Exemple #10
0
        public ImageComponent(UnityUGUIContext context, string tag = "image") : base(context, tag)
        {
            ImageContainer = new ContainerComponent(context, "");
            ImageContainer.GameObject.name = "[ImageContent]";
            Image = ImageContainer.AddComponent <Image>();

            Measurer         = ImageContainer.AddComponent <ImageMeasurer>();
            Measurer.Context = context;
            Measurer.Layout  = ImageContainer.Layout;
            Measurer.Sprite  = Image.sprite;
            ImageContainer.Layout.SetMeasureFunction(Measurer.Measure);

            ImageContainer.SetParent(this);
        }
Exemple #11
0
        protected override void Get(UnityUGUIContext context, AssetReferenceType realType, object realValue, Action <Texture2D> callback)
        {
            if (realType == AssetReferenceType.Url)
            {
                webDeferred = MainThreadDispatcher.StartDeferred(GetTexture(realValue as string, callback));
            }
            else if (realType == AssetReferenceType.Data)
            {
                var    base64   = realValue as string;
                byte[] fileData = Convert.FromBase64String(base64);
                var    texture  = new Texture2D(1, 1);
                texture.LoadImage(fileData);
                callback(texture);
            }
            else if (realType == AssetReferenceType.File)
            {
                var       filePath = realValue as string;
                Texture2D texture  = null;
                byte[]    fileData;

                if (File.Exists(filePath))
                {
                    fileData = File.ReadAllBytes(filePath);
                    texture  = new Texture2D(1, 1);
                    texture.LoadImage(fileData);
                }
                callback(texture);
            }
            else if (realType == AssetReferenceType.Procedural)
            {
                var color = ParserMap.ColorConverter.Convert(realValue);

                if (color is Color c)
                {
                    var t = new Texture2D(1, 1);
                    t.SetPixel(0, 0, c);
                    t.Apply();
                    callback(t);
                }
                else
                {
                    callback(null);
                }
            }
            else
            {
                base.Get(context, realType, realValue, callback);
            }
        }
Exemple #12
0
        public TextComponent(string text, UnityUGUIContext context, string tag) : base(context, tag)
        {
            GameObject.name = "TEXT";
            Text            = AddComponent <TextMeshProUGUI>();

            Measurer         = AddComponent <TextMeasurer>();
            Measurer.Layout  = Layout;
            Measurer.Context = context;
            Layout.SetMeasureFunction(Measurer.Measure);

            if (text != null)
            {
                SetText(text);
            }
        }
Exemple #13
0
        public TextComponent(string text, UnityUGUIContext context) : base(context, "text")
        {
            GameObject.name = "TEXT";
            Text            = GameObject.AddComponent <TextMeshProUGUI>();

            SelfControl         = GameObject.AddComponent <FlexSelfControlledElement>();
            SelfControl.Layout  = Layout;
            SelfControl.Context = context;
            Layout.SetMeasureFunction(SelfControl.Measure);

            if (text != null)
            {
                SetText(text);
            }
        }
        public UnityComponent(UnityUGUIContext context)
        {
            Context       = context;
            GameObject    = new GameObject();
            RectTransform = GameObject.AddComponent <RectTransform>();

            RectTransform.anchorMin = Vector2.up;
            RectTransform.anchorMax = Vector2.up;
            RectTransform.pivot     = Vector2.up;


            Style          = new NodeStyle();
            Layout         = new YogaNode(DefaultLayout);
            Flex           = GameObject.AddComponent <FlexElement>();
            Flex.Layout    = Layout;
            Flex.Style     = Style;
            Flex.Component = this;
        }
Exemple #15
0
 protected override void Get(UnityUGUIContext context, AssetReferenceType realType, object realValue, Action <TMP_FontAsset> callback)
 {
     if (realType == AssetReferenceType.Procedural)
     {
         if (context.FontFamilies.TryGetValue((realValue as string).ToLowerInvariant(), out var found))
         {
             found.Get(context, callback);
         }
         else
         {
             callback(null);
             IsCached = false;
         }
     }
     else
     {
         base.Get(context, realType, realValue, callback);
     }
 }
Exemple #16
0
 protected override void Get(UnityUGUIContext context, AssetReferenceType realType, object realValue, Action <VideoComponentSource> callback)
 {
     if (realType == AssetReferenceType.Url)
     {
         callback(new VideoComponentSource()
         {
             Type = UnityEngine.Video.VideoSource.Url, Url = realValue as string
         });
     }
     else if (realType == AssetReferenceType.File)
     {
         callback(new VideoComponentSource()
         {
             Type = UnityEngine.Video.VideoSource.Url, Url = "file://" + realValue as string
         });
     }
     else
     {
         base.Get(context, realType, realValue, callback);
     }
 }
Exemple #17
0
        static public Sprite GetSpriteFromObject(object source, UnityUGUIContext Context)
        {
            switch (source)
            {
            case Sprite s:
                return(s);

            case Texture2D s:
                return(Sprite.Create(s, new Rect(0, 0, s.width, s.height), Vector2.one / 2));

            case AssetReference a:
                return(a.Get <Sprite>(Context.NamedAssets));

            case string s:
                return(new AssetReference(AssetReferenceType.Procedural, s).Get <Sprite>(Context.NamedAssets));

            default:
                break;
            }
            return(null);
        }
 public ContainerComponent(UnityUGUIContext context) : base(context)
 {
     Container = RectTransform;
 }
 protected ContainerComponent(RectTransform existing, UnityUGUIContext context) : base(existing, context)
 {
     Container = existing;
 }
 public RenderTextureComponent(UnityUGUIContext context, string tag = "render") : base(context, tag)
 {
     RenderTexture = new RenderTexture(1, 1, 1);
     SetTexture(RenderTexture);
 }
Exemple #21
0
 public ButtonComponent(UnityUGUIContext context) : base(context, "button")
 {
     Button = AddComponent <Button>();
 }
Exemple #22
0
 public CustomButtonComponent(UnityUGUIContext context, Color backgroundColor) : base(context)
 {
     Style.backgroundColor = backgroundColor;
 }
Exemple #23
0
 public ContainerComponent(UnityUGUIContext context, string tag) : base(context, tag)
 {
     Container = RectTransform;
 }
Exemple #24
0
 public AnchorComponent(UnityUGUIContext context) : base(context, "anchor")
 {
     clickHandler          = AddComponent <AnchorClickHandler>();
     clickHandler.OnEvent += OnClick;
 }
Exemple #25
0
 public ButtonComponent(UnityUGUIContext context) : base(context, "button")
 {
     Button     = GameObject.AddComponent <Button>();
     Selectable = Button;
 }