Beispiel #1
0
    public void GeneratePipesFromSavedParams()
    {
        for (int i = 0; i < savedControlPoints.pipesParams.Count; i++)
        {
            ScriptableControlPoints.PipeParams param = savedControlPoints.pipesParams[i];
            GameObject child = new GameObject("Pipe_" + (transform.childCount - 1));
            child.transform.parent = transform;
            CustomPipe cp = child.AddComponent <CustomPipe>();
            cp.shapeIndex   = param.shapeIndex;
            cp.minArchNum   = param.minArchNum;
            cp.maxArchNum   = param.maxArchNum;
            cp.startAngle   = param.startAngle;
            cp.endAngle     = param.endAngle;
            cp.pipeWidth    = param.pipeWidth;
            cp.thickness    = param.thickness;
            cp.borderHeight = param.borderHeight;
            cp.borderWidth  = param.borderWidth;
            cp.bezierPoints = param.bezierPoints.ToList();
            cp.CreateMesh();
            child.AddComponent <MeshCollider>();
        }
        BezierShape bz = gameObject.AddComponent <BezierShape>();

        bz.controlPoints = savedControlPoints.ctrlPoints;
        Destroy(this);
    }
Beispiel #2
0
    void CreateChildPipe(int minArchNum, int maxArchNum, List <Vector3> bezierPoints, float startAngle, float endAngle)
    {
        if (bezierPoints.Count == 0)
        {
            return;
        }
        string     num   = transform.childCount < 10 ? "0" + transform.childCount : transform.childCount + "";
        GameObject child = new GameObject("Pipe_" + num);

        child.transform.parent = transform;
        CustomPipe cp = child.AddComponent <CustomPipe>();

        cp.shapeIndex   = shapeIndex;
        cp.minArchNum   = minArchNum;
        cp.maxArchNum   = maxArchNum;
        cp.startAngle   = startAngle;
        cp.endAngle     = endAngle;
        cp.pipeWidth    = pipeWidth;
        cp.thickness    = thickness;
        cp.borderHeight = borderHeight;
        cp.borderWidth  = borderWidth;
        cp.bezierPoints = bezierPoints;
        cp.CreateMesh();
    }
Beispiel #3
0
    // joint different bezier curve together
    public void GeneratePipes()
    {
        translations    = new Vector3[tobogganParts.Length];
        rotations       = new Quaternion[tobogganParts.Length];
        translations[0] = -tobogganParts[0].pipesParams[0].bezierPoints[0];
        rotations[0]    = Quaternion.Euler(0, 0, 0);

        for (int i = 0; i < tobogganParts.Length; i++)
        {
            if (i != 0)
            {
                int     previousIndex               = i - 1;
                int     nbPipesParamsPreviousPart   = tobogganParts[previousIndex].pipesParams.Count;
                int     nbBezierPointsPreviousPart  = tobogganParts[previousIndex].pipesParams[nbPipesParamsPreviousPart - 1].bezierPoints.Length;
                Vector3 lastBezierPointPreviousPart = tobogganParts[previousIndex].pipesParams[nbPipesParamsPreviousPart - 1].bezierPoints[nbBezierPointsPreviousPart - 1];
                Vector3 previousPartLastDirection   = tobogganParts[i - 1].pipesParams[0].bezierPoints[nbBezierPointsPreviousPart - 1] - tobogganParts[i - 1].pipesParams[0].bezierPoints[nbBezierPointsPreviousPart - 2];
                Vector3 firstDirection              = tobogganParts[i].pipesParams[0].bezierPoints[0] - tobogganParts[i].pipesParams[0].bezierPoints[1];

                //rotation
                rotations[i]  = Quaternion.FromToRotation(Vector3.Normalize(firstDirection), Vector3.Normalize(-previousPartLastDirection));
                rotations[i] *= rotations[i - 1];

                //translation
                Vector3 rotatedFirstPoint            = rotations[i] * tobogganParts[i].pipesParams[0].bezierPoints[0];
                Vector3 rotatedLastPointPreviousPart = rotations[i - 1] * lastBezierPointPreviousPart + translations[i - 1];
                translations[i] = rotatedLastPointPreviousPart - rotatedFirstPoint;
            }

            List <Vector3> newBezierPoints = new List <Vector3>();
            for (int k = 0; k < tobogganParts[i].pipesParams[0].bezierPoints.Length; k++)
            {
                newBezierPoints.Add(rotations[i] * tobogganParts[i].pipesParams[0].bezierPoints[k] + translations[i]);
            }

            foreach (ScriptableControlPoints.PipeParams param in tobogganParts[i].pipesParams)
            {
                string num = transform.childCount + "";
                if (transform.childCount < 100)
                {
                    num = "0" + num;
                }
                if (transform.childCount < 10)
                {
                    num = "0" + num;
                }
                GameObject child = new GameObject("Pipe_" + num);
                child.transform.parent = transform;
                CustomPipe cp = child.AddComponent <CustomPipe>();
                cp.shapeIndex   = param.shapeIndex;
                cp.minArchNum   = param.minArchNum;
                cp.maxArchNum   = param.maxArchNum;
                cp.startAngle   = param.startAngle;
                cp.endAngle     = param.endAngle;
                cp.pipeWidth    = param.pipeWidth;
                cp.thickness    = param.thickness;
                cp.borderHeight = param.borderHeight;
                cp.borderWidth  = param.borderWidth;
                cp.bezierPoints = newBezierPoints;
                cp.CreateMesh();
                child.AddComponent <MeshCollider>();
            }
            //BezierShape bz = gameObject.AddComponent<BezierShape>();
            //bz.controlPoints = tobogganParts[i].ctrlPoints;
        }
        //Destroy(this);
    }