Explorar el Código

Консоль

Виктор Шейко hace 4 años
padre
commit
23a08726ba

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1076 - 165
Assets/Scenes/Location.unity


+ 7 - 0
Assets/Scripts/Controllers/WorkerController.cs

@@ -46,6 +46,8 @@ public class WorkerController : MonoBehaviour
     // Start is called before the first frame update
     void Start()
     {
+        DebugHelper.ActivateConsole();
+
         WorkerMarker(4);
         WorkerMarker(356);
 
@@ -315,5 +317,10 @@ public class WorkerController : MonoBehaviour
             }
         }
     }
+
+    void OnGUI()
+    {
+        DebugHelper.DrawConsole();
+    }
 }
 

+ 97 - 0
Assets/Scripts/DebugHelper.cs

@@ -0,0 +1,97 @@
+/* 
+ * Copyright (C) 2015 Christoph Kutza
+ * 
+ * Please refer to the LICENSE file for license information
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+
+/// <summary>
+/// Shows the console on all platforms. For debugging.
+/// </summary>
+public class DebugHelper
+{
+    public static bool sShowConsole = false;
+    public static bool sConsoleAutoScroll = true;
+
+    private static Vector2 mDebugConsoleScrollPos = new Vector2();
+    private static StringBuilder mLog = null;
+    private static int mLines = 0;
+
+    public static void ActivateConsole()
+    {
+        if (mLog != null)
+            return;
+        mLog = new StringBuilder();
+        Application.logMessageReceived += LogType;
+    }
+    private static void LogType(string condition, string stackTrace, LogType type)
+    {
+        int lines = 0;
+        mLog.Append(condition);
+        if (type == UnityEngine.LogType.Exception)
+        {
+            lines += stackTrace.Count((x) => { return x == '\n'; });
+            mLog.Append(stackTrace);
+        }
+        mLog.Append("\n");
+        lines++;
+
+        mLines += lines;
+
+        int foundLines = 0;
+        for (int i = mLog.Length - 1; i >= 0; i--)
+        {
+            if (mLog[i] == '\n')
+            {
+                foundLines++;
+                if (foundLines  == 100)
+                {
+                    mLog.Remove(0, i + 1);
+                    break;
+                }
+            }
+        }
+    }
+    public static void DrawConsole()
+    {
+        if (mLog == null)
+            return;
+
+        if (sShowConsole == false)
+        {
+            if (GUI.Button(new Rect(Screen.width - 40*2, Screen.height - 20*2, 40*2, 20*2), "Show"))
+            {
+                sShowConsole = true;
+            }
+        }
+        else
+        {
+            if (GUI.Button(new Rect(Screen.width - 40*2, Screen.height * 0.75f - 20*2, 40*2, 20*2), "Hide"))
+            {
+                sShowConsole = false;
+            }
+            if (GUI.Button(new Rect(Screen.width - 90*2, Screen.height * 0.75f - 20*2, 40*2, 20*2), "Auto"))
+            {
+                sConsoleAutoScroll = !sConsoleAutoScroll;
+            }
+
+            GUIStyle textStyle = new GUIStyle();
+
+            textStyle.normal.textColor = Color.white;
+            textStyle.richText = true;
+
+            GUI.Box(new Rect(0, Screen.height * 0.75f, Screen.width, Screen.height * 0.25f), "");
+            GUILayout.BeginArea(new Rect(0, Screen.height * 0.75f, Screen.width, Screen.height * 0.25f));
+            mDebugConsoleScrollPos = GUILayout.BeginScrollView(mDebugConsoleScrollPos);
+            if(sConsoleAutoScroll)
+                mDebugConsoleScrollPos = new Vector2(0, 1000000000);
+            GUILayout.TextArea(mLog.ToString(), textStyle);
+            GUILayout.EndScrollView();
+            GUILayout.EndArea();
+        }
+    }
+}

+ 1 - 1
ProjectSettings/ProjectSettings.asset

@@ -13,7 +13,7 @@ PlayerSettings:
   useOnDemandResources: 0
   accelerometerFrequency: 60
   companyName: DefaultCompany
-  productName: Positioning
+  productName: PositionViewer
   defaultCursor: {fileID: 0}
   cursorHotspot: {x: 0, y: 0}
   m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1}