예제 #1
0
/*+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 * CREATE BALLS
 *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*/

    public static BallData CreateBall(Type type, List <NoteData> notes = null, int bh = 1)
    {
        BallData new_ball = (BallData)ScriptableObject.CreateInstance(type);

        new_ball.Initialize("Generic");

        // If notes were not passed in as a parameter
        // Create new notes up to the min notes of the ball type
        if (notes == null)
        {
            for (int i = 0; i < new_ball.MinNotes; i++)
            {
                new_ball.notes.Add(CreateNote());
            }
        }
        // If notes were passed as parameter,
        // Create new notes, copied from the notes parameter.
        else
        {
            // Copy notes over as long as it doesn't go over the MaxNotes property of the new ball type
            for (int i = 0; i < notes.Count; i++)
            {
                if (new_ball.notes.Count < new_ball.MaxNotes)
                {
                    new_ball.notes.Add(CreateNote(notes[i]));
                }
                else
                {
                    break;
                }
            }
            // If ball still needs more notes after copy
            // (Ex. SimpleBall --> BounceBall)
            // Create the rest of the notes
            if (new_ball.notes.Count < new_ball.MinNotes)
            {
                new_ball.notes.Add(CreateNote());
                //new_ball.bounceHeight = bh;
            }
        }



        SaveNotes(new_ball.notes);
        SaveBall(new_ball);
        return(new_ball);
    }