예제 #1
0
        protected void Awake()
        {
            // Register child brains as prefab brains.
            var brains = GetComponentsInChildren <SpaceshipBrain>();

            foreach (var brain in brains)
            {
                brainPools[brain.DefaultName] = new BrainPool(brain, transform);
            }

            instance = this;
        }
예제 #2
0
        protected void Start()
        {
            // Create all spaceships.
            var secondaryColorIndex = 0;
            var type2colors         = new Dictionary <SpaceshipBody.Type, HashSet <Color> >();
            var nameCount           = new Dictionary <string, int>();

            foreach (var spaceshipName in spaceshipNames)
            {
                var brain      = BrainFactory.GetBrain(spaceshipName);
                var spawnPoint = Space.GetSpawnPoint();
                var angle      = UnityEngine.Random.Range(1, 360 / Spaceship.ROTATION_PER_ACTION) * Spaceship.ROTATION_PER_ACTION;
                var body       = spaceshipBodiesPool.Borrow <SpaceshipBody>(spawnPoint, angle, space, brain);

                // Check for duplicate type and color.
                var bodyType = body.spaceshipType;
                var color    = body.primaryColor;
                if (!type2colors.ContainsKey(bodyType))
                {
                    type2colors[bodyType] = new HashSet <Color>();
                    type2colors[bodyType].Add(color);
                }
                else if (type2colors[bodyType].Contains(color))
                {
                    // Color clash! Set secondary color.
                    body.SetSecondaryColor(secondaryColors[secondaryColorIndex++]);
                }
                else
                {
                    type2colors[bodyType].Add(color);
                }

                if (nameCount.ContainsKey(brain.DefaultName))
                {
                    ++nameCount[brain.DefaultName];
                    brain.Name = brain.DefaultName + " " + nameCount[brain.DefaultName];
                }
                else
                {
                    nameCount[brain.DefaultName] = 1;
                }

                // Register to score board.
                scoreBoard.Add(brain.Name, color, body.secondaryColor);
            }
        }