private void PhysicRaycast(PhysicsRaycaster raycaster)
    {
        if (raycaster == null)
        {
            return;
        }

        List <RaycastResult> _raycast_results = new List <RaycastResult>();

        raycaster.Raycast(pointerData, _raycast_results);

        RaycastResult _firstResult = FindFirstRaycast(_raycast_results);

        pointerData.pointerCurrentRaycast = _firstResult;

        //PrintDebugLog ("PhysicRaycast() first result = " + _firstResult);

        if (_firstResult.gameObject != null)
        {
            if (_firstResult.worldPosition == Vector3.zero)
            {
                _firstResult.worldPosition = GetIntersectionPosition(
                    _firstResult.module.eventCamera,
                    //_eventController.event_data.enterEventCamera,
                    _firstResult
                    );
                pointerData.pointerCurrentRaycast = _firstResult;
            }

            pointerData.position = _firstResult.screenPosition;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Mouse.current.leftButton.wasPressedThisFrame)
        {
            //Set up the new Pointer Event
            PointerEventData     pointerData = new PointerEventData(EventSystem.current);
            List <RaycastResult> results     = new List <RaycastResult>();

            //Raycast using the Physics Raycaster and mouse click position
            pointerData.position = Mouse.current.position.ReadValue();
            raycaster.Raycast(pointerData, results);

            //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
            foreach (RaycastResult result in results)
            {
                //Debug.Log(result.gameObject.tag + " selected");
                if (result.gameObject.tag == "Ship")
                {
                    fleetUnitSelected = result.gameObject.transform.root;
                    //Debug.Log(fleetUnitSelected + " selected");
                    fleetUnitSelected.gameObject.BroadcastMessage("FleetSelected", true);
                }
            }

            if (results.Count == 0 && fleetUnitSelected != null)
            {
                fleetUnitSelected.BroadcastMessage("FleetSelected", false);
            }
        }
    }
示例#3
0
    private void PhysicRaycast(EventController event_controller, PhysicsRaycaster raycaster)
    {
        List <RaycastResult> _raycast_results = new List <RaycastResult>();

        raycaster.Raycast(event_controller.event_data, _raycast_results);

        RaycastResult _firstResult = FindFirstRaycast(_raycast_results);

        event_controller.event_data.pointerCurrentRaycast = _firstResult;

        #if UNITY_EDITOR
        if (_firstResult.module != null)
        {
            //Debug.Log ("PhysicRaycast() device: " + event_controller.device + ", camera: " + _firstResult.module.eventCamera + ", first result = " + _firstResult);
        }
        #endif

        if (_firstResult.gameObject != null)
        {
            if (_firstResult.worldPosition == Vector3.zero)
            {
                _firstResult.worldPosition = GetIntersectionPosition(
                    _firstResult.module.eventCamera,
                    //_eventController.event_data.enterEventCamera,
                    _firstResult
                    );
                event_controller.event_data.pointerCurrentRaycast = _firstResult;
            }

            event_controller.event_data.position = _firstResult.screenPosition;
        }
    }
    private void PhysicsRaycast()
    {
        if (eventCamera == null || pointerPhysicsRaycaster == null)
        {
            return;
        }

        // Clear cache values.
        physicsRaycastResults.Clear();
        physicsRaycastObjects.Clear();

        // Raycasting.
        pointerPhysicsRaycaster.Raycast(mPointerEventData, physicsRaycastResults);
        if (physicsRaycastResults.Count == 0)
        {
            return;
        }

        for (int i = 0; i < physicsRaycastResults.Count; i++)
        {
            // Ignore the GameObject with WaveVR_BonePose component.
            if (physicsRaycastResults [i].gameObject.GetComponent <WaveVR_BonePose> () != null)
            {
                continue;
            }

            physicsRaycastObjects.Add(physicsRaycastResults [i].gameObject);
        }

        firstRaycastResult = FindFirstRaycast(physicsRaycastResults);

        //DEBUG ("PhysicsRaycast() device: " + event_controller.device + ", camera: " + firstRaycastResult.module.eventCamera + ", first result = " + firstRaycastResult);
        mPointerEventData.pointerCurrentRaycast = SelectRaycastResult(mPointerEventData.pointerCurrentRaycast, firstRaycastResult);
    }
        // public override GameState PastState { get; set; }
        // public override GameState PresentState { get; set; }

        public override void Execute(ServerGameEntity damageEntity)
        {
            if (!damageEntity.hasTransform)
            {
                return;
            }

            if (!damageEntity.hasDamage)
            {
                return;
            }

            var testTransform = damageEntity.transform.value;

            if (testTransform == null)
            {
                log.Error("Transform пуст");
                return;
            }
            Vector3 currentPosition = damageEntity.transform.value.position;
            Vector3 direction       = damageEntity.transform.value.rotation * Vector3.forward;
            Vector3 velocity        = damageEntity.rigidbody.value.velocity * tickDeltaTimeStorage.GetDeltaTimeSec();

            //Есть столкновение?
            bool collisionOccurred = physicsRaycaster
                                     .Raycast(currentPosition, direction, velocity.magnitude, out RaycastHit raycastHit);

            if (!collisionOccurred)
            {
                return;
            }

            EntityLink       entityLink   = raycastHit.transform.gameObject.GetEntityLink();
            ServerGameEntity targetEntity = (ServerGameEntity)entityLink.entity;

            if (targetEntity == null)
            {
                return;
            }

            ushort entityId = targetEntity.id.value;

            //Проверка попадания по самому себе
            if (damageEntity.parentWarship.entity.id.value == entityId)
            {
                log.Error($"Попадание по самому себе parentId = {entityId}");
                return;
            }

            ServerGameEntity hitEntity = gameContext.CreateEntity();

            hitEntity.AddHit(damageEntity, targetEntity);
        }
示例#6
0
        private bool ContinueHandleClick(PointerEventData eventData)
        {
            List <RaycastResult> results = new List <RaycastResult>();

            _physicsRaycaster.Raycast(eventData, results);

            if (results.Count == 0)
            {
                return(false);
            }

            ExecuteEvents.Execute <IPointerClickHandler>(results[0].gameObject, eventData, (handler, edata) => handler.OnPointerClick((PointerEventData)edata));

            return(true);
        }
    private Transform FindReference()
    {
        PointerEventData pointerEventData = new PointerEventData(EventSystem.current);

        pointerEventData.position = Input.mousePosition;
        physicsRaycaster.Raycast(pointerEventData, raycastResults);
        if (raycastResults.Count > 0)
        {
            return(raycastResults[0].gameObject.transform);
        }
        else
        {
            return(null);
        }
    }
示例#8
0
 //This is a good example to highlight the difference between prototype and production code. See object Root/Grid.
 public void OnCLick(BaseEventData data)
 {
     _results.Clear();
     _raycaster.Raycast(data as PointerEventData, _results);
     foreach (var hit in _results)
     {
         Vector2       coordinates   = GetWorldToGridPosition(hit.worldPosition);
         BuildingModel buildingModel = _sharedData.SelectedBuilding.Value;
         if (CreateBuilding != null)
         {
             CreateBuilding(buildingModel, coordinates, _selectedCell.transform.position);
         }
         _sharedData.SelectedBuilding.Value = null;
         Debug.LogFormat("{0}, {1}", (int)coordinates.x, (int)coordinates.y);
     }
 }
示例#9
0
    private void PhysicRaycast_Left()
    {
        Camera           _cam       = (Camera)LeftController.GetComponent(typeof(Camera));
        PhysicsRaycaster _raycaster = LeftController.GetComponent <PhysicsRaycaster> ();

        if (_cam == null || _raycaster == null)
        {
            Log.e(LOG_TAG, "PhysicRaycast_Left() no Camera or Physics Raycaster!");
            return;
        }

        if (leftHandPointer == null)
        {
            leftHandPointer = new PointerEventData(eventSystem);
        }

        leftHandPointer.Reset();
        leftHandPointer.position = new Vector2(0.5f * Screen.width, 0.5f * Screen.height);   // center of screen

        List <RaycastResult> _results = new List <RaycastResult>();

        if (_raycaster != null)
        {
            _raycaster.Raycast(leftHandPointer, _results);
        }

        RaycastResult _firstResult = FindFirstRaycast(_results);

        if (_firstResult.module != null)
        {
            #if UNITY_EDITOR
            //Debug.Log ("PhysicRaycast_Left(), camera: " + _firstResult.module.eventCamera + ", first result = " + _firstResult);
            #endif
            //Log.d (LOG_TAG, "PhysicRaycast_Left(), camera: " + _firstResult.module.eventCamera + ", first result = " + _firstResult);
        }

        leftHandPointer.pointerCurrentRaycast = _firstResult;
        if (_firstResult.gameObject != null)
        {
            leftHandPointer.position = _firstResult.screenPosition;
        }
    }
示例#10
0
    public static int Raycast(IntPtr l)
    {
        int result;

        try
        {
            PhysicsRaycaster physicsRaycaster = (PhysicsRaycaster)LuaObject.checkSelf(l);
            PointerEventData eventData;
            LuaObject.checkType <PointerEventData>(l, 2, out eventData);
            List <RaycastResult> resultAppendList;
            LuaObject.checkType <List <RaycastResult> >(l, 3, out resultAppendList);
            physicsRaycaster.Raycast(eventData, resultAppendList);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
    private void CastRay()
    {
        if (Input.GetAxis("Mouse X") == 0 && Input.GetAxis("Mouse Y") == 0)
        {
            return;
        }

        pointerEventData.position = Input.mousePosition;
        raycastResults.Clear();
        physicsRaycaster.Raycast(pointerEventData, raycastResults);
        if (raycastResults.Count == 0)
        {
        }
        else
        {
            foreach (RaycastResult raycastResult in raycastResults)
            {
                if (raycastResult.gameObject.GetComponent <TileController>())
                {
                    DispatchCardOverBuildableTileEvent(grabbedCard.card, raycastResult.gameObject.GetComponent <TileController>().tile);
                }
            }
        }
    }
    private void PhysicsRaycast(PhysicsRaycaster raycaster)
    {
        RaycastResult _firstResult = new RaycastResult();

        physicsRaycastObjectsGaze.Clear();
        physicsRaycastResultsGaze.Clear();

        Profiler.BeginSample("PhysicsRaycaster.Raycast() Gaze.");
        raycaster.Raycast(pointerData, physicsRaycastResultsGaze);
        Profiler.EndSample();

        for (int i = 0; i < physicsRaycastResultsGaze.Count; i++)
        {
            physicsRaycastObjectsGaze.Add(physicsRaycastResultsGaze [i].gameObject);
        }

        _firstResult = FindFirstRaycast(physicsRaycastResultsGaze);

        if (_firstResult.module != null)
        {
            //DEBUG ("PhysicsRaycast() device: " + event_controller.device + ", camera: " + _firstResult.module.eventCamera + ", first result = " + _firstResult);
        }

        if (_firstResult.gameObject != null)
        {
            if (_firstResult.worldPosition == Vector3.zero)
            {
                _firstResult.worldPosition = GetIntersectionPosition(
                    _firstResult.module.eventCamera,
                    _firstResult
                    );
            }

            float new_dist =
                Mathf.Abs(
                    _firstResult.worldPosition.z -
                    _firstResult.module.eventCamera.transform.position.z);
            float origin_dist =
                Mathf.Abs(
                    pointerData.pointerCurrentRaycast.worldPosition.z -
                    _firstResult.module.eventCamera.transform.position.z);

            if (pointerData.pointerCurrentRaycast.gameObject == null || origin_dist > new_dist)
            {
                /*
                 * DEBUG ("PhysicsRaycast()" +
                 *      ", raycasted: " + _firstResult.gameObject.name +
                 *      ", raycasted position: " + _firstResult.worldPosition +
                 *      ", new_dist: " + new_dist +
                 *      ", origin target: " +
                 *      (pointerData.pointerCurrentRaycast.gameObject == null ?
                 *              "null" :
                 *              pointerData.pointerCurrentRaycast.gameObject.name) +
                 *      ", origin position: " + pointerData.pointerCurrentRaycast.worldPosition +
                 *      ", origin distance: " + origin_dist);
                 */
                pointerData.pointerCurrentRaycast = _firstResult;
                pointerData.position = _firstResult.screenPosition;
            }
        }
    }