From 2d4e999821666549d2cd1716f34d52c4fc677649 Mon Sep 17 00:00:00 2001 From: Brandon Dang Date: Thu, 3 Feb 2022 13:30:56 -0600 Subject: [PATCH 1/4] added tips for devs and module devs --- .../KomodoWebXRFullView2020/relay.js | 16 ++++++++++++++-- .../KomodoWebXRFullView2020/relay.js | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js b/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js index 8d4602f..9bd43b5 100644 --- a/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js +++ b/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js @@ -1,19 +1,31 @@ // 'esversion: 6' -// Remember: also change Assets\Packages\KomodoCore\Hidden~\WebGLTemplates\KomodoWebXRFullView2020\relay.js +// Remember: also change Assets\WebGLTemplates\KomodoWebXRFullView2020\relay.js (or re-copy the WebGLTemplates to the Assets folder) if you intend for the changes to be reflected in the build. If you are reading this from inside a build folder, you can change this file as you please. // Tip: if you need to change this on-the-fly, you can edit this file without rebuilding. It's also possible to use the inspector to inspect the VR frame and call `window.RELAY_API_BASE_URL=""`, if for some reason you need to do that in real time. +/* + * --------------------------------------------------------------------------------- + * CONFIG + * --------------------------------------------------------------------------------- + */ + // Replace these with your own server's URLs. var RELAY_BASE_URL = "http://localhost:3000"; var API_BASE_URL = "http://localhost:4040"; -var VR_BASE_URL = "https://localhost:8123"; //TODO -- change this to a better default +var VR_BASE_URL = "http://localhost:8123"; //TODO -- change this to a better default // init globals which Unity will assign when setup is done. var sync = null; var chat = null; +/* + * --------------------------------------------------------------------------------- + * FUNCTIONALITY + * --------------------------------------------------------------------------------- + */ + /** * Get the URL parameters * source: https://css-tricks.com/snippets/javascript/get-url-variables/ diff --git a/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js b/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js index 54e6aef..8046623 100644 --- a/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js +++ b/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js @@ -1,10 +1,15 @@ // 'esversion: 6' -// Replace these with your own server's URLs. +// Remember: also change Assets\Packages\KomodoCore\Hidden~\WebGLTemplates\KomodoWebXRFullView2020\relay.js if you intend for the changes to be reflected in projects that use the package. If you are reading this from inside a build folder, you can change this file as you please. -// Remember: also change Assets\WebGLTemplates\KomodoWebXRFullView2020\relay.js // Tip: if you need to change this on-the-fly, you can edit this file without rebuilding. It's also possible to use the inspector to inspect the VR frame and call `window.RELAY_API_BASE_URL=""`, if for some reason you need to do that in real time. +/* + * --------------------------------------------------------------------------------- + * CONFIG + * --------------------------------------------------------------------------------- + */ + // Replace these with your own server's URLs. var RELAY_BASE_URL = "http://localhost:3000"; @@ -15,6 +20,12 @@ var VR_BASE_URL = "http://localhost:8123"; //TODO -- change this to a better def var sync = null; var chat = null; +/* + * --------------------------------------------------------------------------------- + * FUNCTIONALITY + * --------------------------------------------------------------------------------- + */ + /** * Get the URL parameters * source: https://css-tricks.com/snippets/javascript/get-url-variables/ From 41b6fc3f2cdedd4250d4f730806ad9ecb82d5728 Mon Sep 17 00:00:00 2001 From: Brandon Dang <8165314+parseccentric@users.noreply.github.com> Date: Mon, 7 Feb 2022 14:59:14 -0600 Subject: [PATCH 2/4] Re-enabled grabbable drawing feature --- .../Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs b/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs index 91825a7..6f84ed0 100644 --- a/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs +++ b/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs @@ -60,7 +60,7 @@ public void CreateUserStrokeInstance(int strokeID, LineRenderer lineRenderer, bo var nAGO = NetworkedObjectsManager.Instance.CreateNetworkedGameObject(pivot, strokeID, strokeID); //tag it as a drawing for ECS - pivot.tag = TagList.drawing; + pivot.tag = TagList.interactable; entityManager.AddComponentData(nAGO.Entity, new DrawingTag { }); var bColl = pivot.GetComponent(); @@ -116,7 +116,7 @@ public void CreateExternalClientStrokeInstance(int strokeID, LineRenderer curren NetworkedGameObject nAGO = NetworkedObjectsManager.Instance.CreateNetworkedGameObject(pivot, strokeID, strokeID, true); //overide interactable tag when creatingNetworkGameObject since we are not moving drawings only deleting them - pivot.tag = TagList.drawing; + pivot.tag = TagList.interactable; //tag created drawing object will be useful in the future for having items with multiple tags entityManager.AddComponentData(nAGO.Entity, new DrawingTag { }); From 6c47315df45228e357b281125c8728443f6b9af1 Mon Sep 17 00:00:00 2001 From: Brandon Dang <8165314+parseccentric@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:34:09 -0600 Subject: [PATCH 3/4] added comments for where to find relay vars --- .../KomodoWebXRFullView2020/relay.js | 47 ++++++++++++------ .../KomodoWebXRFullView2020/relay.js | 48 +++++++++++++------ Komodo/ProjectSettings/ProjectSettings.asset | 7 +-- 3 files changed, 69 insertions(+), 33 deletions(-) diff --git a/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js b/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js index 9bd43b5..6010095 100644 --- a/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js +++ b/Komodo/Assets/Packages/KomodoCore/Hidden~/WebGLTemplates/KomodoWebXRFullView2020/relay.js @@ -1,8 +1,14 @@ // 'esversion: 6' -// Remember: also change Assets\WebGLTemplates\KomodoWebXRFullView2020\relay.js (or re-copy the WebGLTemplates to the Assets folder) if you intend for the changes to be reflected in the build. If you are reading this from inside a build folder, you can change this file as you please. +// Remember: also change Assets\WebGLTemplates\KomodoWebXRFullView2020\relay.js (or +// re-copy the WebGLTemplates to the Assets folder) if you intend for the changes to +// be reflected in the build. If you are reading this from inside a build folder, +// you can change this file as you please. -// Tip: if you need to change this on-the-fly, you can edit this file without rebuilding. It's also possible to use the inspector to inspect the VR frame and call `window.RELAY_API_BASE_URL=""`, if for some reason you need to do that in real time. +// Tip: if you need to change this on-the-fly, you can edit this file without +// rebuilding. It's also possible to use the inspector to inspect the VR frame and +// call `window.RELAY_API_BASE_URL=""`, if for some reason you +// need to do that in real time. /* * --------------------------------------------------------------------------------- @@ -11,14 +17,22 @@ */ // Replace these with your own server's URLs. - -var RELAY_BASE_URL = "http://localhost:3000"; -var API_BASE_URL = "http://localhost:4040"; -var VR_BASE_URL = "http://localhost:8123"; //TODO -- change this to a better default - -// init globals which Unity will assign when setup is done. -var sync = null; -var chat = null; +// +// If running each of these without Docker: +// - RELAY_BASE_URL: Look in komodo-relay > serve.js or config.js for the port number +// - API_BASE_URL: Look in komodo-portal > config.js > web.port for the port number +// - VR_BASE_URL: This will be unused for local builds +// +// If running each of these with Docker: +// - RELAY_BASE_URL: Look in komodo-relay > docker-compose.yml > +// services.komodo-relay.labels > traefik.frontend.rule +// - API_BASE_URL: Look in komodo-portal > docker-compose.yml > +// services.backend.labels > traefik.frontend.rule +// - VR_BASE_URL: Look in komodo-portal > .env.* > VUE_APP_VR_CLIENT_BASE_URL + +var RELAY_BASE_URL = "http://localhost:3000"; +var API_BASE_URL = "http://localhost:4040"; +var VR_BASE_URL = "http://localhost:8123"; /* * --------------------------------------------------------------------------------- @@ -26,6 +40,10 @@ var chat = null; * --------------------------------------------------------------------------------- */ +// init globals which Unity will assign when setup is done. +var sync = null; +var chat = null; + /** * Get the URL parameters * source: https://css-tricks.com/snippets/javascript/get-url-variables/ @@ -92,8 +110,6 @@ var splitAppAndBuild = function (appAndBuild) { var runtimeAppAndBuild = removeVRBaseUrl(removeQuery(window.location.href)); -//console.log(runtimeAppAndBuild); - // TODO(Brandon): in the future, pass app and build as separate details like this: // var result = splitAppAndBuild(runtimeAppAndBuild); // var runtimeApp = result.app; @@ -130,7 +146,7 @@ request.open("GET", url, true); request.responseType = "json"; request.send(); -request.onload = function(){ +request.onload = function() { let res = request.response; // session details @@ -145,14 +161,15 @@ request.onload = function(){ details.users = res.users; let assets_response = res.assetList; - for (idx = 0; idx < assets_response.length; idx++) - { + + for (idx = 0; idx < assets_response.length; idx++) { asset = new Object; asset.id = assets_response[idx].asset_id; asset.name = assets_response[idx].asset_name; asset.url = assets_response[idx].path; asset.isWholeObject = Boolean(assets_response[idx].is_whole_object); asset.scale = assets_response[idx].scale || 1; + details.assets.push(asset); } }; diff --git a/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js b/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js index 8046623..3f46ff4 100644 --- a/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js +++ b/Komodo/Assets/WebGLTemplates/KomodoWebXRFullView2020/relay.js @@ -1,8 +1,15 @@ // 'esversion: 6' -// Remember: also change Assets\Packages\KomodoCore\Hidden~\WebGLTemplates\KomodoWebXRFullView2020\relay.js if you intend for the changes to be reflected in projects that use the package. If you are reading this from inside a build folder, you can change this file as you please. +// Remember: also change +// Assets\Packages\KomodoCore\Hidden~\WebGLTemplates\KomodoWebXRFullView2020\relay.js +// if you intend for the changes to be reflected in projects that use the package. +// If you are reading this from inside a build folder, you can change this file as +// you please. -// Tip: if you need to change this on-the-fly, you can edit this file without rebuilding. It's also possible to use the inspector to inspect the VR frame and call `window.RELAY_API_BASE_URL=""`, if for some reason you need to do that in real time. +// Tip: if you need to change this on-the-fly, you can edit this file without +// rebuilding. It's also possible to use the inspector to inspect the VR frame and +// call `window.RELAY_API_BASE_URL=""`, if for some reason you need +// to do that in real time. /* * --------------------------------------------------------------------------------- @@ -11,14 +18,22 @@ */ // Replace these with your own server's URLs. - -var RELAY_BASE_URL = "http://localhost:3000"; -var API_BASE_URL = "http://localhost:4040"; -var VR_BASE_URL = "http://localhost:8123"; //TODO -- change this to a better default - -// init globals which Unity will assign when setup is done. -var sync = null; -var chat = null; +// +// If running each of these without Docker: +// - RELAY_BASE_URL: Look in komodo-relay > serve.js or config.js for the port number +// - API_BASE_URL: Look in komodo-portal > config.js > web.port for the port number +// - VR_BASE_URL: This will be unused for local builds +// +// If running each of these with Docker: +// - RELAY_BASE_URL: Look in komodo-relay > docker-compose.yml > +// services.komodo-relay.labels > traefik.frontend.rule +// - API_BASE_URL: Look in komodo-portal > docker-compose.yml > +// services.backend.labels > traefik.frontend.rule +// - VR_BASE_URL: Look in komodo-portal > .env.* > VUE_APP_VR_CLIENT_BASE_URL + +var RELAY_BASE_URL = "http://localhost:3000"; +var API_BASE_URL = "http://localhost:4040"; +var VR_BASE_URL = "http://localhost:8123"; /* * --------------------------------------------------------------------------------- @@ -26,6 +41,10 @@ var chat = null; * --------------------------------------------------------------------------------- */ +// init globals which Unity will assign when setup is done. +var sync = null; +var chat = null; + /** * Get the URL parameters * source: https://css-tricks.com/snippets/javascript/get-url-variables/ @@ -92,8 +111,6 @@ var splitAppAndBuild = function (appAndBuild) { var runtimeAppAndBuild = removeVRBaseUrl(removeQuery(window.location.href)); -//console.log(runtimeAppAndBuild); - // TODO(Brandon): in the future, pass app and build as separate details like this: // var result = splitAppAndBuild(runtimeAppAndBuild); // var runtimeApp = result.app; @@ -130,7 +147,7 @@ request.open("GET", url, true); request.responseType = "json"; request.send(); -request.onload = function(){ +request.onload = function() { let res = request.response; // session details @@ -145,14 +162,15 @@ request.onload = function(){ details.users = res.users; let assets_response = res.assetList; - for (idx = 0; idx < assets_response.length; idx++) - { + + for (idx = 0; idx < assets_response.length; idx++) { asset = new Object; asset.id = assets_response[idx].asset_id; asset.name = assets_response[idx].asset_name; asset.url = assets_response[idx].path; asset.isWholeObject = Boolean(assets_response[idx].is_whole_object); asset.scale = assets_response[idx].scale || 1; + details.assets.push(asset); } }; diff --git a/Komodo/ProjectSettings/ProjectSettings.asset b/Komodo/ProjectSettings/ProjectSettings.asset index 9b9f28a..48f26e1 100644 --- a/Komodo/ProjectSettings/ProjectSettings.asset +++ b/Komodo/ProjectSettings/ProjectSettings.asset @@ -211,6 +211,7 @@ PlayerSettings: - {fileID: 11400000, guid: a5e5b7605fb48984988490688c2a74e2, type: 2} - {fileID: 11400000, guid: 8fed9c7708c5a6b46bbde22d82990e10, type: 2} - {fileID: 2478256764130162806, guid: 552445d583cb06c4eaf9d56596dd45c2, type: 2} + - {fileID: 0} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1 @@ -727,7 +728,6 @@ PlayerSettings: metroSplashScreenUseBackgroundColor: 0 platformCapabilities: WindowsStoreApps: - EnterpriseAuthentication: False OfflineMapsManagement: False HumanInterfaceDevice: False Location: False @@ -740,6 +740,7 @@ PlayerSettings: InternetClientServer: False VideosLibrary: False Objects3D: False + InternetClient: False RemoteSystem: False BlockedChatMessages: False PhoneCall: False @@ -760,10 +761,10 @@ PlayerSettings: PointOfService: False RecordedCallsFolder: False Contacts: False - InternetClient: False + Proximity: False CodeGeneration: False BackgroundMediaPlayback: False - Proximity: False + EnterpriseAuthentication: False metroTargetDeviceFamilies: Desktop: False Holographic: False From 4266589da347a6bcb7b0e32ece87f8a3438467f3 Mon Sep 17 00:00:00 2001 From: Brandon Dang <8165314+parseccentric@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:48:29 -0600 Subject: [PATCH 4/4] fixed whitespace, removed stale comments and regions --- .../Managers/DrawingInstanceManager.cs | 132 ++++++++++-------- 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs b/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs index 6f84ed0..ee2a313 100644 --- a/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs +++ b/Komodo/Assets/Packages/KomodoCore/Runtime/Scripts/RuntimeSession/Managers/DrawingInstanceManager.cs @@ -3,16 +3,15 @@ using System.Collections.Generic; using System; using Komodo.Utilities; -//using static Komodo.Runtime.NetworkUpdateHandler; namespace Komodo.Runtime { - //may need to rename this if we are including primitive shapes to our list public class DrawingInstanceManager : SingletonComponent { public static DrawingInstanceManager Instance { - get { return ((DrawingInstanceManager)_Instance); } + get { return (DrawingInstanceManager) _Instance; } + set { _Instance = value; } } @@ -21,8 +20,13 @@ public static DrawingInstanceManager Instance public EntityManager entityManager; [HideInInspector] public Transform userStrokeParent; + [HideInInspector] public Transform externalStrokeParent; + private Dictionary lineRenderersInQueue = new Dictionary(); + + private Dictionary allStrokeIDValidator = new Dictionary(); + public void Awake() { //used to set our managers alive state to true to detect if it exist within scene @@ -34,18 +38,19 @@ public void Awake() //parent for our stored lines userStrokeParent = new GameObject("UserStrokeParent").transform; + externalStrokeParent = new GameObject("ExternalClientStrokeParent").transform; userStrokeParent.SetParent(transform); + externalStrokeParent.SetParent(transform); - //register our message type with the funcion GlobalMessageManager.Instance.Subscribe("draw", (str) => Draw_Refresh(str)); } public void CreateUserStrokeInstance(int strokeID, LineRenderer lineRenderer, bool sendNetworkCall) { - //used to set correct pivot point when scalling object by grabbing + //set correct pivot point when scaling object by grabbing GameObject pivot = new GameObject("LineRender:" + strokeID, typeof(BoxCollider)); if (lineRendererContainerPrefab == null) @@ -54,69 +59,84 @@ public void CreateUserStrokeInstance(int strokeID, LineRenderer lineRenderer, bo } GameObject lineRendCopy = Instantiate(lineRendererContainerPrefab).gameObject; + lineRendCopy.name = "LineR:" + strokeID; //Create a reference to use in network var nAGO = NetworkedObjectsManager.Instance.CreateNetworkedGameObject(pivot, strokeID, strokeID); - //tag it as a drawing for ECS + // Make own client's draw strokes grabbable pivot.tag = TagList.interactable; + entityManager.AddComponentData(nAGO.Entity, new DrawingTag { }); var bColl = pivot.GetComponent(); + LineRenderer copiedLR = lineRendCopy.GetComponent(); var color = lineRenderer.startColor; + copiedLR.startColor = color; + copiedLR.endColor = color; copiedLR.widthMultiplier = lineRenderer.widthMultiplier; Bounds newBounds = new Bounds(lineRenderer.GetPosition(0), Vector3.one * 0.01f); + copiedLR.positionCount = 0; for (int i = 0; i < lineRenderer.positionCount; i++) { copiedLR.positionCount++; + copiedLR.SetPosition(i, lineRenderer.GetPosition(i)); - newBounds.Encapsulate(new Bounds(lineRenderer.GetPosition(i), Vector3.one * 0.01f));//lineRenderer.GetPosition(i)); + newBounds.Encapsulate(new Bounds(lineRenderer.GetPosition(i), Vector3.one * 0.01f)); } pivot.transform.position = newBounds.center; - bColl.center = lineRendCopy.transform.position; //newBounds.center;//averageLoc / lr.positionCount;//lr.GetPosition(0)/2; + + bColl.center = lineRendCopy.transform.position; + bColl.size = newBounds.size; lineRendCopy.transform.SetParent(pivot.transform, true); if (sendNetworkCall) { - SendStrokeNetworkUpdate(strokeID, Entity_Type.LineEnd, copiedLR.widthMultiplier, lineRenderer.GetPosition(lineRenderer.positionCount - 1), new Vector4(lineRenderer.startColor.r, lineRenderer.startColor.g, lineRenderer.startColor.b, lineRenderer.startColor.a)); + SendStrokeNetworkUpdate( + strokeID, + Entity_Type.LineEnd, + copiedLR.widthMultiplier, + lineRenderer.GetPosition(lineRenderer.positionCount - 1), + new Vector4(lineRenderer.startColor.r, lineRenderer.startColor.g, lineRenderer.startColor.b, lineRenderer.startColor.a) + ); } pivot.transform.SetParent(userStrokeParent, true); if (UndoRedoManager.IsAlive) + { //save undoing process for ourselves and others UndoRedoManager.Instance.savedStrokeActions.Push(() => { pivot.SetActive(false); - //send network update call for everyone else SendStrokeNetworkUpdate(strokeID, Entity_Type.LineNotRender); }); - + } } - public void CreateExternalClientStrokeInstance(int strokeID, LineRenderer currentLineRenderer) { GameObject pivot = new GameObject("LineRender:" + strokeID, typeof(BoxCollider)); NetworkedGameObject nAGO = NetworkedObjectsManager.Instance.CreateNetworkedGameObject(pivot, strokeID, strokeID, true); - //overide interactable tag when creatingNetworkGameObject since we are not moving drawings only deleting them + // Make other clients' draw strokes grabbable pivot.tag = TagList.interactable; + //tag created drawing object will be useful in the future for having items with multiple tags entityManager.AddComponentData(nAGO.Entity, new DrawingTag { }); @@ -125,10 +145,14 @@ public void CreateExternalClientStrokeInstance(int strokeID, LineRenderer curren Bounds newBounds = new Bounds(currentLineRenderer.GetPosition(0), Vector3.one * 0.01f); for (int i = 0; i < currentLineRenderer.positionCount; i++) + { newBounds.Encapsulate(new Bounds(currentLineRenderer.GetPosition(i), Vector3.one * 0.01f)); + } pivot.transform.position = newBounds.center; + bColl.center = currentLineRenderer.transform.position; + bColl.size = newBounds.size; currentLineRenderer.transform.SetParent(pivot.transform, true); @@ -136,120 +160,114 @@ public void CreateExternalClientStrokeInstance(int strokeID, LineRenderer curren pivot.transform.SetParent(externalStrokeParent, true); } - public void SendStrokeNetworkUpdate(int sID, Entity_Type entityType, float lineWidth = 1, Vector3 curPos = default, Vector4 color = default) { - var drawUpdate = new Draw((int)NetworkUpdateHandler.Instance.client_id, sID - , (int)entityType, lineWidth, curPos, - color); + var drawUpdate = new Draw((int) NetworkUpdateHandler.Instance.client_id, sID, (int) entityType, lineWidth, curPos, color); var drawSer = JsonUtility.ToJson(drawUpdate); KomodoMessage komodoMessage = new KomodoMessage("draw", drawSer); + komodoMessage.Send(); } - - - #region Draw Receive Calls - //Setting up Line Rendering Calls - private Dictionary lineRenderersInQueue = new Dictionary(); - private Dictionary allStrokeIDValidator = new Dictionary(); - - //To avoid duplicating stroke ids because sending different ids states ma - public void Draw_Refresh(string stringData)//Draw newData) + public void Draw_Refresh (string stringData) { Draw newData = JsonUtility.FromJson(stringData); - LineRenderer currentLineRenderer = default; //we start a new line if there is no ID already corresponding to one in the scene if (!allStrokeIDValidator.ContainsKey(newData.strokeId)) { GameObject lineRendCopy = Instantiate(DrawingInstanceManager.Instance.lineRendererContainerPrefab).gameObject; + lineRendCopy.name = "LineR:" + newData.strokeId; lineRendCopy.transform.SetParent(DrawingInstanceManager.Instance.externalStrokeParent, true); + currentLineRenderer = lineRendCopy.GetComponent(); currentLineRenderer.positionCount = 0; allStrokeIDValidator.Add(newData.strokeId, newData.strokeId); + lineRenderersInQueue.Add(newData.strokeId, currentLineRenderer); } - //we get reference to the linenderer we are supposed to be working with + // get reference to the line renderer we are supposed to be working with if (lineRenderersInQueue.ContainsKey(newData.strokeId)) + { currentLineRenderer = lineRenderersInQueue[newData.strokeId]; + } switch (newData.strokeType) { - //Continues A Line - case (int)Entity_Type.Line: - + // Continues a Line + case (int) Entity_Type.Line: + { var brushColor = new Vector4(newData.curColor.x, newData.curColor.y, newData.curColor.z, newData.curColor.w); + currentLineRenderer.startColor = brushColor; + currentLineRenderer.endColor = brushColor; + currentLineRenderer.widthMultiplier = newData.lineWidth; ++currentLineRenderer.positionCount; + currentLineRenderer.SetPosition(currentLineRenderer.positionCount - 1, newData.curStrokePos); break; + } - //Ends A Line A completes its setup - case (int)Entity_Type.LineEnd: - + case (int) Entity_Type.LineEnd: + { ++currentLineRenderer.positionCount; + currentLineRenderer.SetPosition(currentLineRenderer.positionCount - 1, newData.curStrokePos); - //Create external client stroke instance - DrawingInstanceManager.Instance.CreateExternalClientStrokeInstance(newData.strokeId, currentLineRenderer); //new GameObject("LineRender:" + (newData.strokeId), typeof(BoxCollider//; + DrawingInstanceManager.Instance.CreateExternalClientStrokeInstance(newData.strokeId, currentLineRenderer); break; + } - //Deletes a Line - case (int)Entity_Type.LineDelete: - + case (int) Entity_Type.LineDelete: + { if (NetworkedObjectsManager.Instance.networkedObjectFromEntityId.ContainsKey(newData.strokeId)) { if (lineRenderersInQueue.ContainsKey(newData.strokeId)) + { lineRenderersInQueue.Remove(newData.strokeId); + } Destroy(NetworkedObjectsManager.Instance.networkedObjectFromEntityId[newData.strokeId].gameObject); + NetworkedObjectsManager.Instance.networkedObjectFromEntityId.Remove(newData.strokeId); } break; + } - case (int)Entity_Type.LineRender: - + case (int) Entity_Type.LineRender: + { if (NetworkedObjectsManager.Instance.networkedObjectFromEntityId.ContainsKey(newData.strokeId)) + { NetworkedObjectsManager.Instance.networkedObjectFromEntityId[newData.strokeId].gameObject.SetActive(true); + } break; + } - case (int)Entity_Type.LineNotRender: - + case (int) Entity_Type.LineNotRender: + { if (NetworkedObjectsManager.Instance.networkedObjectFromEntityId.ContainsKey(newData.strokeId)) + { NetworkedObjectsManager.Instance.networkedObjectFromEntityId[newData.strokeId].gameObject.SetActive(false); + } break; + } } } - - #endregion - - - - - - - - - - } - - }