示例#1
0
    // Use this for initialization
    void Start()
    {
        mode = Application.isEditor ? "Editor" : "Release";
        OpenLogFile($"Wumpus Unity ({mode}).csv");
        LogFile.WriteLine("Iteration No.;Iterate time (ms);Comment");

        world = new CaveWorld(WumpusPositions, PitPositions, GoldPosition);
        CreateWorldPlatform();
        _agent          = Instantiate(WumpusPrefabs["Agent"], new Vector3(0, YPosition, 0), Quaternion.Euler(0, 180f, 0)).GetComponent <Agent>();
        EffectsAudioSrc = _agent.GetComponent <AudioSource>();

        world.OnBreezePercepted += () =>
        {
            PlaySound("Breeze");
        };
        world.OnMove += (Position p) =>
        {
            var vecPos = new Vector3(p.X, _agent.transform.position.y, p.Y);
            _agent.SetLerpPos(vecPos);
            PlaySound("Move", false);
        };
        world.OnPitEncountered += () =>
        {
            Destroy(_agent);
            PlaySound("Pit");
            _gameRunning = false;
        };
        world.OnStenchPercepted     += () => PlaySound("Stench");
        world.OnTreasureEncountered += () =>
        {
            Destroy(Treasure);
            PlaySound("Gold");
        };
        world.OnWumpusEncountered += () =>
        {
            Destroy(_agent);
            PlaySound("Wumpus");
            _gameRunning = false;
        };
        world.OnGoalComplete += () =>
        {
            PlaySound("Goal");

            world.Reset();
            Treasure = Instantiate(WumpusPrefabs["Treasure"], new Vector3(GoldPosition.X, YPosition, GoldPosition.Y), Quaternion.Euler(0, 180f, 0));
            iterations++;
            _gameRunning = iterations < numberOfIterations;
            comment      = "reset";
        };
    }
示例#2
0
    void Start()
    {
        mode = Application.isEditor ? "Editor" : "Release";
        OpenLogFile($"Wumpus Unity ({mode}).csv");
        LogFile.WriteLine("Iteration No.,Iterate time (microseconds),Comment");

        world = new CaveWorld(WumpusPositions, PitPositions, GoldPosition);
        CreateWorldPlatform();
//        _agent = Instantiate(WumpusPrefabs["Agent"], new Vector3(0, YPosition, 0), Quaternion.Euler(0, 180f, 0)).GetComponent<Agent>(); //Is instantiated in another place

        world.OnBreezePercepted += () =>
        {
            PlaySound("Breeze");
        };
        world.OnMove += (Position p) =>
        {
            var vecPos = new Vector3(p.X, YPosition, p.Y);
//            _agent.SetLerpPos(vecPos);
            MoveAgent(vecPos, 1);
            PlaySound("Move", false);
        };
        world.OnPitEncountered += () =>
        {
//            Destroy(_agent);
            UnityEngine.Debug.LogError("Dead");
            PlaySound("Pit");
            _gameRunning = false;
        };
        world.OnStenchPercepted     += () => PlaySound("Stench");
        world.OnTreasureEncountered += () =>
        {
            EM.DestroyEntity(Treasure);

            PlaySound("Gold");
            comment = "gold";
        };
        world.OnWumpusEncountered += () =>
        {
//            Destroy(_agent);
// TODO Kill agent?
            PlaySound("Wumpus");
            _gameRunning = false;
        };
        world.OnGoalComplete += () =>
        {
            PlaySound("Goal");

            world.Reset();

            Treasure = EM.CreateEntity(typeof(Translation),
                                       typeof(LocalToWorld),
                                       typeof(RenderMesh));
            EM.SetSharedComponentData(Treasure, new RenderMesh
            {
                mesh     = blockMesh,
                material = treasureMat
            });
            EM.SetComponentData(Treasure, new Translation
            {
                Value = new float3(1, 1, 2)
            });

//            Treasure = Instantiate(WumpusPrefabs["Treasure"], new Vector3(GoldPosition.X, YPosition, GoldPosition.Y), Quaternion.Euler(0, 180f, 0));
            EM.SetComponentData(Treasure, new Translation
            {
                Value = new float3(1, YPosition, 2) //Hopefully the treasure position
            });
            iterations++;
            _gameRunning = iterations < numberOfIterations;
            comment      = "reset";
        };
    }