Beispiel #1
0
    public void SpawnPeople()
    {
        if (par == null)
        {
            par = new GameObject();
            par.transform.parent = gameObject.transform;
            par.name             = "people";
        }

        int s;

        s = pointLength[0] - 2;

        for (int b = 0; b < numberOfWays; b++)
        {
            float mSpeed = moveSpeed + UnityEngine.Random.Range(moveSpeed * -0.15f, moveSpeed * 0.15f);

            for (int a = 1; a <= s; a++)
            {
                if (a == 1 || a == 2 || a == 65 ||
                    a == 33 || a == 34 || a == 66 ||
                    a == 67 || a == 68 || a == 64 ||
                    a == 69 || a == 70 || a == 71 ||
                    a == 72 || a == 73 || a == 74 ||
                    a == 75 || a == 5 || a == 76 ||
                    a == 77 || a == 78 || a == 6 ||
                    a == 79 || a == 80 || a == 81 ||
                    a == 82 || a == 7 || a == 83 ||
                    a == 86 || a == 85 || a == 88 ||
                    a == 8 || a == 89 || a == 90 ||
                    a == 91 || a == 92 || a == 9 ||
                    a == 94 || a == 95 || a == 96 ||
                    a == 93 || a == 10 || a == 100 ||
                    a == 97 || a == 99 || a == 98 ||
                    a == 11 || a == 12 || a == 13 ||
                    a == 15 || a == 16 || a == 17 ||
                    a == 27 || a == 26 || a == 28 ||
                    a == 29 || a == 40 || a == 39 ||
                    a == 4 || a == 38 || a == 63 ||
                    a == 37 || a == 35 || a == 36 ||
                    a == 32 || a == 3
                    )
                {
                    bool forward_ = false;
                    if (direction.ToString() == "Forward")
                    {
                        forward_ = true;
                    }

                    else if (direction.ToString() == "Backward")
                    {
                        forward_ = false;
                    }

                    else if (direction.ToString() == "HugLeft")
                    {
                        if ((b + 2) % 2 == 0)
                        {
                            forward_ = true;
                        }
                        else
                        {
                            forward_ = false;
                        }
                    }

                    else if (direction.ToString() == "HugRight")
                    {
                        if ((b + 2) % 2 == 0)
                        {
                            forward_ = false;
                        }
                        else
                        {
                            forward_ = true;
                        }
                    }

                    else if (direction.ToString() == "WeaveLeft")
                    {
                        if (b == 1 || b == 2 || (b - 1) % 4 == 0 || (b - 2) % 4 == 0)
                        {
                            forward_ = false;
                        }
                        else
                        {
                            forward_ = true;
                        }
                    }

                    else if (direction.ToString() == "WeaveRight")
                    {
                        if (b == 1 || b == 2 || (b - 1) % 4 == 0 || (b - 2) % 4 == 0)
                        {
                            forward_ = true;
                        }
                        else
                        {
                            forward_ = false;
                        }
                    }

                    Vector3 myVector = Vector3.zero;

                    myVector = points[b, a + 1] - points[b, a];

                    float myVectorMagnitude = myVector.magnitude;
                    int   peopleCount       = (int)((density / 5.0f) * myVectorMagnitude);

                    if (peopleCount < 1)
                    {
                        peopleCount = 1;
                    }

                    //float step = myVectorMagnitude / peopleCount;
                    //float totalStep = 0;

                    for (int i = 0; i < peopleCount; i++)
                    {
                        float randomPos = 0;
                        randomPos = Random.Range(-4, 4);
                        var  people = gameObject;
                        bool gender = NPCAttributeController.GenerateGender();
                        if (gender == true)
                        {
                            int prefabNum = UnityEngine.Random.Range(0, 7);
                            if (forward_)
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                            else
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                        }
                        else
                        {
                            int prefabNum = UnityEngine.Random.Range(7, peoplePrefabs.Length);
                            if (forward_)
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                            else
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                        }
                        people.transform.parent = par.transform;
                        people.gameObject.transform.Rotate(new Vector3(0, 90, 0));
                        changeLayerTarget(people.transform);
                        var _movePath = people.AddComponent <MovePath1>();
                        _movePath.walkPath = gameObject;

                        _movePath.MyStart(b, a, /*animName*/ "listen", loopPath, forward_, gender);
                    }
                }
            }
        }
    }
Beispiel #2
0
    public void SpawnPeople()
    {
        if (par == null)
        {
            par = new GameObject();
            par.transform.parent = gameObject.transform;
            par.name             = "people";
        }

        int s;

        s = pointLength[0] - 2;

        for (int b = 0; b < numberOfWays; b++)
        {
            for (int a = 1; a <= s; a++)
            {
                if (a != 58 && a != 35 && a != 34 &&
                    a != 32 && a != 33 && a != 26 &&
                    a != 27 && a != 62)
                {
                    bool forward_ = false;
                    if (direction.ToString() == "Forward")
                    {
                        forward_ = true;
                    }

                    else if (direction.ToString() == "Backward")
                    {
                        forward_ = false;
                    }

                    else if (direction.ToString() == "HugLeft")
                    {
                        if ((b + 2) % 2 == 0)
                        {
                            forward_ = true;
                        }
                        else
                        {
                            forward_ = false;
                        }
                    }

                    else if (direction.ToString() == "HugRight")
                    {
                        if ((b + 2) % 2 == 0)
                        {
                            forward_ = false;
                        }
                        else
                        {
                            forward_ = true;
                        }
                    }

                    else if (direction.ToString() == "WeaveLeft")
                    {
                        if (b == 1 || b == 2 || (b - 1) % 4 == 0 || (b - 2) % 4 == 0)
                        {
                            forward_ = false;
                        }
                        else
                        {
                            forward_ = true;
                        }
                    }

                    else if (direction.ToString() == "WeaveRight")
                    {
                        if (b == 1 || b == 2 || (b - 1) % 4 == 0 || (b - 2) % 4 == 0)
                        {
                            forward_ = true;
                        }
                        else
                        {
                            forward_ = false;
                        }
                    }

                    Vector3 myVector = Vector3.zero;

                    myVector = points[b, a + 1] - points[b, a];

                    float myVectorMagnitude = myVector.magnitude;
                    int   peopleCount       = (int)((density / 5.0f) * myVectorMagnitude);

                    if (peopleCount < 1)
                    {
                        peopleCount = 1;
                    }

                    //float step = myVectorMagnitude / peopleCount;
                    //float totalStep = 0;

                    for (int i = 0; i < peopleCount; i++)
                    {
                        float randomPos = 0;
                        randomPos = Random.Range(-4f, 4f);
                        var  people = gameObject;
                        bool gender = NPCAttributeController.GenerateGender();
                        if (gender == true)
                        {
                            int prefabNum = UnityEngine.Random.Range(0, 7);
                            if (forward_)
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                            else
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                        }
                        else
                        {
                            int prefabNum = UnityEngine.Random.Range(7, peoplePrefabs.Length);
                            if (forward_)
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                            else
                            {
                                people = Instantiate(peoplePrefabs[prefabNum], points[b, a] /*+ new Vector3(randomPos, 0, randomPos)*/, Quaternion.identity) as GameObject;
                            }
                        }
                        people.transform.parent = par.transform;
                        people.gameObject.transform.Rotate(new Vector3(0, -180, 0));
                        changeLayerTarget(people.transform);
                        var _movePath = people.AddComponent <MovePath4>();
                        _movePath.walkPath = gameObject;
                        _movePath.MyStart(b, a, /*animName*/ "listen", loopPath, forward_, gender);
                    }
                }
            }
        }
    }
    public void DrawCurved(bool withDraw)
    {
        if (numberOfWays < 1)
        {
            numberOfWays = 1;
        }
        if (lineSpacing < 0.6f)
        {
            lineSpacing = 0.6f;
        }
        _forward = new bool[numberOfWays];

        for (int w = 0; w < numberOfWays; w++)
        {
            if (direction.ToString() == "Forward")
            {
                _forward[w] = true;
            }

            else if (direction.ToString() == "Backward")
            {
                _forward[w] = false;
            }

            else if (direction.ToString() == "HugLeft")
            {
                if ((w + 2) % 2 == 0)
                {
                    _forward[w] = true;
                }
                else
                {
                    _forward[w] = false;
                }
            }

            else if (direction.ToString() == "HugRight")
            {
                if ((w + 2) % 2 == 0)
                {
                    _forward[w] = false;
                }
                else
                {
                    _forward[w] = true;
                }
            }

            else if (direction.ToString() == "WeaveLeft")
            {
                if (w == 1 || w == 2 || (w - 1) % 4 == 0 || (w - 2) % 4 == 0)
                {
                    _forward[w] = false;
                }
                else
                {
                    _forward[w] = true;
                }
            }

            else if (direction.ToString() == "WeaveRight")
            {
                if (w == 1 || w == 2 || (w - 1) % 4 == 0 || (w - 2) % 4 == 0)
                {
                    _forward[w] = true;
                }
                else
                {
                    _forward[w] = false;
                }
            }
        }


        if (pathPoint.Count < 2)
        {
            return;
        }
        points = new Vector3[numberOfWays, pathPoint.Count + 2];

        pointLength[0] = pathPoint.Count + 2;

        for (int i = 0; i < pathPointTransform.Count; i++)
        {
            Vector3 vectorStart;
            Vector3 vectorEnd;
            if (i == 0)
            {
                if (loopPath)
                {
                    vectorStart = pathPointTransform[pathPointTransform.Count - 1].transform.position - pathPointTransform[i].transform.position;
                }
                else
                {
                    vectorStart = Vector3.zero;
                }
                vectorEnd = pathPointTransform[i].transform.position - pathPointTransform[i + 1].transform.position;
            }
            else if (i == pathPointTransform.Count - 1)
            {
                vectorStart = pathPointTransform[i - 1].transform.position - pathPointTransform[i].transform.position;
                if (loopPath)
                {
                    vectorEnd = pathPointTransform[i].transform.position - pathPointTransform[0].transform.position;
                }
                else
                {
                    vectorEnd = Vector3.zero;
                }
            }
            else
            {
                vectorStart = pathPointTransform[i - 1].transform.position - pathPointTransform[i].transform.position;
                vectorEnd   = pathPointTransform[i].transform.position - pathPointTransform[i + 1].transform.position;
            }
            //
            Vector3 vectorShift = Vector3.Normalize((Quaternion.Euler(0, 90, 0) * (vectorStart + vectorEnd)));
            //
            points[0, i + 1] = numberOfWays % 2 == 1 ? pathPointTransform[i].transform.position : pathPointTransform[i].transform.position + vectorShift * lineSpacing / 2;
            if (numberOfWays > 1)
            {
                points[1, i + 1] = points[0, i + 1] - vectorShift * lineSpacing;
            }
            //if (i == 0)
            //{

            //}
            //else
            //{
            for (int w = 1; w < numberOfWays; w++)
            {
                points[w, i + 1] = points[0, i + 1] + vectorShift * lineSpacing * (float)(Math.Pow(-1, w)) * ((w + 1) / 2);
            }
            //}
        }
        for (int w = 0; w < numberOfWays; w++)
        {
            points[w, 0] = points[w, 1];
            points[w, pointLength[0] - 1] = points[w, pointLength[0] - 2];
        }
        if (withDraw)
        {
            for (int w = 0; w < numberOfWays; w++)
            {
                if (loopPath)
                {
                    Gizmos.color = (_forward[w] ? Color.green : Color.red);
                    Gizmos.DrawLine(points[w, 0], points[w, pathPoint.Count]);
                }
                for (int i = 1; i < pathPoint.Count; i++)
                {
                    Gizmos.color = (_forward[w] ? Color.green : Color.red);
                    Gizmos.DrawLine(points[w, i + 1], points[w, i]);
                }
            }
        }

        /*
         * //расчет точек первой полосы
         * for (int i = 0; i < pathPoint.Count; i++)
         * {
         *  points[0, i + 1] = pathPointTransform[i].transform.position;
         * }
         *
         * points[0, 0] = points[0, 1];
         * points[0, pointLength[0] - 1] = points[0, pointLength[0] - 2];
         *
         * //отображение первой полосы
         * for (int i = 0; i < pointLength[0]; i++)
         *  if (i != 0)
         *  {
         *      if (withDraw)
         *      {
         *          Gizmos.color = (_forward[0] ? Color.green : Color.red);
         *          Gizmos.DrawLine(points[0, i], points[0, i - 1]);
         *      }
         *  }
         * if (loopPath)
         *  if (withDraw)
         *  {
         *      Gizmos.color = (_forward[0] ? Color.green : Color.red);
         *      Gizmos.DrawLine(points[0, 1], points[0, pointLength[0] - 2]);
         *  }
         *
         * //расчет остальных полос
         * for (int w = 1; w < numberOfWays; w++)
         * {
         *
         *  if (numberOfWays > 1)//Тупо: сначала запуск цикла, потом проверка на необходимость запуска цикла
         *  {
         *      if (!loopPath)//пока не понял для чего
         *      {
         *          Vector3 vectorStart = points[0, 2] - points[0, 1];
         *          Vector3 pointVectorStart = vectorStart;
         *          pointVectorStart = Quaternion.Euler(0, -90, 0) * pointVectorStart;
         *
         *          if (w % 2 == 0)
         *              pointVectorStart = pointVectorStart.normalized * (float)(w * 0.5f * lineSpacing);
         *          else if (w % 2 == 1)
         *              pointVectorStart = pointVectorStart.normalized * (float)((w + 1) * 0.5f * lineSpacing);
         *
         *          Vector3 pointStart1 = Vector3.zero;
         *          if (w % 2 == 1)
         *              pointStart1 = (points[0, 1] - pointVectorStart);
         *          else if (w % 2 == 0)
         *              pointStart1 = (points[0, 1] + pointVectorStart);
         *
         *          pointStart1.y = points[0, 1].y;
         *
         *          points[w, 0] = pointStart1;
         *          points[w, 1] = pointStart1;
         *
         *
         *          Vector3 vectorFinish = points[0, pointLength[0] - 3] - points[0, pointLength[0] - 2];
         *          Vector3 pointVectorFinish = vectorFinish;
         *          pointVectorFinish = Quaternion.Euler(0, 90, 0) * pointVectorFinish;
         *
         *          if (w % 2 == 0)
         *              pointVectorFinish = pointVectorFinish.normalized * (float)(w * 0.5f * lineSpacing);
         *          else if (w % 2 == 1)
         *              pointVectorFinish = pointVectorFinish.normalized * (float)((w + 1) * 0.5f * lineSpacing);
         *
         *          Vector3 pointFinish1 = Vector3.zero;
         *
         *          if (w % 2 == 1)
         *              pointFinish1 = points[0, pointLength[0] - 2] - pointVectorFinish;
         *          else if (w % 2 == 0)
         *              pointFinish1 = points[0, pointLength[0] - 2] + pointVectorFinish;
         *
         *          pointFinish1.y = points[0, pointLength[0] - 2].y;
         *
         *          points[w, pointLength[0] - 2] = pointFinish1;
         *          points[w, pointLength[0] - 1] = pointFinish1;
         *      }
         *
         *      else
         *      {
         *          Vector3 vectorNext = points[0, pointLength[0] - 2] - points[0, 1];
         *          Vector3 vectorPrev = points[0, 1] - points[0, 2];
         *
         *          Vector3 pointVector1 = vectorPrev;
         *          Vector3 pointVector2 = vectorNext;
         *
         *          float angle = Mathf.DeltaAngle(Mathf.Atan2(pointVector1.x, pointVector1.z) * Mathf.Rad2Deg,
         *                  Mathf.Atan2(pointVector2.x, pointVector2.z) * Mathf.Rad2Deg);
         *
         *          if (w % 2 == 0)
         *              pointVector1 = pointVector1.normalized * (float)(w * 0.5f * lineSpacing);
         *          else if (w % 2 == 1)
         *              pointVector1 = pointVector1.normalized * (float)((w + 1) * 0.5f * lineSpacing);
         *
         *          pointVector1 = Quaternion.Euler(0, 90 + angle / 2, 0) * pointVector1;
         *
         *          Vector3 point1 = Vector3.zero;
         *
         *          if (w % 2 == 1)
         *          {
         *              point1 = points[0, 1] - pointVector1;
         *          }
         *          else if (w % 2 == 0)
         *              point1 = points[0, 1] + pointVector1;
         *
         *
         *          point1.y = points[0, 1].y;
         *
         *          points[w, 1] = point1;
         *          points[w, 0] = point1;
         *
         *          Vector3 vectorNext1 = points[0, pointLength[0] - 2] - points[0, 1];
         *          Vector3 vectorPrev1 = points[0, pointLength[0] - 3] - points[0, pointLength[0] - 2];
         *
         *          Vector3 pointVector11 = vectorPrev1;
         *          Vector3 pointVector22 = vectorNext1;
         *
         *          float angle2 = Mathf.DeltaAngle(Mathf.Atan2(pointVector11.x, pointVector11.z) * Mathf.Rad2Deg,
         *                  Mathf.Atan2(pointVector22.x, pointVector22.z) * Mathf.Rad2Deg);
         *
         *          if (w % 2 == 0)
         *              pointVector11 = pointVector11.normalized * (float)(w * 0.5f * lineSpacing);
         *          else if (w % 2 == 1)
         *              pointVector11 = pointVector11.normalized * (float)((w + 1) * 0.5f * lineSpacing);
         *
         *          pointVector11 = Quaternion.Euler(0, 90 + angle2 / 2, 0) * pointVector11;
         *
         *          Vector3 point11 = Vector3.zero;
         *          if (w % 2 == 1)
         *          {
         *              point11 = points[0, pointLength[0] - 2] - pointVector11;
         *          }
         *          else if (w % 2 == 0)
         *              point11 = points[0, pointLength[0] - 2] + pointVector11;
         *
         *
         *          point11.y = points[0, pointLength[0] - 2].y;
         *
         *          points[w, pointLength[0] - 2] = point11;
         *          points[w, pointLength[0] - 1] = point11;
         *      }
         *
         *      for (int i = 2; i < pointLength[0] - 2; i++)//сам расчет точек
         *      {
         *          Vector3 vectorNext = points[0, i] - points[0, i + 1];
         *          Vector3 vectorPrev = points[0, i - 1] - points[0, i];
         *
         *          Vector3 pointVector1 = vectorPrev;
         *          Vector3 pointVector2 = vectorNext;
         *
         *          float angle = Mathf.DeltaAngle(Mathf.Atan2(pointVector1.x, pointVector1.z) * Mathf.Rad2Deg,
         *                  Mathf.Atan2(pointVector2.x, pointVector2.z) * Mathf.Rad2Deg);
         *
         *          if (w % 2 == 0)
         *              pointVector1 = pointVector1.normalized * (float)(w * 0.5f * lineSpacing);
         *          else if (w % 2 == 1)
         *              pointVector1 = pointVector1.normalized * (float)((w + 1) * 0.5f * lineSpacing);
         *
         *          pointVector1 = Quaternion.Euler(0, 90 + angle / 2, 0) * pointVector1;
         *
         *          Vector3 point1 = Vector3.zero;
         *          if (w % 2 == 1)
         *          {
         *              point1 = points[0, i] - pointVector1;
         *          }
         *          else if (w % 2 == 0)
         *              point1 = points[0, i] + pointVector1;
         *
         *
         *          point1.y = points[0, i].y;
         *
         *          points[w, i] = point1;
         *
         *          if (withDraw)
         *          {
         *              Gizmos.color = (_forward[w] ? Color.green : Color.red);
         *              Gizmos.DrawLine(points[w, i - 1], points[w, i]);
         *          }
         *      }
         *
         *      if (withDraw)
         *      {
         *          Gizmos.color = (_forward[w] ? Color.green : Color.red);
         *          Gizmos.DrawLine(points[w, pointLength[0] - 2], points[w, pointLength[0] - 3]);
         *      }
         *
         *      if (withDraw && loopPath)
         *      {
         *          Gizmos.color = (_forward[w] ? Color.green : Color.red);
         *          Gizmos.DrawLine(points[w, 1], points[w, pointLength[0] - 2]);
         *      }
         *  }
         * }
         * //конец расчёта и отрисовки полос
         */
    }