コード例 #1
0
    GameObject SpawnBot(
        SpawnPointRuntimeSet spawns,
        NamedPrefab namedPrefab,
        Vector3 lookAt,
        bool player
        )
    {
        var spawnPoint = spawns.PickRandom();
        var rotation   = Quaternion.LookRotation(lookAt - spawnPoint.transform.position);
        var botGo      = Object.Instantiate(namedPrefab.prefab, spawnPoint.transform.position + namedPrefab.offset, rotation);

        botGo.name = namedPrefab.name;
        var health = botGo.GetComponent <BotHealth>();

        if (health != null)
        {
            health.onDeath.AddListener(OnBotDeath);
        }

        // add new bot to list of active bots
        activeBots.Add(botGo.GetComponent <BotBuilder>());

        // add AI script, disable controls
        BotBrain brain;

        if (player)
        {
            brain = botGo.AddComponent <HumanController>();
            gameEventChannel.Raise(GameRecord.GamePlayerDeclared(botGo));
        }
        else
        {
            brain = botGo.AddComponent <AIController>();
            gameEventChannel.Raise(GameRecord.GameEnemyDeclared(botGo));
            ((AIController)brain).AssignConfig(defaultAIConfig);
            ((AIController)brain).TargetPlayer();
        }
        aiControllers.Add(brain);
        brain.DisableControls();

        // change color of bot
        var materialDistributor = botGo.GetComponent <MaterialDistributor>();

        if (materialDistributor != null)
        {
            materialDistributor.SetMaterials((player) ? MaterialTag.Player : MaterialTag.Enemy);
        }

        return(botGo);
    }
コード例 #2
0
 void OnJointBreak()
 {
     if (gameEventChannel != null)
     {
         gameEventChannel.Raise(GameRecord.BotJointBroke(gameObject));
     }
 }
コード例 #3
0
 void OnTakeDamage(GameObject from, int amount)
 {
     onChange.Invoke(health);
     onChangePercent.Invoke(healthPercent);
     if (healthPercent <= 0 && !dead)
     {
         onDeath.Invoke(gameObject);
         dead = true;
         if (gameEventChannel != null)
         {
             gameEventChannel.Raise(GameRecord.BotDied(gameObject, from));
         }
     }
     // notify channel
     if (gameEventChannel != null)
     {
         gameEventChannel.Raise(GameRecord.BotTookDamage(gameObject, from, amount));
     }
 }
コード例 #4
0
 IEnumerator DetectFlip()
 {
     while (botAlive)
     {
         var currentFlip = Vector3.Angle(Vector3.up, transform.up) > 90;
         if (currentFlip != flipped)
         {
             flipped = currentFlip;
             if (eventChannel != null)
             {
                 eventChannel.Raise(GameRecord.BotFlipped(gameObject));
             }
         }
         // wait until next frame;
         yield return(null);
     }
 }