Exemplo n.º 1
0
    public void OnInteractionComplete(IInteractableObject interaction, bool state)
    {
        bool allComplete = true;

        for (int i = 0; i < m_interactions.Count; ++i)
        {
            if (m_interactions[i] == interaction)
            {
                if (!hasInteracted(i) && state)
                {
                    interactionsComplete[i] = true;
                }
                else if (hasInteracted(i) && !state)
                {
                    interactionsComplete[i] = false;
                }
            }
            else if (m_type == Objective.ObjectiveType.Sequentive && state)
            {
                return;
            }

            allComplete = allComplete && hasInteracted(i);
        }

        if (allComplete)
        {
            m_state = ObjectiveState.Completed;
            m_onObjectiveComplete.Invoke();

            Debug.Log("Objective completed");

            ObjectivesManager.Instance.InitializeNextObjective();
        }
    }
Exemplo n.º 2
0
        public void PlaceMines(IGameField field)
        {
            int    count        = 0;
            Random randomNumber = new Random();
            int    minPercent   = Convert.ToInt32(this.MinChance * (field.Size * field.Size));
            int    maxPercent   = Convert.ToInt32(this.MaxChance * (field.Size * field.Size));
            int    countMines   = randomNumber.Next(minPercent, maxPercent);

            while (count <= countMines)
            {
                int       x        = randomNumber.Next(0, field.Size);
                int       y        = randomNumber.Next(0, field.Size);
                IPosition position = new Position(x, y);

                if (!field.AllObjects.ContainsKey(position))
                {
                    MineFactory factory = new MineFactory();

                    IInteractableObject mine = factory.CreateMine(position, randomNumber.Next(1, 6));
                    field.AllObjects[position]          = mine;
                    field.InteractableObjects[position] = mine;
                    count++;
                }
            }
        }
Exemplo n.º 3
0
    public bool IsInteractionEligable(IInteractableObject interaction)
    {
        if (m_objectives.Length == 0)
        {
            return(true);
        }

        Objective currentObj = m_objectives[objectiveIdx];

        if (currentObj.m_type == Objective.ObjectiveType.Sequentive &&
            currentObj.m_interactions.Contains(interaction))
        {
            for (int i = 0; i < currentObj.m_interactions.Count; ++i)
            {
                if (!currentObj.hasInteracted(i))
                {
                    if (currentObj.m_interactions[i] == interaction)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }

        return(true);
    }
Exemplo n.º 4
0
    private void CheckForCloseInteractions()
    {
        // iterate over all the interactions,
        // checking on distance
        // adding to the active list if close

        for (int i = 0; i < m_sceneInteractions.Count; i++)
        {
            IInteractableObject interaction = m_sceneInteractions[i];

            bool isEligable =
                interaction.IsInteracting || interaction.ActiveWhen == IInteractableObject.WorkState.WorksAlways;

            if (interaction.ActiveWhen != IInteractableObject.WorkState.WorksAlways)
            {
                isEligable = true && !LightStatesMachine.Instance.IsLightOn();
            }

            bool closeInteraction = interaction.enabled && isEligable && IsCharCloserThan(interaction, 3.0f);


            if (closeInteraction)
            {
                OnInteractionEnter(interaction);
            }

            if (!closeInteraction)
            {
                OnInteractionExit(interaction);
            }
        }
    }
Exemplo n.º 5
0
    private void handleInteraction()
    {
        Debug.Log("Trying to attach to game object");
        Vector2 travelDirection = new Vector2(1, 0);

        if (!_facingRight)
        {
            travelDirection.x *= -1;
        }
        var radius = 2.0f;

        Collider2D hit = Physics2D.OverlapCircle(_transform.position, radius, _interactableLayer);

        if (hit == null)
        {
            return;
        }
        SetState(PlayerState.INTERACTING);
        _rigidbody.velocity    = Vector2.zero;
        _rigidbody.isKinematic = true;
        Debug.Log($"Gameobject hit is {hit.gameObject.name}");
        _interactingObject = hit.gameObject.GetComponent <IInteractableObject>();
        if (_interactingObject.CanInteract(InteractableType.GEAR))
        {
            head.StartInteraction(_interactingObject);
        }
        else if (_interactingObject.CanInteract(InteractableType.POWER))
        {
            //
        }
        // RaycastHit2D hit = Physics2D.Raycast(_transform.position, travelDirection, 2.0f, _interactableLayer);
        // if (hit.collider != null) {
        //  _interactingObject = hit.collider.gameObject.GetComponent<IInteractableObject>();
        // }
    }
Exemplo n.º 6
0
    private void OnTriggerEnter(Collider other)
    {
        IInteractableObject interactable = other.GetComponent <IInteractableObject>();

        interactable.Activate();

        Debug.Log(interactable.gameObject.name);
    }
Exemplo n.º 7
0
 public void AddItem(IInteractableObject item)
 {
     if (HasItem(item.Name))
     {
         return;
     }
     inventory.Add(item);
 }
    public void OnInteractionComplete( IInteractableObject interaction, bool state )
	{
        if(m_objectives.Length == 0)
            return;
        
		Objective current = m_objectives[objectiveIdx];
		if( current.m_interactions.Contains( interaction ) )
		   	current.OnInteractionComplete(interaction, state ); 
	}
Exemplo n.º 9
0
    private void CheckCurrentSelection()
    {
        // select current interaction object going through the list
        if (CurrentObject != null && !IsCharCloserThan(CurrentObject, 1.5f))
        {
            DeselectCurrentObject(CurrentObject);
        }

        float closestDistToCenter = Mathf.Infinity;
        IInteractableObject closestInteraction = null;

        foreach (var interactionPair in interactionObjects)
        {
            IInteractableObject iObject     = interactionPair.Key;
            ButtonPrompt        promtObject = interactionPair.Value;

            //if (!iObject.isVisible())
            //    continue;

            //if (!promtObject.IsVisible)
            //    continue;

            bool showText = LightStatesMachine.Instance.IsLightOn() && !iObject.IsInteracting;
            if (iObject is DoorInteraction)
            {
                showText = true;
            }

            UpdatePromtButton(showText, iObject, promtObject);

            Vector3 viewPos     = Camera.main.WorldToViewportPoint(iObject.transform.position);
            float   distance    = Vector2.Distance(viewPos, Vector2.one * 0.5f);
            bool    isRealClose = IsCharCloserThan(iObject, 1.5f);

            if (distance < closestDistToCenter && isRealClose)
            {
                closestDistToCenter = distance;
                closestInteraction  = iObject;
            }
        }

        if (closestInteraction == null)
        {
            return;
        }

        // switching to the new interactable object
        if (CurrentObject != closestInteraction)
        {
            if (CurrentObject != null)
            {
                DeselectCurrentObject(CurrentObject);
            }

            SelectCurrentObject(closestInteraction);
        }
    }
Exemplo n.º 10
0
    private void DeselectCurrentObject(IInteractableObject obj)
    {
        CurrentObject.IsSelected = false;
        CurrentObject            = null;

        //m_charBeh.m_characterAnimation.SetLookingPoint(transform.forward, 0f);
        //m_charBeh.m_characterAnimation.SetRightHandIK(Vector3.zero, 0f);

        //HighlightsImageEffect.Instance.OnObjectMouseExit();
        GlowController.ResetAllObjects();
    }
Exemplo n.º 11
0
    public void PushToStackObject(IInteractableObject interactItem)
    {
        m_StackComponent.PushToStackObject(interactItem);

        if (m_isMyCharacter)
        {
            CameraManager.Instance.PlusDistance(0.15f, 0.15f);
            UIManager.Instance.ShowStackHUD();
        }
        ChangeAniamtion("Run");
    }
Exemplo n.º 12
0
    void FaceDirection()
    {
        var face_x = ((Direction.Left & Direction) == Direction.Left) ? -0.25f :
                     ((Direction.Right & Direction) == Direction.Right) ? 0.25f : 0f;
        var face_y = ((Direction.Up & Direction) == Direction.Up) ? 0.125f :
                     ((Direction.Down & Direction) == Direction.Down) ? -0.125f : 0f;
        var face_pos = transform.position + new Vector3(face_x, face_y);

        Collider2D[] hits = Physics2D.OverlapBoxAll(face_pos,
                                                    new Vector2(0.5f, 0.25f), 0, 1 << 9);

        var dist = 10f;
        IInteractableObject iio = null;

        for (int i = 0; i < hits.Length; i++)
        {
            var tiio = hits[i].GetComponent <IInteractableObject>();
            if (tiio != null &&
                tiio.InteractState == InteractState.Interactable &&
                currentHold == null)
            {
                var t_dist = Vector3.Distance(hits[i].transform.position, transform.position);
                if (t_dist < dist &&
                    (currentHold == null || (currentHold != null && tiio.GameObject != currentHold.GameObject)))
                {
                    dist = t_dist;
                    iio  = tiio;
                }
            }
        }

        if (iio != null)
        {
            if (currentItem == null)
            {
                currentItem = iio;
                currentItem.ShowInteractable();
            }
            else if (currentItem != iio)
            {
                currentItem.HideInteractable();
                currentItem = iio;
                iio.ShowInteractable();
            }
        }
        else
        {
            if (currentItem != null)
            {
                currentItem.HideInteractable();
                currentItem = null;
            }
        }
    }
Exemplo n.º 13
0
    private void UpdatePromtButton(bool showText, IInteractableObject iObject, ButtonPrompt promtObject)
    {
        if (IsInteracting)
        {
            showText = false;
        }

        string textToOutput = iObject.IsSelected ? iObject.ActionsToDisplay : iObject.TextToDisplay;

        promtObject.SetText(showText ? textToOutput : "");
        promtObject.setInteractableUI(iObject.IsSelected && !IsInteracting);
    }
Exemplo n.º 14
0
    private void OnInteractionExit(IInteractableObject interactionObject)
    {
        if (!interactionObjects.ContainsKey(interactionObject))
        {
            return;
        }

        Destroy(interactionObjects[interactionObject].gameObject);
        interactionObject.onInteractionDestroyed -= OnInteractionDestroyed;
        interactionObject.onInteractionDisabled  -= OnInteractionDisabled;
        interactionObjects.Remove(interactionObject);
    }
Exemplo n.º 15
0
 private void handleReleaseInput()
 {
     if (_interactingObject.CanInteract(InteractableType.GEAR))
     {
         head.EndInteraction();
     }
     else if (_interactingObject.CanInteract(InteractableType.POWER))
     {
     }
     _interactingObject     = null;
     _rigidbody.isKinematic = false;
     SetState(PlayerState.ACTIVE);
 }
Exemplo n.º 16
0
    public void OnInteractionComplete(IInteractableObject interaction, bool state)
    {
        if (m_objectives.Length == 0)
        {
            return;
        }

        Objective current = m_objectives[objectiveIdx];

        if (current.m_interactions.Contains(interaction))
        {
            current.OnInteractionComplete(interaction, state);
        }
    }
Exemplo n.º 17
0
        private void TryInteracting()
        {
            RaycastHit hit;

            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, interactRange))
            {
                Debug.DrawLine(transform.position, transform.position + (transform.TransformDirection(Vector3.forward) * interactRange), Color.white, 20);
                IInteractableObject objectHit = hit.transform.GetComponent <IInteractableObject>();
                if (objectHit != null)
                {
                    objectHit.DoAction();
                }
            }
        }
Exemplo n.º 18
0
    private void TryActivateObjectFromRay()
    {
        RaycastHit hit;

        if (Physics.Raycast(camera.position, camera.TransformDirection(Vector3.forward), out hit, maxActivateDistance))
        {
            IInteractableObject interactableObject = hit.collider.gameObject.GetComponentInParent <IInteractableObject>();

            if (interactableObject != null)
            {
                interactableObject.OnObjectClick();
            }
        }
    }
Exemplo n.º 19
0
    public IInteractableObject PopFromStackObject()
    {
        if (m_stackItem.Count > 0)
        {
            IInteractableObject interactObject = m_stackItem.Pop();

            InteractObject obj = interactObject as InteractObject;
            obj.OnPopFromStack();

            return(interactObject);
        }

        return(null);
    }
Exemplo n.º 20
0
    public IInteractableObject PopFromStackObject()
    {
        IInteractableObject obj = m_StackComponent.PopFromStackObject();

        if (m_isMyCharacter && obj != null)
        {
            CameraManager.Instance.PlusDistance(-0.15f, -0.15f);
        }

        if (StackCount == 0)
        {
            ChangeAniamtion("Run");
        }

        return(obj);
    }
Exemplo n.º 21
0
    private void SelectCurrentObject(IInteractableObject obj)
    {
        CurrentObject            = obj;
        CurrentObject.IsSelected = true;

        var position  = obj.transform.position;
        var direction = (obj.transform.position - headTransf.position).normalized;

        //m_charBeh.m_characterAnimation.SetLookingPoint(direction, 0.5f);
        //m_charBeh.m_characterAnimation.SetRightHandIK(obj.transform.position, 0.3f);

        foreach (var rend in obj.m_renderers)
        {
            //HighlightsImageEffect.Instance.OnObjectMouseOver(obj.m_renderer, Color.white);
            GlowController.RegisterObject(rend);
        }
    }
Exemplo n.º 22
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == m_myCharacter.gameObject)
        {
            return;
        }
        if (other.gameObject.layer == LayerMask.NameToLayer("Interactive"))
        {
            IInteractableObject interactObject = other.GetComponent <IInteractableObject>();
            if (interactObject == null)
            {
                return;
            }

            interactObject.OnEnterCollision(m_myCharacter, m_myCharacter.transform.position);
        }
    }
Exemplo n.º 23
0
    private void Hit(GameObject target, Constants.HitDirection dir, bool isHitInside)
    {
        // Hit self reaction
        if (hitEvent != null)
        {
            hitEvent(target, dir, isHitInside);
        }

        // Hit notify the other
        IInteractableObject interactableObj = target.GetComponentRecursiveUp <IInteractableObject>();

        if (interactableObj != null)
        {
            //Debug.LogFormat("Object: {2}, Hit: {0}, From: {1}", target.name, dir, gameObject.name);
            interactableObj.IsHit(gameObject, dir);
        }
    }
Exemplo n.º 24
0
 public Lever(ContentManager content,
     Vector3 position, Vector3 rotation,
     float scale, Vector3 openFromDirection,
     IInteractableObject LeverUseObject,
     bool isUsed = false)
     : base(@"Models\Environment\Lever",
         content, position, rotation, scale)
 {
     this.isUsed = isUsed;
     closedModel = base.GetModel();
     usedModel = content.Load<Model>(@"Models\Environment\LeverUsed");
     CreateUseAABB(openFromDirection, Position, 100, 100);
     this.onUseObject = LeverUseObject;
     Interactables.AddInteractable(this);
     emitter = new AudioEmitter();
     emitter.Position = position;
 }
        public DuoLever(Lever lever1, Lever lever2,
            IInteractableObject LeverUseObject, float useDuration)
        {
            this.useDuration = useDuration;
            timesToPlay = (int)Math.Floor(useDuration / 1.270);
            this.lever1 = lever1;
            this.lever2 = lever2;
            this.OnUseObject = LeverUseObject;

            base.SetAABB(GameConstants.MapMinBounds,
                new Vector3(GameConstants.MapMaxBounds.X,
                    GameConstants.InteractablesUseHeight,
                    GameConstants.MapMaxBounds.Z));

            Interactables.AddInteractable(this);
            if (LeverUseObject is Gate)
            {
                gate = (Gate)LeverUseObject;
            }
        }
Exemplo n.º 26
0
 private void Update()
 {
     if (Input.GetButtonDown("Interact"))
     {
         RaycastHit hit;
         Ray        ray = Camera.main.ViewportPointToRay(Vector3.one * 0.5f);
         // if (Physics.Raycast(transform.position + transform.up * 1.2f, Camera.main.transform.forward * interactionRange, out hit, 2f))
         if (Physics.Raycast(ray, out hit, 50f))
         {
             Debug.Log(hit.transform.name);
             Debug.Log("distance" + Vector3.Distance(transform.position, hit.point));
             if (Vector3.Distance(transform.position, hit.transform.position) <= interactionRange)
             {
                 IInteractableObject interactable = hit.transform.GetComponent <IInteractableObject>();
                 if (interactable != null)
                 {
                     interactable.OnInteract(transform);
                 }
             }
         }
     }
 }
	public bool IsInteractionEligable( IInteractableObject interaction )
	{
        if(m_objectives.Length == 0)
            return true;
        
		Objective currentObj = m_objectives[objectiveIdx];

		if( currentObj.m_type == Objective.ObjectiveType.Sequentive &&
            currentObj.m_interactions.Contains(interaction) )
		{
            for (int i=0; i< currentObj.m_interactions.Count; ++i)
            {
                if (!currentObj.hasInteracted(i))
                {
                    if (currentObj.m_interactions[i] == interaction)
                        return true;
                    else return false;
                }
            }
		}

		return true;
	}
Exemplo n.º 28
0
    private void OnInteractionEnter(IInteractableObject interactionObject)
    {
        if (interactionObjects.ContainsKey(interactionObject))
        {
            return;
        }

        GameObject   promtPrefab  = UIManager.Instance.m_buttonPromtPrefab;
        GameObject   promtGO      = Instantiate(promtPrefab) as GameObject;
        ButtonPrompt buttonPrompt = promtGO.GetComponent <ButtonPrompt>();

        buttonPrompt.SetText("");
        buttonPrompt.SetConnectedTransform(interactionObject.transform);

        // setting the object under Canvas
        //promtGO.transform.SetParent(UIManager.s_canvas.transform);
        //promtGO.transform.localScale = Vector3.one;


        interactionObjects.Add(interactionObject, buttonPrompt);
        interactionObject.onInteractionDestroyed += OnInteractionDestroyed;
        interactionObject.onInteractionDisabled  += OnInteractionDisabled;
    }
Exemplo n.º 29
0
    public override void UpdateState()
    {
        InputManager.Instance.UpdateInput();
        m_Character.transform.position += (m_Character.transform.forward * Time.deltaTime * m_Character.m_RunSpeed);

        time += Time.deltaTime;

        if (m_Character.CheckAllLayer(LayerMask.GetMask("Victory"), out hitRay, 1.5f))
        {
            m_Character.ChangeState(E_CHARACTER_STATE.VICTORY);
        }
        else if (m_Character.CheckAllLayer(LayerMask.GetMask("Ground"), out hitRay, 1.5f))
        {
            m_Character.ChangeState(E_CHARACTER_STATE.RUN);
        }
        else if (time > (0.10f))
        {
            if (!m_Character.CheckLayer(LayerMask.GetMask("GroundItem"), out hitRay))
            {
                IInteractableObject ob = m_Character.PopFromStackObject();

                if (ob == null)
                {
                    m_Character.ChangeState(E_CHARACTER_STATE.JUMP);
                }
            }
            else
            {
                Vector3 pos = m_Character.transform.position;
                pos.y = hitRay.point.y + 0.03f;
                m_Character.transform.position = pos;
            }

            time = 0.0f;
        }
    }
Exemplo n.º 30
0
    private void UpdatePromtButton(bool showText, IInteractableObject iObject, ButtonPrompt promtObject)
    {
        if(IsInteracting)
            showText = false;

        string textToOutput = iObject.IsSelected ? iObject.ActionsToDisplay : iObject.TextToDisplay;       
        promtObject.SetText (showText ? textToOutput : "");
        promtObject.setInteractableUI(iObject.IsSelected && !IsInteracting);
    }
Exemplo n.º 31
0
 private void OnInteractionDisabled(IInteractableObject obj)
 {
     m_sceneInteractions.Remove(obj);
     OnInteractionExit(obj);
 }
 protected void CreateDuoLever(Vector3 pos1, Vector3 rot1, float scale1, Vector3 openDir1,
     Vector3 pos2, Vector3 rot2, float scale2, Vector3 openDir2,
     IInteractableObject onUseObject, float useDuration)
 {
     Lever lever1 = new Lever(contentMan, pos1, rot1, scale1, openDir1);
     Lever lever2 = new Lever(contentMan, pos2, rot2, scale2, openDir2);
     environment.Add(new DuoLever(lever1, lever2, onUseObject, useDuration));
 }
Exemplo n.º 33
0
    private void DeselectCurrentObject(IInteractableObject obj)
    {
        CurrentObject.IsSelected = false;
        CurrentObject = null;

        HighlightsImageEffect.Instance.OnObjectMouseExit();
    }
Exemplo n.º 34
0
    private void SelectCurrentObject(IInteractableObject obj)
    {
        CurrentObject = obj;
        CurrentObject.IsSelected = true;

        if(obj.m_renderer != null)
        {
            HighlightsImageEffect.Instance.OnObjectMouseOver(obj.m_renderer, Color.white);
        }
    }
Exemplo n.º 35
0
    private void OnInteractionExit( IInteractableObject interactionObject)
    {
        if( !interactionObjects.ContainsKey( interactionObject ) )
            return;

        Destroy(interactionObjects[interactionObject].gameObject);
        interactionObject.onInteractionDestroyed -= OnInteractionDestroyed;
        interactionObject.onInteractionDisabled -= OnInteractionDisabled;
        interactionObjects.Remove( interactionObject ); 
    }
Exemplo n.º 36
0
    private void OnInteractionEnter( IInteractableObject interactionObject )
    {
        if( interactionObjects.ContainsKey( interactionObject ) )
            return;

        GameObject promtPrefab = UIManager.Instance.m_buttonPromtPrefab;
        GameObject promtGO = Instantiate(promtPrefab) as GameObject;
        ButtonPrompt buttonPrompt = promtGO.GetComponent<ButtonPrompt>(); 
        buttonPrompt.SetText ("");
        buttonPrompt.SetConnectedTransform (interactionObject.transform);

        // setting the object under Canvas
        //promtGO.transform.SetParent(UIManager.s_canvas.transform);
        //promtGO.transform.localScale = Vector3.one;


        interactionObjects.Add(interactionObject, buttonPrompt);
        interactionObject.onInteractionDestroyed += OnInteractionDestroyed;
        interactionObject.onInteractionDisabled += OnInteractionDisabled;
    }
Exemplo n.º 37
0
 public bool IsCharCloserThan(IInteractableObject obj, float dist)
 {
     return (transform.position - obj.transform.position).magnitude < dist;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Simulates grabbing the given object.
 /// </summary>
 public abstract void Grab(IInteractableObject interactable);
	public void OnInteractionComplete(IInteractableObject interaction, bool state )
	{
        bool allComplete = true;
        
        for (int i = 0; i < m_interactions.Count; ++i)
        {
            if (m_interactions[i] == interaction)
            {
                if (!hasInteracted(i) && state)
                    interactionsComplete[i] = true;
                else if (hasInteracted(i) && !state)
                    interactionsComplete[i] = false;
            }
            else if (m_type == Objective.ObjectiveType.Sequentive && state)
            {
                return;
            }

            allComplete = allComplete && hasInteracted(i);
        }
       
		if( allComplete )
		{
			m_state = ObjectiveState.Completed;
			m_onObjectiveComplete.Invoke();

			Debug.Log("Objective completed");

			ObjectivesManager.Instance.InitializeNextObjective();
		}
	}