浏览代码

add a script to put text on screen using canvas and Text components. Also create a text prefab that will live throughout scene cycling and move other common files for text scenes into common folder

/main
Filip Iliescu 7 年前
当前提交
7e17d6c0
共有 10 个文件被更改,包括 581 次插入0 次删除
  1. 40
      Assets/TestScenes/MobileDeferredTest/Common/DisplayText.cs
  2. 13
      Assets/TestScenes/MobileDeferredTest/Common/DisplayText.cs.meta
  3. 297
      Assets/TestScenes/MobileDeferredTest/Common/FPSTimer.prefab
  4. 10
      Assets/TestScenes/MobileDeferredTest/Common/FPSTimer.prefab.meta
  5. 17
      Assets/TestScenes/MobileDeferredTest/Common/KeepMeAlive.cs
  6. 13
      Assets/TestScenes/MobileDeferredTest/Common/KeepMeAlive.cs.meta
  7. 114
      Assets/TestScenes/MobileDeferredTest/Common/MobileTestSceneManager.cs
  8. 13
      Assets/TestScenes/MobileDeferredTest/Common/MobileTestSceneManager.cs.meta
  9. 54
      Assets/TestScenes/MobileDeferredTest/Common/TestSceneManager.prefab
  10. 10
      Assets/TestScenes/MobileDeferredTest/Common/TestSceneManager.prefab.meta

40
Assets/TestScenes/MobileDeferredTest/Common/DisplayText.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
public class DisplayText : MonoBehaviour {
public UnityEngine.Experimental.Rendering.OnTileDeferredRenderPipeline.OnTileDeferredRenderPipeline pipeline;
float updateInterval = 0.5f;
double lastInterval = 0;
int frames = 0;
void Start () {
lastInterval = Time.realtimeSinceStartup;
frames = 0;
//Random.state = 13;
}
string renderPipeline()
{
if (GraphicsSettings.renderPipelineAsset != null)
return GraphicsSettings.renderPipelineAsset.name + (pipeline.UseLegacyCookies?", legacy cookies":", colored cookies") + ", transparency shadows " + (pipeline.TransparencyShadows?"enabled":"disabled");
else
return "None (See Camera Settings)";
}
void Update () {
++frames;
double timeNow = Time.realtimeSinceStartup;
if (timeNow > lastInterval + updateInterval) {
double ms = (timeNow - lastInterval) / frames * 1000.0;
GetComponent<Text>().text = SceneManager.GetActiveScene().name + ": " + ms.ToString ("f2") + "ms, RenderPipeline " + renderPipeline();
frames = 0;
lastInterval = timeNow;
}
}
}

13
Assets/TestScenes/MobileDeferredTest/Common/DisplayText.cs.meta


fileFormatVersion: 2
guid: ae8097aab7e6740ea9bd759f0a19a3b2
timeCreated: 1499977226
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

297
Assets/TestScenes/MobileDeferredTest/Common/FPSTimer.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1121820646398486}
m_IsPrefabParent: 1
--- !u!1 &1013281858178976
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224166700731761670}
- component: {fileID: 222389056106554244}
- component: {fileID: 114482082042512324}
- component: {fileID: 114252703039089632}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1121820646398486
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4439273907834604}
- component: {fileID: 114891995347070368}
m_Layer: 0
m_Name: FPSTimer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1406958758550900
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4008540221238366}
- component: {fileID: 114023755111267706}
- component: {fileID: 114273719731859764}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1502671064356410
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224481898928072308}
- component: {fileID: 223778902342606020}
- component: {fileID: 114042891209588914}
- component: {fileID: 114119966467554224}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4008540221238366
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1406958758550900}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.30451882, y: -0.036157057, z: -0.6549205}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4439273907834604}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4439273907834604
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1121820646398486}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.30451882, y: 0.036157057, z: 0.6549205}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 224481898928072308}
- {fileID: 4008540221238366}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &114023755111267706
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1406958758550900}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!114 &114042891209588914
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1502671064356410}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!114 &114119966467554224
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1502671064356410}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &114252703039089632
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1013281858178976}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ae8097aab7e6740ea9bd759f0a19a3b2, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &114273719731859764
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1406958758550900}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &114482082042512324
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1013281858178976}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 18
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: FPS
--- !u!114 &114891995347070368
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1121820646398486}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 438ab085cb7f24ff4bf64860b2077794, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!222 &222389056106554244
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1013281858178976}
--- !u!223 &223778902342606020
Canvas:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1502671064356410}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &224166700731761670
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1013281858178976}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 30, y: -35, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 224481898928072308}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 80, y: 15}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224481898928072308
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1502671064356410}
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:
- {fileID: 224166700731761670}
m_Father: {fileID: 4439273907834604}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}

10
Assets/TestScenes/MobileDeferredTest/Common/FPSTimer.prefab.meta


fileFormatVersion: 2
guid: 2627a28fac90a47aa9e011e46bf5d2f7
timeCreated: 1499978307
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

17
Assets/TestScenes/MobileDeferredTest/Common/KeepMeAlive.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeepMeAlive : MonoBehaviour {
static KeepMeAlive Instance;
void Start () {
if (Instance != null) {
GameObject.Destroy (gameObject);
} else {
GameObject.DontDestroyOnLoad (gameObject);
Instance = this;
}
}
}

13
Assets/TestScenes/MobileDeferredTest/Common/KeepMeAlive.cs.meta


fileFormatVersion: 2
guid: 438ab085cb7f24ff4bf64860b2077794
timeCreated: 1499978116
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

114
Assets/TestScenes/MobileDeferredTest/Common/MobileTestSceneManager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Rendering;
public class MobileTestSceneManager : MonoBehaviour {
static int m_NextSceneIndex = 0;
static MobileTestSceneManager Instance;
private Vector2 startPosition;
private float startTime;
public UnityEngine.Experimental.Rendering.OnTileDeferredRenderPipeline.OnTileDeferredRenderPipeline pipeline;
void Start () {
if (Instance != null) {
GameObject.Destroy (gameObject);
} else {
GameObject.DontDestroyOnLoad (gameObject);
Instance = this;
}
}
// bool processRightSwipe()
// {
// if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began) {
// Vector2 touchDeltaPosition = Input.GetTouch(0).position;
// if (touchDeltaPosition.x > Screen.width/2)
// return true;
// }
// return false;
// }
//
// bool processLeftSwipe()
// {
// if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began) {
// Vector2 touchDeltaPosition = Input.GetTouch(0).position;
// if (touchDeltaPosition.x < Screen.width/2)
// return true;
// }
// return false;
// }
int detectSwipe() {
if (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Ended) {
Vector2 endPosition = Input.GetTouch (0).position;
Vector2 delta = endPosition - startPosition;
// float dist = Mathf.Sqrt(Mathf.Pow(delta.x, 2) + Mathf.Pow (delta.y, 2));
// float angle = Mathf.Atan (delta.y/delta.x) * (180.0f/Mathf.PI);
// float duration = Time.time - startTime;
// float speed = dist/duration;
if (startPosition.x < endPosition.x)
return 1;
else if (startPosition.x > endPosition.x)
return -1;
}
return 0;
}
void detectTouchBegan() {
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began) {
startPosition = Input.GetTouch(0).position;
startTime = Time.time;
}
}
void Update () {
#if (UNITY_EDITOR || UNITY_STANDALONE)
if (Input.GetKeyDown(KeyCode.Space)) {
#else
if (Input.touchCount == 3 && Input.GetTouch(0).phase == TouchPhase.Began) {
#endif
SceneManager.LoadScene(m_NextSceneIndex++);
}
#if (UNITY_EDITOR || UNITY_STANDALONE)
if (Input.GetKeyDown(KeyCode.S)) {
#else
if (detectSwipe() == 1) {
#endif
pipeline.TransparencyShadows = !pipeline.TransparencyShadows;
}
#if (UNITY_EDITOR || UNITY_STANDALONE)
if (Input.GetKeyDown(KeyCode.C)) {
#else
if (detectSwipe() == -1) {
#endif
pipeline.UseLegacyCookies = !pipeline.UseLegacyCookies;
}
#if (UNITY_EDITOR || UNITY_STANDALONE)
if (Input.GetKeyDown(KeyCode.Return)) {
#else
if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Ended) {
#endif
if (GraphicsSettings.renderPipelineAsset == null)
GraphicsSettings.renderPipelineAsset = pipeline;
else
GraphicsSettings.renderPipelineAsset = null;
}
#if !(UNITY_EDITOR || UNITY_STANDALONE)
detectTouchBegan();
#endif
}
}

13
Assets/TestScenes/MobileDeferredTest/Common/MobileTestSceneManager.cs.meta


fileFormatVersion: 2
guid: 875be5407d1be4ece86b5bd6ea22c095
timeCreated: 1498100035
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

54
Assets/TestScenes/MobileDeferredTest/Common/TestSceneManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1046928737890152}
m_IsPrefabParent: 1
--- !u!1 &1046928737890152
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4942927082311418}
- component: {fileID: 114150254131087770}
m_Layer: 0
m_Name: TestSceneManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4942927082311418
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046928737890152}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.5, y: 0, z: 0.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &114150254131087770
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046928737890152}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 875be5407d1be4ece86b5bd6ea22c095, type: 3}
m_Name:
m_EditorClassIdentifier:
pipeline: {fileID: 0}

10
Assets/TestScenes/MobileDeferredTest/Common/TestSceneManager.prefab.meta


fileFormatVersion: 2
guid: 73dfbb376901b4b7b98b292ba7c203e5
timeCreated: 1498101259
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存