bool LoadChair() { StaticMeshScript.ClearHintLocators(); GameObject[] chairs = StaticMeshScript.GetSemanticObjects(SceneUnderstandingObjectType.CHAIR); if (chairs.Length == 0) { return(false); } for (int i = 0; i < chairs.Length; i++) { GameObject go = chairs[i]; ViveSR_Experience_Chair chair = go.AddComponent <ViveSR_Experience_Chair>(); ViveSR_SceneUnderstanding.SceneObject obj = ViveSR_SceneUnderstanding.GetCorrespondingSceneObject(go.name); if (obj.objTypeID == SceneUnderstandingObjectType.NONE) { Debug.Log("[SemanticSegmentation] Cannot find corresponding game object."); return(false); } chair.CreateChair(obj.positions[0], obj.forward); //move chair MR_Chairs.Add(chair); } return(true); }
public void StartAnimationSequence_ChairNotFound(ViveSR_Experience_Chair facingChair)//turn and look at player { ActionSequence = ViveSR_Experience_ActionSequence.CreateActionSequence(gameObject); ActionSequence.AddAction(() => Walk(new Vector3(facingChair.transform.position.x, 0, facingChair.transform.position.z) + facingChair.transform.forward * 2, ActionSequence.ActionFinished)); ActionSequence.AddAction(() => Turn(-facingChair.transform.forward, ActionSequence.ActionFinished)); ActionSequence.StartSequence(); }
public void StartAnimationSequence_ChairFound(ViveSR_Experience_Chair chair)//go sit on chair { this.chair = chair; ResetCharacter(); Vector3 FloorPosition = new Vector3(chair.transform.position.x, 0f, chair.transform.position.z) + chair.transform.forward * 0.5f; FloorPosition = new Vector3(FloorPosition.x, 0f, FloorPosition.z); // clear height ActionSequence = ViveSR_Experience_ActionSequence.CreateActionSequence(gameObject); // if (Vector3.Distance(FloorPosition, NPCRef.transform.position) > 0.1f) // ActionSequence.AddAction(() => Turn((FloorPosition - NPCRef.transform.position) / Vector3.Distance(FloorPosition, NPCRef.transform.position), ActionSequence.ActionFinished)); ActionSequence.AddAction(() => Walk(FloorPosition, ActionSequence.ActionFinished)); ActionSequence.AddAction(() => Turn(chair.transform.forward, ActionSequence.ActionFinished)); ActionSequence.AddAction(() => Sit(chair.transform.position, ActionSequence.ActionFinished)); ActionSequence.StartSequence(); }
void AssignClosestChair(ViveSR_Experience_NPCAnimationRef NPCRef, ViveSR_Experience_Chair OldChair = null) { if (NPCRef.NPCAnimController.isActing) { return; } float minDist = 999; ViveSR_Experience_Chair targetChair = null; for (int i = 0; i < Chairs.Count; i++) { bool isChairOccupied = Chairs[i].Occupier != ViveSR_Experience_Chair.OccupierType.None; if (isChairOccupied) { continue; } float distToNpc = Vector3.Distance(NPCRef.transform.position, Chairs[i].transform.position); if (distToNpc < minDist) { minDist = distToNpc; targetChair = Chairs[i]; } } if (targetChair != null) { targetChair.AssignFairyAsOccupier(NPCRef); NPCRef.NPCAnimController.StartAnimationSequence_ChairFound(targetChair); } else { if (OldChair != null) { NPCRef.NPCAnimController.StartAnimationSequence_ChairNotFound(OldChair); } } }
void LoadChair() { foreach (ViveSR_Experience_Chair MR_Chair in MR_Chairs) { Destroy(MR_Chair.gameObject); } MR_Chairs.Clear(); foreach (GameObject go in HintLocators) { Destroy(go); } HintLocators.Clear(); List <SceneUnderstandingObjects.Element> ChairElements = StaticMeshScript.GetSegmentationInfo(SceneUnderstandingObjectType.CHAIR); for (int i = 0; i < ChairElements.Count; i++) { GameObject go = new GameObject("MR_Chair" + i, typeof(ViveSR_Experience_Chair)); ViveSR_Experience_Chair chair = go.GetComponent <ViveSR_Experience_Chair>(); chair.CreateChair(new Vector3(ChairElements[i].position[0].x, ChairElements[i].position[0].y, ChairElements[i].position[0].z), new Vector3(ChairElements[i].forward.x, ChairElements[i].forward.y, ChairElements[i].forward.z)); MR_Chairs.Add(chair); } }
void YieldToPlayer() { //Player walks away from a chair; if (PlayersChair != null && Vector3.Distance(ViveSR_Experience.instance.PlayerHeadCollision.transform.position, PlayersChair.transform.position) > 1) { PlayersChair.RemoveOccupier(); PlayersChair = null; } //player find a closet chair within a distance float minDist = 999; ViveSR_Experience_Chair targetChair = null; for (int i = 0; i < Chairs.Count; i++) { Vector3 chairPos = Chairs[i].transform.position; Vector3 playerHeadPos = ViveSR_Experience.instance.PlayerHeadCollision.transform.position; float dist = Vector3.Distance(playerHeadPos, new Vector3(chairPos.x, playerHeadPos.y, chairPos.z)); if (dist < minDist) { minDist = dist; } else { continue; // this chair isn't the closest } if (minDist >= 1f) { continue; // the closest chair is too far } if (PlayersChair == Chairs[i]) { continue; // player is already using the closet chair. } targetChair = Chairs[i]; } if (targetChair == null) { return; } //NPC on the chair yields to the player if (targetChair.OccupyingNPC != null) { if (targetChair.OccupyingNPC.NPCAnimController.isActing) { return; } if (PlayersChair != null) { PlayersChair.RemoveOccupier(); } ViveSR_Experience_NPCAnimationRef NPCToYield = targetChair.OccupyingNPC; PlayersChair = targetChair; PlayersChair.AssignPlayerAsOccupier(); NPCToYield.NPCAnimController.Stand(() => AssignClosestChair(NPCToYield, targetChair)); } else { if (PlayersChair != null) { PlayersChair.RemoveOccupier(); } PlayersChair = targetChair; PlayersChair.AssignPlayerAsOccupier(); } }