//TODO: Move crosshair to here
        public HotbarScreen()
        {
            //Init the hotbar
            Hotbar         = new UiImage(this, new Point(0, 0), new Point(5, 5), "textures/ui/hotbar_gui");
            Hotbar.size    = new Point(Hotbar.image.Width, Hotbar.image.Height);
            Hotbar.rawSize = Hotbar.size;
            Hotbar.UV      = new Vector4(0, 0, 0.3515625f, 0.0390625f);
            AddComponent(Hotbar);

            //init the items
            for (int i = 0; i < 9; i++)
            {
                items[i]         = new ItemImage(this, 0, 0, 64, 64);
                items[i].rawSize = new Point(16, 16);
                AddComponent(items[i]);
            }

            //init the selection dot
            Selected         = new UiImage(this, new Point(0, 0), new Point(5, 5), "textures/ui/hotbar_gui");
            Selected.size    = new Point(Selected.image.Width, Selected.image.Height);
            Selected.rawSize = Selected.size;
            Selected.UV      = new Vector4(0, 0.0625f, 0.04296875f, 0.10546875f);
            AddComponent(Selected);

            //init the crosshair
            CrosshairX = new UiImage(this, Point.Zero, new Point(CrossHairWidth, CrossHairThickness));
            CrosshairY = new UiImage(this, Point.Zero, new Point(CrossHairThickness, CrossHairWidth));
            AddComponent(CrosshairX);
            AddComponent(CrosshairY);

            HoverText = new UiText(this, Point.Zero, "");
            AddComponent(HoverText);
        }
Example #2
0
 public EquippedWeaponView(Point position)
     : base(new Rectangle(position.X, position.Y, 220, 84), true, 1)
 {
     _weaponArt = new UiImage {
         Transform = new Transform2(new Rectangle(position.X + 60, position.Y + 4, 130, 52))
     };
     _nameLabel = new Label
     {
         Font      = GuiFonts.Body,
         Transform = new Transform2(new Rectangle(position.X, position.Y + 54, 250, 30)),
         TextColor = UiColors.InGame_Text
     };
     _rangeLabel = new Label
     {
         Font      = GuiFonts.Body,
         Transform = new Transform2(new Rectangle(position.X, position.Y + 80, 250, 30)),
         TextColor = UiColors.InGame_Text
     };
     _visuals.Add(new UiImage
     {
         Image     = "UI/weapon-panel.png",
         Tint      = 180.Alpha(),
         Transform = new Transform2(new Rectangle(position.X, position.Y, 250, 114))
     });
     _visuals.Add(_weaponArt);
     _visuals.Add(_nameLabel);
     _visuals.Add(_rangeLabel);
 }
Example #3
0
    //自动设置对话框文字、长度、背景宽度
    private void SetDialogText(UiText text, UiImage dialogBg, string str)
    {
        var dialogAdd = dialogBg.rectTransform.sizeDelta.x - text.rectTransform.sizeDelta.x;

        //得到单行文字宽度
        Font font     = text.font;
        int  fontsize = text.fontSize;

        font.RequestCharactersInTexture(str, fontsize, FontStyle.Normal);
        float width = 0f;

        for (int i = 0; i < str.Length; i++)
        {
            font.GetCharacterInfo(str[i], out CharacterInfo characterInfo, fontsize);
            width += characterInfo.advance;
        }

        //默认是显示2行的
        width = width / 2;

        var txtSize = text.rectTransform.sizeDelta;

        if (txtSize.x < width)
        {
            txtSize.x = width;
            text.rectTransform.sizeDelta = txtSize;

            var dialogSize = dialogBg.rectTransform.sizeDelta;
            dialogSize.x = width + dialogAdd;
            dialogBg.rectTransform.sizeDelta = dialogSize;
        }
        text.text = str;
    }
        public ActionOptionsMenu(ClickUI clickUI)
        {
            _clickUI = clickUI;
            var ctx = new Buttons.MenuContext {
                X = _menuX, Y = _menuY, Width = _menuWidth, FirstButtonYOffset = 30
            };

            var menu = new UiImage
            {
                Transform = new Transform2(new Rectangle(_menuX, _menuY, _menuWidth, _menuHeight)),
                Image     = "UI/menu-tall-panel.png"
            };

            _buttons = new List <TextButton>
            {
                Buttons.Text(ctx, 0, "Hide", () => Select(ActionType.Hide), () => _options.ContainsKey(ActionType.Hide)),
                Buttons.Text(ctx, 1, "Shoot", () => Select(ActionType.Shoot), () => _options.ContainsKey(ActionType.Shoot)),
                Buttons.Text(ctx, 2, "Overwatch", () => Select(ActionType.Overwatch), () => _options.ContainsKey(ActionType.Overwatch)),
                Buttons.Text(ctx, 3, "Pass", () => Select(ActionType.Pass), () => _options.ContainsKey(ActionType.Pass))
            };

            _visuals.Add(menu);
            _buttons.ForEach(x =>
            {
                _visuals.Add(x);
                _branch.Add(x);
            });

            Event.Subscribe <ActionOptionsAvailable>(UpdateOptions, this);
            Event.Subscribe <ActionSelected>(e => HideDisplay(), this);
            Event.Subscribe <ActionCancelled>(x => PresentOptions(), this);
            Event.Subscribe <ActionConfirmed>(x => _options.Clear(), this);
            Event.Subscribe <GameOver>(e => HideDisplay(), this);
        }
Example #5
0
        private UiRegion[] GetAllImages()
        {
            uiNode.clippingRegion = null;
            UiImage UIObject = uiNode.Screenshot();

            return(UIObject.FindAll(image, GetAccuracy()).Select(x => UiFactory.Instance.Cast <UiRegion>(x)).ToArray());
        }
Example #6
0
 public static void SetSprite(this UiImage image, EImagePath path, string spriteName, bool nativeSize = false)
 {
     if (string.IsNullOrEmpty(spriteName))
     {
         //Debug.LogError("XUI_Image SetSprite 不要为空! path:" + path + " spriteName:" + spriteName);
         image.Sprite = null;
         image.SetActiveByCanvasGroup(false);
     }
     else
     {
         var bSame = image.Sprite != null && spriteName == image.Sprite.name;
         if (!bSame)
         {
             SpriteAtlasMgr.LoadSprite(path.ToString(), atlas =>
             {
                 image.Sprite = atlas.GetSprite(spriteName);
                 if (nativeSize)
                 {
                     image.SetNativeSize();
                 }
                 image.SetActiveByCanvasGroup(true);
             });
         }
     }
 }
Example #7
0
        public InGameMenu(ClickUI clickUi)
        {
            _clickUI = clickUi;
            var ctx = new Buttons.MenuContext {
                X = _menuX, Y = _menuY, Width = _menuWidth, FirstButtonYOffset = 50
            };

            var menu = new UiImage
            {
                Transform = new Transform2(new Rectangle(_menuX, _menuY, _menuWidth, _menuHeight)),
                Image     = "UI/menu-wide-panel.png"
            };

            var mainMenuButton  = Buttons.Text(ctx, 4, "Return to Main Menu", () => Scene.NavigateTo("MainMenu"), () => true);
            var characterStatus = Buttons.Text(ctx, 3, "Character Status", () => Event.Publish(new DisplayCharacterStatusRequested(GameWorld.CurrentCharacter)), () => true);

            _visuals.Add(new ColoredRectangle
            {
                Color     = UiColors.InGameMenu_FullScreenRectangle,
                Transform = new Transform2(new Size2(1920, 1080))
            });
            _visuals.Add(menu);
            _visuals.Add(mainMenuButton);
            _visuals.Add(characterStatus);
            _interceptLayer.Add(new ScreenClickable(HideDisplay));
            _branch.Add(mainMenuButton);
            _branch.Add(characterStatus);
            Input.On(Control.Menu, ToggleMenu);
            Event.Subscribe(EventSubscription.Create <MenuRequested>(x => PresentOptions(), this));
            Event.Subscribe(EventSubscription.Create <SubviewRequested>(x => HideDisplay(), this));
            Event.Subscribe(EventSubscription.Create <SubviewDismissed>(x => PresentOptions(), this));
        }
Example #8
0
        public MultiplayerScreen() : base()
        {
            background = new UiImage(this, Point.Zero, Point.Zero, "textures/ui/ui_background");
            AddComponent(background);

            serverIP = new UiTextbox(this, Point.Zero, new Point(264, 20), "multiplayer.add.ip");
            serverIP.maxCharacters  = 256;
            serverIP.isLanguageText = true;
            AddComponent(serverIP);

            serverPort = new UiTextbox(this, Point.Zero, new Point(164, 20), "multiplayer.server.port");
            serverPort.maxCharacters  = 5;
            serverPort.isLanguageText = true;
            AddComponent(serverPort);

            cancelBtn = new UiButton(this, "multiplayer.add.cancel", Point.Zero, new Point(164, 20));
            AddComponent(cancelBtn);
            cancelBtn.OnClicked += OnCancelClicked;

            joinBtn = new UiButton(this, "multiplayer.add.join", Point.Zero, new Point(164, 20));
            AddComponent(joinBtn);
            joinBtn.OnClicked += OnJoinClicked;

            serverJoinHeader = new UiLangText(this, Point.Zero, "multiplayer.add.title");
            AddComponent(serverJoinHeader);

            visible = false;
            Reset();
        }
 public CurrentCharacterView(Point position)
 {
     _visuals.Add(new UiImage
     {
         Image     = "UI/weapon-panel.png", Tint = 180.Alpha(),
         Transform = new Transform2(new Rectangle(position.X, position.Y, 250, 114))
     });
     _face = _visuals.Added(new UiImage
     {
         Transform = new Transform2(new Rectangle(position.X + 5, position.Y + 8, 100, 100))
     });
     _name = _visuals.Added(new Label
     {
         Font      = "Fonts/12",
         Transform = new Transform2(new Rectangle(position.X + 80, position.Y + 75, 170, 30)),
         TextColor = UiColors.InGame_Text
     });
     _hp = _visuals.Added(new Label
     {
         Font      = "Fonts/12",
         Transform = new Transform2(new Rectangle(position.X + 80, position.Y + 44, 170, 30)),
         TextColor = UiColors.InGame_Text
     });
     _level = _visuals.Added(new Label
     {
         Font      = "Fonts/12",
         Transform = new Transform2(new Rectangle(position.X + 80, position.Y + 10, 170, 30)),
         TextColor = UiColors.InGame_Text
     });
 }
Example #10
0
        public override void OnInspectorGUI()
        {
            _image = target as UiImage;
            serializedObject.Update();

            serializedObject.ApplyModifiedProperties();

            base.OnInspectorGUI();
        }
Example #11
0
        public CombatantSummary(bool shouldFlip)
        {
            var width      = 300;
            var textHeight = 30;

            _background = new UiImage
            {
                Image     = "UI/menu-tall-panel.png",
                Transform = new Transform2(new Size2(350, 400))
            };
            var yOff = 25;

            _name = new Label
            {
                Font      = GuiFonts.Large,
                Transform = new Transform2(new Rectangle(25, yOff, width, 50)),
                TextColor = UiColors.InGame_Text
            };
            yOff += 60;

            _face = new UiImage
            {
                Transform = new Transform2(new Rectangle(40, yOff, 120, 120)),
                Effects   = shouldFlip ? SpriteEffects.FlipHorizontally : SpriteEffects.None
            };
            _hitChance = new Label
            {
                Font      = GuiFonts.Large,
                Transform = new Transform2(new Rectangle(130, yOff + 25, 220, 50)),
                TextColor = UiColors.InGame_Text
            };
            _bullets = new Label
            {
                Font      = GuiFonts.Large,
                Transform = new Transform2(new Rectangle(130, yOff + 60, 220, 50)),
                TextColor = UiColors.InGame_Text
            };
            yOff += 140;

            _damageBarOffset = new Vector2(50, yOff); //250, 50
            yOff            += 50;

            _weapon = new UiImage
            {
                Transform = new Transform2(new Rectangle(100, yOff, 150, 60)),
                Effects   = shouldFlip ? SpriteEffects.FlipHorizontally : SpriteEffects.None
            };
            yOff       += 60;
            _weaponName = new Label
            {
                Font      = GuiFonts.Body,
                Transform = new Transform2(new Rectangle(25, yOff, width, textHeight)),
                TextColor = UiColors.InGame_Text
            };
            yOff += textHeight;
        }
Example #12
0
 public OptionUI(string name, Vector2 offset, Action onClick, params IVisual[] visuals) : base(new Rectangle((int)offset.X, (int)offset.Y, 350, 600))
 {
     _image = new UiImage {
         Image = "UI/menu-tall-panel.png", Transform = new Transform2(Area), Tint = 127.Alpha()
     };
     _optionName = new Label {
         Text = name, Transform = new Transform2(new Vector2(25 + Area.X, 25 + Area.Y), new Size2(300, 50))
     };
     _offset  = offset;
     _onClick = onClick;
     _visuals = visuals.ToList();
 }
 public IntroCutscene(string nextScene)
 {
     _nextScene = nextScene;
     _chatBox   = new ChatBox(_texts[_index++], 0.7.VW(), GuiFonts.BodySpriteFont, 40, 40)
     {
         Position = new Vector2(0.15.VW(), 0.34.VH())
     };
     _bg = new UiImage
     {
         Image     = "UI/intro-bg",
         Transform = new Transform2(new Size2(1.0.VW(), 1.0.VH())),
         Tint      = 90.Alpha()
     };
 }
Example #14
0
        static Ui()
        {
            #region definitions

            LoginForm                      = new Container(Names.LoginForm);
            RegistrationForms              = new Container(Names.RegistrationForms);
            RegistrationEmailForm          = new Container(Names.RegistrationEmailForm);
            RegistrationNumbersForm        = new Container(Names.RegistrationNumbersForm);
            RegistrationUserDataForm       = new Container(Names.RegistrationUserDataForm);
            ResourcesLineForm              = new Container(Names.ResourcesLineForm);
            GameBuildingsContainer         = new Container(Names.GameBuildingsContainer);
            ContextForm                    = new Container(Names.ContextForm);
            ContextButtonsContainer        = new Container(Names.ContextButtons);
            ContextOpaqueElementsContainer = new Container(Names.ContextOpaqueElements);

            RegistrationEmailField    = new InputField(Names.RegistrationEmailField);
            RegistrationNumbersField  = new InputField(Names.RegistrationNumbersField);
            RegistrationLoginField    = new InputField(Names.RegistrationLoginField);
            RegistrationPasswordField = new InputField(Names.RegistrationPasswordField);
            LoginEmailField           = new InputField(Names.LoginEmailField);
            LoginPasswordField        = new InputField(Names.LoginPasswordField);

            RegistrationEmailStatus    = new Status(Names.RegistrationEmailStatus);
            RegistrationNumbersStatus  = new Status(Names.RegistrationNumbersStatus);
            RegistrationUserDataStatus = new Status(Names.RegistrationUserDataStatus);
            LoginStatus = new Status(Names.LoginStatus);
            ResourcesLineConnectionStatus = new Status(Names.ResourcesLineConnectionStatus);

            Resources = new[]
            {
                new Resource(Names.ResourceGold),
                new Resource(Names.ResourceMeat),
                new Resource(Names.ResourceCorn),
                new Resource(Names.ResourceStone),
                new Resource(Names.ResourceWood),
                new Resource(Names.ResourcePeople),
                new Resource(Names.ResourceProgress),
            };

            ContextBuildingImage   = new UiImage(Names.ContextBuilding);
            ContextHolderImage     = new UiImage(Names.ContextHolder);
            ContextBackgroundImage = new UiImage(Names.ContextBackground);

            #endregion
        }
Example #15
0
 public DialogueView(List <Dialogue> dialogs)
 {
     _dialogs   = dialogs;
     _dialogBox = new UiImage
     {
         Image     = "UI/weapon-panel.png",
         Transform = new Transform2(new Rectangle(350, 200, 900, 300))
     };
     _chatBox = new ChatBox(_dialogs[_index].Message, 400, GuiFonts.BodySpriteFont, 40, 40)
     {
         Position = new Vector2(625, 245), Color = UiColors.InGame_Text
     };
     _faceImage = new UiImage {
         Image = _dialogs[_index].CharacterImage, Transform = new Transform2(new Rectangle(375, 225, 250, 250))
     };
     Input.On(Control.Start, Advance);
     Branch.Add(new ScreenClickable(Advance));
 }
        public SwitchWeaponsMenu(ClickUI clickUI)
        {
            _clickUI = clickUI;
            var ctx = new Buttons.MenuContext {
                X = _menuX, Y = _menuY, Width = _menuWidth, FirstButtonYOffset = 40
            };
            var menu = new UiImage
            {
                Transform = new Transform2(new Rectangle(_menuX, _menuY, _menuWidth, _menuHeight)),
                Image     = "UI/menu-tall-panel.png"
            };

            _switchWeaponsButton = Buttons.Text(ctx, 0, "Switch Weapons", () => GameWorld.CurrentCharacter.Gear.SwitchWeapons(), () => _show);
            _branch.Add(_switchWeaponsButton);
            _visuals.Add(menu);
            _visuals.Add(_switchWeaponsButton);
            Event.Subscribe <TurnBegun>(_ => Show(), this);
            Event.Subscribe <MovementConfirmed>(_ => Hide(), this);
        }
Example #17
0
        private VerticalFlyInAnimation CreateTitle()
        {
            var titleImage = new UiImage
            {
                Image     = "UI/title-bg.png",
                Transform = new Transform2(new Vector2(0.5f.VW() - 338, 0.5f.VH() + 500), new Size2(678, 263))
            };

            titleImage.Transform.Location = new Vector2(titleImage.Transform.Location.X, titleImage.Transform.Location.Y + 800);
            return(new VerticalFlyInAnimation(titleImage)
            {
                FromDir = VerticalDirection.Down,
                ToDir = VerticalDirection.Up,
                Drift = 200,
                DurationIn = TimeSpan.FromMilliseconds(200),
                DurationWait = TimeSpan.FromMilliseconds(3000),
                DurationOut = TimeSpan.FromMilliseconds(200)
            });
        }
Example #18
0
    protected override void Awake()
    {
        base.Awake();

#if UNITY_EDITOR
        if (transform.GetComponent <UiImage>() == null)
        {
            transform.gameObject.AddComponent <UiImage>();
        }
#endif

        var img = transform.Find(ImageName);
        _displayImage = img != null?img.GetComponent <UiImage>() : transform.GetComponent <UiImage>();

        if (Application.isPlaying && isDebug && !Debug.isDebugBuild)
        {
            SetActiveByCanvasGroup(false);
        }
    }
Example #19
0
        private void SelectImage_Click(object sender, EventArgs e)
        {
            try
            {
                WindowState = FormWindowState.Minimized;
                System.Threading.Thread.Sleep(200);

                image = UiFactory.Instance.NewUiImage();
                uiNode.FromScreenRegion(image.SelectInteractive());

                SelectorTextBox.Text = uiNode.GetSelector(true);
                //show image on form
                Bitmap pic = System.Drawing.Image.FromHbitmap((IntPtr)image.hBitmap);
                picture.Image   = (Image)pic;
                picture.Visible = true;
                WindowState     = FormWindowState.Normal;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #20
0
        public PauseScreen()
        {
            //Darken overlay
            darken          = new UiImage(this, 0, 0, int.MaxValue, int.MaxValue, new Color(0, 0, 0, 123));
            darken.location = Point.Zero;
            AddComponent(darken);

            PausedText = new UiLangText(this, 0, 0, "pause.title", Color.White);
            AddComponent(PausedText);

            Resume = new UiButton(this, "pause.resume", new Point(0, 0), new Point(164, 20));
            AddComponent(Resume);
            Resume.OnClicked += OnResumeClick;

            Options = new UiButton(this, "pause.options", new Point(0, 0), new Point(164, 20));
            AddComponent(Options);
            Options.OnClicked += OnOptionsClick;

            MainMenu = new UiButton(this, "pause.mainmenu", new Point(0, 0), new Point(164, 20));
            AddComponent(MainMenu);
            MainMenu.OnClicked += OnMainMenuClick;
        }
        public CharacterStatusView(Point position)
        {
            var visuals = new List <IVisual>();

            visuals.Add(new UiImage
            {
                Image     = "UI/menu-tall-panel.png", Tint = 220.Alpha(),
                Transform = new Transform2(new Rectangle(position.X, position.Y, _viewWidth, _viewHeight))
            });

            _face = visuals.Added(new UiImage {
                Transform = new Transform2(new Rectangle(position.X + 50, position.Y + 60, 200, 200))
            });
            _name = visuals.Added(new Label
            {
                Font      = GuiFonts.Large,
                Transform = new Transform2(new Rectangle(position.X + 20, position.Y + 0.02.VH(), _viewWidth, 50)),
                TextColor = UiColors.InGame_Text
            });
            _level = visuals.Added(new Label
            {
                Font      = GuiFonts.Large,
                Transform = new Transform2(new Rectangle(position.X + 10, position.Y + 0.02.VH() + 240, _viewWidth / 2, 50)),
                TextColor = UiColors.InGame_Text
            });

            var index = -1;

            _maxHp      = visuals.Added(StatLabel(position, ++index));
            _movement   = visuals.Added(StatLabel(position, ++index));
            _accuracy   = visuals.Added(StatLabel(position, ++index));
            _guts       = visuals.Added(StatLabel(position, ++index));
            _agility    = visuals.Added(StatLabel(position, ++index));
            _perception = visuals.Added(StatLabel(position, ++index));

            _visuals = visuals;
            Event.Subscribe <DisplayCharacterStatusRequested>(DisplayCharacter, this);
        }
Example #22
0
        private void SelectImage_Click(object sender, EventArgs e)
        {
            try
            {
                WindowState = FormWindowState.Minimized;
                System.Threading.Thread.Sleep(200);

                image = UiFactory.Instance.NewUiImage();
                uiNode.FromScreenRegion(image.SelectInteractive());

                SelectorTextBox.Text = uiNode.GetSelector(true);
                //show image on form
                Bitmap pic = System.Drawing.Image.FromHbitmap((IntPtr)image.hBitmap);
                picture.Image = (Image)pic;
                picture.Visible = true;
                WindowState = FormWindowState.Normal;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public override void Init()
 {
     Event.Subscribe <SelectionMade>(s => _queuedSelections.Enqueue(s), this);
     _mySelection = new UiImage {
         Image = "none", Transform = new Transform2(new Vector2(100, 100), new Size2(200, 400)), IsActive = () => _phase == RockPaperScissorsPhase.Resolving
     };
     _opponentSelection = new UiImage {
         Image = "none", Transform = new Transform2(new Vector2(500, 100), new Size2(200, 400)), IsActive = () => _phase == RockPaperScissorsPhase.Resolving
     };
     _winnerLabel = new Label {
         Text = "", IsVisible = () => _phase.Equals(RockPaperScissorsPhase.Resolving)
     };
     Add(new ExpandingImageButton("rock", "rock", "rock", new Transform2(new Vector2(100, 100), new Size2(200, 400)), new Size2(10, 10), () => Select(RPSOption.Rock), () => _phase.Equals(RockPaperScissorsPhase.Selecting)));
     Add(new ExpandingImageButton("paper", "paper", "paper", new Transform2(new Vector2(350, 100), new Size2(200, 400)), new Size2(10, 10), () => Select(RPSOption.Paper), () => _phase.Equals(RockPaperScissorsPhase.Selecting)));
     Add(new ExpandingImageButton("scissors", "scissors", "scissors", new Transform2(new Vector2(600, 100), new Size2(200, 400)), new Size2(10, 10), () => Select(RPSOption.Scissors), () => _phase.Equals(RockPaperScissorsPhase.Selecting)));
     Add(new Label {
         Text = "Waiting On Opponent", IsVisible = () => _phase.Equals(RockPaperScissorsPhase.Waiting)
     });
     Add(Buttons.Text("New Game", new Point(250, 10), () => _phase = RockPaperScissorsPhase.Selecting, () => _phase.Equals(RockPaperScissorsPhase.Resolving)));
     Add(_winnerLabel);
     Add(_mySelection);
     Add(_opponentSelection);
     Add(new ActionAutomaton(ProcessSelections));
 }
Example #24
0
 public static bool GetActiveState(this UiImage c)
 {
     return(c.CanvasGroup.alpha > 0);
 }
Example #25
0
		private void InitUiPathObjects()
		{
			uiNode = UiFactory.Instance.NewUiNode();
			uiImage = UiFactory.Instance.NewUiImage();
			uiSystem = UiFactory.Instance.NewUiSystem();
		}
Example #26
0
    private void SetButtonUseDisplayImage(bool b)
    {
#if UNITY_EDITOR
        //如果是use tween, 需要区分点击区域与事件区域
        if (!enabled)
        {
            return;
        }
        var sourceImage = GetComponent <UiImage>();
        if (sourceImage == null)
        {
            return;
        }
        if (!sourceImage.enabled)
        {
            return;
        }

        Transform img = transform.Find(ImageName);
        if (b)
        {
            UiImage displayImage = null;
            if (img == null)
            {
                GameObject imageObj = new GameObject();
                imageObj.layer = Layers.Ui;
                imageObj.name  = ImageName;
                imageObj.transform.SetParent(transform);
                displayImage = imageObj.AddComponent <UiImage>();
            }
            else
            {
                img.gameObject.layer = Layers.Ui;
                if (img.gameObject.activeSelf == false)
                {
                    img.gameObject.SetActiveSafe(true);
                    displayImage = img.GetComponent <UiImage>();
                }
            }

            if (displayImage != null)
            {
                displayImage.rectTransform.sizeDelta        = sourceImage.rectTransform.sizeDelta;
                displayImage.RectTransform.anchoredPosition = Vector2.zero;
                displayImage.color         = sourceImage.color;
                displayImage.material      = sourceImage.material;
                displayImage.type          = sourceImage.type;
                displayImage.fillAmount    = sourceImage.fillAmount;
                displayImage.fillCenter    = sourceImage.fillCenter;
                displayImage.sprite        = sourceImage.sprite;
                displayImage.raycastTarget = false;
                displayImage.transform.SetAsFirstSibling();
                sourceImage.Alpha = 0;

                var objs = transform.GetComponentsInChildren <Transform>(true);
                for (int i = 0; i < objs.Length; i++)
                {
                    if (objs[i].parent != transform)
                    {
                        continue;
                    }
                    if (objs[i] == transform)
                    {
                        continue;
                    }
                    if (objs[i] == displayImage.transform)
                    {
                        continue;
                    }
                    objs[i].SetParent(displayImage.transform);
                }
            }
        }
        else
        {
            if (img != null)
            {
                var objs = img.transform.GetComponentsInChildren <Transform>(true);
                for (int i = 0; i < objs.Length; i++)
                {
                    if (objs[i].parent != img.transform)
                    {
                        continue;
                    }
                    if (objs[i] == transform)
                    {
                        continue;
                    }
                    objs[i].SetParent(transform);
                }
                img.gameObject.SetActiveSafe(false);
            }
            sourceImage.Alpha = 1;
        }
#endif
    }
Example #27
0
    public void RefreshImage()
    {
        if (ButtonType == EControllerBtns.None)
        {
            gameObject.SetActiveSafe(false);
            return;
        }
        if (_activeState)
        {
            gameObject.SetActiveSafe(true);
        }


        var style = InputDeviceStyle.Unknown;

        if (InputManager.Devices.Count > 0)
        {
            style = InputManager.Devices[InputManager.Devices.Count - 1].DeviceStyle;
        }

        _image     = GetComponentInChildren <UiImage>();
        _text      = GetComponentInChildren <UiText>();
        _text.text = "";
        switch (style)
        {
        case InputDeviceStyle.Unknown:
            //Pc显示方案
            var mouse = ControllerUtility.GetMouseType(ButtonType);
            if (mouse != Mouse.None)
            {
                var mouseImg = ControllerUtility.GetImageMouse(mouse);
                _image.SetSprite(EImagePath.Public, mouseImg);
            }
            else
            {
                var    key  = ControllerUtility.GetKeyBoardType(ButtonType);
                string text = "";
                var    img  = ControllerUtility.GetImageKeyboard(key, out text);
                _image.SetSprite(EImagePath.Public, img);
                _text.text = text;
            }
            break;

        case InputDeviceStyle.Ouya:
        case InputDeviceStyle.AppleMFi:
        case InputDeviceStyle.AmazonFireTV:
        case InputDeviceStyle.NVIDIAShield:
        case InputDeviceStyle.Steam:
        case InputDeviceStyle.Xbox360:
        case InputDeviceStyle.XboxOne:
        case InputDeviceStyle.Vive:
        case InputDeviceStyle.Oculus:
            //xbox 显示方案
            var imgStr = ControllerUtility.GetImageXBox(ControllerUtility.GetControlType(ButtonType));
            _image.SetSprite(EImagePath.Public, imgStr);
            break;

        case InputDeviceStyle.PlayStation2:
        case InputDeviceStyle.PlayStation3:
        case InputDeviceStyle.PlayStation4:
        case InputDeviceStyle.PlayStationVita:
        case InputDeviceStyle.PlayStationMove:
            //ps 显示方案
            var psImageStr = ControllerUtility.GetImagePlayStation(ControllerUtility.GetControlType(ButtonType));
            _image.SetSprite(EImagePath.Public, psImageStr);
            break;

        case InputDeviceStyle.NintendoNES:
        case InputDeviceStyle.NintendoSNES:
        case InputDeviceStyle.Nintendo64:
        case InputDeviceStyle.NintendoGameCube:
        case InputDeviceStyle.NintendoWii:
        case InputDeviceStyle.NintendoWiiU:
        case InputDeviceStyle.NintendoSwitch:
            //switch 显示方案
            var nintendoImageStr = ControllerUtility.GetImageNintendo(ControllerUtility.GetControlType(ButtonType));
            _image.SetSprite(EImagePath.Public, nintendoImageStr);
            break;
        }
    }
Example #28
0
 private void InitUiPathObjects()
 {
     uiNode   = UiFactory.Instance.NewUiNode();
     uiImage  = UiFactory.Instance.NewUiImage();
     uiSystem = UiFactory.Instance.NewUiSystem();
 }