private void AddProps() { if (values.propAmountToAdd == 0) { return; } float segmentSize = 1f / (float)values.propAmountToAdd; switch (values.propType) { case GenerationPropTypes.Decoration: for (int i = 0; i < values.propAmountToAdd; i++) { GenerationProp pr = Instantiate(values.propToAdd.gameObject).GetComponent <GenerationProp>(); if (values.spacePropsEqually) { if (values.propAmountToAdd == 1) { pr.localPropPos.positionOnSpline = 0.5f; } if (segmentSize * i == 0) { pr.localPropPos.positionOnSpline = 0.005f; } else { pr.localPropPos.positionOnSpline = segmentSize * i; } } pr.transform.parent = values.propController.transform; if (values.propController.DecorativeGenerationProps == null) { values.propController.DecorativeGenerationProps = new List <GenerationProp>(); } values.propController.DecorativeGenerationProps.Add(pr); } break; case GenerationPropTypes.Hazard: for (int i = 0; i < values.propAmountToAdd; i++) { GenerationProp pr = Instantiate(values.propToAdd.gameObject).GetComponent <GenerationProp>(); if (values.spacePropsEqually) { if (values.propAmountToAdd == 1) { pr.localPropPos.positionOnSpline = 0.5f; } if (segmentSize * i == 0) { pr.localPropPos.positionOnSpline = 0.005f; } else { pr.localPropPos.positionOnSpline = segmentSize * i; } } pr.transform.parent = values.propController.transform; if (values.propController.HazardGenerationProps == null) { values.propController.HazardGenerationProps = new List <GenerationProp>(); } values.propController.HazardGenerationProps.Add(pr); } break; case GenerationPropTypes.Reward: for (int i = 0; i < values.propAmountToAdd; i++) { GenerationProp pr = Instantiate(values.propToAdd.gameObject).GetComponent <GenerationProp>(); if (values.spacePropsEqually) { if (values.propAmountToAdd == 1) { pr.localPropPos.positionOnSpline = 0.5f; } if (segmentSize * i == 0) { pr.localPropPos.positionOnSpline = 0.005f; } else { pr.localPropPos.positionOnSpline = segmentSize * i; } } pr.transform.parent = values.propController.transform; if (values.propController.RewardGenerationProps == null) { values.propController.RewardGenerationProps = new List <GenerationProp>(); } values.propController.RewardGenerationProps.Add(pr); } break; } }
public void DisplayPropSettings() { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Add a new prop: "); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("New prop: "); GenerationProp prop = values.propToAdd; prop = EditorGUILayout.ObjectField(values.propToAdd, typeof(GenerationProp), false) as GenerationProp; if (prop != values.propToAdd) { values.propToAdd = prop; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Prop type: "); values.propType = (GenerationPropTypes)EditorGUILayout.EnumPopup(values.propType); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Space props equally along spline: "); values.spacePropsEqually = EditorGUILayout.Toggle(values.spacePropsEqually); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Amount to add: "); values.propAmountToAdd = EditorGUILayout.IntField(values.propAmountToAdd); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (values.propToAdd == null || values.propAmountToAdd <= 0) { EditorGUILayout.HelpBox("Make sure you assign a new prop and have a valid amount above 0.", MessageType.Error); } else { if (GUILayout.Button("Add prop", GUILayout.Height(bigButtonHeight))) { AddProps(); values.propToAdd = null; values.propType = GenerationPropTypes.Decoration; values.propAmountToAdd = 30; values.spacePropsEqually = false; values.isAssigningNewProp = false; } } if (GUILayout.Button("Cancel", GUILayout.Height(bigButtonHeight))) { values.propToAdd = null; values.propType = GenerationPropTypes.Decoration; values.propAmountToAdd = 30; values.spacePropsEqually = false; values.isAssigningNewProp = false; } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; GUILayout.Label(""); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Toggle reset menu " + ((values.isOpenedResetMenu) ? "off" : "on"), GUILayout.Height(smallButtonHeight), GUILayout.Width(smallButtonWidth))) { values.isOpenedResetMenu = !values.isOpenedResetMenu; } } EditorGUILayout.EndHorizontal(); if (values.isOpenedResetMenu) { //EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reset decor props", GUILayout.Height(smallButtonHeight), GUILayout.Width(smallButtonWidth * 0.5f))) { RemoveDeco(); } if (GUILayout.Button("Reset reward props", GUILayout.Height(smallButtonHeight), GUILayout.Width(smallButtonWidth * 0.5f))) { RemoveReward(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reset hazard props", GUILayout.Height(smallButtonHeight), GUILayout.Width(smallButtonWidth * 0.5f))) { RemoveHazard(); } if (GUILayout.Button("Reset all props", GUILayout.Height(smallButtonHeight), GUILayout.Width(smallButtonWidth * 0.5f))) { RemoveAllProps(); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); GUILayout.Label(""); EditorGUILayout.EndVertical(); }