Skip to content

Commit

Permalink
Maintenance update: Update Unity and SteamVR
Browse files Browse the repository at this point in the history
Does this even still work in VR?
  • Loading branch information
0x0ade committed May 18, 2017
1 parent e5771fd commit 917be82
Show file tree
Hide file tree
Showing 97 changed files with 508 additions and 223 deletions.
20 changes: 11 additions & 9 deletions Assets/FezUnity/FezManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public FezManager() {
public Material SkyLayerFullbrightMaterial;

public Material WaterMaterial;

public Mesh QuadMesh;
public Mesh WaterMesh;
public Mesh BackgroundPlaneMesh;
public Mesh SkyLayerMesh;

public Transform Player;

public Font SpeechFont;

public Transform Player;

public Light Sun;
public float Time = 12f * 3600f;
Expand Down Expand Up @@ -158,7 +160,7 @@ void Start() {
15, 14, 13
}
};
SkyLayerMesh.Optimize();
;
SkyLayerMesh.RecalculateNormals();
}

Expand All @@ -182,14 +184,14 @@ void Start() {
return;
}

var joystickNames = Input.GetJoystickNames();
for (int i = 0; i < Mathf.Min(8, joystickNames.Length); i++)
if (joystickNames[i].IndexOf("xbox", System.StringComparison.InvariantCultureIgnoreCase) != -1)
{
string[] joystickNames = Input.GetJoystickNames();
for (int i = 0; i < Mathf.Min(8, joystickNames.Length); i++) {
if (joystickNames[i].IndexOf("xbox", System.StringComparison.InvariantCultureIgnoreCase) != -1) {
ChosenJoystickTriggerAxis = string.Format("Time_J{0}", i + 1);
Debug.Log(string.Format("Chose joystick #{0} for the time axis", i + 1));
break;
}
}
}

void Awake() {
Expand Down Expand Up @@ -421,7 +423,7 @@ public Mesh GenMesh<T>(ShaderInstancedIndexedPrimitives<VertexPositionNormalText
mesh.uv = uv;

mesh.RecalculateNormals();
mesh.Optimize();
;

return mesh;
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/FezUnity/FezManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Assets/FezUnity/FezText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//Taken from FEZMod
using System;
using System.Collections.Generic;
using FmbLib;
using System.IO;

public class TextType {
public string Name;
public Dictionary<string, Dictionary<string, string>> Map;
public Dictionary<string, string> Fallback;

public string this[string key] {
get {
return Get(key);
}
}

public TextType()
: this("UNKNOWN") {
}

public TextType(string name) {
Name = name;
}

public void Load() {
try {
using (BinaryReader reader = FezManager.Instance.ReadFromPack("Texts/" + Name) ?? FezManager.Instance.ReadFromPack("Resources/" + Name + "text")) {
Map = FmbUtil.ReadObject(reader) as Dictionary<string, Dictionary<string, string>>;
}
Fallback = Map[string.Empty];
} catch (Exception e) {
UnityEngine.Debug.Log(e);
//loading failed - fall back to empty maps
Map = new Dictionary<string, Dictionary<string, string>>();
Fallback = Map[string.Empty] = new Dictionary<string, string>();
}
}

public string Get(string tag) {
if (tag == null) {
return "[error:nulltag]";
}

Dictionary<string, string> map;
if (!Map.TryGetValue(System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName, out map)) {
map = Fallback;
}

string str;
if ((!map.TryGetValue(tag, out str)) && (!Fallback.TryGetValue(tag, out str))) {
return "[" + Name + ":" + tag + "]";
}
return str;
}
}

public static class FezText {

public readonly static TextType Game = new TextType("game");
public readonly static TextType Static = new TextType("static");

static FezText() {
Game.Load();
Static.Load();
}

}
12 changes: 12 additions & 0 deletions Assets/FezUnity/FezText.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Assets/FezUnity/FezUnityAnimatedTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ public class FezUnityAnimatedTexture : MonoBehaviour, IFillable<AnimatedTexture>
public Material Material;

public float Speed = 1f;

protected bool _flipH = false;
public bool FlipH {
get {
return _flipH;
}
set {
if (_flipH != value) {
Material.mainTextureScale = new Vector2(
-Material.mainTextureScale.x,
Material.mainTextureScale.y
);
}
_flipH = value;
}
}

public void Fill(AnimatedTexture animation) {
Animation = animation;
Expand All @@ -36,6 +52,12 @@ public void Update() {
offset.X / (float) Material.mainTexture.width,
offset.Y / (float) Material.mainTexture.height
);
if (FlipH) {
Material.mainTextureOffset = new Vector2(
Material.mainTextureOffset.x - Material.mainTextureScale.x,
Material.mainTextureOffset.y
);
}

}

Expand Down
4 changes: 2 additions & 2 deletions Assets/FezUnity/FezUnityAnimatedTexture.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/FezUnity/FezUnityBackgroundPlane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Fill(BackgroundPlane plane) {

public void Update() {
if (Plane.Billboard) {
transform.LookAt(Camera.main.transform.position);
transform.LookAt(transform.position + (transform.position - Camera.main.transform.position));
}

}
Expand Down
105 changes: 90 additions & 15 deletions Assets/FezUnity/FezUnityNpcInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
using FezEngine.Tools;
using FmbLib;
using System.IO;
using UnityEngine.UI;

public class FezUnityNpcInstance : MonoBehaviour, IFillable<NpcInstance> {

public static Action<FezUnityNpcInstance> DefaultTalk = _Talk;
public static Func<FezUnityNpcInstance, bool> DefaultStopTalking = _StopTalking;

[HideInInspector]
public NpcInstance NPC;

public GameObject SpeechBubble;

public Dictionary<NpcAction, FezUnityAnimatedTexture> Animations = new Dictionary<NpcAction, FezUnityAnimatedTexture>();

public bool LookingRight = true;
Expand Down Expand Up @@ -48,6 +54,7 @@ public NpcAction CurrentAction {
if (value != NpcAction.None) {
FezUnityAnimatedTexture animation = Animations[value];
animation.Animation.Timing.Restart();
CurrentAnimation = animation;
CurrentTiming = animation.Animation.Timing;
animation.enabled = true;
meshRenderer.sharedMaterial = animation.Material;
Expand All @@ -64,6 +71,7 @@ public NpcAction CurrentAction {
}
}

public FezUnityAnimatedTexture CurrentAnimation { get; protected set; }
public AnimationTiming CurrentTiming { get; protected set; }

public void Fill(NpcInstance npc) {
Expand Down Expand Up @@ -118,9 +126,10 @@ public void Fill(NpcInstance npc) {
Animations[action] = animation;
}

BinaryReader metadataReader = FezManager.Instance.ReadFromPack("character animations/" + NPC.Name + "/metadata");
if (metadataReader != null) {
npc.FillMetadata(FmbUtil.ReadObject(metadataReader) as NpcMetadata);
using (BinaryReader metadataReader = FezManager.Instance.ReadFromPack("character animations/" + NPC.Name + "/metadata")) {
if (metadataReader != null) {
npc.FillMetadata(FmbUtil.ReadObject(metadataReader) as NpcMetadata);
}
}

CanIdle = Animations.ContainsKey(NpcAction.Idle);
Expand All @@ -131,6 +140,71 @@ public void Fill(NpcInstance npc) {
CanTurn = Animations.ContainsKey(NpcAction.Turn);

CurrentAction = CanIdle ? NpcAction.Idle : NpcAction.Walk;

if (!CanTalk) {
return;
}

SpeechBubble = new GameObject("Speech Bubble");
SpeechBubble.transform.parent = transform;
SpeechBubble.transform.localPosition = Vector3.up * transform.localScale.y * 0.5f;
SpeechBubble.transform.localScale = new Vector3(
0.01f / transform.localScale.x,
0.01f / transform.localScale.y,
1f
);

Canvas bubbleCanvas = SpeechBubble.AddComponent<Canvas>();
RectTransform bubbleTransform = SpeechBubble.GetComponent<RectTransform>();
bubbleTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200f);
bubbleTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100f);

AddSpeechCorner(0f, 0f, "speechbubblese");
AddSpeechCorner(0f, 1f, "speechbubblese");
AddSpeechCorner(1f, 0f, "speechbubblese");
AddSpeechCorner(1f, 1f, "speechbubblese");

GameObject textObj = new GameObject("Text");
textObj.transform.parent = SpeechBubble.transform;
textObj.transform.localPosition = Vector3.zero;
textObj.transform.localScale = new Vector3(0.25f, 0.25f, 1f);

Text text = textObj.AddComponent<Text>();
text.font = FezManager.Instance.SpeechFont;
text.fontSize = 50;
text.alignment = TextAnchor.MiddleCenter;
text.verticalOverflow = VerticalWrapMode.Overflow;
text.text = FezText.Game[NPC.Speech[0].Text];

RectTransform textTransform = textObj.GetComponent<RectTransform>();
textTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200f);
textTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 243f);
}

protected void AddSpeechCorner(float x, float y, string imgName) {
Texture2D tex = FezManager.Instance.GetTexture2D("other textures/speech_bubble/" + imgName);
tex.filterMode = FilterMode.Point;
tex.wrapMode = TextureWrapMode.Clamp;

GameObject imgObj = new GameObject(imgName);
imgObj.transform.parent = SpeechBubble.transform;
imgObj.transform.localPosition = Vector3.zero;
imgObj.transform.localScale = Vector3.one;

Image img = imgObj.AddComponent<Image>();
// Cache sprites?
img.sprite = Sprite.Create(
tex,
new Rect((1f - x) * tex.width, y * tex.height, (2f * (x - 0.5f)) * tex.width, (2f * (y - 0.5f)) * -tex.height),
new Vector2(tex.width * 0.5f, tex.height * 0.5f),
16f
);
img.sprite.name = imgName;

RectTransform imgTransform = imgObj.GetComponent<RectTransform>();
imgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 20f);
imgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 20f);
imgTransform.pivot = new Vector2(1f - x, y);
}

public void Update() {
Expand All @@ -148,27 +222,27 @@ public void Update() {
}

if (CurrentAction != NpcAction.Talk) {
if (CanTalk && (NPC.Speech.Count > 0 || NPC.CustomSpeechLine != null)) {
Talk();
if (Talk != null && CanTalk && (NPC.Speech.Count > 0 || NPC.CustomSpeechLine != null)) {
Talk(this);
}
if (CurrentAction == NpcAction.Walk) {
Walk();
}
} else if (StopTalking() && CurrentAction != NpcAction.TakeOff) {
} else if (StopTalking != null && StopTalking(this) && CurrentAction != NpcAction.TakeOff) {
ToggleAction();
}

transform.LookAt(transform.position + (transform.position - Camera.main.transform.position));
Vector3 ssPosition = Camera.main.WorldToScreenPoint(transform.position);
bool lookingRight;
if (FezHelper.AlmostEqual(ssPositionOld.x, ssPosition.x)) {
lookingRight = LookingRight;
} else {
lookingRight = ssPositionOld.x < ssPosition.x;
}
if (lookingRight) {
transform.LookAt(transform.position + (transform.position - Camera.main.transform.position));
} else {
transform.LookAt(Camera.main.transform.position);
if ((!lookingRight && 0f < meshRenderer.sharedMaterial.mainTextureScale.x) ||
(lookingRight && meshRenderer.sharedMaterial.mainTextureScale.x < 0f)) {
CurrentAnimation.FlipH = !lookingRight;
}
}

Expand All @@ -189,12 +263,13 @@ private void Walk() {
gameObject.FezZ();
}

private void Talk() {
// TODO
}
// Talking needs to be overriden by HoloFEZ
public Action<FezUnityNpcInstance> Talk = DefaultTalk;
public Func<FezUnityNpcInstance, bool> StopTalking = DefaultStopTalking;

private bool StopTalking() {
// TODO
private static void _Talk(FezUnityNpcInstance self) {
}
private static bool _StopTalking(FezUnityNpcInstance self) {
return false;
}

Expand Down
Loading

0 comments on commit 917be82

Please sign in to comment.