int TurnOnSpeaker(bool success) { if (success) { this.GetComponent <Animator>().Play("SpeakerBouncing"); float thisx = transform.position.x; float thisy = transform.position.y; List <GameObject> objects = grid.GetObjectsFromGrid(thisx - 2.0f, thisy, thisx + 2.0f, thisy - 4.0f); // Iterate through objects in speaker range and make them dance if it's an NPC foreach (GameObject o in objects) { InteractableInfo info = o.GetComponent <Interactable>().info; // Check if object is an NPC if (info.GetType() == dummyPersonInfo.GetType()) { PersonInfo newInfo = (PersonInfo)info; // Tell NPC to dance newInfo.Dance(); } } } return(0); }
private static void OnEnterPortal(InteractableInfo info) { #if UNITY_EDITOR Debug.Log("Entered Portal"); #endif //Get PortalComponent PortalData data = World.DefaultGameObjectInjectionWorld.EntityManager .GetComponentData <PortalData>(info.TriggerEntity); //Get PortalInfo MapInfo.Portal portal = MapHolder.MapsInfo[MapEvents.CurrentTypeLoaded].Portals[data.Value]; if (!TryEnterPortal(portal.MapTypeLeadingTo, portal.PortalIdLeadingTo)) { #if UNITY_EDITOR Debug.Log("The Portal ur trying to teleport to doesnt exist yet..."); #endif return; } //Get PortalInfo of other map MapInfo.Portal objectivePortal = MapHolder.MapsInfo[portal.MapTypeLeadingTo].Portals[portal.PortalIdLeadingTo]; //Change Map MapEvents.LoadMap(portal.MapTypeLeadingTo); //Set player position/rotation GlobalEvents.PlayerEvents.SetPlayerPosition(objectivePortal.Position); GlobalEvents.PlayerEvents.SetPlayerRotation(objectivePortal.Rotation); }
int TurnOffSpeaker(bool success) { if (success) { this.GetComponent <Animator>().Play("Idle"); float thisx = transform.position.x; float thisy = transform.position.y; List <GameObject> objects = grid.GetObjectsFromGrid(thisx - 2.0f, thisy, thisx + 2.0f, thisy - 4.0f); // Iterate through objects in speaker range and make them stand still if NPC foreach (GameObject o in objects) { InteractableInfo info = o.GetComponent <Interactable>().info; PersonInfo targetType = new PersonInfo(); // Check if object is an NPC if (info.GetType() == targetType.GetType()) { PersonInfo newInfo = (PersonInfo)info; // Tell NPC to stop dancing newInfo.StopDancing(); } } } return(0); }
private static void OnEnterDoorClosingTrigger(InteractableInfo info) { //Get Door Entity Entity door = manager.GetComponentData <InteractableComponent>(info.TriggerEntity).DoorToOpen; //Activate door manager.SetEnabled(door, true); //Remove Trigger (because its been use so...) manager.DestroyEntity(info.TriggerEntity); }
private static void UseOnInputDispatch(InteractableInfo info) { switch (info.CollisionType) { case InteractableInfo.InteractableCollisionType.OnTriggerEnter: OnEnterInputInteractable(info); break; case InteractableInfo.InteractableCollisionType.OnTriggerExit: OnExitInputInteractable(info); break; } }
private static void OnWalkOverDeepHole(InteractableInfo info) { //Make sure entity has a LifeComponent if (!manager.HasComponent <LifeComponent>(info.CollidedEntity)) { return; } //Get LifeComponent of Entity LifeComponent life = manager.GetComponentData <LifeComponent>(info.CollidedEntity); //Kill and set back life.Life.Value = 0; manager.SetComponentData(info.CollidedEntity, life); }
// Pops up a selection dialog at coords x,y with 1-4 options public void CreateSelection(float x, float y, InteractableInfo item) { DisableSelection(); item.Selected(); selectionGroup.transform.position = new Vector3(x, y, selectionGroupDepth); currentItem = item; currentSelectionCount = item.commandAmount; // Render appropriate boxes/texts if (currentSelectionCount > 0) { selectionName.GetComponent <TextMesh>().text = item.GetName(); selection1.GetComponent <Renderer>().enabled = true; selection1.GetComponent <BoxCollider>().enabled = true; selection1text.GetComponent <Renderer>().enabled = true; selection1text.GetComponent <TextMesh>().text = item.commands[0]; if (item.commands[0] == "Take Snap") { selection1.GetComponent <SpriteRenderer>().sprite = eventSelectionBox; } else { selection1.GetComponent <SpriteRenderer>().sprite = defaultSelectionBox; } } if (currentSelectionCount > 1) { selection2.GetComponent <Renderer>().enabled = true; selection2.GetComponent <BoxCollider>().enabled = true; selection2text.GetComponent <Renderer>().enabled = true; selection2text.GetComponent <TextMesh>().text = item.commands[1]; } if (currentSelectionCount > 2) { selection3.GetComponent <Renderer>().enabled = true; selection3.GetComponent <BoxCollider>().enabled = true; selection3text.GetComponent <Renderer>().enabled = true; selection3text.GetComponent <TextMesh>().text = item.commands[2]; } if (currentSelectionCount > 3) { selection4.GetComponent <Renderer>().enabled = true; selection4.GetComponent <BoxCollider>().enabled = true; selection4text.GetComponent <Renderer>().enabled = true; selection4text.GetComponent <TextMesh>().text = item.commands[3]; } }
private static void OnEnterDoorTrigger(InteractableInfo info) { //Get Door Entity Entity door = manager.GetComponentData <InteractableComponent>(info.TriggerEntity).DoorToOpen; //Remove Door collider manager.RemoveComponent <PhysicsCollider>(door); //TODO Start animation //TODO REMOVE UNDER manager.RemoveComponent <RenderMesh>(door); //Remove Trigger (because its been use so...) manager.DestroyEntity(info.TriggerEntity); }
public static InteractableInfo AddToStages(InteractableTemplate interactable, List <string> sceneNames, String contentPackIdentifier = null) { contentPackIdentifier = contentPackIdentifier ?? Assembly.GetCallingAssembly().GetName().Name; var spawnCard = GenerateSpawnCard(interactable); var interactableDirectorCard = GenerateDirectorCard(interactable, spawnCard); InteractableInfo info = new InteractableInfo(interactableDirectorCard, interactable.interactableCategory, sceneNames, interactable, interactable.multiplayerOnly, interactable.minimumCount); if (interactable.interactablePrefab.GetComponent <NetworkIdentity>()) { NetworkedPrefabs.Add(interactable.interactablePrefab, contentPackIdentifier); } registeredInteractables.Add(info); return(info); }
public override void Selection3() { GetComponent <Animator>().Play("Dancing"); HighlightSquares(); var thisx = transform.position.x; var thisy = transform.position.y; var objects = grid.GetObjectsSurroundingCoords(thisx, thisy); foreach (GameObject obj in objects) { InteractableInfo info = obj.GetComponent <Interactable>().info; PersonInfo targetType = new PersonInfo(); // Check if object is an NPC if (info && info.GetType() == targetType.GetType()) { PersonInfo newInfo = (PersonInfo)info; newInfo.React("Dancing"); } } }
private static void OnExitInputInteractable(InteractableInfo info) { #if UNITY_EDITOR Debug.Log($"Exited InputInteractable of type {info.ObjectType}"); #endif //Remove Object in GameVariables GameVariables.Interactables.PreviousInteractableSelected = GameVariables.Interactables.CurrentInteractableSelected; GameVariables.Interactables.CurrentInteractableSelected = null; //Toggle desired system off switch (info.ObjectType) { case InteractableObjectType.Switch: break; case InteractableObjectType.Door: ToggleSystem <InteractableDoorSystem>(false); break; } }
private static void OnWalkOverWeapon(InteractableInfo info) { //Get WeaponType WeaponType type = manager.GetComponentData <InteractableComponent>(info.TriggerEntity).WeaponType; //Make sure Player doesnt already have this weapon if (GameVariables.Player.PlayerCurrentWeapons.Contains(type)) { #if UNITY_EDITOR Debug.Log($"Player already has weapon {type}, not adding new one..."); #endif } else { //Add to player inventory GameVariables.Player.PlayerCurrentWeapons.Add(type); } //Destroy Interactable manager.DestroyEntity(info.TriggerEntity); }
private static void UseOnEnterZoneDispatch(InteractableInfo info) { //Make sure its an OnEnterTrigger if (info.CollisionType != InteractableInfo.InteractableCollisionType.OnTriggerEnter) { return; } //Use depending on object type switch (info.ObjectType) { case InteractableObjectType.Portal: OnEnterPortal(info); break; case InteractableObjectType.Ammo: OnWalkOverAmmo(info); break; case InteractableObjectType.Door: OnEnterDoorTrigger(info); break; case InteractableObjectType.DoorClosing: OnEnterDoorClosingTrigger(info); break; case InteractableObjectType.Weapon: OnWalkOverWeapon(info); break; case InteractableObjectType.DeepHole: OnWalkOverDeepHole(info); break; case InteractableObjectType.WinningPortal: OnWinningPortal(info); break; } }
private static void OnEnterInputInteractable(InteractableInfo info) { #if UNITY_EDITOR Debug.Log($"Entered InputInteractable of type {info.ObjectType}"); #endif //Set Object in GameVariables GameVariables.Interactables.CurrentInteractableSelected = new GameVariables.Interactables.Interactable { Entity = info.TriggerEntity, ObjectType = info.ObjectType }; //Toggle desired system on switch (info.ObjectType) { case InteractableObjectType.Switch: break; case InteractableObjectType.Door: ToggleSystem <InteractableDoorSystem>(true); break; } }
// Here is the logic for either selecting a path to walk to or an // object to interact with (NPC or item) void ClickAction() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { switch (hit.collider.name) { case "SelectBox1": uiController.ChoiceClicked(1); break; case "SelectBox2": uiController.ChoiceClicked(2); break; case "SelectBox3": uiController.ChoiceClicked(3); break; case "SelectBox4": uiController.ChoiceClicked(4); break; case "PhoneIcon": uiController.CreatePhone(); break; case "DialogBox1": convoController.MakeConversationChoice(1); break; case "DialogBox2": convoController.MakeConversationChoice(2); break; case "DialogBox3": convoController.MakeConversationChoice(3); break; default: Debug.Log(hit.collider.name + " clicked .. no event"); break; } } else // If no hitbox, then check the node clicked on { uiController.WipeUI(); Vector3 point = ray.origin + (ray.direction * 4.5f); // Check the node clicked on to see if there is an action to take on it NodeGrid pointNode = grid.FindClosestNode(point.x, point.y); if (pointNode != null) { if (pointNode.IsEmpty()) { hero.StartPath(pointNode); } else { tempInteractable = pointNode.occupyingObject.GetComponent <Interactable>(); InteractableInfo interactableInfo = tempInteractable.GetComponent <Interactable>().info; if (interactableInfo != null) { uiController.CreateSelection(tempInteractable.transform.position.x, tempInteractable.transform.position.y, interactableInfo); } } } } }
private static void OnWalkOverAmmo(InteractableInfo info) { #if UNITY_EDITOR Debug.Log("Walked Over Ammo"); #endif }
private static void OnWinningPortal(InteractableInfo info) { //Start winning system Unity.Entities.World.DefaultGameObjectInjectionWorld.GetExistingSystem <WinningSystem>().Enabled = true; }