Add a texture renderer for text textures

This commit is contained in:
excitedneon 2017-05-11 06:13:52 +03:00
parent af75616e2c
commit ec84bb38ad
11 changed files with 582 additions and 14 deletions

View File

@ -191,7 +191,7 @@ Camera:
m_Depth: 1 m_Depth: 1
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967039
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 0} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0

View File

@ -130,7 +130,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 19192149} m_GameObject: {fileID: 19192149}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 769207969} - {fileID: 769207969}
@ -503,13 +503,14 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 344272454} m_GameObject: {fileID: 344272454}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 605817615} - {fileID: 605817615}
- {fileID: 1463006272} - {fileID: 1463006272}
- {fileID: 1939832658} - {fileID: 1939832658}
- {fileID: 375619906} - {fileID: 375619906}
- {fileID: 1610252930}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -570,7 +571,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 375619905} m_GameObject: {fileID: 375619905}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 344272455} m_Father: {fileID: 344272455}
@ -920,7 +921,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 605817613} m_GameObject: {fileID: 605817613}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 344272455} m_Father: {fileID: 344272455}
@ -1001,7 +1002,7 @@ Camera:
m_Depth: 0 m_Depth: 0
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967039
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 0} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0
@ -1020,12 +1021,116 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 769207964} m_GameObject: {fileID: 769207964}
m_LocalRotation: {x: 0.3826837, y: -0, z: -0, w: 0.9238795} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 19192150} m_Father: {fileID: 19192150}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 45.000004, y: 0, z: 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 --- !u!1 &792995699
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1298,7 +1403,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 949094012} m_GameObject: {fileID: 949094012}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 1444061385} - {fileID: 1444061385}
@ -1448,7 +1553,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1116159554} m_GameObject: {fileID: 1116159554}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 1490933147} m_Father: {fileID: 1490933147}
@ -1894,7 +1999,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1463006270} m_GameObject: {fileID: 1463006270}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 344272455} m_Father: {fileID: 344272455}
@ -1922,7 +2027,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1490933146} m_GameObject: {fileID: 1490933146}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 1116159557} - {fileID: 1116159557}
@ -1930,6 +2035,133 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 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 --- !u!1 &1708261006
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2018,7 +2250,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1810916631} m_GameObject: {fileID: 1810916631}
m_LocalRotation: {x: 0.30459416, y: -0.7348772, z: 0.2774102, w: 0.53872216} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 19192150} m_Father: {fileID: 19192150}
@ -2138,7 +2370,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1939832656} m_GameObject: {fileID: 1939832656}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} 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_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 344272455} m_Father: {fileID: 344272455}
@ -2238,3 +2470,92 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 500} m_AnchoredPosition: {x: 0, y: 500}
m_SizeDelta: {x: 0, y: -1000} m_SizeDelta: {x: 0, y: -1000}
m_Pivot: {x: 0.5, y: 0.5} 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

View File

@ -4,6 +4,10 @@ using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace Cyber.Entities.SyncBases { namespace Cyber.Entities.SyncBases {
/// <summary>
/// Door that slides open and closed. Can be interacted to toggle openness.
/// </summary>
public class Door : Interactable { public class Door : Interactable {
/// <summary> /// <summary>

9
Assets/Scripts/Util.meta Normal file
View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c732179008d0f433dbdd20e90ee9a420
folderAsset: yes
timeCreated: 1494463798
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Util;
namespace Cyber.Util {
/// <summary>
/// Applies a texture to a specificed material containing specified text.
/// </summary>
public class TextTextureApplier : MonoBehaviour {
/// <summary>
/// The text and related properties that defines the texture that
/// will be applied.
/// </summary>
public TextTextureProperties TextProperties = new TextTextureProperties("");
/// <summary>
/// The mesh that has the material that should use this texture.
/// </summary>
public MeshRenderer Mesh;
/// <summary>
/// The index of the material that should use this texture.
/// </summary>
public int MaterialIndex = 0;
/// <summary>
/// Whether the Emissive or Albedo map is set.
/// </summary>
public bool Emissive = true;
/// <summary>
/// The brightness of the texture if this is <see cref="Emissive"/>.
/// </summary>
public float Brightness = 1f;
private TextTextureProperties LastText = new TextTextureProperties("");
private Material Material;
private bool Dirty = true;
/// <summary>
/// Sets the text properties.
/// </summary>
/// <param name="Props">Properties.</param>
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;
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0e0b8f69a817648969bf8ecd70b13d4d
timeCreated: 1494467411
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Cyber.Util {
/// <summary>
/// Text texture properties. See <see cref="TextTextureRenderer"/>.
/// </summary>
[System.Serializable]
public struct TextTextureProperties {
/// <summary>
/// The text.
/// </summary>
public string Text;
/// <summary>
/// The background color.
/// </summary>
public Color Background;
/// <summary>
/// The size of the font.
/// </summary>
public int FontSize;
/// <summary>
/// The width of the texture.
/// </summary>
public int Width;
/// <summary>
/// The height of the texture.
/// </summary>
public int Height;
/// <summary>
/// Creates new properties for a specified kind of text. See
/// <see cref="TextTextureRenderer"/> for usage.
/// </summary>
/// <param name="text">Text.</param>
/// <param name="background">Background.</param>
/// <param name="fontSize">Font size.</param>
/// <param name="width">Width.</param>
/// <param name="height">Height.</param>
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;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4075e2774340b42f481a6dd2f5ec0259
timeCreated: 1494463973
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Console;
namespace Cyber.Util {
/// <summary>
/// Renders textures that have text written on them.
/// </summary>
public class TextTextureRenderer : MonoBehaviour {
private static TextTextureRenderer Singleton;
private static Dictionary<string, Texture2D> Cache =
new Dictionary<string, Texture2D>();
/// <summary>
/// The camera the text is rendered with.
/// </summary>
public Camera Camera;
/// <summary>
/// The text that is rendered on screen.
/// </summary>
public TextMesh Text;
/// <summary>
/// Sets the singleton.
/// </summary>
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;
}
/// <summary>
/// Renders a texture and caches it so it can be used as a texture
/// for a material (like a computer screen for example).
/// </summary>
/// <returns>The text.</returns>
/// <param name="text">Text.</param>
/// <param name="forceRender">Whether the texture should be rendered
/// again even if it's cached.</param>
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];
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9ca1db55c3aa94e6681ab393b7bae3d3
timeCreated: 1494463810
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,7 +13,7 @@ TagManager:
- UI - UI
- -
- -
- - TextTextureRendering
- -
- -
- -