public void OnEnable() { cullArea = (CullArea)target; // Destroying the newly created cull area if there is already one existing if (FindObjectsOfType <CullArea>().Length > 1) { Debug.LogWarning("Destroying newly created cull area because there is already one existing in the scene."); DestroyImmediate(cullArea); return; } // Prevents the dropdown from resetting if (cullArea != null) { upAxisOptions = cullArea.YIsUpAxis ? UP_AXIS_OPTIONS.SideScrollerMode : UP_AXIS_OPTIONS.TopDownOr3DMode; } }
/// <summary> /// Represents the inspector GUI when edit mode is active. /// </summary> private void OnInspectorGUIEditMode() { EditorGUI.BeginChangeCheck(); #region DEFINE_UP_AXIS { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Select game type", EditorStyles.boldLabel); upAxisOptions = (UP_AXIS_OPTIONS)EditorGUILayout.EnumPopup("Game type", upAxisOptions); cullArea.YIsUpAxis = (upAxisOptions == UP_AXIS_OPTIONS.SideScrollerMode); EditorGUILayout.EndVertical(); } #endregion EditorGUILayout.Space(); #region SUBDIVISION { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Set the number of subdivisions", EditorStyles.boldLabel); cullArea.NumberOfSubdivisions = EditorGUILayout.IntSlider("Number of subdivisions", cullArea.NumberOfSubdivisions, 0, CullArea.MAX_NUMBER_OF_SUBDIVISIONS); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); if (cullArea.NumberOfSubdivisions != 0) { for (int index = 0; index < cullArea.Subdivisions.Length; ++index) { if ((index + 1) <= cullArea.NumberOfSubdivisions) { string countMessage = (index + 1) + ". Subdivision: row / column count"; EditorGUILayout.BeginVertical(); cullArea.Subdivisions[index] = EditorGUILayout.Vector2Field(countMessage, cullArea.Subdivisions[index]); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } else { cullArea.Subdivisions[index] = new UnityEngine.Vector2(1, 1); } } } } #endregion EditorGUILayout.Space(); #region UPDATING_MAIN_CAMERA { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("View and camera options", EditorStyles.boldLabel); alignEditorCamera = EditorGUILayout.Toggle("Automatically align editor view with grid", alignEditorCamera); if (Camera.main != null) { if (GUILayout.Button("Align main camera with grid")) { Undo.RecordObject(Camera.main.transform, "Align main camera with grid."); float yCoord = cullArea.YIsUpAxis ? cullArea.Center.y : Mathf.Max(cullArea.Size.x, cullArea.Size.y); float zCoord = cullArea.YIsUpAxis ? -Mathf.Max(cullArea.Size.x, cullArea.Size.y) : cullArea.Center.y; Camera.main.transform.position = new Vector3(cullArea.Center.x, yCoord, zCoord); Camera.main.transform.LookAt(cullArea.transform.position); } EditorGUILayout.LabelField("Current main camera position is " + Camera.main.transform.position.ToString()); } EditorGUILayout.EndVertical(); } #endregion if (EditorGUI.EndChangeCheck()) { cullArea.RecreateCellHierarchy = true; AlignEditorView(); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); showHelpEntries = EditorGUILayout.Foldout(showHelpEntries, "Need help with this component?"); if (showHelpEntries) { EditorGUILayout.HelpBox("To find help you can either follow the tutorial or have a look at the forums by clicking on the buttons below.", MessageType.Info); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Open the tutorial")) { Application.OpenURL("https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/package-demos/culling-demo"); } if (GUILayout.Button("Take me to the forums")) { Application.OpenURL("https://forum.photonengine.com/categories/unity-networking-plugin-pun"); } EditorGUILayout.EndHorizontal(); } }
/// <summary> /// Represents the inspector GUI when edit mode is active. /// </summary> private void OnInspectorGUIEditMode() { EditorGUI.BeginChangeCheck(); #region DEFINE_UP_AXIS { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Select game type", EditorStyles.boldLabel); upAxisOptions = (UP_AXIS_OPTIONS)EditorGUILayout.EnumPopup("Game type", upAxisOptions); cullArea.YIsUpAxis = (upAxisOptions == UP_AXIS_OPTIONS.SideScrollerMode); EditorGUILayout.EndVertical(); } #endregion EditorGUILayout.Space(); #region SUBDIVISION { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Set the number of subdivisions", EditorStyles.boldLabel); cullArea.NumberOfSubdivisions = EditorGUILayout.IntSlider("Number of subdivisions", cullArea.NumberOfSubdivisions, 0, CullArea.MAX_NUMBER_OF_SUBDIVISIONS); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); if (cullArea.NumberOfSubdivisions != 0) { for (int index = 0; index < cullArea.Subdivisions.Length; ++index) { if ((index + 1) <= cullArea.NumberOfSubdivisions) { string countMessage = (index + 1) + ". Subdivision: row / column count"; EditorGUILayout.BeginVertical(); cullArea.Subdivisions[index] = EditorGUILayout.Vector2Field(countMessage, cullArea.Subdivisions[index]); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } else { cullArea.Subdivisions[index] = new UnityEngine.Vector2(1, 1); } } } } #endregion EditorGUILayout.Space(); #region UPDATING_MAIN_CAMERA { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("View and camera options", EditorStyles.boldLabel); alignEditorCamera = EditorGUILayout.Toggle("Automatically align editor view with grid", alignEditorCamera); if (Camera.main != null) { if (GUILayout.Button("Align main camera with grid")) { Undo.RecordObject(Camera.main.transform, "Align main camera with grid."); float yCoord = cullArea.YIsUpAxis ? cullArea.Center.y : Mathf.Max(cullArea.Size.x, cullArea.Size.y); float zCoord = cullArea.YIsUpAxis ? -Mathf.Max(cullArea.Size.x, cullArea.Size.y) : cullArea.Center.y; Camera.main.transform.position = new Vector3(cullArea.Center.x, yCoord, zCoord); Camera.main.transform.LookAt(cullArea.transform.position); } EditorGUILayout.LabelField("Current main camera position is " + Camera.main.transform.position.ToString()); } EditorGUILayout.EndVertical(); } #endregion if (EditorGUI.EndChangeCheck()) { cullArea.RecreateCellHierarchy = true; AlignEditorView(); } }