/// <summary>
        /// Call this method in the Update if the entity needs pathfinding, the result is stored in : "pathDirection"
        /// </summary>
        protected Vector2 UpdatePath()
        {
            Vector2 lastValidPos = pathDestination;

            if (timeBeforeNextPathUpdate <= 0)
            {
                RaycastHit hit;
                timeBeforeNextPathUpdate = pathUpdatingFrequency;
                Debug.DrawLine(Coordinates.ConvertVector2ToWorld(coords.position) + Vector3.up * 0.9f, Coordinates.ConvertVector2ToWorld(pathDestination) + Vector3.up * 0.99f, Color.yellow, 0.5f);
                Vector3 destDirection = (Coordinates.ConvertVector2ToWorld(pathDestination)) - (Coordinates.ConvertVector2ToWorld(coords.position));
                float   destDistance  = destDirection.magnitude;
                destDirection.Normalize();
                if (!Physics.Raycast(Coordinates.ConvertVector2ToWorld(coords.position) + Vector3.up * 0.5f, destDirection, out hit, destDistance, LayerMask.GetMask("LandPathfinding")))
                {
                    pathDirection = pathDestination - coords.position;
                    pathDirection.Normalize();
                }
                else
                {
                    Debug.DrawRay(hit.point, Vector3.up, Color.red, 0.5f);
                    CalculatePath();

                    if (path != null)
                    {
                        if (environment.ZoneIn(pathDestination) != 0 &&
                            environment.zones[environment.ZoneIn(pathDestination) - 1].state == ZoneState.LandCoast)
                        {
                            lastValidPos = Coordinates.ConvertWorldToVector2(path.vectorPath[path.vectorPath.Count - 1]);
                        }

                        if (currentWaypoint >= path.vectorPath.Count)
                        {
                            pathEndReached = true;
                        }
                        else
                        {
                            pathEndReached = false;

                            while (Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance && path.vectorPath.Count > currentWaypoint + 1)
                            {
                                currentWaypoint++;
                            }

                            pathDirection = (Coordinates.ConvertWorldToVector2(path.vectorPath[currentWaypoint + (((currentWaypoint + waypointAhead) < path.vectorPath.Count) ? waypointAhead : 0)] - transform.position)).normalized;
                        }
                    }
                }
            }

            if (timeBeforeNextPathUpdate > 0)
            {
                timeBeforeNextPathUpdate -= Time.deltaTime;
            }
            return(lastValidPos);
        }
示例#2
0
        IEnumerator DropFlash(PlayerOceanEntity user)
        {
            float timer    = 0;
            float distance = 0;

            Environnement currentEnviro = GameManager.Instance.levelManager.environnement;
            Zone          testedZone    = currentEnviro.zones[currentEnviro.ZoneIn(user.coords.position) - 1];

            FlashFeedback flashFeedback = (FlashFeedback)feedbackBehavior;

            flashFeedback.DropFlash(dropDuration, new Vector3(currentUser.transform.position.x, currentUser.transform.position.y + heightOffset, currentUser.transform.position.z));

            Helicopter helicopter = (Helicopter)user;

            helicopter.isDroppingFlash = true;

            //Wait the drop duration before apply effect
            //Insert Somehow feedback of drop here
            while (timer < dropDuration)
            {
                yield return(new WaitForFixedUpdate());

                timer += Time.deltaTime;
            }

            helicopter.isDroppingFlash = false;

            //Test all submarine in the scene
            //If they are in winning range Win the game (need method implementation to win In GameManager probably)
            //If they are in extended range show submarine trail for the specified time (need method impletation for that in Submarine)
            foreach (Submarine submarine in levelManager.enemyEntitiesInScene)
            {
                distance = Mathf.Abs(Vector2.Distance(submarine.coords.position, user.coords.position));
                if (distance <= winningRange)
                {
                    GameManager.Instance.uiHandler.victoryScreenManager.Victory(true);
                }
                else if (distance <= extendedRange && testedZone.state != ZoneState.SeaTurbulent)
                {
                    submarine.MaterialChangedByFlash(revealDuration);
                }
            }
        }
    public static void GenerateZoneDataTexture(Environnement map, string name)
    {
        //generate the path
        string path = TextureGenerator.PathAsking(name);

        if (path == null || path == string.Empty)
        {
            Debug.Log("SeaTexture creation have been cancel");
            return;
        }

        #region Set the Texture size
        //detail level must be a multiple of 4
        int detailLevel = 12;
        if (detailLevel % 4 != 0)
        {
            Debug.LogError("DetailLevel must be a multiple of 4");
            return;
        }
        float inverseDetail = (float)1f / detailLevel;

        //Determine quel coté est le plus long
        bool  maxIsX       = map.limit.size.x > map.limit.size.y;
        float mapMaxLenght = maxIsX ? map.limit.size.x : map.limit.size.y;

        int   textureSize      = Mathf.CeilToInt(mapMaxLenght * detailLevel);
        float textNormalizer   = (float)1f / textureSize;
        float borderEmptySpace = (maxIsX ? map.limit.size.x - map.limit.size.y : map.limit.size.y - map.limit.size.x) * 0.5f;
        #endregion
        //Creating The texture
        Texture2D texture = TextureGenerator.CreateTexture(textureSize);

        float textStartPosX = map.limit.offSet.x + map.limit.leftBorder;
        float textStartPosY = map.limit.offSet.y + map.limit.downBorder;
        if (maxIsX)
        {
            textStartPosY -= borderEmptySpace;
        }
        else
        {
            textStartPosX -= borderEmptySpace;
        }


        //Set les couleurs de chaques zone
        List <Color> zoneColor = new List <Color>()
        {
            Color.black, Color.red, Color.green, Color.blue
        };
        if (map.zones.Length != 0)
        {
            zoneColor.RemoveRange(1, 3);
            for (int i = 0; i < map.zones.Length; i++)
            {
                float waveStrenght   = 0;
                float colorIntensity = 0;
                switch (map.zones[i].state)
                {
                case ZoneState.SeaCalm:
                    waveStrenght   = 0.3f;
                    colorIntensity = 0.5f;
                    break;

                case ZoneState.SeaWay:
                    waveStrenght   = 0.5f;
                    colorIntensity = 0.3f;
                    break;

                case ZoneState.SeaTurbulent:
                    waveStrenght   = 1f;
                    colorIntensity = 1f;
                    break;

                case ZoneState.WindyZone:
                    waveStrenght   = 0.7f;
                    colorIntensity = 0.7f;
                    break;

                default:
                    break;
                }

                zoneColor.Add(
                    new Color(
                        map.zones[i].windDir * 0.5f, //R = direction du vent
                        waveStrenght,                //G = Wave Height
                        colorIntensity,              //B = Color Intensity
                        1));
            }
        }

        Color tempColor;
        //Send Data in
        for (int x = 0; x < textureSize; x++)
        {
            for (int y = 0; y < textureSize; y++)
            {
                tempColor = zoneColor[map.ZoneIn(new Vector2(textStartPosX + (x * inverseDetail), textStartPosY + (y * inverseDetail)))];
                texture.SetPixel(x, y, tempColor);
            }
        }

        texture.Apply();

        //texture = TextureGenerator.Blur(texture, 1);

        //Check for copy
        TextureGenerator.DeleteCopy(path);

        //create the asset
        TextureGenerator.TextureToAssetPNG(path, texture);

        //Debug.log the test
        TextureGenerator.TestTextureAtPath(path);
    }
示例#4
0
    private float GetSubZoneWeight(SubZone subZone)
    {
        float weight = 0;

        subZoneDirection = GetDirectionFromAngle(GetNormAngle(subZone.minAngle + Mathf.DeltaAngle(subZone.minAngle, subZone.maxAngle) * 0.5f));

        for (int o = 0; o < bioElements.Count; o++)
        {
            pointDistance      = Vector2.Distance(Coordinates.ConvertWorldToVector2(bioElements[o].position), coords.position);
            pointRelativeAngle = Vector2.SignedAngle(Vector2.right, Coordinates.ConvertWorldToVector2(bioElements[o].position) - coords.position);
            if (pointDistance < subZone.maxRange && pointDistance >= subZone.minRange && IsBetweenAngle(pointRelativeAngle, subZone.minAngle, subZone.maxAngle))
            {
                weight += currentState == VigilanceState.calm ? benefPointFactorBioCalm : 0;
                weight += currentState == VigilanceState.worried ? benefPointFactorBioWorried : 0;
                weight += currentState == VigilanceState.panicked ? benefPointFactorBioPanicked : 0;
            }
        }

        switch (currentState)
        {
        case VigilanceState.calm:
            weight += Mathf.Cos(Mathf.Deg2Rad * Vector2.Angle(targetDirection, subZoneDirection)) * distanceFactorWeightWhileCalm;
            break;

        case VigilanceState.worried:
            weight += Mathf.Cos(Mathf.Deg2Rad * Vector2.Angle(targetDirection, subZoneDirection)) * distanceFactorWeightWhileWorried;
            break;

        case VigilanceState.panicked:
            weight += Mathf.Cos(Mathf.Deg2Rad * Vector2.Angle(targetDirection, subZoneDirection)) * distanceFactorWeightWhilePanicked;
            break;
        }

        if (environnement.ZoneIn(coords.position) != 0)
        {
            if (environnement.zones[environnement.ZoneIn(coords.position) - 1].state == ZoneState.SeaWay)
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorSeaWayCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorSeaWayWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorSeaWayPanicked;
                    break;
                }
            }
            else if (environnement.zones[environnement.ZoneIn(coords.position) - 1].state == ZoneState.WindyZone)
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorWindyZoneCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorWindyZoneWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorWindyZonePanicked;
                    break;
                }
            }
            else if (environnement.zones[environnement.ZoneIn(coords.position) - 1].state == ZoneState.SeaTurbulent)
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorSeaTurbulentCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorSeaTurbulentWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorSeaTurbulentPanicked;
                    break;
                }
            }
        }

        pointDistance      = Vector2.Distance(ship.coords.position, coords.position);
        pointRelativeAngle = Vector2.SignedAngle(Vector2.right, ship.coords.position - coords.position);
        if (pointDistance < subZone.maxRange && pointDistance >= subZone.minRange && IsBetweenAngle(pointRelativeAngle, subZone.minAngle, subZone.maxAngle))
        {
            weight = -1000;
            subZone.needToBeAvoided = true;
        }



        for (int b = 0; b < sonobuoys.Count; b++)
        {
            pointDistance      = Vector2.Distance(Coordinates.ConvertWorldToVector2(sonobuoys[b].position), coords.position);
            pointRelativeAngle = Vector2.SignedAngle(Vector2.right, Coordinates.ConvertWorldToVector2(sonobuoys[b].position) - coords.position);
            if (pointDistance < subZone.maxRange && pointDistance >= subZone.minRange && IsBetweenAngle(pointRelativeAngle, subZone.minAngle, subZone.maxAngle))
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorSonobuoyCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorSonobuoyWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorSonobuoyPanicked;
                    break;
                }

                subZone.needToBeAvoided = true;
            }
        }

        return(weight);
    }