public void SetUseHead(bool b)
    {
        if (useHead == b) return;

          useHead = b;

          if (!useHead)
          {
         Destroy(head.gameObject);
          }
          else if (head == null)
          {
         head = (Instantiate(headPrefab, headLoc, Quaternion.AngleAxis(headRotation, Vector3.forward)) as GameObject).GetComponent<DragonPart>();
         head.transform.parent = transform;
         head.transform.localPosition = headLoc;
         GetComponent<Curve>().SetPartMaterial(head);
          }
    }
    public void SetUseTail(bool b)
    {
        if (useTail == b) return;

          useTail = b;

          if (!useTail)
          {
         Destroy(tail.gameObject);
          }
          else if (tail == null)
          {
         tail = (Instantiate(tailPrefab, tailLoc, Quaternion.AngleAxis(tailRotation, Vector3.forward)) as GameObject).GetComponent<DragonPart>();
         tail.transform.parent = transform;
         tail.transform.localPosition = tailLoc;
         GetComponent<Curve>().SetPartMaterial(tail);
          }
    }
Beispiel #3
0
 public void SetPartMaterial(DragonPart part)
 {
     part.UseSprite(material.matType);
 }
    List<Vector3> GenerateVertices(int numberPoints, List<Vector2> bezierCurve, List<Vector2> normals, 
                                  out List<Vector2> UVs, out List<Vector3> meshNormals, out Bounds meshBounds)
    {
        UVs = new List<Vector2>();
          meshNormals = new List<Vector3>();
          List<Vector3> points = new List<Vector3>();

          float maxX = 0, minX = 0, maxY = 0, minY = 0;

          for (int i = 0; i < numberPoints; ++i)
          {
         Vector3 curvePoint = new Vector3(bezierCurve[i].x, bezierCurve[i].y);
         Vector3 curveNormal = new Vector3(normals[i].x, normals[i].y);
         float u = i == 0 ? initialU : (bezierCurve[i-1] - bezierCurve[i]).magnitude/defaultUVLength + UVs[(i - 1) * thickness].x;
         for (int j = 0; j < thickness; ++j)
         {
            Vector3 point = curvePoint + j * curveNormal * 0.2f;
            points.Add(point);
            meshNormals.Add(Vector3.back);
            UVs.Add(new Vector2(u, 1.0f - (float)j / (thickness - 1)));
            if (point.x > maxX)
               maxX = point.x;
            if (point.x < minX)
               minX = point.x;
            if (point.y > maxY)
               maxY = point.y;
            if (point.y < minY)
               minY = point.y;
         }
          }

          if (useHead)
          {
         headLoc = bezierCurve[numberPoints - 1];
         Vector2 headTangent = new Vector2(-normals[numberPoints - 2].y, normals[numberPoints - 2].x);
         headRotation = Mathf.Acos(Vector2.Dot(headTangent, Vector2.right)) * 180.0f / Mathf.PI;
         if (headTangent.y < 0) headRotation *= -1;
         if (head == null)
         {
            head = (Instantiate(headPrefab, headLoc, Quaternion.AngleAxis(headRotation, Vector3.forward)) as GameObject).GetComponent<DragonPart>();
            head.transform.parent = transform;
            head.transform.localPosition = headLoc;
            GetComponent<Curve>().SetPartMaterial(head);
         }
         else
         {
            head.transform.localPosition = headLoc;
            head.transform.rotation = Quaternion.AngleAxis(headRotation, Vector3.forward);
         }
          }
          if (useTail)
          {
         tailLoc = bezierCurve[0];
         Vector2 tailTangent = new Vector2(-normals[1].y, normals[1].x);
         tailRotation = Mathf.Acos(Vector2.Dot(tailTangent, Vector2.right)) * 180.0f / Mathf.PI;
         if (tailTangent.y < 0) tailRotation *= -1;
         if (tail == null)
         {
            tail = (Instantiate(tailPrefab, tailLoc, Quaternion.AngleAxis(tailRotation, Vector3.forward)) as GameObject).GetComponent<DragonPart>();
            tail.transform.parent = transform;
            tail.transform.localPosition = tailLoc;
            GetComponent<Curve>().SetPartMaterial(tail);
         }
         else
         {
            tail.transform.localPosition = tailLoc;
            tail.transform.rotation = Quaternion.AngleAxis(tailRotation, Vector3.forward);
         }
          }

          meshBounds = new Bounds(new Vector3(maxX + minX, maxY + minY, 0) / 2, new Vector3(maxX - minX, maxY - minY, 0));

          return points;
    }