private static void OnAGXPrefabAdddedToScene(GameObject instance, IO.AGXFileInfo fileInfo)
        {
            if (fileInfo.ExistingPrefab == null)
            {
                Debug.LogWarning("Unable to load parent prefab from file: " + fileInfo.NameWithExtension);
                return;
            }

            Undo.SetCurrentGroupName("Adding: " + instance.name + " to scene.");
            var grouId = Undo.GetCurrentGroup();

            foreach (var cm in fileInfo.GetAssets <ContactMaterial>())
            {
                TopMenu.GetOrCreateUniqueGameObject <ContactMaterialManager>().Add(cm);
            }

            var fileData = fileInfo.ExistingPrefab.GetComponent <AGXUnity.IO.RestoredAGXFile>();

            foreach (var disabledPair in fileData.DisabledGroups)
            {
                TopMenu.GetOrCreateUniqueGameObject <CollisionGroupsManager>().SetEnablePair(disabledPair.First, disabledPair.Second, false);
            }

            var renderDatas = instance.GetComponentsInChildren <AGXUnity.Rendering.ShapeVisual>();

            foreach (var renderData in renderDatas)
            {
                renderData.hideFlags           |= HideFlags.NotEditable;
                renderData.transform.hideFlags |= HideFlags.NotEditable;
            }

            // TODO: Handle fileData.SolverSettings?

            Undo.CollapseUndoOperations(grouId);
        }
Ejemplo n.º 2
0
        public static void OnPrefabAddedToScene(GameObject instance)
        {
            var fileInfo = new IO.AGXFileInfo(instance);

            if (!fileInfo.IsValid || fileInfo.Type != IO.AGXFileInfo.FileType.AGXPrefab)
            {
                return;
            }

            if (fileInfo.ExistingPrefab == null)
            {
                Debug.LogWarning("Unable to load parent prefab from file: " + fileInfo.NameWithExtension);
                return;
            }

            Undo.SetCurrentGroupName("Adding: " + instance.name + " to scene.");
            var grouId = Undo.GetCurrentGroup();

            foreach (var cm in fileInfo.GetAssets <ContactMaterial>())
            {
                TopMenu.GetOrCreateUniqueGameObject <ContactMaterialManager>().Add(cm);
            }

            var fileData = fileInfo.ExistingPrefab.GetComponent <AGXUnity.IO.RestoredAGXFile>();

            AddDisabledPairsToManager(fileData.DisabledGroups);

            var renderDatas = instance.GetComponentsInChildren <AGXUnity.Rendering.ShapeVisual>();

            foreach (var renderData in renderDatas)
            {
                renderData.hideFlags           |= HideFlags.NotEditable;
                renderData.transform.hideFlags |= HideFlags.NotEditable;
            }

            Undo.CollapseUndoOperations(grouId);
        }