Exemplo n.º 1
0
    public void CreateDataAsset()
    {
        LineBase      line      = FindObjectOfType(typeof(LineBase)) as LineBase;
        LineRenderer  lineR     = line.GetComponent <LineRenderer>();
        LineDataClass lineAsset = ScriptableObject.CreateInstance <LineDataClass>();

        lineAsset.points = new Vector3[lineR.positionCount];
        for (int i = 0; i < lineR.positionCount; i++)
        {
            lineAsset.points[i] = lineR.GetPosition(i);
        }
        string path = "Assets/Data/Lines/";

        string[] files       = System.IO.Directory.GetFiles(path, "Line*.asset");
        int      filesCount  = files.GetLength(0);
        string   newFileName = "Line_" + filesCount + ".asset";

        AssetDatabase.CreateAsset(lineAsset, path + newFileName);
        AssetDatabase.SaveAssets();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = lineAsset;
    }
Exemplo n.º 2
0
    public void CreateLine(GameObject linePrefab, LineDataClass lineAsset)
    {
        playerLine = Instantiate(linePrefab).GetComponent <PlayerLine>();
        playerLine.transform.parent = gameObject.transform;

        if (lineAsset)
        {
            playerLine.InitWithPoints(lineAsset.points);
        }

        if (playerBall)
        {
            Renderer ballRenderer = playerBall.GetComponent <Renderer>();
            float    ballWidth    = ballRenderer.bounds.size.x;
            float    lineX        = playerBall.transform.position.x;
            float    lineY        = playerBall.transform.position.y - ballWidth / 2;
            if (lineData)
            {
                lineX += lineData.startBallOffset.x;
                lineY += lineData.startBallOffset.y;
            }
            playerLine.transform.position = new Vector3(lineX, lineY, playerLine.transform.position.z);
        }
    }