Beispiel #1
0
 /// <summary>
 /// Binds a default placement to the context for a part's driver execution.
 /// </summary>
 /// <param name="context">The execution context.</param>
 /// <param name="defaultSettings">PlacementSetting objects to fall back on.</param>
 private void BindPlacement(
     BuildShapeContext context, IEnumerable <PlacementSettings> defaultSettings)
 {
     context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {
         var mockSetting = new PlacementSettings {
             ShapeType      = partShapeType,
             Differentiator = differentiator
         };
         var defaultSetting = defaultSettings.FirstOrDefault(ps => ps.IsSameAs(mockSetting));
         defaultLocation = defaultSetting == null ? defaultLocation :                                  //may still end up with a null defaultLocation
                           defaultSetting.Zone + (string.IsNullOrEmpty(defaultSetting.Position) ? "" : ":" + defaultSetting.Position);
         defaultLocation = string.IsNullOrWhiteSpace(defaultLocation) ? "Content:1" : defaultLocation; //avoid null fallbacks
         return(new PlacementInfo {
             Location = defaultLocation,
             Source = string.Empty
         });
     };
 }
Beispiel #2
0
    private void ProcessPlacementSettings(GameObject targetContainer, RoomGeneratorHelper generator, PlacementSettings settings, Vector3 placeOffset, bool randomRotations, bool useAccessibleSlots)
    {
        int placeCount = Random.Range(settings.m_MinPlacements, settings.m_MaxPlacements);

        if (targetContainer == m_EnemyContentContainer && m_IsBossRoom)
        {
            placeCount = 1 + GameController.Main.CurrentLevel * 2;
        }

        if (m_IsBossRoom)         //?
        {
            placeOffset += new Vector3(0, -1.62f, 0);
        }

        for (int n = 0; n < placeCount; ++n)
        {
            bool hasSlots = useAccessibleSlots ? generator.AccessibleSpots.Any() : generator.InaccessibleSpots.Any();
            if (!hasSlots)
            {
                return;
            }

            GroupPlacementSettings groupSettings = settings.SelectRandomGroup();
            int objectCount = Random.Range(groupSettings.m_MinElements, groupSettings.m_MaxElements) + groupSettings.m_AlwaysPlacedObjects.Length;

            var spots = useAccessibleSlots ? generator.GetFreeAccessibleSpot(objectCount) : generator.GetFreeInaccessibleSpot(objectCount);

            for (int i = 0; i < spots.Count(); ++i)
            {
                GameObject targetObj;

                if (i < groupSettings.m_AlwaysPlacedObjects.Length)
                {
                    targetObj = groupSettings.m_AlwaysPlacedObjects[i];
                }
                else
                {
                    targetObj = groupSettings.SelectRandomObject().m_PlacedObject;
                }

                Vector3 offset = new Vector3(Random.Range(-1.0f, 1.0f), -1.0f, Random.Range(-1.0f, 1.0f)) + placeOffset;
                float   angle  = randomRotations ? Random.Range(0, 360f) : 0.0f;

                Vector3    spawnPosition = transform.position + offset + spots.ElementAt(i) - new Vector3(m_Extents.x, 0, m_Extents.z) * 0.5f;
                GameObject newObj        = Instantiate(targetObj, spawnPosition, Quaternion.AngleAxis(angle, Vector3.up), targetContainer.transform);

                // Should spawn weapon too?
                CharacterController character = newObj.GetComponentInChildren <CharacterController>();
                if (character != null)
                {
                    foreach (GameObject weapon in GetDefaultWeapons())
                    {
                        Instantiate(weapon, spawnPosition + Vector3.up * 1.5f, Quaternion.identity, targetContainer.transform);
                    }

                    AIController aiController = newObj.GetComponentInChildren <AIController>();
                    if (!aiController.HasDefaultProfile)
                    {
                        aiController.SetProfile(GetAIProfile());
                    }
                }
            }
        }
    }