diff --git a/Assets/Prefabs/PC.prefab b/Assets/Prefabs/PC.prefab index d3d7e6a..75276d8 100644 --- a/Assets/Prefabs/PC.prefab +++ b/Assets/Prefabs/PC.prefab @@ -191,7 +191,7 @@ Camera: m_Depth: 1 m_CullingMask: serializedVersion: 2 - m_Bits: 4294967295 + m_Bits: 4294967039 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 diff --git a/Assets/Scenes/TestMap.unity b/Assets/Scenes/TestMap.unity index eb68262..b30345b 100644 --- a/Assets/Scenes/TestMap.unity +++ b/Assets/Scenes/TestMap.unity @@ -130,7 +130,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 19192149} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 4.039651, y: -2.292325, z: -10.772432} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 769207969} @@ -503,13 +503,14 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 344272454} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 2.2207036, y: -2.900241, z: -12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 605817615} - {fileID: 1463006272} - {fileID: 1939832658} - {fileID: 375619906} + - {fileID: 1610252930} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -570,7 +571,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 375619905} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.2207036, y: 2.900241, z: 12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 344272455} @@ -920,7 +921,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 605817613} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.2207036, y: 2.900241, z: 12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 344272455} @@ -1001,7 +1002,7 @@ Camera: m_Depth: 0 m_CullingMask: serializedVersion: 2 - m_Bits: 4294967295 + m_Bits: 4294967039 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 @@ -1020,12 +1021,116 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 769207964} m_LocalRotation: {x: 0.3826837, y: -0, z: -0, w: 0.9238795} - m_LocalPosition: {x: -4.039651, y: 7.292325, z: 5.7724323} + m_LocalPosition: {x: 0, y: 5, z: -5} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 19192150} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 45.000004, y: 0, z: 0} +--- !u!1 &784099992 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 784099997} + - component: {fileID: 784099996} + - component: {fileID: 784099995} + - component: {fileID: 784099994} + - component: {fileID: 784099993} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &784099993 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 784099992} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0e0b8f69a817648969bf8ecd70b13d4d, type: 3} + m_Name: + m_EditorClassIdentifier: + TextProperties: + Text: Hello, world!\nBoo! + Background: {r: 0, g: 0, b: 0, a: 0} + FontSize: 32 + Width: 256 + Height: 256 + Mesh: {fileID: 784099994} + MaterialIndex: 0 + Emissive: 1 + Brightness: 1 +--- !u!23 &784099994 +MeshRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 784099992} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 2100000, guid: 82a7d1c3c9154445794eb04c29ab2bd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!65 &784099995 +BoxCollider: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 784099992} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!33 &784099996 +MeshFilter: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 784099992} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &784099997 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 784099992} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 3, y: 1.5, z: 0} + m_LocalScale: {x: 0.05, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &792995699 GameObject: m_ObjectHideFlags: 0 @@ -1298,7 +1403,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 949094012} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -4.039651, y: 2.292325, z: 10.772432} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1444061385} @@ -1448,7 +1553,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1116159554} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.2207036, y: 2.900241, z: 12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1490933147} @@ -1894,7 +1999,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1463006270} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.2207036, y: 2.900241, z: 12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 344272455} @@ -1922,7 +2027,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1490933146} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 2.2207036, y: -2.900241, z: -12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1116159557} @@ -1930,6 +2035,133 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1610252928 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1610252930} + - component: {fileID: 1610252929} + m_Layer: 8 + m_Name: TextRenderer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1610252929 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1610252928} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9ca1db55c3aa94e6681ab393b7bae3d3, type: 3} + m_Name: + m_EditorClassIdentifier: + Camera: {fileID: 2130629208} + Text: {fileID: 1706692500} +--- !u!4 &1610252930 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1610252928} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 10, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 2130629204} + - {fileID: 1706692499} + m_Father: {fileID: 344272455} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1706692498 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1706692499} + - component: {fileID: 1706692501} + - component: {fileID: 1706692500} + m_Layer: 8 + m_Name: Rendered Text + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1706692499 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1706692498} + m_LocalRotation: {x: -0.000000014901159, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1, y: 1, z: 0.5} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1610252930} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!102 &1706692500 +TextMesh: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1706692498} + m_Text: + m_OffsetZ: 0 + m_CharacterSize: 1 + m_LineSpacing: 1 + m_Anchor: 0 + m_Alignment: 0 + m_TabSize: 4 + m_FontSize: 32 + m_FontStyle: 0 + m_RichText: 1 + m_Font: {fileID: 12800000, guid: 2073ef28104464427b1884c25180485b, type: 3} + m_Color: + serializedVersion: 2 + rgba: 4294967295 +--- !u!23 &1706692501 +MeshRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1706692498} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 2100000, guid: 2073ef28104464427b1884c25180485b, type: 3} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 --- !u!1 &1708261006 GameObject: m_ObjectHideFlags: 0 @@ -2018,7 +2250,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1810916631} m_LocalRotation: {x: 0.30459416, y: -0.7348772, z: 0.2774102, w: 0.53872216} - m_LocalPosition: {x: -4.039651, y: 5.292325, z: 10.772432} + m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 19192150} @@ -2138,7 +2370,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1939832656} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.2207036, y: 2.900241, z: 12.007475} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 344272455} @@ -2238,3 +2470,92 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 500} m_SizeDelta: {x: 0, y: -1000} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &2130629203 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 2130629204} + - component: {fileID: 2130629208} + - component: {fileID: 2130629207} + - component: {fileID: 2130629206} + - component: {fileID: 2130629205} + m_Layer: 8 + m_Name: Camera + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2130629204 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130629203} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1610252930} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!81 &2130629205 +AudioListener: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130629203} + m_Enabled: 0 +--- !u!92 &2130629206 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130629203} + m_Enabled: 0 +--- !u!124 &2130629207 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130629203} + m_Enabled: 0 +--- !u!20 &2130629208 +Camera: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130629203} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 2 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.1 + far clip plane: 1 + field of view: 60 + orthographic: 1 + orthographic size: 1 + m_Depth: -100 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 + m_StereoMirrorMode: 0 diff --git a/Assets/Scripts/Entities/SyncBases/Door.cs b/Assets/Scripts/Entities/SyncBases/Door.cs index 6557071..1aa2605 100644 --- a/Assets/Scripts/Entities/SyncBases/Door.cs +++ b/Assets/Scripts/Entities/SyncBases/Door.cs @@ -4,6 +4,10 @@ using UnityEngine; using UnityEngine.Networking; namespace Cyber.Entities.SyncBases { + + /// + /// Door that slides open and closed. Can be interacted to toggle openness. + /// public class Door : Interactable { /// diff --git a/Assets/Scripts/Util.meta b/Assets/Scripts/Util.meta new file mode 100644 index 0000000..3025af2 --- /dev/null +++ b/Assets/Scripts/Util.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c732179008d0f433dbdd20e90ee9a420 +folderAsset: yes +timeCreated: 1494463798 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Util/TextTextureApplier.cs b/Assets/Scripts/Util/TextTextureApplier.cs new file mode 100644 index 0000000..42cfa59 --- /dev/null +++ b/Assets/Scripts/Util/TextTextureApplier.cs @@ -0,0 +1,70 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Cyber.Util; + +namespace Cyber.Util { + + /// + /// Applies a texture to a specificed material containing specified text. + /// + public class TextTextureApplier : MonoBehaviour { + + /// + /// The text and related properties that defines the texture that + /// will be applied. + /// + public TextTextureProperties TextProperties = new TextTextureProperties(""); + + /// + /// The mesh that has the material that should use this texture. + /// + public MeshRenderer Mesh; + + /// + /// The index of the material that should use this texture. + /// + public int MaterialIndex = 0; + + /// + /// Whether the Emissive or Albedo map is set. + /// + public bool Emissive = true; + + /// + /// The brightness of the texture if this is . + /// + public float Brightness = 1f; + + private TextTextureProperties LastText = new TextTextureProperties(""); + private Material Material; + private bool Dirty = true; + + /// + /// Sets the text properties. + /// + /// Properties. + public void SetTextProperties(TextTextureProperties Props) { + TextProperties = Props; + Dirty = true; + } + + private void Start() { + Material = Mesh.materials[MaterialIndex]; + } + + private void Update() { + Texture2D Tex; + if (Dirty && (Tex = TextTextureRenderer.GetText(TextProperties)) != null) { + if (Emissive) { + Material.SetTexture("_EmissionMap", Tex); + Material.SetColor("_EmissionColor", + new Color(Brightness, Brightness, Brightness)); + } else { + Material.SetTexture("_MainTex", Tex); + } + Dirty = false; + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Util/TextTextureApplier.cs.meta b/Assets/Scripts/Util/TextTextureApplier.cs.meta new file mode 100644 index 0000000..f74badd --- /dev/null +++ b/Assets/Scripts/Util/TextTextureApplier.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0e0b8f69a817648969bf8ecd70b13d4d +timeCreated: 1494467411 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Util/TextTextureProperties.cs b/Assets/Scripts/Util/TextTextureProperties.cs new file mode 100644 index 0000000..fa89e70 --- /dev/null +++ b/Assets/Scripts/Util/TextTextureProperties.cs @@ -0,0 +1,55 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Cyber.Util { + + /// + /// Text texture properties. See . + /// + [System.Serializable] + public struct TextTextureProperties { + + /// + /// The text. + /// + public string Text; + + /// + /// The background color. + /// + public Color Background; + + /// + /// The size of the font. + /// + public int FontSize; + + /// + /// The width of the texture. + /// + public int Width; + + /// + /// The height of the texture. + /// + public int Height; + + /// + /// Creates new properties for a specified kind of text. See + /// for usage. + /// + /// Text. + /// Background. + /// Font size. + /// Width. + /// Height. + public TextTextureProperties(string text, Color background = new Color(), int fontSize = 32, int width = 128, int height = 128) { + Text = text; + Background = background; + FontSize = fontSize; + Width = width; + Height = height; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Util/TextTextureProperties.cs.meta b/Assets/Scripts/Util/TextTextureProperties.cs.meta new file mode 100644 index 0000000..fbd31e0 --- /dev/null +++ b/Assets/Scripts/Util/TextTextureProperties.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4075e2774340b42f481a6dd2f5ec0259 +timeCreated: 1494463973 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Util/TextTextureRenderer.cs b/Assets/Scripts/Util/TextTextureRenderer.cs new file mode 100644 index 0000000..9b2bafd --- /dev/null +++ b/Assets/Scripts/Util/TextTextureRenderer.cs @@ -0,0 +1,73 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Cyber.Console; + +namespace Cyber.Util { + + /// + /// Renders textures that have text written on them. + /// + public class TextTextureRenderer : MonoBehaviour { + private static TextTextureRenderer Singleton; + private static Dictionary Cache = + new Dictionary(); + + /// + /// The camera the text is rendered with. + /// + public Camera Camera; + + /// + /// The text that is rendered on screen. + /// + public TextMesh Text; + + /// + /// Sets the singleton. + /// + public TextTextureRenderer() { + Singleton = this; + } + + private Texture2D RenderText(TextTextureProperties text) { + Term.Println("Rendering: " + text.Text); + Text.text = text.Text.Replace("\\n", "\n"); + Text.fontSize = text.FontSize; + Text.characterSize = 0.5f * text.FontSize / text.Width; + + RenderTexture TextTexture = RenderTexture.GetTemporary(text.Width, text.Height); + RenderTexture OldRT = Camera.targetTexture; + Camera.targetTexture = TextTexture; + Camera.backgroundColor = text.Background; + Camera.Render(); + Camera.targetTexture = OldRT; + + OldRT = RenderTexture.active; + Texture2D Result = new Texture2D(text.Width, text.Height); + RenderTexture.active = TextTexture; + Result.ReadPixels(new Rect(0, 0, Result.width, Result.height), 0, 0); + Result.Apply(); + + RenderTexture.active = OldRT; + RenderTexture.ReleaseTemporary(TextTexture); + + return Result; + } + + /// + /// Renders a texture and caches it so it can be used as a texture + /// for a material (like a computer screen for example). + /// + /// The text. + /// Text. + /// Whether the texture should be rendered + /// again even if it's cached. + public static Texture2D GetText(TextTextureProperties text, bool forceRender = false) { + if (forceRender || !Cache.ContainsKey(text.Text)) { + Cache[text.Text] = Singleton.RenderText(text); + } + return Cache[text.Text]; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Util/TextTextureRenderer.cs.meta b/Assets/Scripts/Util/TextTextureRenderer.cs.meta new file mode 100644 index 0000000..413187f --- /dev/null +++ b/Assets/Scripts/Util/TextTextureRenderer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9ca1db55c3aa94e6681ab393b7bae3d3 +timeCreated: 1494463810 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c92a78..0c64e0b 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -13,7 +13,7 @@ TagManager: - UI - - - - + - TextTextureRendering - - -