/// <summary> /// Parents the given XR Item's transform to the current User, /// allowing the User to "carry" the XR Item somewhere. /// </summary> /// <param name="item">The XR Item to hold.</param> public void HoldItem(XRItem item) { // Parent the XR Item to the current player Transform t = item.gameObject.transform; t.parent = TeleportalPlayer.Current.transform; }
private void setIsMoving(bool isMoving) { if (selectedItem == null) { isMoving = false; return; } isMovingObject = isMoving; float alpha = 1.0f; if (isMoving) { selectButtonText.text = "Unselect"; // prevent floor from being added if (!selectedItem.gameObject.name.Equals("Floor")) { if (snapGridToggle.isOn) { actuallySelectedObject = new GameObject(); actuallySelectedObject.transform.position = selectedItem.gameObject.transform.position; actuallySelectedObject.transform.SetParent(TeleportalAr.Shared.CurrentCamera.transform); } else { TeleportalAr.Shared.HoldItem(selectedItem); } } alpha = 0.5f; } else { selectButtonText.text = "Select"; if (!snapGridToggle.isOn) { TeleportalAr.Shared.ReleaseItem(selectedItem); } selectedItem.gameObject.transform.SetParent(null); selectedItem.gameObject.transform.SetParent(floor.transform); } for (int i = 0; i < selectedItem.gameObject.transform.childCount; i++) { MeshRenderer renderer = selectedItem.gameObject.transform.GetChild(i).gameObject.GetComponent <MeshRenderer>(); if (renderer != null) { Color oldColor = renderer.material.color; renderer.material.color = new Color(oldColor.r, oldColor.g, oldColor.b, alpha); } } if (!isMovingObject) { selectedItem = null; } }
/// <summary> /// Adds an XR Item to the world scene. /// </summary> /// <param name="id">The unique id of the XR Item.</param> /// <param name="lat">The latitude location of the XR Item.</param> /// <param name="lon">The longitude location of the XR Item.</param> /// <param name="heading">The euler heading (in degrees) of the XR Item, relative to the origin normal.</param> /// <param name="pitch">The euler pitch rotation (in degrees) of the XR Item, relative to the origin normal.</param> public void AddItem(string type, string id, double lat, double y, double lon, double heading, double pitch) { // Get prefab to use string path = "P_" + type; // "P" means "prefab" here GameObject prefab = Resources.Load(path) as GameObject; // Create new XR Item & set its location + rotation GameObject itemGO = Instantiate(prefab); XRItem item = itemGO.GetComponent <XRItem>(); item.SetId(id); item.SetLocation(lat, y, lon); // // TP // makes so placement does not have specific rotation as camera unless placing a camera object if (!type.Contains("camera")) { item.SetRotation(0, 0); } else { item.SetRotation(heading, pitch); } // Reposition item.Reposition(); // Add to dictionaries Items[id] = item; // TP // if (EditorToggleButton.Shared.waitingForDuplication) { EditorToggleButton.Shared.OnDuplication(id, item); EditorToggleButton.Shared.waitingForDuplication = false; // reset } }
public Model3D(string name, XRItem item, string filePath, Model3DType type) { this.name = name; this.XRI = item; this.filePath = filePath; this.type = type; // TODO spawn object if not null }
public void OnClickTakeShot() { XRItem lookingAtItem = XRItemRaycaster.Shared.ItemFocus; if (lookingAtItem != null) { lookingAtItem.gameObject.GetComponent <ComposarCamera>().SaveImage(); } }
public void OnClickDelete() { XRItem item = XRItemRaycaster.Shared.ItemFocus; if (item != null) { TeleportalAr.Shared.DeleteItem(item.Id); } }
/// <summary> /// Releases the given XR Item from the "grip" of the current User, /// and sends the new position to Teleportal. /// </summary> /// <param name="item">The XR Item to release.</param> public void ReleaseItem(XRItem item) { // Clear the parent transform Transform t = item.gameObject.transform; t.parent = null; // Ask Teleportal to move the item MoveItem(item.Id, t.position.x, t.position.y, t.position.z, t.eulerAngles.y, t.eulerAngles.x); }
public void Hold(List <string> args) { string name = args[1]; float pitch = float.Parse(args[2]); float volume = float.Parse(args[3]); float zVal = float.Parse(args[4]); if (TeleportalAr.Shared.Items.ContainsKey(name)) { XRItem xri = TeleportalAr.Shared.Items[name]; if (xri == null) { return; } PlaySound script = xri.transform.GetChild(0).GetComponent <PlaySound>(); if (script == null) { return; } script.audio.pitch = pitch; script.audio.volume = volume; script.zVal = Mathf.Abs(zVal); if (script.mixer != null) { script.mixer.audioMixer.SetFloat("MyExposedParam 1", script.zVal * 10f); script.mixer.audioMixer.SetFloat("MyExposedParam 4", script.zVal * 20f); } switch (name) { case "snare": script.changeDrums(false); Debug.Log("f*** this snare"); break; case "lead": script.changeLead(false); Debug.Log("f*** this lead"); break; default: script.changePitch(false); Debug.Log("f*** this other"); break; } } }
public void OnClickMove() { if (isMovingObject) { // place object setIsMoving(false); } else { // pickup object selectedItem = XRItemRaycaster.Shared.ItemFocus; selectedObjectEulerAngles = selectedItem.transform.eulerAngles; setIsMoving(true); } }
public Shot(string name, XRItem item, Camera camera) { // Set variables this.name = name; this.XRI = item; this.camera = camera; // Create camera if does not exist if (this.camera == null) { this.camera = GameObject.Instantiate(DefaultCameraPrefab).GetComponent <Camera>(); } // Add XRItem if does not exist if (this.XRI == null) { this.XRI = this.camera.gameObject.AddComponent(typeof(XRWorldItem)) as XRItem; } }
public void OnDuplication(string id, XRItem newItem) { XRItem lookingAt = XRItemRaycaster.Shared.ItemFocus; if (lookingAt == null) { return; } Transform selected = lookingAt.gameObject.transform; TeleportalAr.Shared.MoveItem(id, selected.position.x, selected.position.y, selected.position.z, selected.eulerAngles.y, selected.eulerAngles.x); newItem.gameObject.transform.eulerAngles = new Vector3(selected.eulerAngles.x, selected.eulerAngles.y, selected.eulerAngles.z); newItem.gameObject.transform.localScale = new Vector3(selected.localScale.x, selected.localScale.y, selected.localScale.y); selectedItem = lookingAt; selectedObjectEulerAngles = selectedItem.transform.eulerAngles; setIsMoving(true); }
/// <summary> /// Adds an XR Item to the world scene. /// </summary> /// <param name="id">The unique id of the XR Item.</param> /// <param name="lat">The latitude location of the XR Item.</param> /// <param name="lon">The longitude location of the XR Item.</param> /// <param name="heading">The euler heading (in degrees) of the XR Item, relative to the origin normal.</param> /// <param name="pitch">The euler pitch rotation (in degrees) of the XR Item, relative to the origin normal.</param> public void AddItem(string type, string id, double lat, double lon, double heading, double pitch) { // Get prefab to use string path = "P_" + type; // "P" means "prefab" here GameObject prefab = Resources.Load(path) as GameObject; // Create new XR Item & set its location + rotation GameObject itemGO = Instantiate(prefab); XRItem item = itemGO.GetComponent <XRItem>(); item.SetId(id); item.SetLocation(lat, lon); item.SetRotation(heading, pitch); // Reposition item.Reposition(); // Add to dictionaries Items[id] = item; }
private void AddItemWizard() { // Create layout GUILayout.Label("XR Item Wizard", EditorStyles.boldLabel); itemId = EditorGUILayout.TextField("Item ID (string)", itemId); main = EditorGUILayout.ObjectField(main, typeof(GameObject), true) as GameObject; hand = EditorGUILayout.ObjectField(hand, typeof(GameObject), true) as GameObject; tex = EditorGUILayout.ObjectField(tex, typeof(Texture2D), true) as Texture2D; if (GUILayout.Button("Create XR Item +")) { // Check whether every object is filled in the panel if (main != null && hand != null && tex != null) { // Hand hand.name = "H_" + itemId; this.SavePrefab(hand); // Main main.name = "P_" + itemId; main.layer = LayerMask.NameToLayer("XR"); XRItem xri = main.GetComponent <XRItem>(); if (xri == null) { main.AddComponent(typeof(XRItem)); xri = main.GetComponent <XRItem>(); } xri.Type = XRItem.XRItemType.Inventory; xri.Id = itemId; this.SavePrefab(main); // Texture tex.name = "T_" + itemId; this.SaveTexture(tex); } } }
/// <summary> /// Raycasts from the attached camera center, outward. /// </summary> private void Raycast() { // Raycast from attached camera center outward Vector3 position = TeleportalAr.Shared.CurrentCamera.transform.position; Vector3 direction = TeleportalAr.Shared.CurrentCamera.transform.forward; Ray ray = new Ray(position, direction); // CAMERA VERSION - Ray ray = TeleportalAr.Shared.CurrentCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); RaycastHit hit; int layerMask = 1 << LayerMask.NameToLayer("XR"); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { // Test if collided object is an XRItem (has the XRItem component) if (hit.collider.gameObject.GetComponent(typeof(XRItem)) != null) { // Get the raycasted item XRItem item = hit.collider.gameObject.GetComponent <XRItem>(); // If this XRItem already has focus, skip. if (item == ItemFocus) { // return; } // Current focus was changed (if it exists) if (ItemFocus != null) { ItemFocus.LostFocus(); } // Store new item focus ItemFocus = item; // Tell item it got focus ItemFocus.GotFocus(); // Set reticle to ready TeleportalUi.Shared.SetReticle(ReactiveReticle.ReticleType.Ready); // If the item is a player... if (item.Type == XRItem.XRItemType.Player) { // Save their username PlayerFocus = item.Title; // Set the Reactive Reticle to FireMiss (blue) TeleportalUi.Shared.SetReticle(ReactiveReticle.ReticleType.FireMiss); } // If this item was an inventory item... else if (item.Type == XRItem.XRItemType.Inventory) { // Hold item (press E key) if (Input.GetKeyDown(KeyCode.E)) { TeleportalAr.Shared.HoldItem(item); } // Release item & reposition it (press E key again) else if (Input.GetKeyUp(KeyCode.E)) { TeleportalAr.Shared.ReleaseItem(item); } } return; } // Stop here return; } // Current focus was lost (if it exists) if (ItemFocus != null) { ItemFocus.LostFocus(); } // Clear out stored focuses ItemFocus = null; PlayerFocus = null; // Set reticle to not ready TeleportalUi.Shared.SetReticle(ReactiveReticle.ReticleType.NotReady); }
// i guess they never miss, huh? void Update() { EditorMode newEditorMode = EditorMode.None; // they already have an item, so they are moving an object if (selectedItem != null) { // Snap position to actualMovePosition if (snapGridToggle.isOn) { Debug.Log("test"); float GridSnapSize = 0.25f; // meters Vector3 snappedPosition = actuallySelectedObject.transform.position; snappedPosition.x = (float)Math.Round(snappedPosition.x / GridSnapSize) * GridSnapSize; snappedPosition.y = (float)Math.Round(snappedPosition.y / GridSnapSize) * GridSnapSize; snappedPosition.z = (float)Math.Round(snappedPosition.z / GridSnapSize) * GridSnapSize; /* Experiments: * float div = 5.0f; * double k = 0.1; * Debug.Log("actual transfor x " + Math.Abs(actuallySelectedObject.transform.position.x) % 2); * Debug.Log("actual transfor y " + Math.Abs(actuallySelectedObject.transform.position.y) % 2); * Debug.Log("actual transfor z " + Math.Abs(actuallySelectedObject.transform.position.z) % 2); * * Vector3 snappedPosition = new Vector3( * Math.Abs(actuallySelectedObject.transform.position.x) % 2 <= k ? actuallySelectedObject.transform.position.x : selectedItem.gameObject.transform.position.x, * Math.Abs(actuallySelectedObject.transform.position.y) % 2 <= k ? actuallySelectedObject.transform.position.y : selectedItem.gameObject.transform.position.y, * Math.Abs(actuallySelectedObject.transform.position.z) % 2 <= k ? actuallySelectedObject.transform.position.z : selectedItem.gameObject.transform.position.z); * * float absX = Math.Abs(actuallySelectedObject.transform.position.x - actuallySelectedObject.transform.position.x) % div; * float absY = Math.Abs(actuallySelectedObject.transform.position.y - actuallySelectedObject.transform.position.y) % div; * float absZ = Math.Abs(actuallySelectedObject.transform.position.z - actuallySelectedObject.transform.position.z) % div; * print(absX); * print(absY); * print(absZ); * snappedPosition.y = absY < k ? actuallySelectedObject.transform.position.y : selectedItem.gameObject.transform.position.y; * snappedPosition.z = absZ < k ? actuallySelectedObject.transform.position.z : selectedItem.gameObject.transform.position.z; */ // LOCAL ONLY version - selectedItem.gameObject.transform.position = snappedPosition; TeleportalAr.Shared.MoveItem(selectedItem.Id, snappedPosition.x, snappedPosition.y, snappedPosition.z, selectedObjectEulerAngles.y, selectedObjectEulerAngles.x); } else { // TODO: rotation z does not work // TODO: grab mesh and set alpha selectedItem.gameObject.transform.eulerAngles = selectedObjectEulerAngles; } newEditorMode = EditorMode.SelectedObject; } else { XRItem lookingAtItem = XRItemRaycaster.Shared.ItemFocus; // if they are looking at an item and not holding one, determine if it is camera/object if (lookingAtItem != null) { GameObject lookingAtObject = lookingAtItem.gameObject; if (lookingAtObject.transform.name.Contains("camera")) { newEditorMode = EditorMode.Camera; } else { newEditorMode = EditorMode.LookingAtObject; } } else { // if they are not looking at an item, they are looking at none newEditorMode = EditorMode.None; } } setEditorMode(newEditorMode); }
public void SetXRItem(XRItem item) { this.XRI = item; }
private void setEditorMode(EditorMode newMode) { XRItem lookingAtItem = XRItemRaycaster.Shared.ItemFocus; if (currentEditMode == EditorMode.Camera && newMode != EditorMode.Camera) { // disable camera if (highlightedCamera != null) { highlightedCamera.DisableRender(); } } else if (newMode == currentEditMode) { // double check if looking at floor, dup/delete button are deleted if (newMode == EditorMode.LookingAtObject && lookingAtItem != null && !lookingAtItem.gameObject.transform.name.Contains("Floor")) { duplicateButton.gameObject.SetActive(true); deleteButton.gameObject.SetActive(true); } return; } bool showExitButton = false; // selected object controls bool showScaleSlider = false; bool showRotateSlider = false; bool showRotateDropdown = false; bool showScaleDropdown = false; // looking at object controls bool showSelectButton = false; bool showDuplicateButton = false; bool showDeleteButton = false; bool showTakeShotButton = false; bool showRawImage = false; if (newMode == EditorMode.None) { showExitButton = true; } else if (newMode == EditorMode.LookingAtObject) { showSelectButton = true; showExitButton = true; // prevent deleting and duplicating of floor if (lookingAtItem != null && !lookingAtItem.gameObject.transform.name.Contains("Floor")) { showDuplicateButton = true; showDeleteButton = true; } } else if (newMode == EditorMode.SelectedObject) { showSelectButton = true; showScaleSlider = true; showRotateSlider = true; showRotateDropdown = true; showScaleDropdown = true; // set values back if (selectedItem != null) { DropdownValueChange(); ScaleDropdownValueChange(); } if (lookingAtItem != null && lookingAtItem.gameObject.transform.name.Contains("camera")) { highlightedCamera = lookingAtItem.gameObject.GetComponent <ComposarCamera>(); highlightedCamera.EnableRender(); cameraDisplay.texture = lookingAtItem.gameObject.GetComponent <ComposarCamera>().GetRenderTexture(); showRawImage = true; showTakeShotButton = true; } } else if (newMode == EditorMode.Camera) { showSelectButton = true; showDuplicateButton = true; showDeleteButton = true; showRawImage = true; showTakeShotButton = true; if (lookingAtItem != null) { highlightedCamera = lookingAtItem.gameObject.GetComponent <ComposarCamera>(); highlightedCamera.EnableRender(); cameraDisplay.texture = highlightedCamera.GetRenderTexture(); } } scaleSlider.gameObject.SetActive(showScaleSlider); rotateSlider.gameObject.SetActive(showRotateSlider); rotationDropdown.gameObject.SetActive(showRotateDropdown); scaleDropdown.gameObject.SetActive(showScaleDropdown); selectButton.gameObject.SetActive(showSelectButton); duplicateButton.gameObject.SetActive(showDuplicateButton); deleteButton.gameObject.SetActive(showDeleteButton); cameraDisplay.gameObject.SetActive(showRawImage); takeShotButton.gameObject.SetActive(showTakeShotButton); exitButton.gameObject.SetActive(showExitButton); currentEditMode = newMode; }