Exemplo n.º 1
0
        private static object DefaultV4(string name, object obj)
        {
            Vector4 value = (Vector4)obj;

            ImGuiExtension.DragVector4(name, ref value, Vector4.Zero);
            return(value);
        }
Exemplo n.º 2
0
        //serialize transform component
        public static void Transform(Transform transform)
        {
            ImGui.PushID("PositionV3");
            ImGuiExtension.DragVector3("Position", ref transform.Position, Vector3.Zero, 0.05f);
            ImGui.PopID();

            ImGui.PushID("RotationV3");
            Vector3 euler = transform.EulerAngles;

            ImGuiExtension.DragVector3("Rotation", ref euler, Vector3.Zero, 0.5f);
            transform.EulerAngles = euler;
            ImGui.PopID();

            ImGui.PushID("ScaleV3");
            ImGuiExtension.DragVector3("Scale", ref transform.Scale, Vector3.One, 0.05f);
            ImGui.PopID();
        }
Exemplo n.º 3
0
        private void OnImGui()
        {
            if (ImGui.Begin("Inspector"))
            {
                if (SceneHierachy.SelectedEntity == null)
                {
                    ImGui.Text("No Entity selected.");
                    goto EndMenu;
                }

                ImGui.SetNextItemWidth(160f);
                ImGui.InputText("Name", ref SceneHierachy.SelectedEntity.Name, 255);

                ImGui.SameLine();

                ImGui.SetNextItemWidth(160f);
                ImGui.InputText("Tag", ref SceneHierachy.SelectedEntity.Tag, 255);

                if (ImGui.Button("Add Component"))
                {
                    ImGui.OpenPopup("comp-menu");
                }

                ImGui.SameLine();

                ImGui.Checkbox("Enabled", ref SceneHierachy.SelectedEntity.Active);

                //get all components
                Component[] components = SceneHierachy.SelectedEntity.GetComponents <Component>();

                //add component menu
                if (ImGui.BeginPopup("comp-menu"))
                {
                    foreach (var comp in SerializeableComponents)
                    {
                        if (!components.Any(x => x.GetType() == comp.Key))
                        {
                            if (ImGui.Selectable(comp.Key.Name))
                            {
                                SceneHierachy.SelectedEntity.AddComponent((Component)Activator.CreateInstance(comp.Key)); //create new component and add
                            }
                        }
                    }
                    ImGui.EndPopup();
                }

                //render transform editor
                ImGui.Separator();
                ImGui.Text("Transform");

                ImGuiExtension.DragVector3("Position", ref SceneHierachy.SelectedEntity.Transform.Position, Vector3.Zero, 0.1f);

                Vector3 euler = SceneHierachy.SelectedEntity.Transform.EulerAngles;
                ImGuiExtension.DragVector3("Rotation", ref euler, Vector3.Zero);
                SceneHierachy.SelectedEntity.Transform.EulerAngles = euler;

                ImGuiExtension.DragVector3("Scale", ref SceneHierachy.SelectedEntity.Transform.Scale, Vector3.One, 0.1f);

                ImGui.Separator();

                ImGuiExtension.DragVector3("Origin Offset", ref SceneHierachy.SelectedEntity.Transform.OriginOffset, Vector3.Zero, 0.1f);

                //serialize components in an entity
                for (int i = 0; i < components.Length; i++)
                {
                    ImGui.Separator();

                    Component component = components[i];

                    ImGui.PushID(i);
                    if (ImGui.CollapsingHeader(component.GetType().Name))
                    {
                        //get serialize function in dictionary
                        SerializeableComponents.TryGetValue(component.GetType(), out Action <Component> serializeFunc);

                        //if none was found, use the default serialize function
                        if (serializeFunc == null)
                        {
                            SerializeFunc.DefaultSerializeFunc(component);
                        }
                        else
                        {
                            serializeFunc.Invoke(component);
                        }

                        //enable/disable button
                        ImGui.Checkbox("Enabled", ref component.Enabled);

                        ImGui.SameLine();

                        //remove component button
                        ImGui.SetCursorPosX(ImGui.GetContentRegionAvail().X - 30f);
                        if (ImGui.Button("Remove Component"))
                        {
                            SceneHierachy.SelectedEntity.RemoveComponent(component);
                        }
                    }
                    ImGui.PopID();
                }

EndMenu:
                ImGui.End();
            }
        }