コード例 #1
0
    void Start()
    {
        // GUI has four types of objects. Controlpoints, in and out controls and a line between all of these.
        // All these are RageSpline objects, instantiated from a prefab
        controlPoints    = new RageSpline[rageSpline.GetPointCount()];
        inControlPoints  = new RageSpline[rageSpline.GetPointCount()];
        outControlPoints = new RageSpline[rageSpline.GetPointCount()];
        handleLines      = new RageSpline[rageSpline.GetPointCount()];

        for (int index = 0; index < rageSpline.GetPointCount(); index++)
        {
            // Instantiate control point GUI object from the controlPointPrefab -prefab
            GameObject controlPointGO = Instantiate(
                controlPointPrefab,
                rageSpline.GetPositionWorldSpace(index) + new Vector3(0f, 0f, -1f),
                Quaternion.identity) as GameObject;

            // Save the new RageSpline instance reference of the GUI object
            controlPoints[index] = controlPointGO.GetComponent(typeof(RageSpline)) as RageSpline;
            controlPoints[index].SetFillColor1(unSelectedColor);

            // Instantiate inCtrl handle GUI object from the handleControlPointPrefab -prefab
            GameObject inControlPointGO = Instantiate(
                handleControlPointPrefab,
                rageSpline.GetInControlPositionWorldSpace(index) + new Vector3(0f, 0f, -1f),
                Quaternion.identity) as GameObject;

            // Save the new RageSpline instance reference of the GUI object
            inControlPoints[index] = inControlPointGO.GetComponent(typeof(RageSpline)) as RageSpline;
            inControlPoints[index].SetFillColor1(unSelectedColor);

            // Instantiate outCtrl handle GUI object from the handleControlPointPrefab -prefab
            GameObject outControlPointGO = Instantiate(
                handleControlPointPrefab,
                rageSpline.GetOutControlPositionWorldSpace(index) + new Vector3(0f, 0f, -1f),
                Quaternion.identity) as GameObject;

            // Save the new RageSpline instance reference of the GUI object
            outControlPoints[index] = outControlPointGO.GetComponent(typeof(RageSpline)) as RageSpline;
            outControlPoints[index].SetFillColor1(unSelectedColor);

            // Instantiate line GUI object from the handleLinePrefab -prefab
            GameObject handleLineGO = Instantiate(
                handleLinePrefab,
                rageSpline.GetPositionWorldSpace(index) + new Vector3(0f, 0f, -0.5f),
                Quaternion.identity) as GameObject;

            handleLines[index] = handleLineGO.GetComponent(typeof(RageSpline)) as RageSpline;
        }

        refreshEditorGUI();
    }
コード例 #2
0
 public static bool RemoveOverlap(this IRageSpline path, int index0, int index1, float snapRadius, bool debug)
 {
     if (index1 == 0)
     {
         index0 = path.GetPointCount() - 1;
     }
     if (Vector3.Distance(path.GetPositionWorldSpace(index0), path.GetPositionWorldSpace(index1)) <= snapRadius)
     {
         if (debug)
         {
             Debug.Log("overlap path pos = " + path.GetPositionWorldSpace(index0));
         }
         path.SetNatural(index1, false);
         path.SetInControlPositionWorldSpace(index1, path.GetInControlPositionWorldSpace(index0));
         path.RemovePoint(index0);      // Then deletes the duplicate previous point
         return(true);
     }
     return(false);
 }
コード例 #3
0
    void Start()
    {
        float t = Vector3.Distance(spline.GetPositionWorldSpace(0), thisTransform.position);

        radius = t;
        float w = spline.GetAntialiasingWidth();

        spline.SetAntialiasingWidth(w * AntiAliasPlaftformFactor);
        //antiAliasFactor = radius * spline.GetAntialiasingWidth();
        antiAliasWidth = spline.GetAntialiasingWidth();
        mass           = density * radius * radius;
    }
コード例 #4
0
    /// <summary> Special case for start-end points, where the out tangent must be copied instead of the in tangent </summary>
    public static bool MergeStartEndPoints(this IRageSpline rageSpline, bool debug)
    {
        if (rageSpline.GetPointCount() <= 2)
        {
            return(false);
        }
        var lastPointIdx  = rageSpline.GetPointCount() - 1;
        var lastPointPos  = rageSpline.GetPositionWorldSpace(lastPointIdx);
        var firstPointPos = rageSpline.GetPositionWorldSpace(0);

        if (Vector3.Distance(firstPointPos, lastPointPos) < 0.0001f)
        {
            if (debug)
            {
                Debug.Log("\t Removing endpoint overlap ");
            }
            rageSpline.SetInControlPositionWorldSpace(0, rageSpline.GetInControlPositionWorldSpace(lastPointIdx));
            rageSpline.RemovePoint(lastPointIdx);      // Then deletes the last point
            return(true);
        }
        return(false);
    }
コード例 #5
0
ファイル: PropHandler.cs プロジェクト: r618/RageSpline
    private void PlantGameObjectToLandscape(GameObject obj, float splinePos, float faceSplineNormal)
    {
        float oldZ = obj.transform.position.z;

        obj.transform.position = landscapeSpline.GetPositionWorldSpace(splinePos);
        obj.transform.position = new Vector3(obj.transform.position.x, obj.transform.position.y, oldZ);
        obj.transform.LookAt(obj.transform.position + transform.forward, (landscapeSpline.GetNormalInterpolated(splinePos) * faceSplineNormal + Vector3.up * (1f - faceSplineNormal)).normalized);

        if (obj.name == "Rock")
        {
            obj.transform.position += new Vector3(Random.Range(-4f, 4f), Random.Range(0f, 5f), 0f);
            obj.GetComponent <Rigidbody>().velocity = new Vector3(Random.Range(Mathf.Clamp(-0.01f * transform.position.x, -60f, 0f), 0f), 0f, 0f);
        }
    }
コード例 #6
0
    // Update is called once per frame
    void FixedUpdate()
    {
        for (int i = 0; i < rageSpline.GetPointCount() - 1; i++)
        {
            if (rageSpline.GetPositionWorldSpace(i + 1).x < cam.transform.position.x - (1024f / 768f) * cam.orthographicSize * 2f)
            {
                rageSpline.RemovePoint(i - 1);
                float x = (rageSpline.GetPositionWorldSpace(rageSpline.GetPointCount() - 1).x + pointGapWidth);
                rageSpline.AddPointWorldSpace(rageSpline.GetPointCount(), GetNewLandscapePoint(x), transform.right * pointGapWidth * 0.33f);

                transform.position += new Vector3(pointGapWidth, 0f, 0f);
                for (int a = 0; a < rageSpline.GetPointCount(); a++)
                {
                    rageSpline.SetPoint(a, rageSpline.GetPosition(a) + new Vector3(-pointGapWidth, 0f, 0f));
                }

                rageSpline.RefreshMesh();
            }
        }

        curSteepness = steepness + transform.position.x * 0.0001f;
        maxY         = Mathf.Clamp(transform.position.x * 0.05f, 0f, 10f);
    }