void MigrateBaseProperties(ShapeObject3D oldShape, ShapeObject3D newShape)
        {
            // Shape settings
            newShape.UserDataString = (string)oldShape.GetType().GetProperty("UserDataString").GetValue(oldShape, null);
            newShape.ExportShape    = (bool)oldShape.GetType().GetProperty("ExportShape").GetValue(oldShape, null);
            newShape.Visible        = (bool)oldShape.GetType().GetProperty("Visible").GetValue(oldShape, null);
            newShape.TextLabel      = (string)oldShape.GetType().GetProperty("TextLabel").GetValue(oldShape, null);
            newShape.ObjectKey      = (string)oldShape.GetType().GetProperty("ObjectKey").GetValue(oldShape, null);
            newShape.LocalID        = oldShape.LocalID; // preserve the ID as sound instances might be identified by this in customer plugins [#5893]

            // Components
            if (oldShape.ComponentCount > 0)
            {
                foreach (ShapeComponent comp in oldShape.Components)
                {
                    if (comp.Missing)
                    {
                        continue;
                    }
                    newShape.AddComponentInternal((ShapeComponent)comp.Clone());
                }
            }

            // Transformation
            newShape.Position    = (Vector3F)oldShape.GetType().GetProperty("Position").GetValue(oldShape, null);
            newShape.Orientation = (Vector3F)oldShape.GetType().GetProperty("Orientation").GetValue(oldShape, null);
            newShape.Scaling     = (Vector3F)oldShape.GetType().GetProperty("Scaling").GetValue(oldShape, null);
        }
        void MigrateSoundCollisionShapeProperties(ShapeObject3D oldShape, FmodCollisionMeshShape newShape)
        {
            MigrateBaseProperties(oldShape, newShape);

            // Sound-Collision specific
            newShape.MeshFilename    = (string)oldShape.GetType().GetProperty("ModelFilename").GetValue(oldShape, null);
            newShape.DirectOcclusion = (float)oldShape.GetType().GetProperty("DirectOcclusion").GetValue(oldShape, null);
            newShape.ReverbOcclusion = (float)oldShape.GetType().GetProperty("ReverbOcclusion").GetValue(oldShape, null);
        }
        void MigrateSoundShapeProperties(ShapeObject3D oldShape, FmodSoundShape newShape)
        {
            MigrateBaseProperties(oldShape, newShape);

            // Sound specific
            newShape.Filename  = (string)oldShape.GetType().GetProperty("Filename").GetValue(oldShape, null);
            newShape.Is3D      = (bool)oldShape.GetType().GetProperty("Is3D").GetValue(oldShape, null);
            newShape.Streaming = (bool)oldShape.GetType().GetProperty("Streaming").GetValue(oldShape, null);
            newShape.Looped    = (bool)oldShape.GetType().GetProperty("Looped").GetValue(oldShape, null);
            {
                PropertyInfo propInfo = oldShape.GetType().GetProperty("StartPaused");
                if (propInfo != null)
                {
                    newShape.StartPaused = (bool)propInfo.GetValue(oldShape, null);
                }
            }
            {
                PropertyInfo propInfo = oldShape.GetType().GetProperty("DisposeWhenFinished");
                if (propInfo != null)
                {
                    newShape.DisposeWhenFinished = (bool)propInfo.GetValue(oldShape, null);
                }
            }
            newShape.Volume      = (float)oldShape.GetType().GetProperty("Volume").GetValue(oldShape, null);
            newShape.MinDistance = (float)oldShape.GetType().GetProperty("MinDistance").GetValue(oldShape, null);
            newShape.MaxDistance = (float)oldShape.GetType().GetProperty("MaxDistance").GetValue(oldShape, null);
            newShape.Pan         = (float)oldShape.GetType().GetProperty("Pan").GetValue(oldShape, null);
            newShape.Priority    = (int)oldShape.GetType().GetProperty("Priority").GetValue(oldShape, null);
            newShape.Directional = (bool)oldShape.GetType().GetProperty("Directional").GetValue(oldShape, null);
            newShape.ConeInside  = (float)oldShape.GetType().GetProperty("ConeInside").GetValue(oldShape, null);
            newShape.ConeOutside = (float)oldShape.GetType().GetProperty("ConeOutside").GetValue(oldShape, null);
            {
                PropertyInfo propInfo = oldShape.GetType().GetProperty("BackgroundMusic");
                if (propInfo != null)
                {
                    newShape.BackgroundMusic = (bool)propInfo.GetValue(oldShape, null);
                }
            }
        }
 public MigrateSoundLinksAction(ShapeObject3D oldShape, FmodSoundShape newShape)
 {
     _oldShape = oldShape;
     _newShape = newShape;
 }
 public MigrateChildrenAction(ShapeObject3D oldShape, ShapeObject3D newShape)
 {
     _oldShape = oldShape;
     _newShape = newShape;
 }
        void MigrateSoundShapeProperties(ShapeObject3D oldShape, FmodSoundShape newShape)
        {
            MigrateBaseProperties(oldShape, newShape);

              // Sound specific
              newShape.Filename = (string)oldShape.GetType().GetProperty("Filename").GetValue(oldShape, null);
              newShape.Is3D = (bool)oldShape.GetType().GetProperty("Is3D").GetValue(oldShape, null);
              newShape.Streaming = (bool)oldShape.GetType().GetProperty("Streaming").GetValue(oldShape, null);
              newShape.Looped = (bool)oldShape.GetType().GetProperty("Looped").GetValue(oldShape, null);
              {
            PropertyInfo propInfo = oldShape.GetType().GetProperty("StartPaused");
            if (propInfo != null)
              newShape.StartPaused = (bool)propInfo.GetValue(oldShape, null);
              }
              {
            PropertyInfo propInfo = oldShape.GetType().GetProperty("DisposeWhenFinished");
            if (propInfo != null)
              newShape.DisposeWhenFinished = (bool)propInfo.GetValue(oldShape, null);
              }
              newShape.Volume = (float)oldShape.GetType().GetProperty("Volume").GetValue(oldShape, null);
              newShape.MinDistance = (float)oldShape.GetType().GetProperty("MinDistance").GetValue(oldShape, null);
              newShape.MaxDistance = (float)oldShape.GetType().GetProperty("MaxDistance").GetValue(oldShape, null);
              newShape.Pan = (float)oldShape.GetType().GetProperty("Pan").GetValue(oldShape, null);
              newShape.Priority = (int)oldShape.GetType().GetProperty("Priority").GetValue(oldShape, null);
              newShape.Directional = (bool)oldShape.GetType().GetProperty("Directional").GetValue(oldShape, null);
              newShape.ConeInside = (float)oldShape.GetType().GetProperty("ConeInside").GetValue(oldShape, null);
              newShape.ConeOutside = (float)oldShape.GetType().GetProperty("ConeOutside").GetValue(oldShape, null);
              {
            PropertyInfo propInfo = oldShape.GetType().GetProperty("BackgroundMusic");
            if (propInfo != null)
              newShape.BackgroundMusic = (bool)propInfo.GetValue(oldShape, null);
              }
        }
        void MigrateSoundCollisionShapeProperties(ShapeObject3D oldShape, FmodCollisionMeshShape newShape)
        {
            MigrateBaseProperties(oldShape, newShape);

              // Sound-Collision specific
              newShape.MeshFilename = (string)oldShape.GetType().GetProperty("ModelFilename").GetValue(oldShape, null);
              newShape.DirectOcclusion = (float)oldShape.GetType().GetProperty("DirectOcclusion").GetValue(oldShape, null);
              newShape.ReverbOcclusion = (float)oldShape.GetType().GetProperty("ReverbOcclusion").GetValue(oldShape, null);
        }
        void MigrateBaseProperties(ShapeObject3D oldShape, ShapeObject3D newShape)
        {
            // Shape settings
              newShape.UserDataString = (string)oldShape.GetType().GetProperty("UserDataString").GetValue(oldShape, null);
              newShape.ExportShape = (bool)oldShape.GetType().GetProperty("ExportShape").GetValue(oldShape, null);
              newShape.Visible = (bool)oldShape.GetType().GetProperty("Visible").GetValue(oldShape, null);
              newShape.TextLabel = (string)oldShape.GetType().GetProperty("TextLabel").GetValue(oldShape, null);
              newShape.ObjectKey = (string)oldShape.GetType().GetProperty("ObjectKey").GetValue(oldShape, null);
              newShape.LocalID = oldShape.LocalID; // preserve the ID as sound instances might be identified by this in customer plugins [#5893]

              // Components
              if (oldShape.ComponentCount > 0)
              {
            foreach (ShapeComponent comp in oldShape.Components)
            {
              if (comp.Missing)
            continue;
              newShape.AddComponentInternal((ShapeComponent)comp.Clone());
            }
              }

              // Transformation
              newShape.Position = (Vector3F)oldShape.GetType().GetProperty("Position").GetValue(oldShape, null);
              newShape.Orientation = (Vector3F)oldShape.GetType().GetProperty("Orientation").GetValue(oldShape, null);
              newShape.Scaling = (Vector3F)oldShape.GetType().GetProperty("Scaling").GetValue(oldShape, null);
        }
        /// <summary>
        /// This function converts all shapes from the old SoundPlugin to the corresponding shapes of the new FmodPlugin
        /// </summary>
        void MigrateToFmodShapes()
        {
            // If old Sound plugin is not loaded, don't do anything
            IEditorPluginModule soundPlugin = EditorManager.GetPluginByName("SoundEditorPlugin.EditorPlugin");

            if (soundPlugin == null || !soundPlugin.Initialized)
            {
                return;
            }

            // collect all sound specific shapes
            ShapeCollection soundShapes = new ShapeCollection();

            foreach (Layer layer in EditorManager.Scene.Layers)
            {
                if (layer.Modifiable && layer.Loaded)
                {
                    AddSoundShapesRecursive(soundShapes, layer.Root);
                }
            }

            if (soundShapes.Count == 0)
            {
                return;
            }

            // prompt a dialog
            DialogResult res = EditorManager.ShowMessageBox("Shapes from old Sound Plugin have been found in loaded layers.\n\nShould these be permanently converted to the corresponding shapes of the Fmod Plugin?", "Old Sound Plugin and Fmod Plugin are both loaded", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res != DialogResult.Yes)
            {
                return;
            }

            ShapeCollection newShapes       = new ShapeCollection();
            int             iConvertedCount = 0;

            if (soundShapes.Count > 0)
            {
                GroupAction actions = new GroupAction("Migrate Sound shapes");
                foreach (ShapeObject3D oldShape in soundShapes)
                {
                    ShapeObject3D newShape = null;
                    if (oldShape.GetType().FullName == "SoundEditorPlugin.SoundShape")
                    {
                        newShape = new FmodSoundShape(oldShape.ShapeName);
                        MigrateSoundShapeProperties(oldShape, (FmodSoundShape)newShape);

                        actions.Add(AddShapeAction.CreateAddShapeAction(newShape, oldShape.Parent, oldShape.ParentLayer, false));

                        actions.Add(new MigrateSoundLinksAction(oldShape, (FmodSoundShape)newShape));
                        actions.Add(new MigrateChildrenAction(oldShape, newShape));
                        actions.Add(RemoveShapeAction.CreateRemoveShapeAction(oldShape));
                        newShapes.Add(newShape);
                    }
                    else if (oldShape.GetType().FullName == "SoundEditorPlugin.SoundCollisionShape")
                    {
                        newShape = new FmodCollisionMeshShape(oldShape.ShapeName);
                        MigrateSoundCollisionShapeProperties(oldShape, (FmodCollisionMeshShape)newShape);

                        actions.Add(AddShapeAction.CreateAddShapeAction(newShape, oldShape.Parent, oldShape.ParentLayer, false));
                        actions.Add(new MigrateChildrenAction(oldShape, newShape));
                        actions.Add(RemoveShapeAction.CreateRemoveShapeAction(oldShape));
                        newShapes.Add(newShape);
                    }
                    if (newShape == null)
                    {
                        continue;
                    }

                    iConvertedCount++;
                }

                // EditorManager.Actions.Add() is not used, in order to prevent a undo of the conversion
                actions.Do();
            }

            // ensure, that all migrated childs have valid engine instances
            foreach (ShapeBase shape in newShapes)
            {
                foreach (ShapeBase child in shape.ChildCollection)
                {
                    child.ReCreateEngineInstance(true);
                }
            }

            EditorManager.ShowMessageBox(iConvertedCount.ToString() + " Shape(s) have been successfully converted.", "Sound to Fmod shapes conversion", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 public MigrateChildrenAction(ShapeObject3D oldShape, ShapeObject3D newShape)
 {
     _oldShape = oldShape;
     _newShape = newShape;
 }
 public MigrateSoundLinksAction(ShapeObject3D oldShape, FmodSoundShape newShape)
 {
     _oldShape = oldShape;
     _newShape = newShape;
 }