상속: MonoBehaviour
예제 #1
0
 public Event(Vector3 cpos, Quaternion rot, Interactable interact, bool hasInteracted)
 {
     position = cpos;
     interactable = interact;
     rotation = rot;
     this.hasInteracted = hasInteracted;
 }
예제 #2
0
 void Start()
 {
     GameObject n = new GameObject ();
         n.AddComponent<Interactable>();
         b = n.GetComponent<Interactable> ();
     GameObject.Destroy(n);
 }
 /*
 void FixedUpdate(){
     localMover.moveFixed(lastMoveDirection, moveafterjumping);
 }
 */
 public void setInteracting(bool isInteracting)
 {
     interacting = isInteracting;
     if(!isInteracting){
         currentInteractable = null;
     }
 }
예제 #4
0
    /// <summary>
    /// Resets interact target and navigates to position
    /// </summary>
    /// <param name="pos">Where the object will try to move</param>

    #region Movement 
	public void MoveTo(Vector3 pos)
	{
        m_InteractTarget = null;
        m_PathLocator.position = pos;
        m_Path.target = m_PathLocator;
        m_Path.SearchPath();
	}
예제 #5
0
    public void initRay()
    {
        // Make a ray from the transforms pos and forward
        ray = new Ray(transform.position, transform.forward);
        Debug.DrawRay(transform.position, transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit)) {

            Interactable interactable = hit.transform.GetComponent<Interactable>();

            if(interactable != null){
                if(lastObjectHit != null && interactable != lastObjectHit){
                    lastObjectHit.OnRayExit(playerIndex);
                    lastObjectHit = null;
                }
                if (interactable != lastObjectHit){
                    interactable.OnRayEnter(playerIndex,ray, hit);
                    lastObjectHit = interactable;
                }
            }
        }else if(lastObjectHit != null){
            lastObjectHit.OnRayExit(playerIndex);
            lastObjectHit = null;
        }
    }
    public override void OnInspectorGUI()
    {
        thisObject = (Interactable)target;
        thisObject.Type = (Interactable.ObjectType)EditorGUILayout.EnumPopup ("Type: ", thisObject.Type);

        switch (thisObject.Type)
        {
            case Interactable.ObjectType.Ladder:

                // Calculate height of ladder from it's collider
                float height = thisObject.transform.localScale.y * ((BoxCollider)thisObject.GetComponent<Collider>()).size.y;

                // Get world position of top and bottom of ladder
                Vector3 top = new Vector3(thisObject.transform.position.x, (thisObject.transform.position.y + (height / 2)), thisObject.transform.position.z);
                Vector3 bottom = new Vector3(thisObject.transform.position.x, thisObject.transform.position.y - (height / 2), thisObject.transform.position.z);

                // Move the positions forward a small amount and set them to the ladders variables
                thisObject.ladderBottom = bottom + (thisObject.transform.forward / 2);
                thisObject.ladderTop = top + (thisObject.transform.forward / 2);

                EditorGUILayout.Vector3Field("Start: ", thisObject.ladderBottom);
                EditorGUILayout.Vector3Field("End: ", thisObject.ladderTop);

                break;
        }

        if (GUI.changed) {
            EditorUtility.SetDirty(thisObject);
        }
    }
예제 #7
0
    void Update()
    {
        _ray = new Ray(transform.position, transform.forward);
            if (Physics.Raycast(_ray, out _hit, interactionRange))
            {
                Interactable i = _hit.transform.GetComponent<Interactable>();
            if (i) {
                if (_interactableObject != null && !i.Equals (_interactableObject)) {
                    _interactableObject.interacting = false;
                    this.interacting = false;
                }

                _interactableObject = _hit.transform.GetComponent<Interactable> ();
                this.interacting = true;
                _interactableObject.interacting = true;
                _interactableObject.interactPosition = _hit.point;
                b = i;
            }
            else
                b.interacting = false;

            }
            else if (_interactableObject)
            {
                _interactableObject.interacting = false;
                this.interacting = false;
                _interactableObject = null;
            }
    }
예제 #8
0
 void OnEnable()
 {
     selectedObject = LevelManager.Instance().GetSelectedInteractable();
     if (selectedObject == null) return;
     Vector3 closerPosition = selectedObject.transform.position;
     SpriteRenderer closerRenderer = selectedObject.GetComponent<SpriteRenderer>();
     this.transform.position = new Vector3(closerPosition.x+closerRenderer.bounds.size.x,
                                          closerPosition.y+2,0);
 }
예제 #9
0
 public bool MarkInUse()
 {
     if (inUse) {
         Debug.LogWarning(inUse.name + " already in use!");
         return false;
     }
     inUse = this;
     return true;
 }
예제 #10
0
	void OnTriggerExit2D(Collider2D _other)
	{
		if(_other.tag == "Player")
		{
			Debug.Log("Player exited altar area");
            m_fNotify.FObject = null;
            Interactable.NearbyInteractable = null;
        }	
	}
예제 #11
0
	void Update()
    {
        floorPosition = new Vector3(transform.position.x, 0.0f, transform.position.z);

        if(interactables.Count > 0)
        {
            Vector3 interactableFloorPosition = Vector3.zero;

            foreach(Interactable i in interactables)
            {
                interactableFloorPosition = new Vector3(i.transform.position.x, 0.0f, i.transform.position.z);
                i.DistanceToPlayer = (interactableFloorPosition - floorPosition).magnitude;
            }

            // Get nearest interactable
            nearestInteractable = interactables.OrderBy(o=>o.DistanceToPlayer).ToList()[0];

            // If player encountered a new nearest interactable
            if(nearestInteractable != prevNearestInteractable)
            {
                nearestInteractable.SetNearestInteractable();

                if(prevNearestInteractable != null)
                {
                    prevNearestInteractable.UnsetNearestInteractable();
                }
            }
        }
        else
        {
            nearestInteractable = null;

            if(nearestInteractable != prevNearestInteractable)
            {
                if(prevNearestInteractable != null)
                {
                    prevNearestInteractable.UnsetNearestInteractable();
                }
            }
        }

        if(nearestInteractable != null)
        {
            nearestInteractable.HandleUse();
        }

        prevNearestInteractable = nearestInteractable;

        #if UNITY_EDITOR

        if(nearestInteractable != null)
        {
            Debug.DrawLine(transform.position, nearestInteractable.gameObject.transform.position, Color.white);
        }

        #endif
	}
예제 #12
0
 public virtual void MoveTo(Vector3 targetPosition, Interactable interactable, bool resetHasInteracted = false)
 {
     this.targetPosition.x = targetPosition.x;
     this.targetPosition.z = targetPosition.z;
     if (resetHasInteracted) {
         hasInteracted = false;
     }
     this.Interactable = interactable;
     agent.SetDestination(targetPosition);
 }
예제 #13
0
	public void onKeyIsPickedUp	(GameObject obj, bool tr ){
		Interactable inter = obj.GetComponent<Interactable>();

		if(inter != null && inter.getPuzzleState() == "notPickedUp"){
			r_Key = inter;
			r_Key.setPuzzleState("pickedUp");

			gameObject.GetComponentInChildren<Behaviour_DoorSimple>().unlockDoor();
		}
	}
 private void GoInside()
 {
     if (this.interactable != null)
     {
         this.interactable.Interact();
         this.interactable = null;
         target.x = transform.position.x;
     }
     interacting = false;
 }
예제 #15
0
 public bool RegisterInteractable(Interactable inter)
 {
     Debug.Log("Registering " + inter.ToString());
     if (!interactableObjects.Contains(inter))
     {
         interactableObjects.Add(inter);
         return true;
     }
     return false;
 }
예제 #16
0
	/// <summary>
	///This function is called on the Interactable as it leaves the players interact zone
	/// </summary>
	void OnTriggerExit( Collider col  ){

		if( r_InFocus != null && col.gameObject == r_InFocus.gameObject ){
			r_InFocus.loseFocus();
			r_InFocus = null;
			r_CachedFocus = null;

			r_GUIManager.interactTextActive( false );
		}
	}
예제 #17
0
    private Renderer _renderer; // local renderer

    #endregion Fields

    #region Methods

    // A GameObject is no more requesting control
    public static bool releaseControl(Interactable io)
    {
        if (_current == io) {
            _current = null;
            io._release ();
            return true;
        } else {
            return false;
        }
    }
예제 #18
0
	void Start() {

		animator = GetComponent<Animator>();
        interactable = GetComponent<Interactable>();

		if (animator && looted) {
			animator.SetTrigger("Looted");
		}

	}
예제 #19
0
 public bool UnregisterInteractable(Interactable inter)
 {
     Debug.Log("Unregistering " + inter.ToString());
     if (interactableObjects.Contains(inter))
     {
         interactableObjects.Remove(inter);
         return true;
     }
     return false;
 }
예제 #20
0
	/// <summary>
	/// This function is called on the Interactable as the interactable enters the players interact zone
	/// </summary>
	void OnTriggerEnter( Collider col ){
		//TODO: Add detection for which interactable is in focus if several objects are within the zone.
		Interactable ii = col.gameObject.GetComponent<Interactable>();
		if( ii != null && ii.enabled ){
			r_InFocus = ii;
			r_CachedFocus = ii;
			r_InFocus.gainFocus();
			setupInteractText();

			r_GUIManager.interactTextActive( true );
		}
	}
예제 #21
0
    void OnTriggerEnter2D(Collider2D _other)
	{
		if (Carryable.CurrentlyCarried != null && this is Dropable)
			return;

		if(_other.tag == "Player")
		{
			Debug.Log("Player entered altar area");
            m_fNotify.FObject = transform;
            Interactable.NearbyInteractable = this;
		}	
	}
예제 #22
0
    void interact()
    {
        if(Highlight != null ) {
            if( Input.GetButtonDown("Interact"))
                Highlight.interact();

        }

        LHighlight = Highlight;
        Highlight = null;
        IntrcDis = float.MaxValue;
    }
예제 #23
0
	// Use this for initialization
	void Start () {
		Messenger.AddListener<GameObject, bool>("onPickupCubeKey", onPickupCubeKey);
		Messenger.AddListener<GameObject, bool>("onCubeKeyDoorUse", onCubeKeyDoorUse);
		Messenger.AddListener<GameObject, bool>("onRequestOpenCubeDoor", onRequestOpenCubeDoor);
		
		foreach(GameObject obj in availableCubesToPlace){
			m_PlacedCubePositions.Add(obj.transform.localPosition);
			m_CubePlaceUsed.Add(false);
		}
		r_Interactable = GetComponent<Interactable>();
		r_FreeLookCamera = Camera.main.transform.parent.transform.parent.gameObject.GetComponent<FreeLookCamera>();

		nrCubes = availableCubesToPlace.Count;
	}
    public void OnSceneGUI()
    {
        thisObject = (Interactable)target;

        switch (thisObject.Type)
        {
            case Interactable.ObjectType.Ladder:
                // Show start and end labels
                Handles.Label(thisObject.ladderBottom, "Start");
                Handles.Label (thisObject.ladderTop, "End");
                break;
        }

        Repaint ();
    }
예제 #25
0
 // A GameObject is requesting control
 public static bool requestControl(Interactable io)
 {
     if (_current == null || !_current.isActiveAndEnabled) {
         _current = io;
         return true;
     // Give control to the nearest requesting GameObject
     } else if (_current.hit.distance > io.hit.distance) {
         Interactable.releaseControl(_current);
         _current = io;
         return true;
     } else {
         if (tracecontrol) Debug.Log(
             "Cannot give control to " + io + " " + _current + " has control");
         return false;
     }
 }
예제 #26
0
    public void SetInteractTarget(Interactable _interactable)
    {
        if (null == _interactable)
            return;

        Vector3 toTarget = _interactable.InteractLocator.position - transform.position;
        float maxInteractRngSqr = m_MaxInteractRange * m_MaxInteractRange;

        if (toTarget.sqrMagnitude > maxInteractRngSqr)
        {
            //m_Path.endReachedDistance = m_MaxInteractRange;
			MoveTo(_interactable.InteractLocator.position);
			m_InteractTarget = _interactable;
        }
        else
            _interactable.HandleInteraction();
    }
예제 #27
0
    public void OnTriggerExit(Collider collider)
    {
        if (collider.gameObject.GetComponent<Actor>() != null)
        {
            // Notifie au joueur qu'il a quitté la zone du PNJ
            playerController.FinishConversation(actorDetected);
            actorDetected = null;
            
        }
        else
        {
            UIManager.instance.statusBarText.text = "";
        }

        objectInteractable = null;

        PlayerController.instance.actorText.SetText("");
    }
예제 #28
0
	public void OnTriggerEnter(Collider collider)
    {
        // Est-ce que le joueur est proche d'un PNJ
        if (collider.gameObject.GetComponent<Actor>() != null)
        {
            // Oui
            actorDetected = collider.GetComponent<Actor>();
            //UIManager.instance.statusBarText.text = InputsMapping.ACTION_KEY.ToString() + " pour discuter avec " + actorDetected.nom; 
            PlayerController.instance.actorText.SetText(InputsMapping.ACTION_KEY.ToString() + " pour discuter avec " + actorDetected.nom, Color.red);

        }
        else if (collider.gameObject.GetComponent<Interactable>() != null)
        {
            // Le joueur est proche d'un objet interactif
            objectInteractable = collider.gameObject.GetComponent<Interactable>();
            PlayerController.instance.actorText.SetText(InputsMapping.ACTION_KEY.ToString() + " " + objectInteractable.message, Color.red);
            //UIManager.instance.statusBarText.text = InputsMapping.ACTION_KEY.ToString() +" " + objectInteractable.message;
        }

        
    }
예제 #29
0
    public void ClickAndInteract()
    {
        ClearNav();
        if (canClick)
        {
            //clear previous data

            Ray ray = new Ray(camOrigin.position, camOrigin.forward);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100, PointingLayers))
            {
                //check that the target is interactable
                if (hit.collider.gameObject.GetComponent<Interactable>())
                {
                    interactionTarget = hit.transform.GetComponent<Interactable>();
                    Vector3 nearestSpot = interactionTarget.NearestSpot(movedChar.transform);
                    //see if the character is close enough. If too far, approach the target and set an interaction to trigger
                    if (Vector3.Distance(movedChar.transform.position, nearestSpot) <= interactionDistance)
                    {
                        interactionTarget.Interact();
                        lookIK.SetIKTarget(interactionTarget.transform.position);
                    }
                    else
                    {
                        //walk to the target and then interact with it
                        approachingTarget = true;
                        SetPath(nearestSpot);
                        lookIK.SetIKTarget(interactionTarget.transform.position);
                    }

                }
                else
                {
                    //indicator that nothing there can be interacted with
                    //some sort of dialogue like "it's nothing special"
                }
            }
        }
    }
예제 #30
0
 public void UpdateAfterCamera()
 {
     if(interactableHeld != null)
     {
         if (gameManager.running && Input.GetMouseButtonDown(0))
         {
             interactableHeld.Throw(this);
             interactableHeld = null;
         }
         else
         {
             interactableHeld.Held(this);
         }
     }
     else
     {
         Vector3 hitPoint;
         Interactable interactable = cameraController.GetInteractable(out hitPoint);
         if (interactableAimed != interactable)
         {
             if (interactableAimed != null)
                 interactableAimed.MouseLeave(this);
             if (interactable != null)
                 interactable.MouseEnter(this);
         }
         if (interactable != null)
         {
             interactable.MouseAimed(this);
             if (gameManager.running && Input.GetMouseButtonDown(0) && interactable.IsCloseEnough(this))
             {
                 interactableHeld = interactable;
                 interactableHeld.Take(this);
                 grabTimer = new Timer();
                 grabTimer.Reset();
             }
         }
         interactableAimed = interactable;
     }
 }
예제 #31
0
 private void OnTriggerEnter(Collider other)
 {
     interactObject = other.GetComponent <Interactable>();
 }
예제 #32
0
 private void AddInteractable(Interactable interactable)
 {
     interactablesInRange.Add(interactable);
     _interactableAddedEvent.Invoke(interactable);
 }
예제 #33
0
 private void Awake()
 {
     it = GetComponent <Interactable>();
 }
예제 #34
0
    void TryInteract()
    {
        // Get tile under player
        Tile tileUnderMe = areaController.active_area.GetTile(transform.position);

        if (tileUnderMe == null)
        {
            return;
        }
        GameObject tileGobj = areaController.GetTileGObj(tileUnderMe);

        if (tileGobj == null)
        {
            return;
        }
        Interactable interactable = null;

        while (interactable == null)
        {
            interactable = tileGobj.GetComponentInChildren <Interactable>();

            if (interactable == null)
            {
                // try its neighbors
                Tile[] neighbors = tileUnderMe.GetNeighbors();
                for (int i = 0; i < neighbors.Length; i++)
                {
                    if (neighbors[i] == null)
                    {
                        continue;
                    }
                    if (neighbors[i].hasTerminal)
                    {
                        interactable = TerminalController.instance.terminal_Interactable;
                        break;
                    }
                    tileGobj = areaController.GetTileGObj(neighbors[i]);
                    if (tileGobj == null)
                    {
                        continue;
                    }

                    interactable = tileGobj.GetComponentInChildren <Interactable>();

                    if (interactable != null)
                    {
                        break;                         // FOUND ONE
                    }
                }

                // if nothing was found, break!
                break;
            }
        }

        if (interactable != null)
        {
            interactable.TryInteract(this.gameObject);
            return;
        }

        Debug.Log("No interactable found!");
    }
예제 #35
0
 public override void MouseDown(MouseInputManager.MouseButton btn, MouseInputManager.MousePointer mouse, Interactable echo = null)
 {
     lastTouched = mouse;
     if (Progress == 0)
     {
         base.MouseDown(btn, mouse, echo);
     }
 }
예제 #36
0
 //------------------------------------
 public void SetFocus(Interactable _scpInteractable)
 {
     agent.stoppingDistance = _scpInteractable.radius * 0.8f;
     agent.updateRotation   = false;
     transTarget            = _scpInteractable.transform;
 }
예제 #37
0
 public override void MouseDown(MouseInputManager.MouseButton btn, MouseInputManager.MousePointer mouse, Interactable echo = null)
 {
     if (!busy)
     {
         StartCoroutine(TailRotate());
     }
 }
예제 #38
0
    // Update is called once per frame
    void Update()
    {
        rigidBody2D    = controller.GetRigidBody2D();
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
        verticalMove   = controller.getVelocityY();

        if (controller.disabled)
        {
            animator.SetFloat("Speed", 0f);
        }

        if (!controller.disabled)
        {
            animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
            animator.SetFloat("verticalSpeed", verticalMove);
            wingsSprite.GetComponent <Animator>().SetFloat("verticalSpeed", verticalMove);
        }

        shooting = Timer(ref shooting, ref shootTimer);

        if (Input.GetButtonDown("Jump") && abilityToJump == true)
        {
            jump = true;
        }
        if (Input.GetButton("Jump") && abilityToFly == true)
        {
            flying = true;
        }
        else
        {
            flying = false;
        }

        if (Input.GetButtonDown("Fire1") && hasGun == true)
        {
            Shoot();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidBody2D.position + Vector2.up * 0.2f, controller.getDirection(), 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                Interactable podium = hit.collider.GetComponent <Interactable>();
                if (podium != null)
                {
                    podium.interactedWith();
                    pedistalPlaced++;
                    DestroyItem();
                }
            }
        }

        hitTarget = Timer(ref hitTarget, ref targetHitTimer);
        killing   = killTimer(ref killing, ref killTime);

        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }
    }
예제 #39
0
 protected override void ImmediateReaction(ref Interactable publisher)
 {
     // Start the scene loading process.
     sceneController.FadeAndLoadScene(this);
 }
예제 #40
0
 // Start is called before the first frame update
 private void Start()
 {
     interactableObj = GetComponent <Interactable>();
     textObj         = GetComponentInChildren <TextMesh>();
 }
예제 #41
0
        public bool satisfied;          // The satisfied state the Condition will be changed to.


        protected override void ImmediateReaction(ref Interactable publisher)
        {
            condition.isSatisfied = satisfied;
        }
예제 #42
0
 private void Start()
 {
     interact = GetComponent <Interactable>();
 }
예제 #43
0
 public void FollowTarget(Interactable newTarget)
 {
     agent.stoppingDistance = newTarget.radius * .8f;
     agent.updateRotation   = false;
     target = newTarget.interactionTransform;
 }
예제 #44
0
 private void Awake()
 {
     interactable             = GetComponent <Interactable>();
     interactable.OnInteract += task.ExecuteTask;
     interactable.OnInteract += () => { interactable.OnInteract -= task.ExecuteTask; };
 }
예제 #45
0
 private void RemoveInteractable(Interactable interactable)
 {
     interactablesInRange.Remove(interactable);
     _interactableRemovedEvent.Invoke(interactable);
 }
    public override void OnInspectorGUI()
    {
        Interactable myTarget = (Interactable)target;

        GUIContent isGeneratorContent = new GUIContent("Is Generator", "Indicates if this object a generator that changes states for other objects.");

        myTarget.IsGenerator = EditorGUILayout.Toggle(isGeneratorContent, myTarget.IsGenerator);
        if (myTarget.IsGenerator)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            SerializedProperty property = serializedObject.FindProperty("ConnectedInteractables");
            EditorGUILayout.PropertyField(property, true);
            serializedObject.ApplyModifiedProperties();
            GUILayout.Space(0);
            EditorGUILayout.EndHorizontal();
        }
        GUIContent canBeInteractedWithContent = new GUIContent("Can Be Interacted With", "Indicates if this object can be interacted with.");

        myTarget.CanBeInteractedWith = EditorGUILayout.Toggle(canBeInteractedWithContent, myTarget.CanBeInteractedWith);
        if (myTarget.CanBeInteractedWith)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            EditorGUILayout.BeginVertical();
            if (!myTarget.IsGenerator)
            {
                GUIContent startStateContent = new GUIContent("Start State", "Indicates what the state of this object is going to be when the game starts.");
                myTarget.StartState = EditorGUILayout.Toggle(startStateContent, myTarget.StartState);

                GUIContent controlledByGeneratorContent = new GUIContent("Controlled Only By Generator", "Indicates if the object is controlled by the state of a external generator. [Removes the option of activating the object without generator]");
                myTarget.ControlledOnlyByGenerator = EditorGUILayout.Toggle(controlledByGeneratorContent, myTarget.ControlledOnlyByGenerator);

                if (!myTarget.ControlledOnlyByGenerator)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    EditorGUILayout.BeginVertical();
                    GUIContent controlsItselfContent = new GUIContent("Controls Itself", "Indicates if this is the object that controls the input from the player.");
                    myTarget.ControlsItself = EditorGUILayout.Toggle(controlsItselfContent, myTarget.ControlsItself);
                    if (myTarget.ControlsItself)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(20);
                        EditorGUILayout.BeginVertical();
                        GUIContent keyContent = new GUIContent("KeyCode", "Key we are going to use to change the state of the object.");
                        myTarget.Key = (KeyCode)EditorGUILayout.EnumPopup(keyContent, myTarget.Key);
                        GUIContent canGetControlledExternallyContent = new GUIContent("Can Get Controlled Externally", "Indicates if this object can get controlled by some other external means.");
                        myTarget.CanGetControlledExternally = EditorGUILayout.Toggle(canGetControlledExternallyContent, myTarget.CanGetControlledExternally);
                        EditorGUILayout.EndVertical();
                        GUILayout.Space(0);
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                    GUILayout.Space(0);
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                GUIContent controlsItselfContent = new GUIContent("Controls Itself", "Indicates if this is the object that controls the input from the player.");
                myTarget.ControlsItself = EditorGUILayout.Toggle(controlsItselfContent, myTarget.ControlsItself);
                if (myTarget.ControlsItself)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    EditorGUILayout.BeginVertical();
                    GUIContent keyContent = new GUIContent("KeyCode", "Key we are going to use to change the state of the object.");
                    myTarget.Key = (KeyCode)EditorGUILayout.EnumPopup(keyContent, myTarget.Key);
                    GUIContent canGetControlledExternallyContent = new GUIContent("Can Get Controlled Externally", "Indicates if this object can get controlled by some other external means.");
                    myTarget.CanGetControlledExternally = EditorGUILayout.Toggle(canGetControlledExternallyContent, myTarget.CanGetControlledExternally);
                    EditorGUILayout.EndVertical();
                    GUILayout.Space(0);
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
            GUILayout.Space(0);
            EditorGUILayout.EndHorizontal();
            GUIContent debugStateChangeContent = new GUIContent("Debug State Change", "Indicates if we should log a message to the console when this object changes it's state.");
            myTarget.DebugStateChange = EditorGUILayout.Toggle(debugStateChangeContent, myTarget.DebugStateChange);
        }

        GUIContent isSingleStateInteractableContent = new GUIContent("Is Single State Interactable", "Is this an object that does the same actions when it's pressed.");

        myTarget.IsSingleStateInteractable = EditorGUILayout.Toggle(isSingleStateInteractableContent, myTarget.IsSingleStateInteractable);

        onStateTrueActionsFoldout = EditorGUILayout.Foldout(onStateTrueActionsFoldout, (myTarget.IsSingleStateInteractable) ? "On Interact Actions" : "On State True Actions");
        if (onStateTrueActionsFoldout)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            EditorGUILayout.BeginVertical();
            GUIContent onStateTrueActionsArraySizeContent = new GUIContent("Size", "The size of this array.");
            myTarget.OnStateTrueActionsArraySize = EditorGUILayout.IntField(onStateTrueActionsArraySizeContent, myTarget.OnStateTrueActionsArraySize);
            myTarget.OnStateTrueActionsArraySize = Mathf.Clamp(myTarget.OnStateTrueActionsArraySize, 0, int.MaxValue);

            if (myTarget.OnStateTrueActions.Count != myTarget.OnStateTrueActionsArraySize)
            {
                if (myTarget.OnStateTrueActions.Count < myTarget.OnStateTrueActionsArraySize)
                {
                    for (int i = myTarget.OnStateTrueActions.Count; i < myTarget.OnStateTrueActionsArraySize; i++)
                    {
                        myTarget.OnStateTrueActions.Add(new Action());
                    }
                }
                else if (myTarget.OnStateTrueActions.Count > myTarget.OnStateTrueActionsArraySize)
                {
                    for (int i = myTarget.OnStateTrueActionsArraySize; i < myTarget.OnStateTrueActions.Count; i++)
                    {
                        myTarget.OnStateTrueActions.RemoveAt(i);
                    }
                }
            }

            for (int i = 0; i < myTarget.OnStateTrueActionsArraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical();
                actionFoldoutsTrue[i] = EditorGUILayout.Foldout(actionFoldoutsTrue[i], "Element " + i);
                if (actionFoldoutsTrue[i])
                {
                    ActionsArrayShow(myTarget.OnStateTrueActions, i);
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(0);
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
            GUILayout.Space(0);
            EditorGUILayout.EndHorizontal();
        }

        if (!myTarget.IsSingleStateInteractable)
        {
            onStateFalseActionsFoldout = EditorGUILayout.Foldout(onStateFalseActionsFoldout, "On State False Actions");
            if (onStateFalseActionsFoldout)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical();
                GUIContent onStateFalseActionsArraySizeContent = new GUIContent("Size", "The size of this array.");
                myTarget.OnStateFalseActionsArraySize = EditorGUILayout.IntField(onStateFalseActionsArraySizeContent, myTarget.OnStateFalseActionsArraySize);
                myTarget.OnStateFalseActionsArraySize = Mathf.Clamp(myTarget.OnStateFalseActionsArraySize, 0, 100);

                if (myTarget.OnStateFalseActions.Count != myTarget.OnStateFalseActionsArraySize)
                {
                    if (myTarget.OnStateFalseActions.Count < myTarget.OnStateFalseActionsArraySize)
                    {
                        for (int i = myTarget.OnStateFalseActions.Count; i < myTarget.OnStateFalseActionsArraySize; i++)
                        {
                            myTarget.OnStateFalseActions.Add(new Action());
                        }
                    }
                    else if (myTarget.OnStateFalseActions.Count > myTarget.OnStateFalseActionsArraySize)
                    {
                        for (int i = myTarget.OnStateFalseActionsArraySize; i < myTarget.OnStateFalseActions.Count; i++)
                        {
                            myTarget.OnStateFalseActions.RemoveAt(i);
                        }
                    }
                }

                for (int i = 0; i < myTarget.OnStateFalseActionsArraySize; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    EditorGUILayout.BeginVertical();
                    actionFoldoutsFalse[i] = EditorGUILayout.Foldout(actionFoldoutsFalse[i], "Element " + i);
                    if (actionFoldoutsFalse[i])
                    {
                        ActionsArrayShow(myTarget.OnStateFalseActions, i);
                    }
                    EditorGUILayout.EndVertical();
                    GUILayout.Space(0);
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(0);
                EditorGUILayout.EndHorizontal();
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(myTarget);
        }

        serializedObject.ApplyModifiedProperties();
    }
예제 #47
0
 /// Request interact function to add interacts.
 public void RequestInteract(Interactable interactObject)
 {
     interactObject.StartInteract();
     interactable = interactObject;
     SetState(PlayerControllerState.INTERACTING);
 }
    // Update is called once per frame
    void Update()
    {
        movementInput.x = Input.GetAxis("Horizontal");
        movementInput.z = Input.GetAxis("Vertical");
        charControl.SimpleMove(movementInput.normalized * speed);

        Ray   ray         = Camera.main.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, transform.position);
        float hitDistance;

        if (groundPlane.Raycast(ray, out hitDistance))
        {
            Vector3 point = ray.GetPoint(hitDistance);
            //Debug.DrawLine (ray.origin,point, Color.red);
            LookAt(point);

            if (Vector3.Distance(point, transform.position) <= interactRange)
            {
                interactHint.position = point;
                interactHint.gameObject.SetActive(true);

                Collider[] hits = Physics.OverlapSphere(point, 3f);
                float      minDistFromCursor = interactRange;
                for (int i = 0; i < hits.Length; i++)
                {
                    if (Vector3.Distance(hits [i].transform.position, transform.position) < interactRange)
                    {
                        float distFromCursor = Vector3.Distance(hits [i].transform.position, point);
                        if (distFromCursor < minDistFromCursor)
                        {
                            Interactable interact = hits [i].GetComponentInParent <Interactable> ();
                            if (interact != null)
                            {
                                interactTarget        = interact;
                                interactHint.position = interactTarget.transform.position;
                                minDistFromCursor     = distFromCursor;
                            }
                        }
                    }
                }
            }
            else
            {
                interactHint.gameObject.SetActive(false);
            }

            /*
             * float distance = Vector3.Distance (point, transform.position);
             * if (distance <= interactRange) {
             *      interactTarget.position = point;
             *      interactTarget.gameObject.SetActive (true);
             * } else if (distance <= interactSnapRange) {
             *      interactTarget.position = transform.position + (point - transform.position).normalized * interactRange;
             *      interactTarget.gameObject.SetActive (true);
             * } else {
             *      interactTarget.gameObject.SetActive (false);
             * }
             */


            if (Input.GetButtonDown("Fire1") && interactTarget != null)
            {
                //Debug.Log ("interacting");
                interactTarget.Interact();
            }
        }
    }
예제 #49
0
 public void CloseCoinUp()
 {
     current = null;
     currentObjLabel.text = "";
     coinUp.SetActive(false);
 }
예제 #50
0
 void Start()
 {
     interactable = GetComponent <Interactable>();
     m_DeleteAction.AddOnStateDownListener(ButtonDown, SteamVR_Input_Sources.LeftHand);
     m_DeleteAction.AddOnStateDownListener(ButtonDown, SteamVR_Input_Sources.RightHand);
 }
        /// <summary>
        /// Generates an interactable from primitives and assigns a select action.
        /// </summary>
        private void AssembleInteractableButton(out Interactable interactable, out Transform translateTargetObject, string selectActionDescription = "Select")
        {
            // Assemble an interactable out of a set of primitives
            // This will be the button housing
            var interactableObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

            interactableObject.name = "RuntimeInteractable";
            interactableObject.transform.position    = new Vector3(0.05f, 0.05f, 0.625f);
            interactableObject.transform.localScale  = new Vector3(0.15f, 0.025f, 0.15f);
            interactableObject.transform.eulerAngles = new Vector3(90f, 0f, 180f);

            // This will be the part that gets scaled
            GameObject childObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            var        renderer    = childObject.GetComponent <Renderer>();

            renderer.material.color  = DefaultColor;
            renderer.material.shader = StandardShaderUtility.MrtkStandardShader;

            childObject.transform.parent        = interactableObject.transform;
            childObject.transform.localScale    = new Vector3(0.9f, 1f, 0.9f);
            childObject.transform.localPosition = new Vector3(0f, 1.5f, 0f);
            childObject.transform.localRotation = Quaternion.identity;
            // Only use a collider on the main object
            GameObject.Destroy(childObject.GetComponent <Collider>());

            translateTargetObject = childObject.transform;

            // Add an interactable
            interactable = interactableObject.AddComponent <Interactable>();

            var themeDefinition = ThemeDefinition.GetDefaultThemeDefinition <ScaleOffsetColorTheme>().Value;

            // themeDefinition.Easing.Enabled = false;
            // Set the offset state property (index = 1) to move on the Pressed state (index = 2)
            themeDefinition.StateProperties[1].Values = new List <ThemePropertyValue>()
            {
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
                new ThemePropertyValue()
                {
                    Vector3 = new Vector3(0.0f, -0.32f, 0.0f)
                },
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
            };
            // Set the color state property (index = 2) values
            themeDefinition.StateProperties[2].Values = new List <ThemePropertyValue>()
            {
                new ThemePropertyValue()
                {
                    Color = DefaultColor
                },
                new ThemePropertyValue()
                {
                    Color = FocusColor
                },
                new ThemePropertyValue()
                {
                    Color = Color.green
                },
                new ThemePropertyValue()
                {
                    Color = DisabledColor
                },
            };

            Theme testTheme = ScriptableObject.CreateInstance <Theme>();

            testTheme.States      = interactable.States;
            testTheme.Definitions = new List <ThemeDefinition>()
            {
                themeDefinition
            };

            interactable.Profiles = new List <InteractableProfileItem>()
            {
                new InteractableProfileItem()
                {
                    Themes = new List <Theme>()
                    {
                        testTheme
                    },
                    Target = translateTargetObject.gameObject,
                },
            };

            // Set the interactable to respond to the requested input action
            MixedRealityInputAction selectAction = CoreServices.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == selectActionDescription).FirstOrDefault();

            Assert.NotNull(selectAction.Description, "Couldn't find " + selectActionDescription + " input action in input system profile.");
            interactable.InputAction = selectAction;
        }
예제 #52
0
 public override bool UseObjectOnObject(Interactable target)
 {
     return(false);
 }
    public override IEnumerator PerformInteraction(Interactable source)
    {
        var keyType = GetInputValue("KeyType", KeyType);
        var key     = GetInputValue("Key", Key);
        var value   = GetInputValue("Value", Value);

        switch (keyType)
        {
        case KeyType.Global:
            switch (setType)
            {
            case SetType.Set:
                GameController.SetGlobal(key, value);
                break;

            case SetType.Add:
                GameController.SetGlobal(key, GameController.GetGlobal(key) + value);
                break;

            case SetType.Subtract:
                GameController.SetGlobal(key, GameController.GetGlobal(key) - value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            break;

        case KeyType.Local:
            switch (setType)
            {
            case SetType.Set:
                source.SetLocal(key, value);
                break;

            case SetType.Add:
                source.SetLocal(key, source.GetLocal(key) + value);
                break;

            case SetType.Subtract:
                source.SetLocal(key, source.GetLocal(key) - value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            break;

        case KeyType.Instance:
            switch (setType)
            {
            case SetType.Set:
                source.SetInstance(key, value);
                break;

            case SetType.Add:
                source.SetInstance(key, (int)source.GetInstance(key, 0) + value);
                break;

            case SetType.Subtract:
                source.SetInstance(key, (int)source.GetInstance(key, 0) - value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            break;
        }
        yield break;
    }
예제 #54
0
    void Update()
    {
        //store script component of interactables.
        if (timeForMaxSpeed >= 0)
        {
            timeForMaxSpeed -= Time.deltaTime;
        }


        if (toInteract)
        {
            Interactable objToInteract = toInteract.GetComponent <Interactable>();
            //check for vegetables
            if (objToInteract.Type == "Vegetable" && Input.GetKeyDown(useKey) &&
                vegetablesInHand.Count < 2)
            {
                //add vege to hand
                string vegeName = objToInteract.Name;
                AddToPlayerHand(vegeName);
            }

            //check for chopping Board
            if (objToInteract.Type == "Board")
            {
                //storing argument to pass on function..
                int boardID = objToInteract.ID;
                choppedVege = toInteract.GetComponent <ChoppingBoard>();
                //chop vegetables.
                if (vegetablesInHand.Count > 0 && Input.GetKeyDown(useKey) &&
                    choppedVege.Container.Count < 3 && !startChoping)
                {
                    isChopping = true;
                    StartCoroutine(ChoppingVege(boardID, choppedVege));
                }
                //pick up dish from Board.
                else if (vegetablesInHand.Count == 0 && Input.GetKeyDown(useKey) &&
                         readyDish.text == "")
                {
                    //add dish on player hand
                    AddSaladOnPlayer(boardID);
                }
            }

            //check for Dustbin
            if (objToInteract.Type == "Dustbin")
            {
                //delete choppedvege list
                if (Input.GetKeyDown(useKey))
                {
                    if (choppedVege)
                    {
                        ClearChoppedVegeBoard(choppedVege);
                    }
                }
            }

            //check for Dish
            if (objToInteract.Type == "Dish" && Input.GetKeyDown(useKey))
            {
                int dishID = objToInteract.ID;
                dishItem = toInteract.GetComponent <Dish>();
                AddToDish(dishID, dishItem);
            }

            //check for Customer
            if (objToInteract.Type == "Customer" && Input.GetKeyDown(useKey))
            {
                //   Debug.Log("Customer Interaction.");
                cust = objToInteract.GetComponent <Customer>();
                isCustomerDone();
            }
        }
    }
예제 #55
0
        public static bool SearchForInteractbleWithConstructPriority_Prefix(HumanAI __instance, ref Interactable __result, Interaction interaction, float distance, List <InteractionRestriction> restrictions = null, bool probablyReachablesOnly = false, bool objectInteraction = false, Vector3 positionOverride = default(Vector3))
        {
            Vector3 position      = (positionOverride == default(Vector3)) ? __instance.GetPosition() : positionOverride;
            int     positionFloor = Mathf.RoundToInt(position.y / 2.3f);
            List <Pair <Interactable, float> > priorities = new List <Pair <Interactable, float> >();

            foreach (Interactable interactable in __instance.SearchForInteractablesWithInteraction(Interaction.Construct, distance, restrictions, probablyReachablesOnly, objectInteraction, positionOverride))
            {
                float dist     = Vector3.Distance(position, interactable.GetWorldPosition());
                float priority = dist;

                if (interactable is FloorInteractable)
                {
                    priority += 0;
                }
                else if (interactable is FurnitureInteractable && interactable.GetPrimaryHolder <Furniture>().HasModule <WallPartModule>() && interactable.GetPrimaryHolder <Furniture>().GetModule <WallPartModule>().isDoor)
                {
                    priority += 20;
                }
                else if (interactable is WallInteractable)
                {
                    priority += 30;
                }
                else if (interactable is FurnitureInteractable && interactable.GetPrimaryHolder <Furniture>().HasModule <StairsModule>())
                {
                    priority += 40;
                }
                else
                {
                    priority += 120;
                }

                int floor = Mathf.RoundToInt(interactable.GetWorldPosition().y / 2.3f);
                priority += 80 * Mathf.Abs(floor - positionFloor);

                priorities.Add(new Pair <Interactable, float>(interactable, priority));
            }

            __result = priorities.MinBy(x => x.second).first;

            return(false);
        }
예제 #56
0
 public void SetSelectedInteractable(Interactable interactable)
 {
     currentInteractable = interactable;
 }
예제 #57
0
    // Update is called once per frame
    void Update()
    {
        //First im collecting the Inputdata and print them out for Debug
        float moveX  = Input.GetAxis("Horizontal") * MovementSpeed;
        float moveZ  = Input.GetAxis("Vertical") * MovementSpeed;
        float mouseX = Input.GetAxis("Mouse X") * MouseSpeed;
        float mouseY = Input.GetAxis("Mouse Y") * MouseSpeed;
        float contX  = Input.GetAxis("Controller X") * ControllerSpeed;
        float contY  = Input.GetAxis("Controller Y") * ControllerSpeed;

        //Now im processing the Input

        if (Input.GetKeyDown(KeyCode.M))
        {
            if (!MiniMapOpen)
            {
                MiniMap.sizeDelta = new Vector2(800, 800);
                MiniMap.position  = new Vector3(564, 317, 0);
                MiniMapOpen       = true;
            }
            else
            {
                MiniMap.sizeDelta = new Vector2(200, 200);
                MiniMap.position  = new Vector3(-400, -200, 0);
                MiniMapOpen       = false;
            }
        }
        if (moveZ < 0 || moveZ > 0)
        {
            if (!Animator.isPlaying)
            {
                Animator.Play("Walk");
            }
        }

        if (Input.GetButtonDown("Crouch") && Controller.isGrounded)
        {
            if (!Crouching)
            {
                Camera.position -= new Vector3(0, .8f, 0);
                Crouching        = true;
            }
            else
            {
                Camera.position += new Vector3(0, .8f, 0);
                Crouching        = false;
            }
        }

        if (Input.GetButton("Run"))
        {
            moveZ = moveZ * 5;
            if (!Animator.IsPlaying("Run"))
            {
                Animator.Stop();
            }
            if (!Animator.isPlaying)
            {
                Animator.Play("Run");
            }
        }

        if (moveZ == 0)
        {
            Animator.Stop();
        }
        Vector3 move = Player.forward * moveZ + Player.right * moveX;

        xRotation -= mouseY;
        xRotation -= contY;
        xRotation  = Mathf.Clamp(xRotation, -90, 90);

        if (Controller.isGrounded)
        {
            AppliedGravity.y = -2f;
        }
        else
        {
            AppliedGravity.y += Gravity * Time.deltaTime;
            Animator.Stop();
        }

        if (Input.GetButtonDown("Jump") && Controller.isGrounded)
        {
            AppliedGravity.y += JumpHeight;
        }

        //Here i'm applying the movement
        Camera.localRotation = Quaternion.Euler(xRotation, 0, 0);
        Player.Rotate(0, mouseX, 0);
        Player.Rotate(0, contX, 0);
        Controller.Move(move * Time.deltaTime);
        Controller.Move(AppliedGravity * Time.deltaTime);


        //Animation


        //Interactable
        // If we press right mouse
        if (Input.GetMouseButtonDown(1))
        {
            // Shoot out a ray
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100f))
            {
                Interactable interactable = hit.collider.GetComponent <Interactable>();
                if (interactable != null)
                {
                    SetFocus(interactable);
                }
            }
        }
    }
예제 #58
0
    // Update is called once per frame
    void Update()
    {
        //if we hover over ui we can't move
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            boxCollider.enabled = false;
            Vector3 mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
            print(mousePos2D);
            //if I want to cast rays only in cross shape
            #region UsedOnlyForCastingRayWithoutDiagonals
            //float distanceFromClickX = (mousePos2D.x - transform.position.x);
            //float distanceFromClickY = (mousePos2D.y - transform.position.y);
            //float distanceFromClickXAbs = Mathf.Abs(distanceFromClickX);
            //float distanceFromClickYAbs = Mathf.Abs(distanceFromClickY);
            //Vector2 direction = Vector2.zero;
            //bool clickedHorizontal = false;
            //if(distanceFromClickXAbs > distanceFromClickYAbs)
            //{
            //    clickedHorizontal = true;
            //}
            //else
            //{
            //    clickedHorizontal = false;
            //}

            //if (clickedHorizontal)
            //{
            //    if(distanceFromClickX > 0)
            //    {
            //        direction = Vector2.right;
            //    } else
            //    {
            //        direction = Vector2.left;
            //    }
            //}else if (!clickedHorizontal)
            //{
            //    if(distanceFromClickY > 0)
            //    {
            //        direction = Vector2.up;
            //    }
            //    else
            //    {
            //        direction = Vector2.down;
            //    }
            //}
            #endregion
            Vector3 rayDirection = mousePos - transform.position;
            Debug.DrawRay(transform.position, rayDirection, Color.red);
            //mamy hit wszystkich obiektow ktore nie sa na layer w odleglosci 1 kratki
            //distance = tu dystans jaki bedziemy miec do interakcji z przedmiotem. Zamienic z interractRadius
            RaycastHit2D hit = Physics2D.Raycast(transform.position, rayDirection, interractRadius, ~layer);

            if (hit)
            {
                Interactable interactable = hit.collider.GetComponent <Interactable>();
                if (interactable != null)
                {
                    SetFocus(interactable);
                }
            }
            else
            {
                RemoveFocus();
            }
            boxCollider.enabled = true;
            //particleEmitter of the cross ray
            //clickedHorizontal = false;
        }
    }
예제 #59
0
 public override void MouseMove(MouseInputManager.MouseButton btn, MouseInputManager.MousePointer mouse, Interactable echo = null)
 {
 }
예제 #60
0
 public override void MouseUp(MouseInputManager.MouseButton btn, MouseInputManager.MousePointer mouse, Interactable echo = null)
 {
     turnTheWheel = false;
     anim.SetBool("appui", false);
     light.SetActive(false);
     AkSoundEngine.PostEvent("Stop_grande_roue", gameObject);
 }