示例#1
0
    public void DrawStarway(Starway line)
    {
        Profiler.BeginSample("DrawStarway()");

        Vector3 start = line.Start;
        Vector3 end   = line.End;

        Material whiteStarway = new Material(Shader.Find("Unlit/Texture"));

        GameObject lineObj = new GameObject("Starway_" + line.Id, typeof(LineRenderer));

        lineObj.transform.SetParent(dummyStarway.transform, true);
        LineRenderer newLine = lineObj.GetComponent <LineRenderer> ();

        newLine.sortingLayerName = "OnTop";
        newLine.sortingOrder     = 5;
        newLine.SetVertexCount(2);
        newLine.SetPosition(0, start);
        newLine.SetPosition(1, end);
        newLine.SetWidth(0.04f, 0.04f);
        newLine.useWorldSpace = true;
        newLine.SetColors(Color.white, Color.white);
        newLine.material = whiteStarway;

        line.gameObject = lineObj;

        Profiler.EndSample();
    }
示例#2
0
        static bool CheckCollision(Vector3 start, Vector3 end, Starway line2, float A1, float B1, float C1)
        {
            Vector3 ps2 = line2.Start;
            Vector3 pe2 = line2.End;

            //Debug.Log (ps2 + " " + pe2);

            // Get A,B,C of second line - points : ps2 to pe2
            float A2 = pe2.y - ps2.y;
            float B2 = ps2.x - pe2.x;
            float C2 = A2 * ps2.x + B2 * ps2.y;

            //Debug.Log(A1 +" "+ B1 +" "+ C1 +" | "+ A2 +" "+ B2 +" "+ C2);
            //Debug.Log ("1:Start:"+start+" End:"+end);

            // Get delta and check if the lines are parallel
            float delta = A1 * B2 - A2 * B1;

            if (delta != 0)
            {
                // now return the Vector2 intersection point
                Vector3 intersection;
                intersection.x = (B2 * C1 - B1 * C2) / delta;
                intersection.y = (A1 * C2 - A2 * C1) / delta;
                intersection.z = 0;


                if (!(intersection == start || intersection == end))
                {
                    //Debug.Log ("Intersection? \n P1 "+ps1+", "+pe1+" : P2 "+ps2+ ", "+pe2);

                    if (NotRect.notRect(start, end, intersection))
                    {
                        //Debug.Log ("Rect1");
                        if (NotRect.notRect(ps2, pe2, intersection))
                        {
                            //Debug.Log ("Rect2");
                            if (Vector3.Distance(start, end) < Vector3.Distance(ps2, pe2))
                            {
                                //Debug.Log ("Shorter.");
                                if (!StarwayCollision.Contains(line2))
                                {
                                    StarwayCollision.Add(line2);
                                }
                            }
                            else
                            {
                                //Debug.Log ("Stop");

                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }