Ejemplo n.º 1
0
 private void RenderLoadActiveConfigurationButton()
 {
     if (GUILayout.Button(GetContentForLoadActiveConfigurationButton()) && _database.ActiveConfiguration != null)
     {
         PathObjectPlacement.Get().PathSettings.TileConnectionSettings.RecordAllTileConnectionTypeSettingsForUndo();
         _database.ActiveConfiguration.ApplyConfigurationDataToSettings(PathObjectPlacement.Get().PathSettings.TileConnectionSettings);
     }
 }
Ejemplo n.º 2
0
 private void RenderCreateNewConfigurationButton()
 {
     if (GUILayout.Button(GetContentForCreateNewConfigurationButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth)))
     {
         UndoEx.RecordForToolAction(_database);
         ObjectPlacementPathTileConnectionConfiguration newConfig = _database.CreateConfiguration(ViewData.NameForNewConfiguration);
         newConfig.ExtractConfigurationDataFromSettings(PathObjectPlacement.Get().PathSettings.TileConnectionSettings);
     }
 }
Ejemplo n.º 3
0
 private void RenderSaveActiveConfigurationButton()
 {
     if (GUILayout.Button(GetContentForSaveActiveConfigurationButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth)) &
         _database.ActiveConfiguration != null)
     {
         UndoEx.RecordForToolAction(_database.ActiveConfiguration);
         _database.ActiveConfiguration.ExtractConfigurationDataFromSettings(PathObjectPlacement.Get().PathSettings.TileConnectionSettings);
     }
 }
        private void RenderPathPlacementControls()
        {
            _settings.PathPlacementSettings.View.Render();

            EditorGUILayout.Separator();
            PathObjectPlacement.Get().PathSettings.View.Render();

            EditorGUILayout.Separator();
            if (PathObjectPlacement.Get().PathSettings.ManualConstructionSettings.HeightAdjustmentSettings.HeightAdjustmentMode == ObjectPlacementPathHeightAdjustmentMode.AutomaticPattern)
            {
                ObjectPlacementPathHeightPatternDatabase.Get().View.Render();
            }
        }
Ejemplo n.º 5
0
        public static bool Validate(bool logMessage)
        {
            if (PathObjectPlacement.Get().IsPathUnderManualConstruction)
            {
                if (logMessage)
                {
                    Debug.LogWarning("This action can not be performed while a path is under construction.");
                }
                return(false);
            }

            return(true);
        }
        private void RenderActiveConfigurationSelectionPopup()
        {
            ObjectPlacementPathTileConnectionConfigurationDatabase configurationDatabase = ObjectPlacementPathTileConnectionConfigurationDatabase.Get();
            string newString = EditorGUILayoutEx.Popup(GetContentForActiveConfigurationSelectionPopup(), configurationDatabase.ActiveConfiguration.Name, configurationDatabase.GetAllConfigurationNames());

            if (newString != configurationDatabase.ActiveConfiguration.Name)
            {
                ObjectPlacementPathTileConnectionConfiguration newActiveConfiguration = configurationDatabase.GetConfigurationByName(newString);
                if (newActiveConfiguration != null)
                {
                    UndoEx.RecordForToolAction(configurationDatabase);
                    PathObjectPlacement.Get().PathSettings.TileConnectionSettings.RecordAllTileConnectionTypeSettingsForUndo();
                    configurationDatabase.SetActiveConfiguration(newActiveConfiguration);
                    newActiveConfiguration.ApplyConfigurationDataToSettings(PathObjectPlacement.Get().PathSettings.TileConnectionSettings);
                }
            }
        }
Ejemplo n.º 7
0
        private bool ValidatePlacementDataCalculationConditions()
        {
            if (_path == null || _path.NumberOfSegments == 0 || !ObjectPlacementGuide.ExistsInScene || _tileConnectionXZSize == 0.0f)
            {
                return(false);
            }

            ObjectPlacementPathTileConnectionSettings tileConnectionSettings = PathObjectPlacement.Get().PathSettings.TileConnectionSettings;

            if (!tileConnectionSettings.DoAllTileConnectionsHavePrefabAssociated(true))
            {
                Debug.LogWarning("Not all tile connections have an associated prefab. Path placement was cancelled.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        private void AssignPrefabToDestinationTileConnection(Prefab prefab)
        {
            ObjectPlacementPathTileConnectionTypeSettings tileConnectionTypeSettings = PathObjectPlacement.Get().PathSettings.TileConnectionSettings.GetSettingsForTileConnectionType(_destinationTileConnectionType);

            UndoEx.RecordForToolAction(tileConnectionTypeSettings);
            tileConnectionTypeSettings.Prefab = prefab;
        }
 protected override void RenderContent()
 {
     PathObjectPlacement.Get().PathRenderSettings.View.Render();
     PathObjectPlacement.Get().PathExtensionPlaneRenderSettings.View.Render();
 }
Ejemplo n.º 10
0
        public List <ObjectPlacementData> Calculate()
        {
            if (!ValidatePlacementDataCalculationConditions())
            {
                return(new List <ObjectPlacementData>());
            }

            _allowObjectIntersection = ObjectPlacementSettings.Get().ObjectIntersectionSettings.AllowIntersectionForPathPlacement;
            List <ObjectPlacementBoxStackSegment> allPathSegments = _path.GetAllSegments();
            float objectMissChance = _path.Settings.ManualConstructionSettings.ObjectMissChance;
            bool  usingSprites     = _path.Settings.TileConnectionSettings.UsesSprites();

            var tileConnectionDetector           = new ObjectPlacementPathTileConnectionDetector();
            var tileConnectionRotationCalculator = new ObjectPlacementPathTileConnectionRotationCalculator();

            List <ObjectPlacementPathTileConnectionGridCell> tileConnectionGridCells = tileConnectionDetector.Detect(_path, _tileConnectionXZSize);

            if (tileConnectionGridCells.Count == 0)
            {
                return(new List <ObjectPlacementData>());
            }

            List <Prefab>  tileConnectionPrefabsExceptAutofill          = PathObjectPlacement.Get().PathSettings.TileConnectionSettings.GetAllTileConnectionPrefabs(true);
            List <Vector3> tileConnectionWorldScaleValuesExceptAutofill = CalculateWorldScaleForAllTileConnectionPrefabsExceptAutofill(PrefabQueries.GetTransformsForAllPrefabs(tileConnectionPrefabsExceptAutofill), PrefabQueries.GetHierarchyWorldOrientedBoxesForAllPrefabs(tileConnectionPrefabsExceptAutofill));
            List <Vector3> tileConnectionOffsetsExceptAutofill          = CalculateOffsetsForAllTileConnectionsExceptAutofill();

            var objectPlacementDataInstances = new List <ObjectPlacementData>(allPathSegments.Count * 10);

            foreach (ObjectPlacementPathTileConnectionGridCell tileConnectionGridCell in tileConnectionGridCells)
            {
                ObjectPlacementPathTileConnectionType tileConnectionType = tileConnectionGridCell.TileConnectionType;
                ObjectPlacementBoxStack tileConnectionStack = tileConnectionGridCell.TileConnectionStack;
                if (tileConnectionStack.IsOverlappedByAnotherStack)
                {
                    continue;
                }

                Prefab     tileConnectionPrefab     = tileConnectionPrefabsExceptAutofill[(int)tileConnectionType];
                Quaternion tileConnectionRotation   = tileConnectionRotationCalculator.Calculate(tileConnectionGridCell);
                Vector3    tileConnectionWorldScale = tileConnectionWorldScaleValuesExceptAutofill[(int)tileConnectionType];
                Vector3    tileConnectionOffset     = tileConnectionOffsetsExceptAutofill[(int)tileConnectionType];

                for (int stackBoxIndex = 0; stackBoxIndex < tileConnectionStack.NumberOfBoxes; ++stackBoxIndex)
                {
                    ObjectPlacementBox box = tileConnectionStack.GetBoxByIndex(stackBoxIndex);
                    if (box.IsHidden)
                    {
                        continue;
                    }

                    if (ObjectPlacementMissChance.Missed(objectMissChance, ObjectPlacementPathManualConstructionSettings.MinObjectMissChance, ObjectPlacementPathManualConstructionSettings.MaxObjectMissChance))
                    {
                        continue;
                    }
                    if (!_allowObjectIntersection && ObjectQueries.IntersectsAnyObjectsInScene(box.OrientedBox, true))
                    {
                        continue;
                    }

                    var objectPlacementData = new ObjectPlacementData();
                    objectPlacementData.WorldPosition  = ObjectPositionCalculator.CalculateObjectHierarchyPosition(tileConnectionPrefab, box.Center, tileConnectionWorldScale, tileConnectionRotation);
                    objectPlacementData.WorldPosition += tileConnectionOffset;

                    objectPlacementData.WorldScale    = tileConnectionWorldScale;
                    objectPlacementData.WorldRotation = tileConnectionRotation;
                    objectPlacementData.Prefab        = tileConnectionPrefab;
                    objectPlacementDataInstances.Add(objectPlacementData);
                }

                // Apply extrusion if necessary
                if (!usingSprites)
                {
                    List <OrientedBox> extrusionOrientedBoxes = ObjectPlacementPathTileConnectionExtrusion.GetTileConnectionExtrusionOrientedBoxes(tileConnectionGridCell);
                    foreach (OrientedBox extrusionBox in extrusionOrientedBoxes)
                    {
                        if (ObjectPlacementMissChance.Missed(objectMissChance, ObjectPlacementPathManualConstructionSettings.MinObjectMissChance, ObjectPlacementPathManualConstructionSettings.MaxObjectMissChance))
                        {
                            continue;
                        }
                        if (!_allowObjectIntersection && ObjectQueries.IntersectsAnyObjectsInScene(extrusionBox, true))
                        {
                            continue;
                        }

                        var objectPlacementData = new ObjectPlacementData();
                        objectPlacementData.WorldPosition = ObjectPositionCalculator.CalculateObjectHierarchyPosition(tileConnectionPrefab, extrusionBox.Center, tileConnectionWorldScale, tileConnectionRotation);
                        objectPlacementData.WorldScale    = tileConnectionWorldScale;
                        objectPlacementData.WorldRotation = tileConnectionRotation;
                        objectPlacementData.Prefab        = tileConnectionPrefab;
                        objectPlacementDataInstances.Add(objectPlacementData);
                    }
                }
            }

            ObjectPlacementPathTileConnectionSettings tileConnectionSettings = _path.Settings.TileConnectionSettings;

            if (tileConnectionSettings.DoesAutofillTileConnectionHavePrefabAssociated())
            {
                objectPlacementDataInstances.AddRange(GetPlacementDataForAutofillTiles(tileConnectionGridCells[0].ParentGrid));
            }

            return(objectPlacementDataInstances);
        }