Esempio n. 1
0
        public Texture2D ToTexture()
        {
            var Result = GUIExtensions.CreateEmptyTexture();

            Result.LoadImage(Data);
            return(Result);
        }
Esempio n. 2
0
    private void Start()
    {
        killButtonManager = UnityEngine.Object.Instantiate(hudManager.KillButton, hudManager.transform);
        startColorButton  = killButtonManager.renderer.color;
        startColorText    = killButtonManager.TimerText.Color;
        killButtonManager.gameObject.SetActive(true);
        killButtonManager.renderer.enabled = true;
        Texture2D tex      = GUIExtensions.CreateEmptyTexture();
        Assembly  assembly = Assembly.GetExecutingAssembly();
        Stream    myStream = assembly.GetManifestResourceStream(ResourceName);

        byte[] buttonTexture = Reactor.Extensions.Extensions.ReadFully(myStream);
        ImageConversion.LoadImage(tex, buttonTexture, false);
        killButtonManager.renderer.sprite = GUIExtensions.CreateSprite(tex);
        PassiveButton button = killButtonManager.GetComponent <PassiveButton>();

        button.OnClick.RemoveAllListeners();
        button.OnClick.AddListener((UnityEngine.Events.UnityAction)listener);
        void listener()
        {
            if (Timer < 0f && canUse)
            {
                killButtonManager.renderer.color = new Color(1f, 1f, 1f, 0.3f);
                if (hasEffectDuration)
                {
                    isEffectActive = true;
                    Timer          = EffectDuration;
                    killButtonManager.TimerText.Color = new Color(0, 255, 0);
                }
                OnClick();
            }
        }
    }
        /// <summary>
        /// Call in HudManager.Start
        /// </summary>
        private CooldownButton(Assembly asm, Action onClick, float cooldown, string embeddedResourcePath /*, float pixelsPerUnit*/, Vector2 positionOffset, ButtonCategory category, HudManager hudManager, bool hasEffectDuration, float effectDuration, Action onEffectEnd)
        {
            OnEffectEnd    = onEffectEnd;
            PositionOffset = positionOffset;
            EffectDuration = effectDuration;
            Category       = category;
            //PixelsPerUnit = pixelsPerUnit;
            MaxTimer = cooldown;
            Timer    = MaxTimer;

            Buttons.Add(this);

            string embeddedResourceFullPath = asm.GetManifestResourceNames().FirstOrDefault(resourceName => resourceName.EndsWith(embeddedResourcePath, StringComparison.Ordinal));

            if (string.IsNullOrEmpty(embeddedResourceFullPath))
            {
                throw new ArgumentNullException(nameof(embeddedResourcePath), $"The embedded resource \"{embeddedResourcePath}\" was not found in assembly \"{asm.GetName().Name}\".");
            }

            Stream resourceStream = asm.GetManifestResourceStream(embeddedResourceFullPath);

            KillButtonManager = Object.Instantiate(hudManager.KillButton, hudManager.transform);

            //StartColorButton = killButtonManager.renderer.color;
            StartColorText = KillButtonManager.TimerText.Color;

            KillButtonManager.gameObject.SetActive(true);
            KillButtonManager.renderer.enabled = true;

            Texture2D tex = GUIExtensions.CreateEmptyTexture();

            byte[] buttonTexture = Reactor.Extensions.Extensions.ReadFully(resourceStream);
            ImageConversion.LoadImage(tex, buttonTexture, false);
            KillButtonManager.renderer.sprite = GUIExtensions.CreateSprite(tex);

            PassiveButton button = KillButtonManager.GetComponent <PassiveButton>();

            button.OnClick.RemoveAllListeners();
            button.OnClick.AddListener(new Action(() =>
            {
                if (Timer < 0f && CanUse)
                {
                    KillButtonManager.renderer.color = new Color(1f, 1f, 1f, 0.3f);

                    if (hasEffectDuration)
                    {
                        IsEffectActive = true;

                        Timer = EffectDuration;

                        KillButtonManager.TimerText.Color = new Color(0, 255, 0);
                    }

                    onClick();
                }
            }));
        }
Esempio n. 4
0
 public static Sprite loadSpriteFromResources(string path, float pixelsPerUnit)
 {
     try {
         Texture2D texture     = GUIExtensions.CreateEmptyTexture();
         Assembly  assembly    = Assembly.GetExecutingAssembly();
         Stream    stream      = assembly.GetManifestResourceStream(path);
         byte[]    byteTexture = Reactor.Extensions.Extensions.ReadFully(stream);
         ImageConversion.LoadImage(texture, byteTexture, false);
         return(Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), pixelsPerUnit));
     } catch {
         System.Console.WriteLine("Error loading sprite from path: " + path);
     }
     return(null);
 }
Esempio n. 5
0
        private static Sprite CreateSprite(string name)
        {
            var assembly    = Assembly.GetExecutingAssembly();
            var tex         = GUIExtensions.CreateEmptyTexture();
            var imageStream = assembly.GetManifestResourceStream(name);
            var img         = imageStream.ReadFully();

            tex.LoadImage(img);
            tex.DontDestroy();
            var sprite = tex.CreateSprite();

            sprite.DontDestroy();
            return(sprite);
        }
Esempio n. 6
0
        public static Sprite CreateSprite(string name, bool hat = false)
        {
            var pixelsPerUnit = hat ? 225f : 100f;
            var pivot         = hat ? new Vector2(0.5f, 0.8f) : new Vector2(0.5f, 0.5f);

            var assembly    = Assembly.GetExecutingAssembly();
            var tex         = GUIExtensions.CreateEmptyTexture();
            var imageStream = assembly.GetManifestResourceStream(name);
            var img         = imageStream.ReadFully();

            LoadImage(tex, img, true);
            tex.DontDestroy();
            var sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, (float)tex.width, (float)tex.height), pivot, pixelsPerUnit);

            sprite.DontDestroy();
            return(sprite);
        }
        /// <summary>
        /// Creates an instance of <see cref="KillButtonManager"/> when one does not exist.
        /// </summary>
        private void CreateButton()
        {
            if (KillButtonManager != null || !HudManager.Instance?.KillButton || ImageData == null)
            {
                return;
            }

            KillButtonManager = Object.Instantiate(HudManager.Instance.KillButton, HudManager.Instance.transform);

            KillButtonManager.gameObject.SetActive(HudVisible && Visible);
            KillButtonManager.renderer.enabled = HudVisible && Visible;

            Texture2D tex = GUIExtensions.CreateEmptyTexture();

            ImageConversion.LoadImage(tex, ImageData, false);

            KillButtonManager.renderer.sprite = ButtonSprite = tex.CreateSprite();

            PassiveButton button = KillButtonManager.GetComponent <PassiveButton>();

            button.OnClick.RemoveAllListeners();
            button.OnClick.AddListener(new Action(() =>
            {
                if (!IsUsable)
                {
                    return;
                }

                CancelEventArgs args = new CancelEventArgs();
                OnClick?.SafeInvoke(this, args, nameof(OnClick));

                if (args.Cancel)
                {
                    return;              // Click was cancelled.
                }
                if (HasEffect)
                {
                    StartEffect();

                    return;
                }

                ApplyCooldown();
            }));
        }
Esempio n. 8
0
        private static Sprite LoadSpriteFromResources(string path, float pixelsPerUnit = 100F)
        {
            path = "CrewOfSalem.Resources." + path;
            try
            {
                Texture2D texture2D   = GUIExtensions.CreateEmptyTexture();
                var       assembly    = Assembly.GetExecutingAssembly();
                Stream    stream      = assembly.GetManifestResourceStream(path);
                byte[]    byteTexture = stream.ReadFully();
                ImageConversion.LoadImage(texture2D, byteTexture, false);
                return(Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height),
                                     new Vector2(0.5F, 0.5F), pixelsPerUnit).DontDestroy());
            }
            catch
            {
                ConsoleTools.Error("Failed loading sprites from path: " + path);
            }

            return(null);
        }