From 52f3c29429603743aa4c59c0b096c050c5deec54 Mon Sep 17 00:00:00 2001 From: GrantMurray Date: Fri, 12 Apr 2024 21:06:44 -0700 Subject: [PATCH] Tried to fix chat box history and position, I give up with unity --- Demo/Assets/Scenes/SampleScene.unity | 34 ++++++++++++++++++---------- Demo/Assets/Scripts/ChatBar.cs | 5 ++-- Demo/Assets/Scripts/MessageInput.cs | 20 ++++++++++------ Demo/Assets/Scripts/Player.cs | 2 +- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/Demo/Assets/Scenes/SampleScene.unity b/Demo/Assets/Scenes/SampleScene.unity index ad9ec6a..dfd2a8a 100644 --- a/Demo/Assets/Scenes/SampleScene.unity +++ b/Demo/Assets/Scenes/SampleScene.unity @@ -30087,8 +30087,8 @@ GameObject: m_Component: - component: {fileID: 1190204998} - component: {fileID: 1190204997} - - component: {fileID: 1190204999} - component: {fileID: 1190205000} + - component: {fileID: 1190205001} m_Layer: 0 m_Name: ChatBar m_TagString: Untagged @@ -30156,16 +30156,16 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1190204992} serializedVersion: 2 - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -7.8, y: -3.59, z: 10} - m_LocalScale: {x: 0.6625, y: 0.77502966, z: 1} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -12.14, y: -4.98, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1340503910} - {fileID: 1602439422} m_Father: {fileID: 519420032} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1190204999 +--- !u!114 &1190205000 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -30174,10 +30174,14 @@ MonoBehaviour: m_GameObject: {fileID: 1190204992} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3aac67e6abf1dd6449a7214b2006f17b, type: 3} + m_Script: {fileID: 11500000, guid: bb133f371ef5953198ea606ff479ae3b, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &1190205000 + spriteRenderer: {fileID: 1190204997} + Online: {fileID: 741323824, guid: a824ceda098699e009d18d7f50077187, type: 3} + Offline: {fileID: 1046802418, guid: a824ceda098699e009d18d7f50077187, type: 3} + keyStrokes: 0 +--- !u!114 &1190205001 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -30186,13 +30190,16 @@ MonoBehaviour: m_GameObject: {fileID: 1190204992} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bb133f371ef5953198ea606ff479ae3b, type: 3} + m_Script: {fileID: 11500000, guid: 9f2510bd6ca652f76b73d0404b807411, type: 3} m_Name: m_EditorClassIdentifier: - spriteRenderer: {fileID: 1190204997} - Online: {fileID: 741323824, guid: a824ceda098699e009d18d7f50077187, type: 3} - Offline: {fileID: 1046802418, guid: a824ceda098699e009d18d7f50077187, type: 3} - keyStrokes: 0 + walkForce: 1 + jumpForce: 1 + spriteRenderer: {fileID: 0} + rb: {fileID: 0} + onlineSprite: {fileID: 0} + offlineSprite: {fileID: 0} + viewRadius: 50 --- !u!1 &1204895785 GameObject: m_ObjectHideFlags: 0 @@ -32989,6 +32996,9 @@ MonoBehaviour: - {fileID: 1249644660, guid: c8720553b870f62869ff34f13c86167e, type: 3} - {fileID: 999460749, guid: c8720553b870f62869ff34f13c86167e, type: 3} - {fileID: 0} + fileLine: + projectPath: + filePath: /Chatbox/messageHistory.txt --- !u!212 &1602439424 SpriteRenderer: m_ObjectHideFlags: 0 diff --git a/Demo/Assets/Scripts/ChatBar.cs b/Demo/Assets/Scripts/ChatBar.cs index 15bb67b..ac583fb 100644 --- a/Demo/Assets/Scripts/ChatBar.cs +++ b/Demo/Assets/Scripts/ChatBar.cs @@ -7,14 +7,13 @@ public class ChatBar : Actor { - public GameObject player; public Sprite onlineSprite; public Sprite offlineSprite; public float viewRadius = 50; public void Start() { - player = GameObject.Find("Player"); + //transform.position = new Vector3(1, 0, transform.position.z); } protected bool WithinView(Vector2 playerPosition) @@ -25,6 +24,6 @@ protected bool WithinView(Vector2 playerPosition) private void Update() { - WithinView(new Vector2 (10, 10)); + //WithinView(new Vector2 (10, 10)); } } \ No newline at end of file diff --git a/Demo/Assets/Scripts/MessageInput.cs b/Demo/Assets/Scripts/MessageInput.cs index 10aee0c..6e1136a 100644 --- a/Demo/Assets/Scripts/MessageInput.cs +++ b/Demo/Assets/Scripts/MessageInput.cs @@ -11,13 +11,13 @@ public class MessageInput : MonoBehaviour public int spriteCount = 9; public Sprite[] spriteArray; public string fileLine = ""; - public string docPath; - public string filePath = "../Chatbox/messageHistory.txt"; + public string projectPath; + public string filePath = "Chatbox/messageHistory.txt"; void Start() { - docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - filePath = Path.Combine(docPath, filePath); + projectPath = Application.dataPath; + filePath = Path.Combine(projectPath, filePath); chatBox = GameObject.Find("ChatBox").GetComponent(); fileLine = System.IO.File.ReadLines( filePath.ToString() ).ToString(); if ( fileLine != "" ) messageIndex = int.Parse(fileLine); @@ -34,13 +34,19 @@ void Update() for (int i = 0 ; i < spriteCount ; i++) { if (Input.GetKeyDown((i + 1).ToString())) { messageIndex = i; - using ( StreamWriter outputFile = new StreamWriter( filePath.ToString() ) ) { - outputFile.WriteLine(messageIndex); - } + } } int realIndex = messageIndex % spriteCount; spriteRenderer.sprite = spriteArray[realIndex]; } + + void OnDestroy() + { + using ( StreamWriter outputFile = new StreamWriter( filePath.ToString() ) ) { + outputFile.WriteLine(messageIndex); + } + + } } diff --git a/Demo/Assets/Scripts/Player.cs b/Demo/Assets/Scripts/Player.cs index a726abc..7f12119 100644 --- a/Demo/Assets/Scripts/Player.cs +++ b/Demo/Assets/Scripts/Player.cs @@ -118,7 +118,7 @@ private void CheckFallDamage() { if (lastVelocity < -30f && CheckIfGrounded()) { - AdjustHealth(lastVelocity * 0.009f); + //AdjustHealth(lastVelocity * 0.009f); } lastVelocity = rb.velocity.y; }