void GenerateVuMarkBorderOutline(VuMarkBehaviour vumarkBehaviour) { this.lineRenderer = vumarkBehaviour.GetComponentInChildren <LineRenderer>(); if (this.lineRenderer == null) { Debug.Log("<color=green>Existing Line Renderer not found. Creating new one.</color>"); GameObject vumarkBorder = new GameObject("VuMarkBorder"); vumarkBorder.transform.SetParent(vumarkBehaviour.transform); vumarkBorder.transform.localPosition = Vector3.zero; vumarkBorder.transform.localEulerAngles = Vector3.zero; vumarkBorder.transform.localScale = new Vector3( 1 / vumarkBehaviour.transform.localScale.x, 1, 1 / vumarkBehaviour.transform.localScale.z); this.lineRenderer = vumarkBorder.AddComponent <LineRenderer>(); this.lineRenderer.enabled = false; this.lineRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; this.lineRenderer.receiveShadows = false; // This shader needs to be added in the Project's Graphics Settings, // unless it is already in use by a Material present in the project. this.lineRenderer.material.shader = Shader.Find("Unlit/Color"); this.lineRenderer.material.color = Color.clear; this.lineRenderer.positionCount = 4; this.lineRenderer.loop = true; this.lineRenderer.useWorldSpace = false; Vector2 vumarkSize = vumarkBehaviour.GetSize(); AnimationCurve curve = new AnimationCurve(); curve.AddKey(0.0f, 1.0f); curve.AddKey(1.0f, 1.0f); this.lineRenderer.widthCurve = curve; this.lineRenderer.widthMultiplier = 0.003f; float vumarkExtentsX = (vumarkSize.x * 0.5f) + (this.lineRenderer.widthMultiplier * 0.5f); float vumarkExtentsZ = (vumarkSize.y * 0.5f) + (this.lineRenderer.widthMultiplier * 0.5f); this.lineRenderer.SetPositions(new Vector3[] { new Vector3(-vumarkExtentsX, 0.001f, vumarkExtentsZ), new Vector3(vumarkExtentsX, 0.001f, vumarkExtentsZ), new Vector3(vumarkExtentsX, 0.001f, -vumarkExtentsZ), new Vector3(-vumarkExtentsX, 0.001f, -vumarkExtentsZ) }); } }
/// <summary> /// Register a callback which is invoked whenever a VuMark-result is newly detected which was not tracked in the frame before /// </summary> /// <param name="vumarkBehaviour"></param> public void OnVuMarkBehaviourDetected(VuMarkBehaviour vumarkBehaviour) { VLog.Log("cyan", "VuMarkHandler.OnVuMarkBehaviourDetected(): " + vumarkBehaviour.TrackableName); // The GameObject with the VuMarkBehaviour component attached gets duplicated whenever // a new VuMark is detected and the augmentations get attached to the new object. // Since this GameObject contains a Canvas, we need to reset the Camera reference when // duplicating, otherwise the MRTK will throw an exception. The MRTK then assigns the // appropriate Camera reference to the Canvas. vumarkBehaviour.GetComponentInChildren <Canvas>().worldCamera = null; GenerateVuMarkBorderOutline(vumarkBehaviour); ToggleRenderers(vumarkBehaviour.gameObject, true); // Check for existance of previous augmentations and delete before instantiating new ones. DestroyChildAugmentationsOfTransform(vumarkBehaviour.transform); StartCoroutine(OnVuMarkTargetAvailable(vumarkBehaviour)); }