Skip to content

Commit

Permalink
Experimental Emote Support, Configurable Background Alpha
Browse files Browse the repository at this point in the history
Emote support is a little messy right now. Something about Unity's
TextMesh Quads causes a crash when running the Release version, but no
errors are being reported in the Editor. For now I'm going to release a
Development version which won't crash when it happens, but instead will
spam some errors to the Development Console which you can just Close and
ignore until the errors go away (after you receive enough messages to
clear the buffer).

Some emotes are still not being displayed properly (seems random) but
you should be able to use up to 7 unique emotes per line, with no
specific limit on the number of emotes per message or at any one time,
aside from the 7 unique emotes per line limit which Unity imposes.

I'm having difficulty pinning down the exact cause of the crash, but it
definitely has something to do with Unity's TextMesh and lots of Quads,
so I may have to work up a more elegant solution.

For now, this version works fine in the Editor and works okay in
Development Mode but some messages bug out :(.

Also in this version, I added a configurable Background Alpha Slider to
the RGB Sliders. This Alpha only controls the Background Alpha, so it is
now possible to have a nearly completely transparent background, with
fully opaque text, if desired. It seems like SteamVR prevents me from
having a fully transparent overlay, but I'll have to look into that when
I get a chance :P

I also updated to the latest Unity SteamVR Plugin files. I don't think
anything changed, but I was having issues until I reimported it for some
reason, so I went through and stripped the files we didn't need again,
and it seems to be working fine so w/e. The controller manager seems to
have changed, but GitHub isn't being really helpful with the file
comparison so I'm not sure what changed exactly.

Speaking of the controller manager, I updated the TrackedDeviceManager
so it won't spam the chat when the controllers aren't detected, it will
just notify you once.

I also made it possible for multiple instances of the Overlay program to
be running simultaneously. You can now correctly run the exe multiple
times and configure them separately such that you can have multiple
Twitch Chat's running/visible at the same time.

I really wanted to wait until Emote support was more mature, but I
haven't updated in a while and I suspect some people are getting
impatient for basic Emote support :o The Emote support is a bit
inefficient but only adds an extra 1% average CPU usage on my PC, so I
think the inefficiencies are acceptable until I can push out a more
optimized version.

I recommend sticking with a previous version unless you really want the
Emotes, because this version has a few bugs to work out.
  • Loading branch information
Hotrian committed Jul 18, 2016
1 parent 47e230a commit 816f3bf
Show file tree
Hide file tree
Showing 28 changed files with 886 additions and 347 deletions.
Binary file modified Assets/HOTK/Example Content/HOTK_TwitchDemoScene.unity
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DropdownSaveLoadController : MonoBehaviour
public MaterialColorMatchSlider RSlider;
public MaterialColorMatchSlider GSlider;
public MaterialColorMatchSlider BSlider;
public MaterialColorMatchSlider ASlider;

public InputField AlphaStartField;
public InputField AlphaEndField;
Expand Down Expand Up @@ -154,6 +155,7 @@ public void OnLoadPressed() // Load an existing save
RSlider.Slider.value = settings.BackgroundR;
GSlider.Slider.value = settings.BackgroundG;
BSlider.Slider.value = settings.BackgroundB;
ASlider.Slider.value = (settings.SaveFileVersion >= 3 ? settings.BackgroundA : 1.0f); // Save File compatability

AlphaStartField.text = settings.AlphaStart.ToString();
AlphaEndField.text = settings.AlphaEnd.ToString();
Expand Down Expand Up @@ -197,16 +199,23 @@ public void OnSavePressed()
settings.Point = OverlayToSave.AnchorPoint;
settings.Animation = OverlayToSave.AnimateOnGaze;

settings.BackgroundR = BackgroundMaterial.color.r;
settings.BackgroundG = BackgroundMaterial.color.g;
settings.BackgroundB = BackgroundMaterial.color.b;
var backgroundColor = GetMaterialTexture().GetPixel(0, 0);
settings.BackgroundR = backgroundColor.r;
settings.BackgroundG = backgroundColor.g;
settings.BackgroundB = backgroundColor.b;
settings.BackgroundA = backgroundColor.a;

settings.AlphaStart = OverlayToSave.Alpha; settings.AlphaEnd = OverlayToSave.Alpha2; settings.AlphaSpeed = OverlayToSave.AlphaSpeed;
settings.ScaleStart = OverlayToSave.Scale; settings.ScaleEnd = OverlayToSave.Scale2; settings.ScaleSpeed = OverlayToSave.ScaleSpeed;
TwitchSettingsSaver.Save();
}
}

private Texture2D GetMaterialTexture()
{
return (Texture2D)(BackgroundMaterial.mainTexture ?? (BackgroundMaterial.mainTexture = TwitchChatTester.GenerateBaseTexture()));
}

public void OnSaveNewPressed()
{
if (string.IsNullOrEmpty(SaveName.text) || TwitchSettingsSaver.SavedSettings.ContainsKey(SaveName.text)) return;
Expand Down
20 changes: 17 additions & 3 deletions Assets/HOTK/Example Content/UI Scripts/MaterialColorMatchSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Slider Slider
public void OnEnable()
{
if (Material == null) return;
var c = Material.color;
var c = GetMaterialTexture().GetPixel(0,0);
switch (Setting)
{
case ColorSetting.R:
Expand All @@ -29,15 +29,24 @@ public void OnEnable()
case ColorSetting.B:
Slider.value = c.b;
break;
case ColorSetting.A:
Slider.value = c.a;
break;
default:
throw new ArgumentOutOfRangeException();
}
}

private Texture2D GetMaterialTexture()
{
return (Texture2D) (Material.mainTexture ?? (Material.mainTexture = TwitchChatTester.GenerateBaseTexture()));
}

public void OnValueChanges()
{
if (Material == null) return;
var c = Material.color;
var tex = GetMaterialTexture();
var c = tex.GetPixel(0, 0);
switch (Setting)
{
case ColorSetting.R:
Expand All @@ -49,17 +58,22 @@ public void OnValueChanges()
case ColorSetting.B:
c.b = Slider.value;
break;
case ColorSetting.A:
c.a = Slider.value;
break;
default:
throw new ArgumentOutOfRangeException();
}

Material.color = c;
tex.SetPixel(0, 0, c);
tex.Apply();
}

public enum ColorSetting
{
R,
G,
B,
A,
}
}
5 changes: 4 additions & 1 deletion Assets/HOTK/HOTK_Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using UnityEngine;
using Valve.VR;
using Random = System.Random;

public class HOTK_Overlay : MonoBehaviour
{
Expand Down Expand Up @@ -49,8 +50,10 @@ public class HOTK_Overlay : MonoBehaviour
#endregion

#region Interal Vars

public static Random rand = new Random();
public static HOTK_Overlay HighQualityOverlay; // Only one Overlay can be HQ at a time
public static string Key { get { return "unity:" + Application.companyName + "." + Application.productName; } }
public static string Key { get { return "unity:" + Application.companyName + "." + Application.productName + "." + rand.Next(); } }
public static GameObject ZeroReference; // Used to get a reference to the world 0, 0, 0 point
public GameObject OverlayReference; // Used to get a reference for the Overlay's transform

Expand Down
6 changes: 3 additions & 3 deletions Assets/HOTK/HOTK_TrackedDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void FindControllers()
return;
}

Log("Searching for Controllers..");
if (_noControllersCount == 0) Log("Searching for Controllers..");
_leftIndex = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
CallIndexChanged(ETrackedControllerRole.LeftHand, _leftIndex);
_rightIndex = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);
Expand Down Expand Up @@ -176,7 +176,7 @@ public void FindControllers()
}
else if (_leftIndex == OpenVR.k_unTrackedDeviceIndexInvalid && _rightIndex == OpenVR.k_unTrackedDeviceIndexInvalid) // Both controllers are unassigned
{
LogWarning("SteamVR Reports No Assigned Controllers..! Searching..");
if (_noControllersCount == 0) LogWarning("SteamVR Reports No Assigned Controllers..! Searching..");
var foundUnassigned = 0;
var slots = new uint[2];
// Sort through all the devices until we find two controllers
Expand Down Expand Up @@ -237,7 +237,7 @@ public void FindControllers()
}
break;
case 0:
LogWarning("Couldn't Find Any Unassigned Controllers!");
if (_noControllersCount == 0) LogWarning("Couldn't Find Any Unassigned Controllers!");
_noControllersCount++;
if (_noControllersCount >= 10)
{
Expand Down
Binary file modified Assets/HOTK/Twitch/TwitchChatBGMat.mat
Binary file not shown.
Loading

0 comments on commit 816f3bf

Please sign in to comment.