/// <summary>
    /// 按键操作
    /// </summary>
    public override void OnUpdate()
    {
        if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.L))
        {
            // TODO 路面桥梁
            //RoadManager.Instance.SetShow(RoadManager.Instance.toBeShow);
            //RoadManager.Instance.toBeShow = !RoadManager.Instance.toBeShow;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            isAdd = false;
        }

        if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            isAdd = true;
        }

        if (Projection.enabled)
        {
            // 更新投影的位置
            hitInfo = Utility.SendRay(LayerMask.GetMask("Terrain"));
            if (!hitInfo.Equals(default(RaycastHit)))
            {
                Projection.transform.position = hitInfo.point + Vector3.up * 10000;
            }
        }
    }
Ejemplo n.º 2
0

        
Ejemplo n.º 3
0
    private void FixedUpdate()
    {
        RaycastHit hit;

        if (Physics.Raycast(p.getPlayerPosition(), Vector3.down, out hit))
        {
            if (!prev.Equals(hit))
            {
                prev          = hit;
                CurrentScript = hit.collider.gameObject.GetComponent <PlankScript>();
                Debug.Log("Trigger");
            }
        }

        if (Input.GetKeyDown(Keys.GetKey(1 + (PlayerNumber - 1) * 2)))
        {
            if (HitCrate)
            {
                if (ReturnTS != null)
                {
                    ReturnTS.ReturnPing(HeldItemID);
                }
                ChangeHeldItem(HitCrateContent);
            }
        }
    }
Ejemplo n.º 4
0
 //返回射线的碰撞信息
 public RaycastHit GetHitInfo()
 {
     if (hitInfo.Equals(null))
     {
         Debug.LogWarning("hitInfo is null");
     }
     return(hitInfo);
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        rightHit           = new RaycastHit();
        leftHit            = new RaycastHit();
        hit                = new RaycastHit();
        avoidPlanner.avoid = false;

        //Debug.DrawRay(transform.position - transform.up + transform.right * 0.75f * transform.lossyScale.x, transform.up * detectingRange, Color.white);
        //Debug.DrawRay(transform.position - transform.up - transform.right * 0.75f * transform.lossyScale.x, transform.up * detectingRange, Color.white);

        if (Physics.Raycast(transform.position + transform.up, transform.up, out hit, detectingRange, ~ignoredLayer))
        {
            if (hit.transform.tag == "Food")
            {
                Debug.DrawRay(transform.position + transform.up, transform.up * hit.distance, Color.green);

                muscle.food        = hit.transform.gameObject;
                muscle.instruction = 2;

                //if (muscle.enemy.Equals(null)) // If there are not enemy around
                //{
                //}
            }
        }

        if (Physics.Raycast(transform.position - transform.up + transform.right * 0.75f * transform.lossyScale.x, transform.up, out rightHit, detectingRange, ~ignoredLayer)) //Right side of the animal
        {
            if (rightHit.transform.tag == "Obstacle" && (muscle.food == null || hit.Equals(new RaycastHit()) || rightHit.distance < hit.distance))                            //If the animal is not seeking a nearer food
            {
                Debug.DrawRay(transform.position - transform.up + transform.right * 0.75f * transform.lossyScale.x, transform.up * rightHit.distance, Color.red);

                avoidPlanner.avoid = true;
            }
        }

        if (Physics.Raycast(transform.position - transform.up - transform.right * 0.75f * transform.lossyScale.x, transform.up, out leftHit, detectingRange, ~ignoredLayer)) //Left side of the animal
        {
            if (leftHit.transform.tag == "Obstacle" && (muscle.food == null || hit.Equals(new RaycastHit()) || leftHit.distance < hit.distance))                             //If the animal is not seeking a nearer food
            {
                Debug.DrawRay(transform.position - transform.up - transform.right * 0.75f * transform.lossyScale.x, transform.up * leftHit.distance, Color.red);

                avoidPlanner.avoid = true;
            }
        }
    }
Ejemplo n.º 6
0
    private void FixedUpdate()
    {
        var thrust = controller.controllerState.rAxis1.x;

        jumping = controller.controllerState.ulButtonPressed;


        //print(controller.controllerState.ulButtonPressed);

        if (jumping == 4)          //&& body.velocity == Vector3.zero
        {
            if (Physics.Raycast(transform.position, Vector3.down, out feet, 2f) && body.velocity.x < maxVelocity && body.velocity.z < maxVelocity)
            {
                body.AddForce(transform.forward * jumpMultipler);
            }
        }


        if (thrust == 1)
        {
            if (stickCheck == false)
            {
                SlingWeb();
                //Physics.Raycast(transform.position, transform.forward, out web, 200);
                stickCheck = true;
            }
            else if (!web.Equals(null))
            {
                //body.velocity += Vector3.Project( -body.velocity, transform.position - web.point);
                if (!swingPoint.Equals(null))
                {
                    if (swingPoint.GetComponent <SpringJoint>().maxDistance > Vector3.Distance(transform.position, web.point))
                    {
                        swingPoint.GetComponent <SpringJoint>().maxDistance     = Vector3.Distance(transform.position, web.point);
                        swingPoint.GetComponent <SpringJoint>().connectedAnchor = transform.GetComponentInParent <Transform>().InverseTransformPoint(new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z));
                    }
                }
                // if(pullDistance > Vector3.Distance(InputTracking.GetLocalPosition(VRNode.Head),transform.localPosition)+.01f)
                //     body.AddForce(Vector3.Normalize(-transform.position + web.point)*pullStrength*(1 - Vector3.Distance(InputTracking.GetLocalPosition(VRNode.Head),transform.localPosition)/pullDistance));
                // //swingPoint.GetComponent<SpringJoint>().maxDistance += 20f;
                // //swingPoint.GetComponent<SpringJoint>().maxDistance *= .9f;
                // pullDistance = Vector3.Distance(InputTracking.GetLocalPosition(VRNode.Head),transform.localPosition);

                if (pullDistance < Vector3.Distance(pullPoint, transform.localPosition) - .01f)
                {
                    body.AddForce(Vector3.Normalize(-transform.position + web.point) * pullStrength);//*(Vector3.Distance(InputTracking.GetLocalPosition(VRNode.Head),transform.localPosition)/pullDistance));
                }
                pullDistance = Vector3.Distance(pullPoint, transform.localPosition);
            }
            //SteamVR_Controller.Input((int)controller.controllerIndex).TriggerHapticPulse((ushort)(200f * forceVector.magnitude));
        }
        else
        {
            stickCheck = false;
            Destroy(swingPoint);
        }
    }
Ejemplo n.º 7
0

        
Ejemplo n.º 8
0
    /// <summary>
    /// 左键按住
    /// </summary>
    public void OnLeftButtonHold()
    {
        hitInfo = Utility.SendRay(LayerMask.GetMask("Terrain"));
        if (hitInfo.Equals(default(RaycastHit)))
        {
            return;
        }

        switch (ModifierType)
        {
        case ModifierType.Terrain:
            switch (TerrainModifierType)
            {
            case TerrainModifierType.Up:
                Game.TerrainModule.ChangeHeightWithBrush(hitInfo.point, slider1.Value, slider2.Value, prototypeIndex, true, true);
                break;

            case TerrainModifierType.Down:
                Game.TerrainModule.ChangeHeightWithBrush(hitInfo.point, slider1.Value, slider2.Value, prototypeIndex, false, true);
                break;

            case TerrainModifierType.Smooth:
                Game.TerrainModule.Smooth(hitInfo.point, slider1.Value, slider2.Value, regesterUndo: true);
                break;

            default:
                break;
            }
            break;

        case ModifierType.Detial:
            if (isAdd)
            {
                Game.TerrainModule.AddDetial(hitInfo.point, slider1.Value, (int)slider2.Value, prototypeIndex, true);
            }
            else
            {
                Game.TerrainModule.RemoveDetial(hitInfo.point, slider1.Value, prototypeIndex, true);
            }
            break;

        case ModifierType.Texture:
            Game.TerrainModule.SetTexture(hitInfo.point, slider1.Value, prototypeIndex, 0.05f * slider2.Value, true);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 9
0
        public void OnGUI()
        {
            if (!DebugCommand.DebugMode)
            {
                return;
            }

            GUILayout.BeginArea(new Rect(15, 250, 450, Screen.height - 400));

            // Title
            GUILayout.Label("<b>DEBUG MODE ACTIVE</b>");
            GUILayout.Space(5);

            // SCENE CONTEXT STUFF
            if (SceneManager.GetActiveScene().name.Equals("worldGenerated"))
            {
                // Vars
                ZoneDirector.Zone zone = SceneContext.Instance.PlayerZoneTracker.GetCurrentZone();
                bool mainHitNull       = mainHit.Equals(default(RaycastHit));

                // Player Info
                GUILayout.Label($"<size=20><b>Player Info:</b></size>");
                GUILayout.Space(3);
                GUILayout.Label($"<b>Position: </b>{SceneContext.Instance.Player.transform.position}");
                GUILayout.Label($"<b>Zone: </b>{zone}");
                GUILayout.Label($"<b>Map Unlocked: </b>{SceneContext.Instance.PlayerState.HasUnlockedMap(zone)}");
                GUILayout.Label($"<b>EndGame Time: </b>{SceneContext.Instance.PlayerState.GetEndGameTime()}");
                GUILayout.Label($"<b>Ammo Mode: </b>{SceneContext.Instance.PlayerState.GetAmmoMode()}");
                GUILayout.Label($"<b>Look At: </b>" + (mainHitNull ? "None" : $"{mainHit.point}"));
                GUILayout.Space(20);
                if (!mainHitNull)
                {
                    // Object Panel
                    GUILayout.Label($"<size=20><b>Object Inspector:</b></size>");
                    GUILayout.Space(3);
                    GUILayout.Label($"<b>Path: </b>{GetPath(mainHit.collider?.transform)}");
                    GUILayout.Label($"<b>Position: </b>{mainHit.collider?.transform.position}");
                    GUILayout.Label($"<b>Rotation: </b>{mainHit.collider?.transform.rotation}");
                    GUILayout.Label($"<b>Scale: </b>{mainHit.collider?.transform.localScale}");
                    Identifiable.Id id = Identifiable.GetId(mainHit.collider.gameObject);
                    if (id != Identifiable.Id.NONE)
                    {
                        GUILayout.Label($"<b>Identifiable.Id: </b>{id}");
                    }
                }
            }

            GUILayout.EndArea();
        }
Ejemplo n.º 10
0
        private void OnDragItemInputInteractionStateTouchPhaseEnded(RaycastHit topHit, TouchEquivalent touch)
        {
            CurrentState.ExitState();
            CurrentState = activeSelectionState;
            bool flag = false;

            if (CurrentlySelectedObject != null)
            {
                if (topHit.Equals(default(RaycastHit)))
                {
                    CurrentlySelectedObject.transform.position = new Vector3(0f, 1000f, 0f);
                    DeleteSelectedItem(deleteChildren: true);
                    InputProcessingPaused = false;
                    CurrentState          = noSelectionState;
                    CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput);
                    return;
                }
                PositionDragItem(topHit, touch);
                ObjectManipulator i = CurrentlySelectedObject.GetComponentInParent <ObjectManipulator>();
                if (i != null && i.IsAllowed)
                {
                    if (BeforeDragComplete != null)
                    {
                        flag = true;
                        BeforeDragComplete.InvokeSafe(i, delegate(bool success)
                        {
                            if (success)
                            {
                                storeOldObject();
                                CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput);
                            }
                            else
                            {
                                i.BaseLocationIsValid = false;
                            }
                        });
                    }
                    else
                    {
                        storeOldObject();
                    }
                }
            }
            if (!flag)
            {
                CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput);
            }
        }
Ejemplo n.º 11
0
    private void Update()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            isAdd = false;
        }

        if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            isAdd = true;
        }

        if (Projection.enabled)
        {
            // 更新投影的位置
            hitInfo = Utility.SendRay(LayerMask.GetMask("Terrain"));
            if (!hitInfo.Equals(default(RaycastHit)))
            {
                Projection.transform.position = hitInfo.point + Vector3.up * 10000;
                Projection.orthographicSize   = slider1.Value;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            OnLeftButtonDown();
        }
        if (Input.GetMouseButton(0))
        {
            OnLeftButtonHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            OnLeftButtonUp();
        }

        if (Input.GetKey(KeyCode.Z))
        {
            Game.TerrainModule.Undo();
        }
    }
Ejemplo n.º 12
0
    void TapAt(Vector3 screenPos)
    {
        RaycastHit hit = ValidHit(screenPos);

        //IF IT HIT SOMETHING VALID
        if (!hit.Equals(new RaycastHit()))
        {
            if (hit.transform.gameObject.layer != 5)
            {
                //IF SUCCESSFULLY CLICKED ON TARGET (DIRECT HIT)
                if (hit.transform.gameObject.tag == "Obstacle" || hit.transform.gameObject.tag == "Police")
                {
                    if (!game.currentWeap.isShotgun)
                    {
                        hit.transform.gameObject.GetComponent <HealthBarScript>().HitFromPlayer(game.currentWeap.chart, true);
                    }
                    ShootBullet(hit.point, true, hit.transform);
                }
                else if (hit.transform.gameObject.tag == "Player")
                {
                    currentReloadCoroutine = StartCoroutine(Reload());
                }
                else
                {
                    ShootBullet(hit.point, false, null);
                }
            }
        }
        else
        {
            //SEE IF PLAYER IS TRYING TO RELOAD
            if (isMobile)
            {
                List <RaycastResult> results = getUIRaycastResults(screenPos);
                foreach (RaycastResult r in results)
                {
                    if (r.gameObject.tag == "Gun Icon")
                    {
                        OnReloadButtonPress();
                        break;
                    }
                }
            }
        }
    }
Ejemplo n.º 13
0
        public void HoverLogic()
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] raycastHits = Physics.RaycastAll(ray);
            RaycastHit   tileHit     = raycastHits.FirstOrDefault(hit => GridLayoutManager.ContainsTile(hit.transform.gameObject));

            if (!tileHit.Equals(default(RaycastHit)))
            {
                KVector2   tilePosition = GridLayoutManager.GetIndicesOfTile(tileHit.transform.gameObject);
                GameObject hitFruiton   = FruitonsGrid[tilePosition.x, tilePosition.y];
                if (hitFruiton != null)
                {
                    UpdateAndShowTooltip(hitFruiton);
                    return;
                }
            }
            FruitonInfoPanel.SetActive(false);
        }
Ejemplo n.º 14
0
 public IEnumerator FindGround(bool debug = false)
 { //I don't know why I have to press a key to make it work...
     if (debug)
     {
         Debug.Log("Trying to find ground!");
     }
     while (!hitted)
     {
         yield return(null);
     }
     if (!hit.Equals(default(RaycastHit)))
     {
         transform.position = hit.point + Vector3.up * transform.localScale.y;
     }
     if (debug)
     {
         Debug.Log("Ground founded and teleported to it!");
     }
 }
    /// <summary>
    /// 左键按住
    /// </summary>
    public override void OnLeftButtonHold()
    {
        hitInfo = Utility.SendRay(LayerMask.GetMask("Terrain"));
        if (hitInfo.Equals(default(RaycastHit)))
        {
            return;
        }

        Terrain terrain = hitInfo.collider.GetComponent <Terrain>();

        switch (Panel.modifierType)
        {
        case TerrainModifierPanel.ModifierType.Up:
            Game.TerrainModule.ChangeHeight(hitInfo.point, (int)Panel.rangeMix.Value, Panel.opticalMix.Value);
            break;

        case TerrainModifierPanel.ModifierType.Down:
            Game.TerrainModule.ChangeHeight(hitInfo.point, (int)Panel.rangeMix.Value, Panel.opticalMix.Value, false);
            break;

        case TerrainModifierPanel.ModifierType.Smooth:
            Game.TerrainModule.Smooth(hitInfo.point, (int)Panel.rangeMix.Value, Panel.opticalMix.Value);
            break;

        case TerrainModifierPanel.ModifierType.AddDetial:
            if (Game.FsmModule.GetFsm <MouseFsm>().MouseMove)
            {
                if (isAdd)
                {
                    Game.TerrainModule.AddDetial(hitInfo.point, Panel.rangeMix.Value, (int)(Panel.opticalMix.Value), Panel.PrototypeIndex);
                }
                else
                {
                    Game.TerrainModule.RemoveDetial(hitInfo.point, Panel.rangeMix.Value, Panel.PrototypeIndex);
                }
            }
            break;

        default:
            break;
        }
    }
Ejemplo n.º 16
0
    bool CheckForPointerOnBall()
    {
        Ray        ray      = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit      = new RaycastHit();
        bool       hitFound = Physics.Raycast(ray, out hit);

        Debug.DrawRay(Camera.main.transform.position, ray.direction, Color.red, 10.0f);

        if (hitFound)
        {
            if (!hit.Equals(null) && !hit.collider.Equals(null))
            {
                if (hit.collider.name.Equals(gameObject.name))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
    public void ReceivePushNotification(RaycastHit hit, bool isHit)
    {
        if (isHit == true)
        {
            // Same target as last frame
            if (!lastHit.Equals(new RaycastHit()) && hit.collider.name == lastHit.collider.name)
            {
                //print("ClickerDwellTime is looking at " + hit.transform.name);

                timer = Time.time;
                dwellTimeIndicator.fillAmount = (timer - startTimer) / dwellTime;

                // is time difference bigger than dwell time?
                if (timer - startTimer > dwellTime)
                {
                    PushClick(1);
                    startTimer = Time.time;
                    dwellTimeIndicator.fillAmount = 0;
                }
            }
            // Target changed - start new startTimer
            else
            {
                lastHit    = hit;
                startTimer = Time.time;
                dwellTimeIndicator.fillAmount = 0;

                //Debug.Log("Raycast target changed to " + lastHit.collider.name);
                // Debug.Log("Target changed at " + startTimer);
            }
        }
        // Raycast hit no UI target - start new startTimer
        else
        {
            lastHit    = hit;
            startTimer = Time.time;
            dwellTimeIndicator.fillAmount = 0;

            //Debug.Log("Raycast target lost.");
        }
    }
    /// <summary>
    /// 左键按下
    /// </summary>
    public override void OnLeftButtonDown()
    {
        hitInfo = Utility.SendRay(LayerMask.GetMask("Terrain"));
        if (hitInfo.Equals(default(RaycastHit)))
        {
            return;
        }

        // TODO 路面桥梁
        //switch (Panel.modifierType)
        //{
        //    case TerrainModifierPanel.ModifierType.BuildRoad:
        //        selectObj = RoadManager.Instance.GetSelectWPN(true)?.parent;
        //        RuntimeHandle.SetTarget(selectObj);
        //        break;
        //    case TerrainModifierPanel.ModifierType.Buildings:
        //        BuildingManager.Instance.AddBuild(Panel.PrototypeIndex, hitInfo.point);
        //        RuntimeHandle.SetTarget(selectObj);
        //        break;
        //}
    }
    /// <summary>
    /// 左键抬起
    /// </summary>
    public override void OnLeftButtonUp()
    {
        hitInfo = Utility.SendRay(LayerMask.GetMask("Terrain"));
        if (hitInfo.Equals(default(RaycastHit)))
        {
            return;
        }

        Terrain terrain = hitInfo.collider.GetComponent <Terrain>();

        switch (Panel.modifierType)
        {
        case TerrainModifierPanel.ModifierType.Up:
        case TerrainModifierPanel.ModifierType.Down:
        case TerrainModifierPanel.ModifierType.Smooth:
            Game.TerrainModule.Refresh();
            Game.TerrainModule.AddOldData();
            break;

        case TerrainModifierPanel.ModifierType.AddTree:
            if (isAdd)
            {
                Game.TerrainModule.CreatTree(terrain, hitInfo.point, (int)(Panel.opticalMix.Value), (int)Panel.rangeMix.Value, Panel.PrototypeIndex);
            }
            else
            {
                Game.TerrainModule.RemoveTree(terrain, hitInfo.point, (int)Panel.rangeMix.Value, Panel.PrototypeIndex);
            }
            break;

        // TODO 路面桥梁
        //case TerrainModifierPanel.ModifierType.BuildRoad:
        //    RoadManager.Instance.ConnetWPN(panel.wayType, (int)Panel.widthMix.Value);
        //    selectObj = null;
        //    break;
        default:
            break;
        }
    }
Ejemplo n.º 20
0
        /// <summary>
        /// Loops through an array of RaycastHits and returned the closest one, relative to a collider's position.
        /// </summary>
        /// <param name="collider">Collider to check against.</param>
        /// <param name="hitCount">Amount of Raycasts in array.</param>
        /// <param name="hits">Array of Raycasts.</param>
        /// <param name="offset">Optional offset to apply to collider position.</param>
        /// <param name="distanceOffset">Optional offset to apply to distance checking. Useful for adding small padding.</param>
        /// <param name="index">Parameter used by recursion for tracking the index of the RaycastHit to check.</param>
        /// <param name="closestHit">Parameter used by recursion for tracking the closest RaycastHit.</param>
        /// <returns></returns>
        public static RaycastHit GetClosestRaycastHitRecursive(
            Collider collider,
            int hitCount,
            RaycastHit[] hits,
            Vector3?offset        = null,
            float distanceOffset  = 0.0f,
            int index             = 0,
            RaycastHit closestHit = default(RaycastHit)
            )
        {
            // Get next index, current hit, and the next hit.
            int        nextIndex  = index + 1;
            RaycastHit currentHit = hits[index];
            RaycastHit nextHit    = nextIndex < hitCount ? hits[nextIndex] : currentHit;

            // Set closest hit to current hit if it hasn't been assigned anything.
            closestHit = closestHit.Equals(default(RaycastHit)) ? currentHit : closestHit;

            // Calculate distances for next hit and closest hit.
            CalculateClosestRaycastHitDistances(
                collider,
                offset != null ? (Vector3)offset : Vector3.zero,
                nextHit,
                closestHit,
                out float nextDistance,
                out float closestDistance
                );

            // If the next hit is closer, then it is the new closest hit.
            if (nextDistance - distanceOffset < closestDistance)
            {
                closestHit = nextHit;
            }

            return(nextIndex < hitCount?
                   GetClosestRaycastHitRecursive(collider, hitCount, hits, offset, distanceOffset, nextIndex, closestHit) :
                       closestHit);
        }
Ejemplo n.º 21
0
 public void DoSelection(RaycastHit raycastHit)
 {
     if (raycastHit.Equals(default(RaycastHit)))
     {
         return;
     }
     if (selectedObject == null)
     {
         // new
         selectedObject       = raycastHit.transform.gameObject;
         selectedObjectBounds = raycastHit.collider.bounds;
         min = Vector3Int.RoundToInt(selectedObjectBounds.min);
         max = Vector3Int.RoundToInt(selectedObjectBounds.max);
     }
     else if (raycastHit.transform.gameObject != selectedObject)
     {
         // extend
         IsMultiSelection = true;
         var        min1 = selectedObjectBounds.min;
         var        max1 = selectedObjectBounds.max;
         var        otherMin = raycastHit.collider.bounds.min;
         var        otherMax = raycastHit.collider.bounds.max;
         Vector3Int newMin = default, newMax = default;
Ejemplo n.º 22
0
        public void Fire()
        {
            _firing = true;

            RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward).OrderBy(h => h.distance).ToArray();

            if (hits.Length > 0)
            {
                _laser.SetPosition(0, transform.position);

                RaycastHit last = new RaycastHit();

                int penetrated = 0;

                bool readyThisLoop = Ready;

                bool firedThisLoop = false;

                foreach (RaycastHit raycastHit in hits)
                {
                    if (raycastHit.transform.gameObject.tag == "Enemy" ||
                        raycastHit.transform.gameObject.tag == "Shrine" && Ready)
                    {
                        if (readyThisLoop)
                        {
                            raycastHit.transform.gameObject.SendMessage("ApplyDamage", Damage);
                            if (Player.Player.StatModifiers[PlayerStat.SlowOnHit] > 1)
                            {
                                raycastHit.transform.gameObject.SendMessage("ApplySlow", Player.Player.StatModifiers[PlayerStat.SlowOnHit]);
                            }
                            firedThisLoop = true;
                        }
                        penetrated++;
                    }
                    else if (raycastHit.transform.gameObject.tag == "Obstacle")
                    {
                        last = raycastHit;
                        break;
                    }

                    if (penetrated >= _penetration)
                    {
                        last = raycastHit;
                        _laser.SetPosition(1, raycastHit.point);
                        break;
                    }
                }

                if (firedThisLoop)
                {
                    Ready = false;
                    StartCoroutine(Wait(FireDelay));
                }

                if (last.Equals(new RaycastHit()))
                {
                    _laser.SetPosition(1, hits.Last().point);
                }
                else
                {
                    _laser.SetPosition(1, last.point);
                }
            }
            else
            {
                _firing = false;
            }
        }
Ejemplo n.º 23
0
        public void Controls()
        {
            if (isMine)
            {
                // Uses : selectedMove, hit and hoverEntity

                if (!(selectedMove != null && selectedMove.IsLaunched()))
                {
                    if ((Input.GetKeyDown("q") || Input.GetKeyDown("a")) && moveSet[0] != null)
                    {
                        SelectMove(0);
                    }
                    else if ((Input.GetKeyDown("w") || Input.GetKeyDown("z")) && moveSet[1] != null)
                    {
                        SelectMove(1);
                    }
                    else if (Input.GetKeyDown("e") && moveSet[2] != null)
                    {
                        SelectMove(2);
                    }
                    else if (Input.GetKeyDown("r") && moveSet[3] != null)
                    {
                        SelectMove(3);
                    }
                }

                if (selectedMove != null && !selectedMove.IsLaunched())
                {
                    Ray ray = myCam.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit) && hit.transform.root.gameObject == SceneHelper.GetContainer(Container.Entities))
                    {
                        hoverEntity = hit.transform.gameObject;

                        SphereCollider targetCollider = (SphereCollider)hoverEntity.GetComponent <Collider>();

                        if (selectedMove.info.TargetKind == MoveTargetKind.Single &&
                            Vector3.Magnitude(hoverEntity.transform.position - transform.position) > selectedMove.info.Range / 100f + nav.radius + targetCollider.radius)
                        {
                            hoverEntity = null;
                        }
                    }
                    else
                    {
                        hoverEntity = null;
                    }
                }

                if (Input.GetMouseButtonDown(0))
                {
                    if (selectedMove == null)
                    {
                        Ray          ray = myCam.ScreenPointToRay(Input.mousePosition);
                        RaycastHit[] hits;
                        hits = Physics.RaycastAll(ray, 100.0f);

                        RaycastHit theChosenHit = new RaycastHit();
                        foreach (RaycastHit singleHit in hits)
                        {
                            if (singleHit.collider.transform.parent.name == "Terrain")
                            {
                                if (theChosenHit.Equals(new RaycastHit()) || singleHit.distance < theChosenHit.distance)
                                {
                                    theChosenHit = singleHit;
                                }
                            }
                        }

                        if (!theChosenHit.Equals(new RaycastHit()))
                        {
                            // The character has to move at least half of its width.
                            //if((theChosenHit.point - transform.position).magnitude >= nav.radius)
                            {
                                theChosenHit.point.Set(theChosenHit.point.x, 0, theChosenHit.point.z);
                                GetComponent <NetworkView>().RPC("ValidateControl", RPCMode.Server, (int)InputType.LeftClick, theChosenHit.point, NetworkViewID.unassigned, -1);
                            }
                        }
                    }
                    else
                    {
                        // If a move is selected, but not launched :
                        if (!selectedMove.IsLaunched())
                        {
                            bool attackLaunched = false;

                            MoveTargetKind targetKind = selectedMove.info.TargetKind;

                            int moveIndex = -1;
                            for (int i = 0; i < moveSet.Count; i++)
                            {
                                if (selectedMove.name == moveSet[i])
                                {
                                    moveIndex = i;
                                }
                            }

                            if (targetKind == MoveTargetKind.Area)
                            {
                                GetComponent <NetworkView>().RPC("ValidateControl", RPCMode.Server, (int)InputType.LeftClick, hit.point, NetworkViewID.unassigned, moveIndex);
                                attackLaunched = true;
                            }
                            else if (targetKind == MoveTargetKind.Single && hoverEntity != null)                            // If the target type is not an area, then it's a single target spell. Therefore he needs a target.
                            {
                                PokemonRelation relation = entityManager.GetRelation(hoverEntity);

                                if ((relation & selectedMove.info.AllowedTargets) != 0)
                                {
                                    SphereCollider targetCollider = (SphereCollider)hoverEntity.GetComponent <Collider>();

                                    if (Vector3.Magnitude(hoverEntity.transform.position - transform.position) <= selectedMove.info.Range / 100f + nav.radius + targetCollider.radius)
                                    {
                                        GetComponent <NetworkView>().RPC("ValidateControl", RPCMode.Server, (int)InputType.LeftClick, hit.point, hoverEntity.GetComponent <NetworkView>().viewID, moveIndex);
                                        attackLaunched = true;
                                    }
                                }
                            }

                            if (!attackLaunched)
                            {
                                selectedMove = null;                                 // If the player failed to click a right target for his attack, then we unselect it.
                            }

                            hoverEntity = null;
                        }
                    }
                }
                else if (Input.GetMouseButtonDown(1))
                {
                    //SetLife(currentHP - 2f);

                    if (selectedMove != null && !selectedMove.IsLaunched())
                    {
                        selectedMove = null;
                    }
                }
            }
        }
Ejemplo n.º 24
0
    void InTurnUpdate()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);

        if (Physics.Raycast(ray, out tempHit, int.MaxValue) && Input.GetMouseButtonDown(0))
        {
            hit = tempHit;
        }
        else if (Physics.Raycast(ray, out tempHit, int.MaxValue) && Input.GetMouseButtonUp(0) && tempHit.Equals(hit))
        {
            if (hit.transform.tag == "Hero")
            {
                specifiedHero = hit.transform;
                specified     = true;
                if (specified)
                {
                    specifiedHero.GetComponent <BasicHero>().SetOutline(true);
                }
            }
            else if (hit.transform.tag == "MapUnit" && specified)
            {
                specifiedHero.GetComponent <BasicHero>().MoveTo(hit.transform.position);
                if (specified)
                {
                    specifiedHero.GetComponent <BasicHero>().SetOutline(false);
                }
                specified     = false;
                specifiedHero = null;
            }
        }
        else if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonDown(1))
        {
            if (specified)
            {
                specifiedHero.GetComponent <BasicHero>().SetOutline(false);
            }
            specified     = false;
            specifiedHero = null;
        }
    }
Ejemplo n.º 25
0
    private void ShootPortal(Portal portal, bool blue)
    {
        // Find where the portal shot hits
        RaycastHit firstHit = GetFirstHit(new Ray(playerCam.transform.position, playerCam.transform.forward), portal.GetComponent <Collider>());

        if (!firstHit.Equals(new RaycastHit()) && firstHit.collider.GetComponent <PortalSurface>() != null)
        {
            Quaternion oldRotation = portal.transform.rotation;
            Vector3    oldPosition = portal.transform.position;

            // Move the portal to where the ray hit
            if (blue)
            {
                portal.transform.rotation = Quaternion.LookRotation(firstHit.normal, playerCam.transform.right);
            }
            else
            {
                portal.transform.rotation = Quaternion.LookRotation(-firstHit.normal, -playerCam.transform.right);
            }
            portal.transform.position = firstHit.point + offsetFromWall * firstHit.normal - portal.transform.up * portal.GetComponent <BoxCollider>().size.y / 2;

            // Find where the portal collides in all four directions
            float   portalWidth  = portal.GetComponent <BoxCollider>().size.y;
            float   portalHeight = portal.GetComponent <BoxCollider>().size.x;
            Vector3 portalCenter = portal.transform.position + portal.transform.up * portalWidth / 2;
            Vector3 portalUp     = portal.transform.right;
            Vector3 portalRight  = portal.transform.up;

            RaycastHit top    = GetFirstHit(new Ray(portalCenter, portalUp), portal.GetComponent <Collider>());
            RaycastHit bottom = GetFirstHit(new Ray(portalCenter, -portalUp), portal.GetComponent <Collider>());
            RaycastHit right  = GetFirstHit(new Ray(portalCenter, portalRight), portal.GetComponent <Collider>());
            RaycastHit left   = GetFirstHit(new Ray(portalCenter, -portalRight), portal.GetComponent <Collider>());

            // Shift the portal so it isn't colliding with anything
            Vector3 verticalShift   = Vector3.zero;
            Vector3 horizontalShift = Vector3.zero;
            bool    notFit          = false;
            if (!bottom.Equals(new RaycastHit()))
            {
                if (bottom.distance < portalHeight / 2)
                {
                    verticalShift = portalUp * (portalHeight / 2 - bottom.distance);
                }
            }
            if (!top.Equals(new RaycastHit()))
            {
                if (top.distance < portalHeight / 2)
                {
                    if (verticalShift == Vector3.zero)
                    {
                        verticalShift = -portalUp * (portalHeight / 2 - top.distance);
                    }
                    else
                    {
                        notFit = true;
                    }
                }
            }
            if (!left.Equals(new RaycastHit()))
            {
                if (left.distance < portalWidth / 2)
                {
                    horizontalShift = portalRight * (portalWidth / 2 - left.distance);
                }
            }
            if (!right.Equals(new RaycastHit()))
            {
                if (right.distance < portalWidth / 2)
                {
                    if (horizontalShift == Vector3.zero)
                    {
                        horizontalShift = -portalRight * (portalWidth / 2 - right.distance);
                    }
                    else
                    {
                        notFit = true;
                    }
                }
            }

            if (notFit)
            {
                portal.transform.position = oldPosition;
                portal.transform.rotation = oldRotation;
            }
            else
            {
                portal.transform.position += verticalShift + horizontalShift;
                portal.embeddedWall        = firstHit.collider;
            }
        }
    }