Commit ba654e33 authored by Haobo38's avatar Haobo38
Browse files

zoom

Make the script find the controller instead of asigning them manually
parent 565631c3
......@@ -150,7 +150,7 @@ Transform:
m_GameObject: {fileID: 49904493}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.8, y: 0.8, z: 0.8}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 403890510}
m_RootOrder: 0
......@@ -1272,8 +1272,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 521988116}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.8, y: 0.8, z: 0.8}
m_LocalPosition: {x: 0, y: 0, z: -0.0000000693}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 382396319}
m_RootOrder: 0
......@@ -2159,7 +2159,7 @@ Transform:
m_GameObject: {fileID: 734326609}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.8, y: 0.8, z: 0.8}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 1707013569}
m_RootOrder: 0
......@@ -3963,7 +3963,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &992863951
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -4186,7 +4186,7 @@ GameObject:
- component: {fileID: 1045741031}
- component: {fileID: 1045741030}
m_Layer: 0
m_Name: Astronaut
m_Name: Earth
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -4201,10 +4201,12 @@ MonoBehaviour:
m_GameObject: {fileID: 1045741029}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6dd9634ad21293a48befa7890f0005dc, type: 3}
m_Script: {fileID: 11500000, guid: bea6283038c0e8941b3dbbc4efc8573f, type: 3}
m_Name:
m_EditorClassIdentifier:
rightHandController: {fileID: 932740382}
xrNode: 5
rightHandRayInteractor: {fileID: 932740381}
--- !u!114 &1045741031
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -4246,10 +4248,34 @@ MonoBehaviour:
m_Calls: []
m_SelectEntered:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
m_MethodName:
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName:
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_SelectExited:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
m_MethodName:
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName:
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_Activated:
m_PersistentCalls:
m_Calls: []
......@@ -4353,7 +4379,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1045741029}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.34, y: 1.09, z: -2.486}
m_LocalPosition: {x: 0.34, y: 1.09, z: -3.658}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
......@@ -4386,7 +4412,7 @@ Transform:
m_GameObject: {fileID: 1202432292}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.8, y: 0.8, z: 0.8}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 1460640532}
m_RootOrder: 0
......@@ -4576,7 +4602,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1258468847
RectTransform:
m_ObjectHideFlags: 0
......@@ -5080,7 +5106,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1572927947}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e5e0030602d62574fae80a2eb74be450, type: 3}
m_Name:
......@@ -5267,6 +5293,196 @@ Canvas:
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!1 &1682379947
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1682379952}
- component: {fileID: 1682379951}
- component: {fileID: 1682379950}
- component: {fileID: 1682379949}
- component: {fileID: 1682379948}
- component: {fileID: 1682379953}
m_Layer: 0
m_Name: Cube (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1682379948
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1682379947}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6052b5178320927468509ae258e7f57e, type: 3}
m_Name:
m_EditorClassIdentifier:
rightHandController: {fileID: 932740382}
xrNode: 5
rightHandRayInteractor: {fileID: 932740381}
--- !u!65 &1682379949
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1682379947}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1682379950
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1682379947}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1682379951
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1682379947}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1682379952
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1682379947}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.5920413, y: 0.5959633, z: 2.8258443}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1682379953
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1682379947}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a35f6cfbfba9b548aaa00d52cfe8a50, type: 3}
m_Name:
m_EditorClassIdentifier:
m_InteractionManager: {fileID: 1948982936}
m_Colliders: []
m_InteractionLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_InteractionLayers:
m_Bits: 1
m_SelectMode: 0
m_CustomReticle: {fileID: 0}
m_FirstHoverEntered:
m_PersistentCalls:
m_Calls: []
m_LastHoverExited:
m_PersistentCalls:
m_Calls: []
m_HoverEntered:
m_PersistentCalls:
m_Calls: []
m_HoverExited:
m_PersistentCalls:
m_Calls: []
m_FirstSelectEntered:
m_PersistentCalls:
m_Calls: []
m_LastSelectExited:
m_PersistentCalls:
m_Calls: []
m_SelectEntered:
m_PersistentCalls:
m_Calls: []
m_SelectExited:
m_PersistentCalls:
m_Calls: []
m_Activated:
m_PersistentCalls:
m_Calls: []
m_Deactivated:
m_PersistentCalls:
m_Calls: []
m_OnFirstHoverEntered:
m_PersistentCalls:
m_Calls: []
m_OnLastHoverExited:
m_PersistentCalls:
m_Calls: []
m_OnHoverEntered:
m_PersistentCalls:
m_Calls: []
m_OnHoverExited:
m_PersistentCalls:
m_Calls: []
m_OnSelectEntered:
m_PersistentCalls:
m_Calls: []
m_OnSelectExited:
m_PersistentCalls:
m_Calls: []
m_OnSelectCanceled:
m_PersistentCalls:
m_Calls: []
m_OnActivate:
m_PersistentCalls:
m_Calls: []
m_OnDeactivate:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1690936500
GameObject:
m_ObjectHideFlags: 0
......@@ -5292,7 +5508,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1690936500}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0.578, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 382396319}
......@@ -5505,7 +5721,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1753898962
Transform:
m_ObjectHideFlags: 0
......@@ -6362,7 +6578,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -0.0005216599, y: 0.009315492}
m_AnchoredPosition: {x: -0.0005216599, y: -0.131}
m_SizeDelta: {x: 1, y: 0.3}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2065384270
......@@ -8461,7 +8677,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &7188185705714248994
MonoBehaviour:
m_ObjectHideFlags: 0
......
This diff is collapsed.
fileFormatVersion: 2
guid: 7785cbc8e9e0fc14f947a0886608e9f2
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -29,6 +29,8 @@ public class ImportPrefabs : MonoBehaviour
m_Joint = rightHandController.transform.GetComponent<FixedJoint>();
Debug.Log(m_Joint);
m_GOName = transform.name;
// print("m_GOName " + m_GOName);
m_ObjPath = "Prefabs" + m_GOName + ".obj";
......@@ -62,32 +64,32 @@ public class ImportPrefabs : MonoBehaviour
Model = (GameObject)Resources.Load("Prefabs/Astronaut", typeof(GameObject));
Model = (GameObject)Resources.Load("Prefabs/Earth", typeof(GameObject));
Instantiate(Model);
Model.name = transform.name;
Model.transform.GetChild(0).transform.position = rightHandController.transform.position + 2 * rightHandController.transform.forward;
Model.transform.GetChild(0).transform.localScale = new Vector3(1, 1, 1);
Model.transform.GetChild(0).transform.position = rightHandController.transform.position + 20 * rightHandController.transform.forward;
// Model.transform.GetChild(0).transform.localScale = new Vector3(1, 1, 1);
Model.transform.GetChild(0).gameObject.AddComponent<XRGrabInteractable>();
Model.transform.GetChild(0).gameObject.AddComponent<Rigidbody>();
Model.transform.GetChild(0).gameObject.AddComponent<ModelPositionFix>();
Model.transform.GetChild(0).gameObject.AddComponent<BoxCollider>();
Model.transform.GetChild(0).GetComponent<Rigidbody>().useGravity = false;
Rigidbody targetBody = Model.transform.GetChild(0).GetComponent<Rigidbody>();
m_Joint.connectedBody = targetBody;
Vector3 GOSize = Model.transform.GetChild(0).GetComponent<BoxCollider>().bounds.size;
/* Vector3 GOSize = Model.transform.GetChild(0).GetComponent<BoxCollider>().bounds.size;
float x = 1 / GOSize.x;
Model.transform.GetChild(0).transform.localScale = new Vector3(x, x, x);
Model.transform.GetChild(0).transform.localScale = new Vector3(x, x, x);*/
Model.transform.GetChild(0).gameObject.AddComponent<XRGrabInteractable>();
}
public void OnSelectExit()
......
......@@ -14,7 +14,8 @@ public class ModelPositionFix : MonoBehaviour
[SerializeField] XRBaseController leftHandController = null;
// private InputDevice deviceLeftHand;
// private InputDevice deviceRightHand;
float x;
private float x;
private bool triggerButtonAction = false;
[SerializeField]
private XRNode xrNode = XRNode.LeftHand;
......@@ -61,26 +62,26 @@ public class ModelPositionFix : MonoBehaviour
/* foreach (var dev in devices)
foreach (var dev in devices)
{
Debug.Log(string.Format("Device found with name '{0}' and role '{1}'", dev.name, dev.isValid.ToString()));
}*/
if(!device.isValid)
}
if(!device.isValid)
{
Debug.Log("getdevice failed");
GetDevice();
}
/*
List<InputFeatureUsage> features = new List<InputFeatureUsage>();
device.TryGetFeatureUsages(features);
foreach ( var feature in features )
{
Debug.Log("feature " + feature.name + " type " + feature.type);
}*/
}
bool triggerButtonAction = false;
if(device.TryGetFeatureValue(CommonUsages.triggerButton,out triggerButtonAction)&& triggerButtonAction)
{
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.XR;
using System.Linq;
public class NewImportPrefabs : MonoBehaviour
{
[SerializeField] XRBaseController rightHandController = null;
[SerializeField]
private XRNode xrNode = XRNode.RightHand;
private List<InputDevice> devices = new List<InputDevice>();
private InputDevice device;
private string m_GOName = null;
private string m_ObjPath = null;
private FixedJoint m_Joint = null;
private GameObject Model;
private Vector3 rightHandControllerPosition;
[SerializeField] XRRayInteractor rightHandRayInteractor = null;
private RaycastHit hit;
bool triggerButtonAction = false;
bool triggerButtonbeforeAction = false;
void GetDevice()
{
InputDevices.GetDevicesAtXRNode(xrNode, devices);
device = devices.FirstOrDefault();
}
private void Awake()
{
m_Joint = rightHandController.transform.GetComponent<FixedJoint>();
m_GOName = transform.name;
m_ObjPath = "Prefabs/" + m_GOName;
}
/* void Update()
{
if (!device.isValid)
{
Debug.Log("getdevice failed");
GetDevice();
}
if (device.TryGetFeatureValue(CommonUsages.triggerButton, out triggerButtonAction) && triggerButtonAction)
{
Debug.Log("triggerButton pressed");
}
}*/
private void LateUpdate()
{
rightHandRayInteractor.TryGetCurrent3DRaycastHit(out hit);
if (hit.transform != null)
{
rightHandControllerPosition = hit.transform.position;
}
if (!device.isValid)
{
Debug.Log("getdevice failed");
GetDevice();
}
device.TryGetFeatureValue(CommonUsages.triggerButton, out triggerButtonAction);
if (triggerButtonAction == true && triggerButtonbeforeAction == false)
{
if (device.TryGetFeatureValue(CommonUsages.triggerButton, out triggerButtonAction) && triggerButtonAction)
OnSelectEnter();
Debug.Log("testing selectEnter funcion OK");
}
if (triggerButtonAction == false && triggerButtonbeforeAction == true)
{
// OnSelectExit();
Debug.Log("testing selectExit funcion OK");
}
triggerButtonbeforeAction = triggerButtonAction;
}
public void OnSelectEnter()
{
Model = (GameObject)Resources.Load("Prefabs/Earth", typeof(GameObject));
Instantiate(Model);
Model.name = transform.name;
Model.transform.GetChild(0).transform.position = rightHandControllerPosition;
// Model.transform.GetChild(0).transform.localScale = new Vector3(1, 1, 1);
// Model.transform.GetChild(0).gameObject.AddComponent<Rigidbody>();
// Model.transform.GetChild(0).gameObject.AddComponent<XRGrabInteractable>();
// Model.transform.GetChild(0).gameObject.AddComponent<ModelPositionFix>();
// Model.transform.GetChild(0).gameObject.AddComponent<BoxCollider>();
Model.transform.GetChild(0).GetComponent<Rigidbody>().useGravity = false;
Rigidbody targetBody = Model.transform.GetChild(0).GetComponent<Rigidbody>();
m_Joint.connectedBody = targetBody;
/* Vector3 GOSize = Model.transform.GetChild(0).GetComponent<BoxCollider>().bounds.size;
float x = 1 / GOSize.x;
Model.transform.GetChild(0).transform.localScale = new Vector3(x, x, x);*/
}
public void OnSelectExit()
{
// Remove the fixed joint
Rigidbody targetBody = Model.transform.GetChild(0).GetComponent<Rigidbody>();
m_Joint.connectedBody = null;
// GetComponent<Image>().color = new Color32(255, 255, 255, 100);
Debug.Log("select exited");
}
}
fileFormatVersion: 2
guid: bea6283038c0e8941b3dbbc4efc8573f
MonoImporter: