/// <summary> /// Unregister a rigidbody in the scene. /// </summary> /// <param name="r">The rigidbody.</param> internal void UnregisterRigidBody(GameElement r) { if (r.HasComponent <RigidBody>()) { RigidBody rb = r.GetComponent <RigidBody>(); _space.Remove(rb.InnerRigidBody); } }
private void _renderSelectedElementBoundingBox() { var selectedElement = SceneEditorScene.SelectedElement; var transform = selectedElement.WorldTransform.Transformation; var boundingBox = ((SceneEditorScene)ParentScene).BoundingBoxes[selectedElement]; var meshRenderer = _aabbGameElement.GetComponent <MeshRenderer>(); meshRenderer.MeshFilter = MeshFactory.CreateCube(Vector3f.TransformPosition(boundingBox.Min, transform), Vector3f.TransformPosition(boundingBox.Max, transform)); meshRenderer.MeshFilter.Mesh.VAO.DrawMode = BeginMode.Lines; meshRenderer.Render(); }
/// <summary> /// Adds a <see cref="GameElement"/> in the scene. /// </summary> /// <param name="gameElement">The <see cref="GameElement"/> to add.</param> public void AddGameElement(GameElement gameElement) { gameElement.SetParentScene(this); _gameElements.Add(gameElement); if (gameElement.HasComponent <Light>()) { _lights.Add(gameElement); } if (gameElement.HasComponent <Camera>()) { Camera cm = gameElement.GetComponent <Camera>(); _cameras.Add(gameElement); if (cm.IsPrimary) { _primaryCamera = gameElement; } } if (gameElement.HasComponent <AudioSource>()) { _audioSources.Add(gameElement); } if (gameElement.HasComponent <AudioReverbZone>()) { _audioReverbZones.Add(gameElement); } if (gameElement.HasComponent <AudioListener>()) { _audioListener = gameElement; } foreach (GameElement child in gameElement.Childs) { AddGameElement(child); } }
public static void AddSwitchToGameElement(Switch swt, GameElement gameElement) { SpriteRenderer spriteRenderer = gameElement.GetComponent<SpriteRenderer>(); if (spriteRenderer != null) { spriteRenderer.enabled = false; } bool alreadyAdded = false; foreach (GameElement ge in gameElement.GameElements) { if (ge == swt) { alreadyAdded = true; break; } } if (alreadyAdded) { return; } SerializedObject serializedObject = new SerializedObject(gameElement); SerializedProperty geProperty = serializedObject.FindProperty("gameElements"); geProperty.InsertArrayElementAtIndex(geProperty.arraySize); SerializedProperty element = geProperty.GetArrayElementAtIndex(geProperty.arraySize - 1); element.objectReferenceValue = swt; serializedObject.ApplyModifiedProperties(); Editor connectorEditor = ConnectorEditor.CreateEditor(gameElement); connectorEditor.OnInspectorGUI(); }
/// <summary> /// Gets and returns the instance of the <see cref="Component"/> /// of type <typeparamref name="T"/> attached to this <see cref="GameElement"/>. /// </summary> /// <typeparam name="T">The type of <see cref="Component"/> to return.</typeparam> /// <remarks> /// In the case where more than one component of the type <typeparamref name="T"/> /// are attached to this game element, the first one will be returned. /// </remarks> protected T GetComponent <T>() where T : Component { return(_gameElement != null?_gameElement.GetComponent <T>() : null); }
public override void Load() { _sceneEditorCamera = new GameElement("camera__sceneEditorElement"); _cameraControl = new SceneEditorCameraControl(); var camera = new GameElement("Main Camera"); camera.AttachComponent(new Camera() { ClearColor = Color4.White, ClearScreenType = ClearScreenTypes.Cubemap, Cubemap = ResourcesManager.LoadResource <Cubemap>(ResourceType.CubeMap, "Assets/Skybox/skyX/posx.png Assets/Skybox/skyX/negx.png Assets/Skybox/skyX/posy.png Assets/Skybox/skyX/negy.png Assets/Skybox/skyX/posz.png Assets/Skybox/skyX/negz.png"), Far = 3000, FieldOfView = 45, Forward = VectorHelper.Forward, IsPrimary = true, Near = 0.25f, ProjectionType = ProjectionTypes.Perspective, Viewport = RendererManager.Viewport }); _sceneEditorCamera.AttachComponent(camera.GetComponent <Camera>()); _sceneEditorCamera.AttachComponent(_cameraControl); var box = new GameElement("Box"); box.AttachComponents( new Material() { ColorAmbient = Color4.Crimson, ColorDiffuse = Color4.Crimson, ColorSpecular = Color4.White, HasColorAmbient = true, HasColorDiffuse = true, HasColorSpecular = true, ShaderProgram = new DiffuseShaderProgram() }, new MeshRenderer() { MeshFilter = MeshFactory.CreateCube(-Vector3f.One * 5, Vector3f.One * 5), Visible = true } ); box.LocalTransform.SetTranslation(0, 0, 50); GameElement light = new GameElement("Sun"); light.AttachComponents( new Light() { AmbientColor = new Color4(255, 244, 214, 255), DiffuseColor = new Color4(255, 244, 214, 255), // DiffuseColor = new Color4(202, 198, 162, 255), SpecularColor = Color4.White, Intensity = 1f, Type = LightType.Directional } ); GameElement plane = new GameElement("Plane"); plane.AttachComponents( new MeshRenderer() { MeshFilter = MeshFactory.CreatePlane(Vector2f.One * -1000, Sizef.One * 2000), Visible = true }, new Material() { TextureTilling = 50, ColorAmbient = Color4.White, HasColorAmbient = true, ColorDiffuse = Color4.White, HasColorDiffuse = true, ShaderProgram = new DiffuseShaderProgram() } ); plane.LocalTransform.SetTranslation(VectorHelper.Down * 20); AddGameElement(light); AddGameElement(plane); AddGameElement(box); AddGameElement(_sceneEditorCamera); AddRenderScript(new GizmoDrawer()); base.Load(); }