Esempio n. 1
0
    void LoadMaze(int index)
    {
        //if there was a pointer to the maze gameobject delete that
        if (CurrentActiveMaze)
        {
            Destroy(CurrentActiveMaze);
        }
        //reinstantiate from prefab
        CurrentActiveMaze = Instantiate(Mazes[MazeIndex], VirtualRoom.transform);
        MazeInformation mazeinfo = Mazes[MazeIndex].GetComponent <MazeInformation>();

        VirtualRobot.transform.localPosition = mazeinfo.StartLocation;
        //correct object rotation, since object has wrong axis
        Vector3 objectRot = Quaternion.Euler(0, -90, 0) * mazeinfo.StartFacingDirection; //

        VirtualRobot.transform.rotation = Quaternion.LookRotation(objectRot, Vector3.up);
    }
Esempio n. 2
0
    void SaveMazePrefab()
    {
        GameObject NewMaze = new GameObject(MazeName);

        foreach (GameObject component in MazeComponents)
        {
            component.transform.parent = NewMaze.transform;
            Rigidbody rig = component.AddComponent <Rigidbody>();
            rig.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            //   rig.constraints = RigidbodyConstraints.FreezeRotationZ;
        }

        //Current global transforms will be assigned to the saved maze

        MazeInformation comp = NewMaze.AddComponent <MazeInformation>();

        comp.StartLocation        = MazeStartLocation;
        comp.StartFacingDirection = StartFacingDirection;
        comp.FinishLocation       = MazeEndLocation;



        string savepath = SaveLocation + "/" + MazeName + ".prefab";

        if (savepath.StartsWith(Application.dataPath))
        {
            savepath = "Assets" + savepath.Substring(Application.dataPath.Length);
        }
        Debug.Log("Maze saved in location : " + savepath);
        GameObject prefab = PrefabUtility.CreatePrefab(savepath, NewMaze);

        PrefabUtility.ReplacePrefab(NewMaze, prefab, ReplacePrefabOptions.ConnectToPrefab);

        NewMaze.transform.parent = ObstacleParent.transform;

        //ResetEverything();
    }