protected override void SetInitialValues() { _animatorVariables = new PlayerAnimatorVariables(); _cinemachine = GameObject.FindObjectOfType <CinemachineVirtualCamera>(); _uIManager = GameObject.FindObjectOfType <UIManager>(); _playerStateManage = GameObject.FindObjectOfType <PlayerStateManager>(); _activePlayerUI = GameObject.FindObjectOfType <ActivePlayersUIComponent>(); _animator = this.GetComponent <Animator>(); _audioComponent = this.GetComponent <AudioComponent>(); _damageDealerComponent = this.GetComponent <DamageDealerComponent>(); _damageTakerComponent = this.GetComponent <DamageTakerComponent>(); _miniMapComponent = GameObject.FindObjectOfType <MiniMapComponent>(); if (_canMoveByClick) { _movementMouseComponent = this.GetComponent <MovementMouseComponent>(); } if (_canInteract) { _interactableComponent = this.GetComponent <InteractableComponent>(); } if (_canPoop) { _stomachComponent = this.GetComponent <StomachComponent>(); } }
// Update is called once per frame void Update() { // Movement float xInput = Input.GetAxis("Horizontal"); Vector2 currentVelocity = new Vector2(xInput * velocity, rb.velocity.y); rb.velocity = currentVelocity; if (Input.GetButtonDown("Jump") && grounded) { rb.velocity += Vector2.up * jumpForce; grounded = false; mainAudio.clip = jumpClip; mainAudio.Play(); } if (rb.velocity.y <= gravityTreshold) { rb.velocity += Vector2.down * gravityMultiplier; } // Interaction if (Input.GetButtonDown("Interact") && interaction != null) { InteractableComponent inte = interaction.gameObject.GetComponent <InteractableComponent>(); inte.InteractStart(); } if (Input.GetButtonUp("Interact") && interaction != null) { InteractableComponent inte = interaction.gameObject.GetComponent <InteractableComponent>(); inte.InteractStop(); } }
public bool StartCombat(DamageDealerComponent damageDealer) { if (!_readyToCombat) { return(false); } PlayerStructure playerStructure = _playerState.GetActivePlayerStructure(); InteractableComponent interactableComponent = playerStructure.GetInteractableComponent(); if (interactableComponent is null) { return(false); } if (!interactableComponent.CheckIfCanAtack()) { return(false); } damageDealer.event_AlertAttack.Invoke(); interactableComponent.SetInteractableState(EnumInteractableState.Atack, this.GetInstanceID()); // Go to the correct position to attack playerStructure.GetMovementMouseComponent().ObjectGoTo(this.transform.position, _colliderToStopMovement.GetInstanceID()); return(true); }
public override void Initialize(Transform[] objects) { // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance InventoryComponent invC = objects[i].GetComponent <InventoryComponent>(); InputComponent inpC = objects[i].GetComponent <InputComponent>(); InteractorComponent intC = objects[i].GetComponent <InteractorComponent>(); MovementComponent movC = objects[i].GetComponent <MovementComponent>(); if (invC && inpC && intC && movC) { tmpFilters.Add(new Filter(index, objects[i].gameObject, invC, inpC, intC, movC)); } } filters = tmpFilters.ToArray(); environmentComponent = GetComponentInChildren <EnvironmentComponent>(); transportableComponent = GetComponentInChildren <CartComponent>(); cartInteractable = transportableComponent.GetComponent <InteractableComponent>(); lightComponent = GetComponentInChildren <LightComponent>(); //villagerComponent = GetComponentInChildren<VillagerComponent>(); travelComponent = GetComponentInChildren <TravelComponent>(); treeComponents = GetComponentsInChildren <CollectibleComponent>(); goapSystem = GetComponent <GOAPSystem>(); navMeshComponent = playerGO.GetComponent <NavMeshComponent>(); }
private void DisplayInteractUIElement(InteractableComponent interactable) { string interactString = "hold [A]" + interactable.interactionString; player.uiComponent.interactPrompt.interactTXT.text = interactString; player.eventComponent.OnDisplayUIElement(player.uiComponent.interactPrompt.gameObject, false); }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _isAttacking = false; _damageDealerComponent = animator.GetComponentInParent <DamageDealerComponent>(); _interactableComponent = animator.GetComponentInParent <InteractableComponent>(); _damageTakerComponent = animator.GetComponentInParent <DamageTakerComponent>(); }
// Dictionary<InteractableComponent.INTERACTION_TYPE, bool> m_InteractiontypesChecker = new Dictionary<InteractableComponent.INTERACTION_TYPE, bool>(); // Update is called once per frame protected override void OnUpdate() { m_RaycastObject = null; if (!CheckInteractionType(InteractableComponent.INTERACTION_TYPE.ON_CLICK) && !CheckInteractionType(InteractableComponent.INTERACTION_TYPE.ON_LONG_PRESS) && !CheckInteractionType(InteractableComponent.INTERACTION_TYPE.ON_CLICK_UP)) { return; } EntityDescriptor desc = FindRayCastObject(); if (desc != null) { InteractableComponent interactable = null; Type interactableType = typeof(InteractableComponent); interactable = (InteractableComponent)desc.m_IComponents[interactableType]; if (interactable.m_IsInteractive) { Debug.Log("Interaction with: " + desc.name); ProcessInteractions(interactable); } } }
public void Btn_EatFlower() { PlayerStructure playerStructure = _playerState.GetActivePlayerStructure(); InteractableComponent interactableComponent = playerStructure.GetInteractableComponent(); this.IniciateSomeInteraction(EnumInteractableState.EatFlower, playerStructure, interactableComponent); }
IEnumerator DefenseOperation(DamageDealerComponent damageDealer) { float _internalCdw = 0f; if (damageDealer != null) { InteractableComponent enemyInteractableComponent = damageDealer.GetComponent <InteractableComponent>(); while (_internalCdw <= damageDealer.CdwDamage) { _internalCdw += Time.deltaTime; yield return(new WaitForFixedUpdate()); } if (enemyInteractableComponent.IsAttackingThisMonster(this.GetInstanceID()) && _readyToCombat) { damageDealer.StartAtackAnimation(this); StartCoroutine(DefenseOperation(damageDealer)); } else { _instanceIdEnemyList.Remove(damageDealer.GetInstanceID()); } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Checkpoint") { lastCheckpoint = collision.transform; return; } if (collision.gameObject.tag == "Star") { collision.gameObject.GetComponent <AudioSource>().Play(); UnityEngine.SceneManagement.SceneManager.LoadScene("Main Menu"); return; } if (collision.gameObject.tag == "Enemy") { Death(); return; } InteractableComponent inter = collision.GetComponent <InteractableComponent>(); if (inter != null) { interaction = collision; } }
public void Deactivate() { _component = null; if (this != null) { this.gameObject.SetActive(false); } }
private void StartPlantingProccess(PlayerStructure playerStrucute, InteractableComponent interactableComponent) { if (_plantSpotState != EnumPlantSpotState.Empty) { return; } this.IniciateSomeInteraction(EnumInteractableState.Plant, playerStrucute, interactableComponent); }
private void OnTriggerStay(Collider other) { if (interacableLayers.ContainsLayer(other.gameObject.layer)) { InteractableComponent interactable = other.GetComponent <InteractableComponent>(); interactables.Add(interactable); SetFocus(); } }
public void RemoveFocus() { if (focus != null) { focus.OnDeFocused(); } focus = null; interactables = new List <InteractableComponent>(); }
public void StopDragging() { (List <RaycastHit2D>, List <RaycastResult>)underTheMouse = _mouseCursorComponent.GetEveryObjectUnderTheMouse(); InventorySlotComponent targetInventorySlot = underTheMouse.Item2.Where(e => e.gameObject.GetComponent <InventorySlotComponent>() != null) .Select(e => e.gameObject.GetComponent <InventorySlotComponent>()) .FirstOrDefault(); InteractableComponent playerInteractableComponent = GetCurrentInteractableComponentUnderTheMouseThatsCanEat(underTheMouse); // => CHANGE ITEM SLOT if (targetInventorySlot != null && targetInventorySlot.GetInstanceID() != _dragInventorySlot.GetInstanceID()) { if (targetInventorySlot.CheckIfCanAcceptItem(_dragItem)) { targetInventorySlot.SetItem(_dragItem); } else { _dragInventorySlot.SetItem(_dragItem); } } // => FEED THE PLAYER else if (playerInteractableComponent != null && _dragItem.Item.ItemType == ScriptableComponents.Item.EnumItemScriptableType.Flower) { _dragItem.Amount--; playerInteractableComponent.EatFlowerByDrag(new ItemDTO() { Item = _dragItem.Item, Amount = 1 }); if (_dragItem.Amount > 0) { _dragInventorySlot.SetItem(_dragItem); } } // => DROP ITEM else if (targetInventorySlot == null) { this.DropItem(); } // => PUT ITEM ON THE SAME SPOT else { _dragInventorySlot.SetItem(_dragItem); } _image.enabled = false; transform.position = _initialPosition; _dragInventorySlot = null; IsDragging = false; _mouseCursorComponent.HasItemUnderTheCursor = false; }
void ProcessInteractions(InteractableComponent _interactable) { //if( interactable.inter InteractableComponent.INTERACTION_TYPE for (int i = 0; i < _interactable.m_Interactions.Count; i++) { if (CheckInteractionType(_interactable.m_Interactions[i].m_InteractionType)) { UnityEvent uEvent = _interactable.m_Interactions[i].myUnityEvent; uEvent.Invoke(); } } }
public DamageDealerComponent GetDamageDealerComponent() { InteractableComponent interactableComponent = this.GetInteractableComponent(); if (interactableComponent is null) { return(null); } if (!interactableComponent.CheckIfCanAtack()) { return(null); } return(_damageDealerComponent); }
bool interactWithObject() { if (currentInteractionObject == null) { Debug.Log("Nothing to interact with"); } else { InteractableComponent interactableComponent = currentInteractionObject.GetComponent <InteractableComponent>(); if (interactableComponent.CanInteract()) { interactableComponent.OnInteraction(); return(true); } } return(false); }
private void ManageMouseOver() { InteractableComponent interactableComponent = _playerStateManager.GetActivePlayerStructure().GetInteractableComponent(); if (interactableComponent is null) { return; } this.ManageMouseClick((hitUI) => { }, (hit) => { IPlantable plantable = hit.collider.gameObject.GetComponent <IPlantable>(); plantable?.MouseOver(true); }); }
public bool Interact() { PlayerStructure playerStructure = _playerState.GetActivePlayerStructure(); InteractableComponent interactableComponent = playerStructure.GetInteractableComponent(); if (interactableComponent is null) { return(false); } if (!interactableComponent.CanPlant && !interactableComponent.CanTakePlant && !interactableComponent.CanTakeSeed) { return(false); } ToggleInternalUIMenu(); StartPlantingProccess(playerStructure, interactableComponent); return(true); }
void Awake() { _interactable = GetComponent <InteractableComponent>(); //_destructible = GetComponent<DestructibleComponent>(); if (_interactable == null) // && _destructible == null) { _interactable = gameObject.AddComponent <InteractableComponent>(); } if (_interactable != null) { _interactable.onInteract += Loot; } //if (_destructible != null) //{ // _destructible.onDestroy += Loot; //} FixIDs(); }
protected override void SetInitialValues() { _internCanMove = true; _animator = this.GetComponent <Animator>(); _rigidBody2D = this.GetComponent <Rigidbody2D>(); _interactableComponent = this.GetComponent <InteractableComponent>(); _playerState = GameObject.FindObjectOfType <PlayerStateManager>(); _inputManager = GameObject.FindObjectOfType <InputManager>(); _isActive = false; _animatorVariables = new MovementCursorAnimatorVariables(); if (_velocity == 0) { _velocity = 5; } if (_stopRange == 0) { _stopRange = 0.2f; } }
private InteractableComponent UpdateCandidateInteractable(InteractableComponent lastChosen) { InteractableComponent result = null; bool resultFound = false; foreach (var interactable in InteractableRegistry.ActiveInteractables) { if (interactable != null) { var closestPointToInteractable = this.FloatillaReference.GetWorldBounds().ClosestPoint(interactable.transform.position); // Find the first interactable that is within use range, and use it. // And then stop looking for others. if (Vector3.Distance(interactable.transform.position, closestPointToInteractable) <= interactable.MinimumDistanceToInteract) { resultFound = true; if (interactable != lastChosen) { // Force the old candidate to no longer be. lastChosen?.EndInteractivity(); // Set up the new candidate. result = interactable; interactable.StartInteractivity(); } // Either way, stop looking for new candidates. We found one that's close enough. break; } } } if (!resultFound) { lastChosen?.EndInteractivity(); } return(result); }
private void SetFocus() { float distanceMin = 100f; if (interactables.Count > 0) { foreach (InteractableComponent inter in interactables) { float distance = Vector3.Distance(transform.position, inter.gameObject.transform.position); if (distance < distanceMin) { distanceMin = distance; focus = inter; } } focus.OnFocused(transform); } else { RemoveFocus(); } }
void Start() { if (_interactable == null) { _interactable = GetComponent <InteractableComponent>(); } if (_interactable == null) { EB.Debug.LogError("InteractableStatsComponent: _interactable is null"); } LocalOnly = _interactable.localOnly; if (!LocalOnly) { _viewRPC = FindReplicationViewForComponent <InteractableStatsComponent>(); if (_viewRPC == null) // && GameStateManager.HasSparxGame) { _viewRPC = gameObject.AddComponent <ReplicationView>(); _viewRPC.observed = this; } } }
public static void Remove(InteractableComponent interactable) { InteractableRegistry.ActiveInteractables.Remove(interactable); }
public void Activate(InteractableComponent component) { _component = component; this.gameObject.SetActive(true); }
public static bool IsGameObjectInteractable(GameObject obj) { return(InteractableComponent.GetInteractableLayer() == obj.layer); }
private void IniciateSomeInteraction(EnumInteractableState interactionState, PlayerStructure playerStructure, InteractableComponent interactableComponent) { if (interactableComponent is null) { return; } interactableComponent.SetInteractableState(interactionState, this.GetInstanceID()); playerStructure.GetMovementMouseComponent().ObjectGoTo(this.transform.position, _radioToInteract); }
private void HandleInteraction() { //get thing, probe and display tooltip, check use bool haveTarget = false; int layerMask = LayerMask.GetMask("Default", "ActorHitbox", "Actor"); Debug.DrawRay(CameraRoot.position, CameraRoot.transform.forward * MaxProbeDist); //raycast all, go through the hits ignoring hits to self RaycastHit[] hits = Physics.RaycastAll(CameraRoot.transform.position, CameraRoot.transform.forward, MaxProbeDist * 2, layerMask, QueryTriggerInteraction.Collide); if (hits != null && hits.Length > 0) { //GameObject nearestObject = null; InteractableComponent nearestInteractable = null; float nearestDist = float.MaxValue; foreach (RaycastHit hit in hits) { //skip if it's further than nearestDist (occluded) or flatdist is further than MaxProbeDist (too far away) if (hit.distance > nearestDist) { continue; } float fDist = VectorUtils.GetFlatVectorToTarget(transform.position, hit.point).magnitude; if (fDist > MaxProbeDist) { continue; } //nearestObject = hit.collider.gameObject; //if there's a PlayerController attached, we've hit ourselves if (hit.collider.GetComponent <PlayerController>() != null) { continue; } //TODO pull a similar trick to see if we're pointing at an Actor? //get the interactable component and hitbox component; if it doesn't have either then it's an obstacle InteractableComponent ic = hit.collider.GetComponent <InteractableComponent>(); IHitboxComponent ahc = hit.collider.GetComponent <IHitboxComponent>(); if (ic == null && ahc == null) { //we null out our hit first since it's occluded by this one nearestInteractable = null; nearestDist = hit.distance; continue; } //it's just us lol if (ahc != null && ahc.ParentController is PlayerController) { continue; } //we have an interactablecomponent and we're not occluded if (ic != null) { nearestInteractable = ic; nearestDist = hit.distance; continue; } //if it doesn't meet any of those criteria then it's an occluder nearestInteractable = null; nearestDist = hit.distance; } //if(nearestObject != null) // Debug.Log("Nearest: " + nearestObject.name); if (nearestInteractable != null && nearestInteractable.enabled) { //Debug.Log("Detected: " + nearestInteractable.Tooltip); //HUDScript.SetTargetMessage(nearestInteractable.Tooltip); nearestInteractable.OnLook(this.gameObject); if (!string.IsNullOrEmpty(nearestInteractable.Tooltip)) { MessageInterface.PushToBus(new QdmsKeyValueMessage("PlayerHasTarget", "Target", nearestInteractable.Tooltip)); HadTargetLastFrame = true; haveTarget = true; } //actual use if (MappedInput.GetButtonDown(DefaultControls.Use) && !GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoInteract)) { nearestInteractable.OnActivate(this.gameObject); } } } if (!haveTarget && HadTargetLastFrame) { MessageInterface.PushToBus(new QdmsFlagMessage("PlayerClearTarget")); //should probably not do this constantly } HadTargetLastFrame = haveTarget; }