Exemplo n.º 1
0
        /// <summary>
        /// Utility to add SO geometry to a parent GO, which would then be passed to Create()
        /// </summary>
        public static void AppendSOGeometry(fGameObject parentGO, SceneObject so, bool bAddMeshColliders)
        {
            fGameObject copy = GameObjectFactory.Duplicate(so.RootGameObject);

            // if so is a DMeshSO, and it doesn't have a collider, add it
            if (so is DMeshSO && bAddMeshColliders)
            {
                foreach (var go in copy.Children())
                {
                    if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null)
                    {
                        go.AddComponent <MeshCollider>();
                    }
                }
            }

            parentGO.AddChild(copy, true);
        }
Exemplo n.º 2
0
        public static GOWrapperSO CombineAnySOs(SceneObject s1, SceneObject s2, bool bDeleteExisting = true)
        {
            FScene scene = s1.GetScene();

            if (scene.IsSelected(s1))
            {
                scene.Deselect(s1);
            }
            if (scene.IsSelected(s2))
            {
                scene.Deselect(s2);
            }

            fGameObject parentGO = GameObjectFactory.CreateParentGO("combined");

            fGameObject copy1 = GameObjectFactory.Duplicate(s1.RootGameObject);
            fGameObject copy2 = GameObjectFactory.Duplicate(s2.RootGameObject);


            // if inputs are DMeshSOs, they do not have colliders, which we will need...
            if (s1 is DMeshSO)
            {
                foreach (var go in copy1.Children())
                {
                    if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null)
                    {
                        go.AddComponent <MeshCollider>();
                    }
                }
            }
            if (s2 is DMeshSO)
            {
                foreach (var go in copy2.Children())
                {
                    if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null)
                    {
                        go.AddComponent <MeshCollider>();
                    }
                }
            }

            parentGO.AddChild(copy1, true);
            parentGO.AddChild(copy2, true);

            GOWrapperSO wrapperSO = new GOWrapperSO()
            {
                AllowMaterialChanges = false
            };

            wrapperSO.Create(parentGO);

            if (bDeleteExisting)
            {
                scene.RemoveSceneObject(s1, false);
                scene.RemoveSceneObject(s2, false);
            }

            scene.AddSceneObject(wrapperSO, false);

            return(wrapperSO);
        }