Beispiel #1
0
        } // AddGameObjectControlsToInspector

        /// <summary>
        /// Add game object component controls to the specified control.
        /// </summary>
        public static void AddGameObjectControls(GameObject gameObject, ClipControl control)
        {
            if (gameObject == null)
            {
                throw new ArgumentNullException("gameObject");
            }
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            #region Name

            var nameLabel = new Label
            {
                Parent    = control,
                Text      = "Name",
                Left      = 10,
                Top       = 10,
                Height    = 25,
                Alignment = Alignment.BottomCenter,
            };
            var nameTextBox = new TextBox
            {
                Parent = control,
                Width  = control.ClientWidth - nameLabel.Width - 12,
                Text   = gameObject.Name,
                Left   = 60,
                Top    = 10,
                Anchor = Anchors.Left | Anchors.Top | Anchors.Right
            };
            var lastSetName = gameObject.Name;
            nameTextBox.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.Key == Keys.Enter)
                {
                    string oldName = gameObject.Name;
                    gameObject.Name = nameTextBox.Text; //asset.SetUniqueName(window.AssetName);
                    if (oldName != gameObject.Name)
                    {
                        nameTextBox.Text = gameObject.Name; // The name could be change if the name entered was not unique.
                        gameObject.Name  = oldName;         // This is done for the undo.
                        using (Transaction.Create())
                        {
                            // Apply the command and store for the undo feature.
                            ActionManager.SetProperty(gameObject, "Name", nameTextBox.Text);
                            ActionManager.CallMethod(// Redo
                                UserInterfaceManager.Invalidate,
                                // Undo
                                UserInterfaceManager.Invalidate);
                        }
                    }
                    lastSetName = gameObject.Name;
                }
            };
            nameTextBox.FocusLost += delegate
            {
                string oldName = gameObject.Name;
                gameObject.Name = nameTextBox.Text; //asset.SetUniqueName(window.AssetName);
                if (oldName != gameObject.Name)
                {
                    nameTextBox.Text = gameObject.Name; // The name could be change if the name entered was not unique.
                    gameObject.Name  = oldName;         // This is done for the undo.
                    using (Transaction.Create())
                    {
                        // Apply the command and store for the undo feature.
                        ActionManager.SetProperty(gameObject, "Name", nameTextBox.Text);
                        ActionManager.CallMethod(// Redo
                            UserInterfaceManager.Invalidate,
                            // Undo
                            UserInterfaceManager.Invalidate);
                    }
                    lastSetName = gameObject.Name;
                }
            };
            nameTextBox.Draw += delegate
            {
                if (lastSetName != gameObject.Name)
                {
                    lastSetName      = gameObject.Name;
                    nameTextBox.Text = gameObject.Name;
                }
            };

            #endregion

            #region Layer

            var comboBoxLayer = CommonControls.ComboBox("", control);
            comboBoxLayer.MaxItemsShow      = 30;
            comboBoxLayer.ItemIndexChanged += delegate
            {
                // Store new asset.
                if (gameObject.Layer.Number != comboBoxLayer.ItemIndex) // If it change
                {
                    using (Transaction.Create())
                    {
                        // Apply the command and store for the undo feature.
                        ActionManager.SetProperty(gameObject, "Layer", Layer.GetLayerByNumber(comboBoxLayer.ItemIndex));
                        ActionManager.CallMethod(// Redo
                            UserInterfaceManager.Invalidate,
                            // Undo
                            UserInterfaceManager.Invalidate);
                    }
                }
            };
            comboBoxLayer.Draw += delegate
            {
                // Add layer names here because someone could change them.
                comboBoxLayer.Items.Clear();
                for (int i = 0; i < 30; i++)
                {
                    comboBoxLayer.Items.Add(Layer.GetLayerByNumber(i).Name);
                }
                if (comboBoxLayer.ListBoxVisible)
                {
                    return;
                }
                // Identify current index
                comboBoxLayer.ItemIndex = gameObject.Layer.Number;
            };

            #endregion )

            #region Active

            CheckBox active = CommonControls.CheckBox("Active", control, gameObject.Active, gameObject, "Active");
            active.Top = comboBoxLayer.Top + 5;

            #endregion

            if (gameObject is GameObject3D)
            {
                GameObject3D gameObject3D = (GameObject3D)gameObject;

                #region Transform Component

                var panel = CommonControls.PanelCollapsible("Transform", control, 0);
                // Position
                var vector3BoxPosition = CommonControls.Vector3Box("Position", panel, gameObject3D.Transform.LocalPosition, gameObject3D.Transform, "LocalPosition");

                // Orientation.
                // This control has too many special cases, I need to do it manually.
                Vector3 initialValue = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI,
                                                   gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI,
                                                   gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI);
                initialValue.X = (float)Math.Round(initialValue.X, 4);
                initialValue.Y = (float)Math.Round(initialValue.Y, 4);
                initialValue.Z = (float)Math.Round(initialValue.Z, 4);
                var vector3BoxRotation = CommonControls.Vector3Box("Rotation", panel, initialValue);
                vector3BoxRotation.ValueChanged += delegate
                {
                    Vector3 propertyValue = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI,
                                                        gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI,
                                                        gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI);
                    // Round to avoid precision problems.
                    propertyValue.X = (float)Math.Round(propertyValue.X, 4);
                    propertyValue.Y = (float)Math.Round(propertyValue.Y, 4);
                    propertyValue.Z = (float)Math.Round(propertyValue.Z, 4);
                    // I compare the value of the transform property rounded to avoid a precision mismatch.
                    if (propertyValue != vector3BoxRotation.Value)
                    {
                        using (Transaction.Create())
                        {
                            Quaternion newValue = Quaternion.CreateFromYawPitchRoll(vector3BoxRotation.Value.Y * (float)Math.PI / 180,
                                                                                    vector3BoxRotation.Value.X * (float)Math.PI / 180,
                                                                                    vector3BoxRotation.Value.Z * (float)Math.PI / 180);
                            ActionManager.SetProperty(gameObject3D.Transform, "LocalRotation", newValue);
                            ActionManager.CallMethod(// Redo
                                UserInterfaceManager.Invalidate,
                                // Undo
                                UserInterfaceManager.Invalidate);
                        }
                    }
                };
                vector3BoxRotation.Draw += delegate
                {
                    Vector3 localRotationDegrees = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI,
                                                               gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI,
                                                               gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI);
                    // Round to avoid precision problems.
                    localRotationDegrees.X = (float)Math.Round(localRotationDegrees.X, 4);
                    localRotationDegrees.Y = (float)Math.Round(localRotationDegrees.Y, 4);
                    localRotationDegrees.Z = (float)Math.Round(localRotationDegrees.Z, 4);
                    if (vector3BoxRotation.Value != localRotationDegrees)
                    {
                        vector3BoxRotation.Value = localRotationDegrees;
                    }
                };

                // Scale
                var vector3BoxScale = CommonControls.Vector3Box("Scale", panel, gameObject3D.Transform.LocalScale, gameObject3D.Transform, "LocalScale");

                #endregion

                #region Camera

                if (gameObject3D.Camera != null)
                {
                    var panelCamera = CommonControls.PanelCollapsible("Camera", control, 0);
                    CameraControls.AddControls(gameObject3D.Camera, panelCamera);
                }

                #endregion

                #region Model Filter

                if (gameObject3D.ModelFilter != null)
                {
                    var panelModelFilter = CommonControls.PanelCollapsible("Model Filter", control, 0);
                    ModelFilterControls.AddControls(gameObject3D.ModelFilter, panelModelFilter);
                }

                #endregion

                #region Model Renderer

                if (gameObject3D.ModelRenderer != null)
                {
                    var panelModelRenderer = CommonControls.PanelCollapsible("Model Renderer", control, 0);
                    ModelRendererControls.AddControls(gameObject3D.ModelRenderer, panelModelRenderer);
                }

                #endregion

                #region Light

                if (gameObject3D.Light != null)
                {
                    if (gameObject3D.SpotLight != null)
                    {
                        var panelSpotLight = CommonControls.PanelCollapsible("Spot Light", control, 0);
                        SpotLightControls.AddControls(gameObject3D.SpotLight, panelSpotLight);
                    }
                    if (gameObject3D.PointLight != null)
                    {
                        var panelPointLight = CommonControls.PanelCollapsible("Point Light", control, 0);
                        PointLightControls.AddControls(gameObject3D.PointLight, panelPointLight);
                    }
                    if (gameObject3D.DirectionalLight != null)
                    {
                        var panelDirectionalLight = CommonControls.PanelCollapsible("Directional Light", control, 0);
                        DirectionalLightControls.AddControls(gameObject3D.DirectionalLight, panelDirectionalLight);
                    }
                }

                #endregion
            }
            else
            {
                GameObject2D gameObject2D = (GameObject2D)gameObject;
            }
        } // AddGameObjectControls