Exemple #1
0
            public void SwapAssets(GameObject gameObject)
            {
                using (var editScope = new EP.EditGameObject(gameObject)) {
                    var editObject = editScope.editObject;

                    foreach (var child in editObject.Children())
                    {
                        if (PrefabUtility.GetPrefabAssetType(child) == PrefabAssetType.NotAPrefab)
                        {
                            SwapAssets(child);
                        }
                    }

                    var renderer = editObject.GetComponent <MeshRenderer>();
                    if (renderer)
                    {
                        materialGatherer.SwapMaterials(renderer);
                        foreach (var material in renderer.sharedMaterials)
                        {
                            if (swapMaterials.Contains(material.name))
                            {
                                continue;
                            }
                            swapMaterials.Add(material.name);
                            textureGatherer.SwapTextures(material);
                        }
                    }

                    var meshFilter = editObject.GetComponent <MeshFilter>();
                    if (meshFilter)
                    {
                        meshGatherer.SwapMeshes(meshFilter);
                    }
                }
            }
Exemple #2
0
        // FIXME: Stop recursion at prefabs - those will be handled separately

        private static void recurseAddColliders(GameObject gameObject, bool hasPhysics)
        {
            using (var editScope = new EP.EditGameObject(gameObject)) {
                var editObject = editScope.editObject;
                hasPhysics |= editObject.GetComponent <Rigidbody>() != null;
                var group = editObject.GetComponent <LODGroup>();
                if (group)
                {
                    // Recurse at lowest LoD Renderers
                    var foundLOD = group.GetLODs();
                    if (foundLOD.Length > 0)
                    {
                        foreach (var renderer in foundLOD[foundLOD.Length - 1].renderers)
                        {
                            if (renderer.transform == editObject.transform)
                            {
                                AddCollider(editObject, hasPhysics);
                            }
                            else if (renderer.transform.IsChildOf(editObject.transform))
                            {
                                recurseAddColliders(renderer.gameObject, hasPhysics);
                            }
                        }
                    }
                    return;
                }

                // Recurse over all children
                AddCollider(editObject, hasPhysics);
                foreach (var child in editObject.Children())
                {
                    recurseAddColliders(child, hasPhysics);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Configure all child MeshRenderers of GameObject for direct lighting
 /// </summary>
 public static void ApplyTo(GameObject gameObject)
 {
     using (var editScope = new EP.EditGameObject(gameObject)) {
         var editObject       = editScope.editObject;
         var meshRendererList = new List <MeshRenderer>(editObject.GetComponentsInChildren <MeshRenderer>());
         foreach (var meshRenderer in meshRendererList)
         {
             ConvertToLightDirect(meshRenderer);
         }
     }
 }
Exemple #4
0
 public static void ApplyTo(GameObject gameObject, string searchRoot = null)
 {
     if (searchRoot == null)
     {
         searchRoot = AssetDatabase.GetAssetOrScenePath(gameObject);
         searchRoot = searchRoot.Substring(0, searchRoot.LastIndexOf('/'));
     }
     using (var editScope = new EP.EditGameObject(gameObject)) {
         var editObject = editScope.editObject;
         ReplacePlaceholders(searchRoot, editObject);
     }
 }
Exemple #5
0
        public static void ApplyTo(GameObject gameObject)
        {
            using (var editScope = new EP.EditGameObject(gameObject)) {
                var editObject = editScope.editObject;
                // Gather all MeshRenderer components that are leaf nodes
                // NOTE: Prefab components will be managed by applying AutoLOD to the prefab
                var children = editObject.Children(true);
                var groups   = new Dictionary <PathName, List <GameObject> >();
                foreach (var child in children)
                {
                    // Only gather leaf node renderers
                    if (child.transform.childCount > 0)
                    {
                        continue;
                    }
                    // AutoLOD will be applied to child prefabs separately
                    var childPrefab = PrefabUtility.GetNearestPrefabInstanceRoot(child);
                    if (childPrefab != null && childPrefab != editObject)
                    {
                        continue;
                    }
                    var hasRenderer = child.GetComponent <Renderer>();
                    if (!hasRenderer)
                    {
                        continue;
                    }
                    // MeshRenderers will be managed by LODGroup
                    var inGroup = child.GetComponentInParent <LODGroup>();
                    if (inGroup)
                    {
                        continue;
                    }
                    // Add renderer to group
                    var path = new PathName(child);
                    if (!groups.ContainsKey(path))
                    {
                        groups.Add(path, new List <GameObject>());
                    }
                    groups[path].Add(child);
                }

                // Combine group renderers under LODGroup managers
                foreach (var pathGroup in groups)
                {
                    MergeGroup(pathGroup.Key, pathGroup.Value);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Recursively configure all objects and components in hierarchy to be static
        /// </summary>
        /// <param name="gameObject">Root of hierarchy to be converted to static configuration</param>
        /// <param name="prefabs">Apply static conversion overrides to prefabs in hierarchy</param>
        public static void ApplyTo(GameObject gameObject, bool prefabs = false)
        {
            using (var editScope = new EP.EditGameObject(gameObject)) {
                var editObject = editScope.editObject;

                // Set static configurations
                GameObjectSetStatic(editObject);
                foreach (var renderer in editObject.GetComponents <Renderer>())
                {
                    RendererSetStatic(renderer);
                }
                foreach (var collider in editObject.GetComponents <Collider>())
                {
                    ColliderSetStatic(collider);
                }
                foreach (var light in editObject.GetComponents <Light>())
                {
                    LightSetStatic(light);
                }

                // Remove dynamic components
                foreach (var monoBehavior in editObject.GetComponents <MonoBehaviour>())
                {
                    EP.Destroy(monoBehavior);
                }
                foreach (var physics in editObject.GetComponents <Rigidbody>())
                {
                    EP.Destroy(physics);
                }

                foreach (var child in editObject.Children())
                {
                    // Limit prefab recursion
                    var prefabAssetType = PrefabUtility.GetPrefabAssetType(child);
                    if (prefabAssetType == PrefabAssetType.MissingAsset)
                    {
                        continue;
                    }
                    if (prefabAssetType != PrefabAssetType.NotAPrefab && !prefabs)
                    {
                        continue;
                    }

                    ApplyTo(child);
                }
            }
        }
Exemple #7
0
        public static void ApplyTo(GameObject mergeTarget, params GameObject[] mergeSources)
        {
            using (var editScope = new EP.EditGameObject(mergeTarget)) {
                var targetEdit = editScope.editObject;
                foreach (var mergeSource in mergeSources)
                {
                    var sourceCopy = EP.Instantiate(mergeSource);

                    // Unpack only root model prefab, constituent prefab links will be retained
                    // NOTE: Applying UnpackPrefabInstance to a non-prefab object results in a crash
                    if (PrefabUtility.GetPrefabAssetType(sourceCopy) != PrefabAssetType.NotAPrefab)
                    {
                        PrefabUtility.UnpackPrefabInstance(sourceCopy, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);
                    }
                    Merge(sourceCopy.transform, targetEdit.transform);

                    EP.Destroy(sourceCopy);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Configure all child MeshRenderers of GameObject according to level of detail
        /// </summary>
        /// <remarks>
        /// Remderers that are managed by a LODGroup will be configured according to their level.
        /// Renderers that are independent will be configured according their static flags.
        /// </remarks>
        public static void ApplyTo(GameObject gameObject)
        {
            using (var editScope = new EP.EditGameObject(gameObject)) {
                var editObject = editScope.editObject;

                var rendererList = new List <Renderer>(editObject.GetComponentsInChildren <Renderer>());
                var lodGroupList = editObject.GetComponentsInChildren <LODGroup>();
                foreach (var lodGroup in lodGroupList)
                {
                    ConfigureLODGroup(lodGroup);

                    foreach (var lod in lodGroup.GetLODs())
                    {
                        foreach (var renderer in lod.renderers)
                        {
                            rendererList.Remove(renderer);
                        }
                    }
                }
                foreach (var renderer in rendererList)
                {
                    var meshRenderer = renderer as MeshRenderer;
                    if (!meshRenderer)
                    {
                        continue;
                    }

                    var staticFlags = GameObjectUtility.GetStaticEditorFlags(meshRenderer.gameObject);
                    if (staticFlags.HasFlag(StaticEditorFlags.ContributeGI))
                    {
                        ConvertToLightCharts(meshRenderer);
                    }
                    else
                    {
                        ConvertToLightProbes(meshRenderer);
                    }
                }
            }
        }