void GrabAttach(AttachData data) { otherGun.OtherGunGrabbed(data.obj); GetNewAnchor(data.pos, data.obj); state = State.grabing; rb.isKinematic = true; grabOffset = rb.transform.position - data.pos; lastPos = spawn.position; grabAnimator.SetBool("IsGrabbing", true); }
void GeneratorAttach(ref ECS_AnimatorSpawner spawnerData, EntityManager dstManager) { ECS_Provider provider = Prefab.GetComponent <ECS_Provider>(); spawnerData.AttachCount = provider.AttachDatas.Length; List <Entity> LODList = new List <Entity>(); for (int attach = 0; attach < spawnerData.AttachCount; attach++) { AttachData attachData = provider.AttachDatas[attach]; GeneratorLOD(ref spawnerData, dstManager, LODList, attach, attachData); } spawnerData.AttachLOD = GeneratorEntityArr(LODList.ToArray()); }
void Extend(AttachData data) { if (otherGun.grabed != null) { if (data.obj == otherGun.grabed.transform) { return; } } if (!hasDisabledTut) { Destroy(FindObjectOfType <TutText>().gameObject); hasDisabledTut = true; } // notify bomb Bomb possibleBomb = data.obj.GetComponent <Bomb>(); if (possibleBomb != null) { possibleBomb.DisableGrabText(); } state = State.extending; grappleSound.Play(); GetNewAnchor(data.pos, data.obj); lr.enabled = true; grabber.parent = null; UpdateGrappler(0f); // calculate timer grabberTimer = 0f; float dist = (grabed.GetAnchorPos() - spawn.position).magnitude; grabberTime = dist / grabberSpeed; }
void Extend(AttachData data) { if (otherGun.grabed != null) { if (data.obj == otherGun.grabed.transform) { return; } } state = State.extending; GetNewAnchor(data.pos, data.obj); lr.enabled = true; grabber.parent = null; UpdateGrappler(0f); // calculate timer grabberTimer = 0f; float dist = (grabed.GetAnchorPos() - spawn.position).magnitude; grabberTime = dist / grabberSpeed; }
void GrabAttach(AttachData data) { otherGun.OtherGunGrabbed(data.obj); GetNewAnchor(data.pos, data.obj); if (data.obj.tag == "Bomb") { AttachBomb(data.obj.GetComponent <Bomb>()); } else { state = State.grabing; holdSound.Stop(); rb.isKinematic = true; grabOffset = rb.transform.position - data.pos; lastPos = spawn.position; grabAnimator.SetBool("IsGrabbing", true); } hand.SetHaptic(HandController.HapticType.grab); }
void Update() { if (SteamVR_Input._default.inActions.GrabPinch.GetStateDown(inputSources)) { if (state == State.detached) { // grab takes priority AttachData?target = GetGrabTarget(); if (target.HasValue) { GrabAttach(target.Value); } else { AttachData data = GetGrappleTarget(); if (data.obj != null) { Extend(data); } } } } if (state != State.retracting && SteamVR_Input._default.inActions.GrabPinch.GetStateUp(inputSources)) { Detach(); } if (state == State.extending) { grabberTimer += Time.deltaTime; if (grabberTimer > grabberTime) { GrappleAttach(); } else { UpdateGrappler(grabberTimer / grabberTime); } } else if (state == State.retracting) { grabberTimer -= Time.deltaTime * 2f; if (grabberTimer <= 0f) { FinishRetract(); } else { UpdateGrappler(grabberTimer / grabberTime); } } else if (state == State.grappling) { UpdateGrappler(1f); Vector3 diff = grabed.GetAnchorPos() - spawn.position; float dist = diff.magnitude; float distDiff = dist - lastDist; float forceMul = 1f; if (distDiff > 0) { forceMul = 1f + (distDiff * swingMultiplier); // to make it so that the force is greater when you are on the upside of a swing } if (dist > grabTolerence * 2f) { Vector3 force = diff.normalized * swingForce * forceMul * Time.deltaTime; rb.AddForce(force); grabed.AddForce(-force); } lastDist = dist; AttachData?possibleGrab = GetGrabTarget(); if (possibleGrab.HasValue) { FinishRetract(); GrabAttach(possibleGrab.Value); } } else if (state == State.grabing) { Vector3 handDiff = lastPos - spawn.position; Vector3 targetPos = grabed.GetAnchorPos() + grabOffset + handDiff; // test to see if the move would put the player into an object Vector3 capsuleOffset = new Vector3(capsule.center.x, 0f, capsule.center.z); Collider[] colls = Physics.OverlapCapsule(targetPos + capsuleOffset + Vector3.up * (capsule.radius), targetPos + capsuleOffset + Vector3.up * (capsule.height - capsule.radius), capsule.radius, collidableLayers); if (colls.Length > 0) { RecenterPlayer(true); } else // position valid { grabOffset += handDiff; rb.transform.position = grabOffset + grabed.GetAnchorPos(); RecenterPlayer(); } lastPos = spawn.position; // check to make sure still on wall AttachData?possibleGrab = GetGrabTarget(); if (!possibleGrab.HasValue) { Detach(); return; } // apply downward force to object we are grabbing grabed.AddForce(rb.mass * Physics.gravity); } if (otherGun.state != State.grabing && state != State.grabing) { RecenterPlayer(); } }
void GeneratorSubLOD(ref ECS_AnimatorSpawner spawnData, ref Entity output, ref Entity hostEntity, int lod, EntityManager dstManager, int attachIndex, AttachData attachData) { var treeType = dstManager.CreateArchetype( typeof(RenderMesh), // Rendering mesh typeof(LocalToWorld), // Needed for rendering typeof(Translation), // Transform position typeof(Rotation), // Transform rotation typeof(Scale), // Transform scale (version with X, Y and Z) typeof(RenderBounds), //Bounds to tell the Renderer where it is typeof(MeshLODComponent) //The actual LOD Component ); Entity childOfGroup = dstManager.CreateEntity(treeType); List <Mesh> lodMesh = new List <Mesh>(); lodMesh.Add(attachData.LODMesh[0]); if (attachData.LODMesh.Length > 0) { lodMesh.Add(attachData.LODMesh[1]); } //需要创建lod,且有lod数据 if (lodMesh.Count > 1) { List <Material> lodMaterial = new List <Material>(); for (int i = 0; i < lodMesh.Count; i++) { lodMaterial.Add(attachData.DrawMaterial); } float4 lodDistances = LODDistance;//new float4(10f, 10000f, 10000f, 10000f); float3 position = new float3(0, 5, 0); CreateLODEntity(ref childOfGroup, ref hostEntity, lod, dstManager, lodMesh.Count, lodMesh.ToArray(), lodMaterial.ToArray(), lodDistances, position); } output = childOfGroup; }
void GeneratorLOD(ref ECS_AnimatorSpawner spawnerData, EntityManager dstManager, List <Entity> lodEntityList, int attachIndex, AttachData attachData) { dstManager.AddComponentData(spawnerData.Prefab, new MeshLODGroupComponent() { LODDistances0 = LODDistance, LODDistances1 = LODDistance, LocalReferencePoint = float3.zero }); for (int lod = 0; lod < 2; lod++) { Entity lodEntity = Entity.Null; GeneratorSubLOD(ref spawnerData, ref lodEntity, ref spawnerData.Prefab, lod, dstManager, attachIndex, attachData); lodEntityList.Add(lodEntity); } }