示例#1
0
    // Functions
    public bool CreateGrindable()
    {
        this.segment = this.segment.points != null ? this.segment : new GrindSegment(this.transform, this.pointPos);

        if (this.segment.points.Length < 2)
        {
            return(false);
        }

        this.gameObject.tag = SXLGrindCore.GetGrindAudioCue(this.grindSurface);
        this.segment.BuildCollisionShapes();

        return(SXLGrindCore.BuildSplineComputer(this.segment));
    }
示例#2
0
    public static bool BuildSplineComputer(GrindSegment segment)
    {
        // Create Spline Computer component and settings for GrindSpline Object
        SplineComputer sc = segment.grindRoot.gameObject.AddComponent <SplineComputer>();

        sc.type = Spline.Type.Linear;
        sc.SetPoints(segment.points, SplineComputer.Space.World);
        sc.Evaluate(0.9);

        // Shift normal vectors up a position for spline points points
        segment.normals[segment.normals.Length - 1] = segment.normals[segment.normals.Length - 2];

        // Set point normals
        for (int i = 0; i < segment.points.Length; i++)
        {
            sc.SetPointNormal(i, sc.GetPoint(i, SplineComputer.Space.World).normal + segment.normals[i], SplineComputer.Space.World);
        }

        return(true);
    }
示例#3
0
    public static void BuildCollisionShapes(this GrindSegment segment)
    {
        segment.normals = new Vector3[segment.points.Length];

        for (int i = 0; i < segment.points.Length - 1; i++)
        {
            // Get object to update position and convert it into collision shape
            GameObject go = segment.grindRoot.gameObject;
            go.transform.position = segment.points[i].position;
            go.name = string.Format("{0}_collision_{1}", segment.grindRoot.parent.gameObject.name, i);
            go.transform.LookAt(segment.points[i + 1].position);
            go.tag   = segment.grindRoot.gameObject.tag;
            go.layer = 12;

            // Set collider size
            float       z  = Vector3.Distance(segment.points[i].position, segment.points[i + 1].position);
            BoxCollider bc = go.AddComponent <BoxCollider>();
            bc.size      = new Vector3(0.05f, 0.05f, z);
            bc.center    = (Vector3.forward * z) / 2f;
            bc.isTrigger = true;

            //DEBUG

            /*
             * LineRenderer line = go.AddComponent<LineRenderer>();
             * line.positionCount = 2;
             * line.widthMultiplier = 0.1f;
             * line.material = new Material(Shader.Find("Sprites/Default"));
             * var trans = bc.transform;
             * var min = bc.center - bc.size * 0.5f;
             * var max = bc.center + bc.size * 0.5f;
             * line.SetPosition(0, trans.TransformPoint(new Vector3(min.x, min.y, min.z)));
             * line.SetPosition(1, trans.TransformPoint(new Vector3(max.x, min.y, min.z)));
             */

            // Assign up vectors
            segment.normals[i] = go.transform.up;
        }
    }