// Start is called before the first frame update void Start() { _deskzone = FindObjectOfType <Deskzone>(); _warpzoneManager = FindObjectOfType <WarpzoneManager>(); _virtualCity = FindObjectOfType <VirtualCity>(); _mainCamera = Camera.main; }
void Start() { #if UNITY_WSA _interactionManager = FindObjectOfType <InteractionManager>(); _map = FindObjectOfType <Map>(); _warpzoneManager = FindObjectOfType <WarpzoneManager>(); _sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); _sphere.transform.localScale = Vector3.one * _interactionManager.InteractionSphereScale; _sphere.name = "InteractionOrb " + gameObject.name; _sphere.GetComponent <SphereCollider>().isTrigger = true; _orbMeshRenderer = _sphere.GetComponent <MeshRenderer>(); var rigidbody = _sphere.AddComponent <Rigidbody>(); rigidbody.useGravity = false; var manipulator = _sphere.AddComponent <ObjectManipulator>(); manipulator.ReleaseBehavior = 0; manipulator.HostTransform = _sphere.transform; manipulator.ManipulationType = ManipulationHandFlags.OneHanded; manipulator.OnManipulationStarted.AddListener(eventData => { IsInteractedWith = true; }); manipulator.OnManipulationEnded.AddListener(eventData => { IsInteractedWith = false; StartCoroutine(StopMovement()); IEnumerator StopMovement() { yield return(null); _sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; _sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } }); _sphere.AddComponent <NearInteractionGrabbable>(); var worldConstrain = _sphere.AddComponent <FixedRotationToWorldConstraint>(); worldConstrain.TargetTransform = _sphere.transform; worldConstrain.HandType = ManipulationHandFlags.OneHanded; if (Target is Warpzone) { manipulator.OnManipulationStarted.AddListener(eventdata => { _warpzoneManager.ActiveWarpzone = (Warpzone)Target; }); manipulator.OnManipulationEnded.AddListener(eventData => { var localPos = _map.Scaler.transform.InverseTransformPoint(_sphere.transform.position); localPos.y = 0; ((Warpzone)Target).LocalPosition = localPos; }); } else if (Target is PlayerAvatar) { _lineRenderer = gameObject.AddComponent <LineRenderer>(); _lineRenderer.useWorldSpace = true; _lineRenderer.material = _map.LineMaterial; _lineRenderer.material.color = Color.blue; _lineRenderer.startWidth = 0.01f; _lineRenderer.endWidth = 0.01f; _renderLine = false; _lineRenderer.enabled = _renderLine; var map = FindObjectOfType <Map>().GetComponentInParent <DefaultTrackableEventHandler>(); map.OnTargetFound.AddListener(() => { StartCoroutine(UpdateLineRenderer()); IEnumerator UpdateLineRenderer() { yield return(null); _lineRenderer.enabled = _renderLine; } }); manipulator.OnManipulationStarted.AddListener(eventData => { _renderLine = true; _lineRenderer.enabled = _renderLine; _lineRenderer.material.color = Color.green; }); manipulator.OnManipulationEnded.AddListener(eventData => { var localPos = _map.Scaler.transform.InverseTransformPoint(_sphere.transform.position); localPos.y = 0; _lineRenderer.material.color = Color.blue; var options = new RaiseEventOptions(); options.TargetActors = new[] { Target.GetComponent <PhotonView>().OwnerActorNr }; PhotonNetwork.RaiseEvent((byte)TargetManager.EventCode.NAVIGATION, localPos, options, SendOptions.SendReliable); }); } #endif }