コード例 #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);
    }
コード例 #2
0
ファイル: BezierShape.cs プロジェクト: videti/Bobsleigh3000
    public void RemoveScripts()
    {
        scriptableControlPoints.pipesParams = new List <ScriptableControlPoints.PipeParams>();
        List <Vector3> bezierPoints = GetBezierPoints(controlPoints.ToList(), nbArches);

        for (int i = 0; i < transform.childCount; i++)
        {
            CustomPipe child = transform.GetChild(i).GetComponent <CustomPipe>();
            child.SaveAssets();
            ScriptableControlPoints.PipeParams pipeParams = new ScriptableControlPoints.PipeParams();
            pipeParams.bezierPoints  = bezierPoints.ToArray();
            pipeParams.minArchNum    = child.minArchNum;
            pipeParams.maxArchNum    = child.maxArchNum;
            pipeParams.startAngle    = child.startAngle;
            pipeParams.endAngle      = child.endAngle;
            pipeParams.pipeWidth     = child.pipeWidth;
            pipeParams.thickness     = child.thickness;
            pipeParams.borderWidth   = child.borderWidth;
            pipeParams.noBorderLeft  = child.noBorderLeft;
            pipeParams.noBorderRight = child.noBorderRight;
            pipeParams.shapeIndex    = child.shapeIndex;
            scriptableControlPoints.pipesParams.Add(pipeParams);
            Destroy(child);
        }
        Destroy(GetComponent <ControlPoints>());
        Destroy(this);
    }
コード例 #3
0
ファイル: BezierShape.cs プロジェクト: videti/Bobsleigh3000
    public void SaveModel()
    {
        ScriptableControlPoints scriptable = ScriptableObject.CreateInstance <ScriptableControlPoints>();

        scriptable.ctrlPoints  = controlPoints;
        scriptable.pipesParams = new List <ScriptableControlPoints.PipeParams>();
        for (int i = 0; i < transform.childCount; i++)
        {
            CustomPipe child = transform.GetChild(i).GetComponent <CustomPipe>();
            foreach (MeshCollider meshCollider in child.gameObject.GetComponents <MeshCollider>())
            {
                Destroy(meshCollider);
            }
            //gameObject.AddComponent<MeshCollider>();
            foreach (MeshCollider meshCollider in child.transform.GetChild(0).GetComponents <MeshCollider>())
            {
                Destroy(meshCollider);
            }
            child.transform.GetChild(0).gameObject.AddComponent <MeshCollider>();
            //layer obstacle = 9
            child.transform.GetChild(0).gameObject.layer = 9;

            ScriptableControlPoints.PipeParams pipeParams = new ScriptableControlPoints.PipeParams();
            pipeParams.bezierPoints  = child.bezierPoints.ToArray();
            pipeParams.minArchNum    = child.minArchNum;
            pipeParams.maxArchNum    = child.maxArchNum;
            pipeParams.startAngle    = child.startAngle;
            pipeParams.endAngle      = child.endAngle;
            pipeParams.pipeWidth     = child.pipeWidth;
            pipeParams.thickness     = child.thickness;
            pipeParams.borderWidth   = child.borderWidth;
            pipeParams.noBorderLeft  = child.noBorderLeft;
            pipeParams.noBorderRight = child.noBorderRight;
            pipeParams.shapeIndex    = child.shapeIndex;
            scriptable.pipesParams.Add(pipeParams);
        }
        AssetDatabase.CreateAsset(scriptable, "Assets/Scripts/ScriptableObject/scriptableControlPoints_" + Mathf.Round(Time.time * 10000f) + ".asset");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.SetDirty(scriptable);
    }
コード例 #4
0
ファイル: CustomPipe.cs プロジェクト: videti/Bobsleigh3000
    public override void OnInspectorGUI()
    {
        CustomPipe myTarget = (CustomPipe)target;

        if (myTarget.GetComponent <MeshRenderer>() == null)
        {
            return;
        }

        if (shapeMaterials == null)
        {
            shapeMaterials = Resources.LoadAll <Material>("Mat/ShapeMat");
        }
        if (borderShapeMaterials == null)
        {
            borderShapeMaterials = Resources.LoadAll <Material>("Mat/BorderShapeMat");
        }
        string[] matNames = shapeMaterials.Select(x => x.name).ToArray();
        myTarget.shapeIndex = EditorGUILayout.Popup(myTarget.shapeIndex, matNames);
        myTarget.GetComponent <MeshRenderer>().material = shapeMaterials[myTarget.shapeIndex];
        myTarget.transform.GetChild(0).GetComponent <MeshRenderer>().material = borderShapeMaterials[myTarget.shapeIndex];
        DrawDefaultInspector();
    }
コード例 #5
0
ファイル: BezierShape.cs プロジェクト: videti/Bobsleigh3000
    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();
    }
コード例 #6
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);
    }