Ejemplo n.º 1
0
    protected override void React(GameEventData eventData)
    {
        RaycastHit hitInfo;
        Ray ray = new Ray();

        // handle different kinds of event data
        // MouseInput event

        MouseInput.MouseData mouseData = (MouseInput.MouseData)eventData.Get(EventDataKeys.InputData).data;
        if (mouseData != null && mouseData.inputValue > 0)
        {
            ray = mouseData.rayFromPosition;
        }

        // raycast
        if (ray.direction != Vector3.zero)
        {
            Physics.Raycast(ray, out hitInfo, raycastDistance, raycastLayers.value);

            if (hitInfo.collider != null)
            {
                GetComponent<RaycastHitEvent>().Trigger(
                    GameEventData.Empty.Add(new DataPiece(EventDataKeys.RaycastData) { data = hitInfo })
                    .Add(new DataPiece(EventDataKeys.TargetObject) { data = hitInfo.collider.gameObject }));
            }
        }
    }
    protected override void React(GameEventData data)
    {
        DataPiece inputData;
        if ((inputData = data.Get(EventDataKeys.InputData)) != null &&
            inputData.dataType == typeof(MouseInput.MouseData))
        {
            Vector2 deltaMovement = ((MouseInput.MouseData)inputData.data).axisValues;

            //((IRotate)Reactor).Rotate(data, deltaMovement);

            float xRotation = Reactor.transform.localEulerAngles.y + deltaMovement.x * Sensitivity;
            yRotation += deltaMovement.y * Sensitivity;

            yRotation = Mathf.Clamp(yRotation, -MaxYRotation, MaxYRotation);

            Reactor.transform.localEulerAngles = new Vector3(-yRotation, xRotation, 0);
        }
    }
Ejemplo n.º 3
0
    protected override void React(GameEventData eventData)
    {
        DataPiece targetObject = eventData.Get(EventDataKeys.TargetObject);
        if (targetObject != null)
        {
            GameObject target = targetObject.data as GameObject;

            if (target != null)
            {
                targetTransform = target.transform;
            }
        }
    }
    protected override void React(GameEventData eventData)
    {
        if (TargetObj == TargetObject.EVENT_TARGET)
        {
            DataPiece o = eventData.Get(EventDataKeys.TargetObject);
            if (o != null && o.data as GameObject)
            {
                gameObjectToDeactivate = o.data as GameObject;
            }
        }
        else
            gameObjectToDeactivate = ObjectToDeactivate.gameObject;

        if (!deactivating)
            StartCoroutine(DeactivateAfter(Timeout));
        deactivating = true;
    }
Ejemplo n.º 5
0
    protected override void React(GameEventData eventData)
    {
        if (DirectionRelativeTo == RelativeTo.ACTOR && ActorDirectionIsRelativeTo == null)
            return;

        float v;
        if (eventData != null && eventData.Get(EventDataKeys.InputData) != null)
        {
            v = ((InputReceived.InputData)eventData.Get(EventDataKeys.InputData).data).inputValue;
        }
        else
            v = 1;

        Transform relevantTransform;
        if (DirectionRelativeTo == RelativeTo.ACTOR)
            relevantTransform = ActorDirectionIsRelativeTo.transform;
        else if (DirectionRelativeTo == RelativeTo.SELF)
            relevantTransform = Reactor.transform;
        else // world
            relevantTransform = new GameObject("origin").transform;

        Vector3 dir = Vector3.zero;
        if (DirectionRelativeTo != RelativeTo.ACTOR)
        {
            switch (MoveDirection)
            {
                case Direction.FORWARD:
                    dir = relevantTransform.forward;
                    dir.y = 0;
                    break;
                case Direction.BACKWARD:
                    dir = -relevantTransform.forward;
                    dir.y = 0;
                    break;
                case Direction.LEFT:
                    dir = -relevantTransform.right;
                    dir.y = 0;
                    break;
                case Direction.RIGHT:
                    dir = relevantTransform.right;
                    dir.y = 0;
                    break;
                case Direction.UP:
                    dir = relevantTransform.up;
                    break;
                case Direction.DOWN:
                    dir = -relevantTransform.up;
                    break;
            }
        }
        else
        {
            dir = (relevantTransform.position - Reactor.transform.position).normalized;
            switch (MoveDirection)
            {
                case Direction.FORWARD:
                    dir.y = 0;
                    break;
                case Direction.BACKWARD:
                    dir = -dir;
                    dir.y = 0;
                    break;
                case Direction.LEFT:
                    dir = -relevantTransform.right;
                    dir.y = 0;
                    break;
                case Direction.RIGHT:
                    dir = relevantTransform.right;
                    dir.y = 0;
                    break;
                case Direction.UP:
                    dir = relevantTransform.up;
                    break;
                case Direction.DOWN:
                    dir = -relevantTransform.up;
                    break;
            }
        }

        Reactor.rigidbody.AddForce(dir * v * MoveSpeed);

        if (relevantTransform.name == "origin")
            Destroy(relevantTransform.gameObject);

        if (RotateWithMovement)
        {
            Vector3 horizontalVelocity = Reactor.rigidbody.velocity;
            horizontalVelocity.y = 0;
            Reactor.transform.forward = Vector3.Lerp(Reactor.transform.forward, horizontalVelocity, RotationSpeed * Time.deltaTime);
        }
    }