Esempio n. 1
0
        static List <GameObject> __rootGameObjects = new List <GameObject>(); // static to avoid allocations
        internal static ChiselModel CreateDefaultModel(ChiselSceneHierarchy sceneHierarchy)
        {
            var currentScene = sceneHierarchy.Scene;

            currentScene.GetRootGameObjects(__rootGameObjects);
            for (int i = 0; i < __rootGameObjects.Count; i++)
            {
                if (!IsDefaultModel(__rootGameObjects[i]))
                {
                    continue;
                }

                var gameObject = __rootGameObjects[i];
                var model      = gameObject.GetComponent <ChiselModel>();
                if (model)
                {
                    return(model);
                }

                var transform = gameObject.GetComponent <Transform>();
                transform.localPosition = Vector3.zero;
                transform.localRotation = Quaternion.identity;
                transform.localScale    = Vector3.one;

                model = gameObject.AddComponent <ChiselModel>();
                UpdateModelFlags(model);
                return(model);
            }


            var oldActiveScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();

            if (currentScene != oldActiveScene)
            {
                UnityEngine.SceneManagement.SceneManager.SetActiveScene(currentScene);
            }

            try
            {
                var model = ChiselComponentFactory.Create <ChiselModel>(GeneratedDefaultModelName);
                UpdateModelFlags(model);
                return(model);
            }
            finally
            {
                if (currentScene != oldActiveScene)
                {
                    UnityEngine.SceneManagement.SceneManager.SetActiveScene(oldActiveScene);
                }
            }
        }
        static List <GameObject> __rootGameObjects = new List <GameObject>(); // static to avoid allocations
        internal static ChiselModel CreateDefaultModel(ChiselSceneHierarchy sceneHierarchy)
        {
            var currentScene = sceneHierarchy.Scene;

            currentScene.GetRootGameObjects(__rootGameObjects);
            for (int i = 0; i < __rootGameObjects.Count; i++)
            {
                if (!IsDefaultModel(__rootGameObjects[i]))
                {
                    continue;
                }

                var gameObject = __rootGameObjects[i];
                var model      = gameObject.GetComponent <ChiselModel>();
                if (model)
                {
                    return(model);
                }

                var transform = gameObject.GetComponent <Transform>();
                ChiselObjectUtility.ResetTransform(transform);

                model = gameObject.AddComponent <ChiselModel>();
                UpdateModelFlags(model);
                return(model);
            }


            var oldActiveScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();

            if (currentScene != oldActiveScene)
            {
                UnityEngine.SceneManagement.SceneManager.SetActiveScene(currentScene);
            }

            try
            {
                var model = ChiselComponentFactory.Create <ChiselModel>(kGeneratedDefaultModelName);
                model.IsDefaultModel = true;
                UpdateModelFlags(model);
                return(model);
            }
            finally
            {
                if (currentScene != oldActiveScene)
                {
                    UnityEngine.SceneManagement.SceneManager.SetActiveScene(oldActiveScene);
                }
            }
        }