Ejemplo n.º 1
0
        public override PresentationResult OnInspectorGui(PresentationParamater parameter)
        {
            FortScene  fortScene = (FortScene)parameter.Instance;
            SceneAsset oldScene  = fortScene == null?null: AssetDatabase.LoadAssetAtPath <SceneAsset>(fortScene.SceneName);

            if (fortScene == null)
            {
                fortScene = new FortScene();
            }
            EditorGUI.BeginChangeCheck();
            Object result = EditorGUILayout.ObjectField(parameter.Title, oldScene, typeof(SceneAsset), false);

            if (EditorGUI.EndChangeCheck())
            {
                var newPath = AssetDatabase.GetAssetPath(result);
                fortScene.SceneName = newPath;
                return(new PresentationResult
                {
                    Result = fortScene,
                    Change = new Change {
                        IsDataChanged = true
                    }
                });
            }
            return(new PresentationResult
            {
                Result = fortScene,
                Change = new Change {
                    IsDataChanged = false
                }
            });
        }
        public override void OnGUI(Rect rect, string name, ref object value)
        {
            base.OnGUI(rect, name, ref value);
            EditorGUI.BeginDisabledGroup(IsReadOnly);
            EditorGUI.HandlePrefixLabel(rect, GetControlRect(), new GUIContent(name));
            try {
                var        scene = (EditorBuildSettingsScene)value;
                SceneAsset asset = null;

                if (scene != null && !string.IsNullOrEmpty(scene.path))
                {
                    asset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path);
                }

                var nAsset = EditorGUI.ObjectField(GetControlRect(), asset, typeof(SceneAsset), true);
                if (nAsset != asset)
                {
                    if (nAsset != null)
                    {
                        value = Find(AssetDatabase.GetAssetOrScenePath(nAsset));
                    }
                    else
                    {
                        value = null;
                    }
                }
            } catch (ExitGUIException) { }
            EditorGUI.EndDisabledGroup();
        }
 public TestResultViewItem(int id, int depth, string displayName, SceneAsset sceneObject)
 {
     this.id          = id;
     this.depth       = depth;
     this.displayName = displayName;
     this.sceneObject = sceneObject;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Return true if the scene belongs to the persistant scene bundle
        /// </summary>
        /// <param name="scene"></param>
        /// <returns></returns>
        public static bool IsPersistantScene(this SceneAsset scene)
        {
            if (scene == null)
            {
                return(false);
            }
            SceneBundleList currentList = EnhancedSceneManager.GetCurrentSceneList();

            if (currentList == null)
            {
                return(false);
            }
            if (currentList.PersistantScenesBundle == null)
            {
                return(false);
            }

            for (int i = 0; i < currentList.PersistantScenesBundle.ScenesCount; i++)
            {
                if (currentList.PersistantScenesBundle.ContainsScene(scene.name))
                {
                    return(true);
                }
            }

            return(false);
        }
        void RestorePreviousValues()
        {
            string serializedJson = EditorPrefs.GetString("JSON_KEY", "");

            // Debug.LogWarning(serializedJson);
            experiences = JsonUtility.FromJson <ListWrapper>(serializedJson);
            // Debug.LogWarning(experiences == null ? "NULL" : "NOT NULL");
            if (experiences != null)
            {
                // foldoutExperiences = new List<bool>(experiences.list.Count);

                // load experiences's scene assets
                for (int experienceID = 0; experienceID < experiences.list.Count; experienceID++)
                {
                    List <SceneAsset> sceneAssets = new List <SceneAsset>();
                    for (int sceneID = 0; sceneID < experiences.list[experienceID].scenePaths.Count; sceneID++)
                    {
                        SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(experiences.list[experienceID].scenePaths[sceneID]);
                        sceneAssets.Add(sceneAsset);
                    }
                    experiencesSceneAssets.Add(sceneAssets);

                    // foldoutExperiences.Add(experiences.list[experienceID].foldout);
                }
            }
            else
            {
                experiences      = new ListWrapper();
                experiences.list = new List <Experience>();
                // foldoutExperiences = new List<bool>();
            }
        }
        private void Reload(SceneAsset _sceneAsset = null)
        {
            sceneAsset = _sceneAsset;

            if (sceneAsset == null)
            {
                return;
            }

            if (templateImage != null && templateImage != Texture2D.whiteTexture)
            {
                DestroyImmediate(templateImage);
            }
            tmpPath = "";
            GetTemplateImage();

            string templatePath = Path.Combine(TestFrameworkTools.s_RootPath, "ImageTemplates");

            templateLocation = Path.Combine(templatePath, string.Format("{0}.{1}", tmpPath, "png"));

            GetDiffMaterial();

            // Search for fail image if it exists.
            GetResultImage();

            diffMaterial.SetTexture("_CompareTex", resultImage);

            ApplyValues();

            testResultTreeView.Reload();
        }
Ejemplo n.º 7
0
        private void OnGUI()
        {
            if (_scenesContainer == null)
            {
                return;
            }

            for (int i = 0; i < _scenesContainer.SceneAssets.Count; i++)
            {
                var        sceneNumber = (i + 1).ToString();
                SceneAsset newAsset    = EditorGUILayout.ObjectField(new GUIContent("Scene " + sceneNumber + " (Shift+" + (i + 1).ToString().Substring(sceneNumber.Length - 1) + ")"), _scenesContainer.SceneAssets[i], typeof(SceneAsset), false) as SceneAsset;
                if (newAsset != _scenesContainer.SceneAssets[i])
                {
                    _scenesContainer.SceneAssets[i] = newAsset;
                    EditorUtility.SetDirty(_scenesContainer);
                }
            }

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Clear"))
            {
                for (int i = 0; i < 10; i++)
                {
                    _scenesContainer.SceneAssets[i] = null;
                }
                EditorUtility.SetDirty(_scenesContainer);
            }

            GUILayout.EndHorizontal();
        }
Ejemplo n.º 8
0
 private void OnEnable()
 {
     // In case domain was not reloaded after entering play mode
     prevSceneAsset = null;
     PopulateScenePath();
     onEnabled?.Invoke(this);
 }
 private void UpdateAsyncOperation()
 {
     if (m_AsyncOperation != null)
     {
         if (m_AsyncOperation.isDone)
         {
             if (m_AsyncOperation.allowSceneActivation)
             {
                 SceneAsset sceneAsset = new SceneAsset();
                 LoadResourceAgentHelperLoadCompleteEventArgs loadResourceAgentHelperLoadCompleteEventArgs = LoadResourceAgentHelperLoadCompleteEventArgs.Create(sceneAsset);
                 m_LoadResourceAgentHelperLoadCompleteEventHandler(this, loadResourceAgentHelperLoadCompleteEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperLoadCompleteEventArgs);
                 m_AssetName      = null;
                 m_LastProgress   = 0f;
                 m_AsyncOperation = null;
             }
             else
             {
                 LoadResourceAgentHelperErrorEventArgs loadResourceAgentHelperErrorEventArgs = LoadResourceAgentHelperErrorEventArgs.Create(LoadResourceStatus.AssetError, Utility.Text.Format("Can not load scene asset '{0}' from asset bundle.", m_AssetName));
                 m_LoadResourceAgentHelperErrorEventHandler(this, loadResourceAgentHelperErrorEventArgs);
                 ReferencePool.Release(loadResourceAgentHelperErrorEventArgs);
             }
         }
         else if (m_AsyncOperation.progress != m_LastProgress)
         {
             m_LastProgress = m_AsyncOperation.progress;
             LoadResourceAgentHelperUpdateEventArgs loadResourceAgentHelperUpdateEventArgs = LoadResourceAgentHelperUpdateEventArgs.Create(LoadResourceProgress.LoadScene, m_AsyncOperation.progress);
             m_LoadResourceAgentHelperUpdateEventHandler(this, loadResourceAgentHelperUpdateEventArgs);
             ReferencePool.Release(loadResourceAgentHelperUpdateEventArgs);
         }
     }
 }
Ejemplo n.º 10
0
        private void GoToMainMenu()
        {
            AssetID    sceneID = "Scenes/MainMenu.scene";
            SceneAsset scene   = _as.Database.LoadAsset <SceneAsset>(sceneID, cache: false);

            _sls.LoadScene(scene);
        }
Ejemplo n.º 11
0
    private static void CreatePresetFromOpenScenes()
    {
        MultiScene multi = CreateInstance <MultiScene>();

        multi.name = "New Multi-Scene";

        Scene activeScene = SceneManager.GetActiveScene();
        int   sceneCount  = SceneManager.sceneCount;

        for (int i = 0; i < sceneCount; i++)
        {
            Scene scene = SceneManager.GetSceneAt(i);

            SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path);

            if (activeScene == scene)
            {
                multi.activeScene = sceneAsset;
            }

            multi.sceneAssets.Add(new MultiScene.SceneInfo(sceneAsset, scene.isLoaded));
        }

        string directory   = AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID());
        bool   isDirectory = Directory.Exists(directory);

        if (!isDirectory)
        {
            directory = Path.GetDirectoryName(directory);
        }

        ProjectWindowUtil.CreateAsset(multi, $"{directory}/{multi.name}.asset");
    }
        /// <summary>
        /// Destroys all scene assets that were created over the course of testing.
        /// Used only in editor tests.
        /// </summary>
        public static void EditorTearDownScenes()
        {
#if UNITY_EDITOR
            if (!EditorApplication.isPlaying)
            {
                // If any of our scenes were saved, tear down the assets
                SceneAsset primaryTestSceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(primaryTestSceneTemporarySavePath);
                if (primaryTestSceneAsset != null)
                {
                    AssetDatabase.DeleteAsset(primaryTestSceneTemporarySavePath);
                }

                for (int i = 0; i < additiveTestScenes.Length; i++)
                {
                    string     path = additiveTestSceneTemporarySavePath.Replace("#", i.ToString());
                    SceneAsset additiveTestSceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(path);
                    if (additiveTestSceneAsset != null)
                    {
                        AssetDatabase.DeleteAsset(path);
                    }
                }
                AssetDatabase.Refresh();
            }
#endif
        }
Ejemplo n.º 13
0
        private void Start()
        {
            SceneManager.sceneLoaded += onSceneLoaded;
            _nextScene = FindObjectOfType <NextSceneStorage>()?.StoredScene;
            Debug.Log("Next scene is " + _nextScene.name);
//            Time.timeScale = 3f;
        }
        public static void RemoveSceneFromBuildSettings(SceneAsset scene)
        {
            if (EditorBuildSettings.scenes.Length == 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(scene)))
            {
                return;
            }

            if (!SceneAddedToBuildCriterion.SceneIsAddedToBuildSettings(scene))
            {
                return;
            }

            var sceneAsset = new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(scene), true);
            var scenes     = new EditorBuildSettingsScene[EditorBuildSettings.scenes.Length - 1];
            var j          = 0;

            for (int i = 0; i < EditorBuildSettings.scenes.Length; ++i)
            {
                if (EditorBuildSettings.scenes[i].guid != sceneAsset.guid)
                {
                    scenes[j++] = EditorBuildSettings.scenes[i];
                }
            }
            EditorBuildSettings.scenes = scenes;
        }
Ejemplo n.º 15
0
    void CreateSceneRootPerfab(SceneAsset sceneAsset)
    {
        Scene needOpenScene = EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(sceneAsset.GetInstanceID()));

        List <GameObject> sceneRootGameObjects = new List <GameObject>();

        sceneRootGameObjects.AddRange(needOpenScene.GetRootGameObjects());

        foreach (GameObject g in sceneRootGameObjects)
        {
            if (CheckNeedRemoveObject(g))
            {
                sceneRootGameObjects.Remove(g);
            }
        }

        GameObject sceneRoot = new GameObject();

        sceneRoot.name = name + "SceneRoot";
        foreach (GameObject g in sceneRootGameObjects)
        {
            g.transform.parent = sceneRoot.transform;
        }

        string     createPrefabPath = "Assets/intermediate/" + needOpenScene.name + "_SceneRoot.prefab";
        GameObject createPrefab     = PrefabUtility.CreatePrefab(createPrefabPath, sceneRoot);

        AssetImporter assetImporter = AssetImporter.GetAtPath(createPrefabPath); //得到Asset

        assetImporter.assetBundleName = createPrefab.name.ToLower();             //最终设置assetBundleName


        EditorSceneManager.NewScene(new NewSceneSetup());
    }
Ejemplo n.º 16
0
        public static IList <IValidationError> ValidateAllGameObjectsInScenes(IEnumerable <Scene> scenes, bool earlyExitOnError = false)
        {
            List <IValidationError> validationErrors = new List <IValidationError>();

            foreach (Scene scene in scenes)
            {
                // NOTE (darren): use SceneAsset instead of Scene as the context object
                // because scene is a struct and was being lost when returning out-of-scope as
                // part of IValidationError
                SceneAsset sceneAsset = AssetDatabase.LoadMainAssetAtPath(scene.path) as SceneAsset;
                if (sceneAsset == null)
                {
                    Debug.LogWarning("Cannot validate game objects with missing SceneAsset at path: " + scene.path);
                    continue;
                }

                GameObject[] rootObjects = scene.GetRootGameObjects();
                foreach (GameObject rootObject in rootObjects)
                {
                    Validator.Validate(rootObject, contextObject: sceneAsset, recursive: true, validationErrors: validationErrors);
                    if (earlyExitOnError && validationErrors.Count > 0)
                    {
                        return(validationErrors);
                    }
                }
            }

            return(validationErrors);
        }
Ejemplo n.º 17
0
    private void DrawLoadingSceneShortcut()
    {
        GUILayout.BeginVertical("box");

        EditorGUILayout.Space();

        string loadingScenePath = EditorPrefs.GetString(LOADING_SCENE_KEY);

        if (_loadingScene == null && !string.IsNullOrEmpty(loadingScenePath))
        {
            _loadingScene = AssetDatabase.LoadAssetAtPath <SceneAsset>(loadingScenePath);
        }

        _loadingScene = EditorGUILayout.ObjectField("Loading Scene", _loadingScene, typeof(SceneAsset), true) as SceneAsset;
        if (_loadingScene != null)
        {
            EditorPrefs.SetString(LOADING_SCENE_KEY, AssetDatabase.GetAssetPath(_loadingScene));
        }

        _automaticallyLoadScenes = EditorGUILayout.Toggle("Automatically Load Scenes", _automaticallyLoadScenes);
        EditorPrefs.SetBool(AUTO_LOAD_KEY, _automaticallyLoadScenes);

        EditorGUILayout.Space();

        GUILayout.EndVertical();
    }
Ejemplo n.º 18
0
    public static void FirstProjectLaunch()
    {
        if (!FindObjectOfType <FMCGameManager>())
        {
            new GameObject("FMC").AddComponent <FMCGameManager>();
            EditorSceneManager.SaveScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene(), fmc.game.GameSceneDefaultPath);

            FMCGameSettings Target = FMCGameSettings.LoadOrCreateGameSettings();

            //Searching scenes in project
            if (string.IsNullOrEmpty(Target.Public.gameSceneGUID))
            {
                SceneAsset s = GetSceneFromGUID(null, fmc.game.GameSceneDefaultName);
                if (s)
                {
                    Target.Public.gameSceneGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetOrScenePath(s));
                }
            }

            if (string.IsNullOrEmpty(Target.Public.splashScreenSceneGUID))
            {
                SceneAsset s = GetSceneFromGUID(null, fmc.game.SplashScreenSceneName);
                if (s)
                {
                    Target.Public.splashScreenSceneGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetOrScenePath(s));
                }
            }

            UpdateUnitySettings(Target);
        }
    }
Ejemplo n.º 19
0
        public async Task <SceneWrapper> LoadScene(Project project, SceneAsset asset)
        {
            if (asset != null)
            {
                if (this.CurrentScene != null && this.HasChanges)
                {
                    var message = this.CurrentScene.SceneAsset != null ? $"Would you like to save {this.CurrentScene.SceneAsset.Name}?" : "Would you like to save the current scene?";
                    var result  = this._dialogService.ShowYesNoCancelMessageBox($"Save Scene", message);
                    if (result == MessageBoxResult.Cancel || (result == MessageBoxResult.Yes && !await this.SaveCurrentScene(project)))
                    {
                        return(null);
                    }
                }

                this.CurrentScene = await Task.Run(() => new SceneWrapper(asset));

                this.RefreshSpritesFromAssets(project);
                this.RefreshAudioClipsFromAssets(project);
                this.RefreshFontsFromAssets(project);

                this.HasChanges = false;
                return(this.CurrentScene);
            }

            return(null);
        }
Ejemplo n.º 20
0
        private void ApplySceneSetting()
        {
            List <EditorBuildSettingsScene> editorScenes = new List <EditorBuildSettingsScene>();

            EditorSceneManager.playModeStartScene = (SceneAsset)preloadSceneProperty.objectReferenceValue;

            // If there is a preload scene, assign it to build index 0
            if (preloadSceneProperty.objectReferenceValue != null)
            {
                SceneAsset preloadScene     = (SceneAsset)preloadSceneProperty.objectReferenceValue;
                string     preloadScenePath = AssetDatabase.GetAssetPath(preloadScene);
                editorScenes.Add(new EditorBuildSettingsScene(preloadScenePath, true));
            }

            for (int i = 0; i < scenesProperty.arraySize; i++)
            {
                SceneAsset scene = (SceneAsset)scenesProperty.GetArrayElementAtIndex(i).objectReferenceValue;

                if (scene != null)
                {
                    string path = AssetDatabase.GetAssetPath(scene);
                    editorScenes.Add(new EditorBuildSettingsScene(path, true));
                }
            }

            EditorBuildSettings.scenes = editorScenes.ToArray();
        }
Ejemplo n.º 21
0
    private void EditMap(string mapName)
    {
        string sceneName = "Edit" + mapName;
        string scenePath = "Assets/Scenes/" + sceneName + ".unity";

        if (EditorSceneManager.GetActiveScene().name != sceneName)
        {
            SceneAsset scene = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath);
            if (scene == null)
            {
                EditorUtility.DisplayDialog("提示", "找不到场景文件" + scenePath, "好的");
                return;
            }
            else
            {
                EditorSceneManager.OpenScene(scenePath);
            }
        }
        GameObject mapGo = GameObject.FindObjectOfType <BaseMap>()?.gameObject;

        if (mapGo == null)
        {
            EditorUtility.DisplayDialog("提示", "该场景中找不到地图", "好的");
            return;
        }
        Selection.activeGameObject = mapGo;
        SetCurrentSceneIndex();
        ToolsHelperEditor.SetStartupScene(mapName);
    }
Ejemplo n.º 22
0
        public void TestCopyPasteEntityAtRoot()
        {
            var sceneAsset = new SceneAsset();
            var entity     = new EntityDesign {
                Entity = new Entity {
                    Id = GuidGenerator.Get(1)
                }
            };

            entity.Entity.Transform.Position = Vector3.UnitZ;
            sceneAsset.Hierarchy.RootParts.Add(entity.Entity);
            sceneAsset.Hierarchy.Parts.Add(entity);

            var assetTest = new CopyPasteTest <SceneAsset>(sceneAsset);
            var service   = TestHelper.CreateCopyPasteService();

            service.PropertyGraphContainer.RegisterGraph(assetTest.AssetGraph);
            var clipboard = Copy(service, assetTest.AssetGraph, new[] { entity });

            Paste(service, clipboard, assetTest.AssetGraph, null, null);
            Assert.Equal(2, assetTest.Asset.Hierarchy.Parts.Count);
            Assert.True(assetTest.Asset.Hierarchy.Parts.Values.Contains(entity));

            var pastedEntity = assetTest.Asset.Hierarchy.Parts.Values.Single(x => x != entity);

            Assert.Equal(2, assetTest.Asset.Hierarchy.RootParts.Count);
            Assert.Contains(pastedEntity.Entity, assetTest.Asset.Hierarchy.RootParts);
            Assert.Equal(string.Empty, pastedEntity.Folder);
            Assert.NotEqual(entity.Entity.Id, pastedEntity.Entity.Id);
            Assert.NotEqual(entity.Entity.Transform.Id, pastedEntity.Entity.Transform.Id);
            Assert.Equal(Vector3.UnitZ, pastedEntity.Entity.Transform.Position);
        }
Ejemplo n.º 23
0
        static SceneData makeData(SceneAsset asset)
        {
            SceneData data = (SceneData)CreateAsset <SceneData>(asset.name + "_data");

            processData(data, asset);
            return(data);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Finds a missing scene asset reference for a SceneInfo struct.
        /// </summary>
        /// <returns>True if scene was found.</returns>
        public static bool FindScene(SerializedProperty nameProperty, SerializedProperty pathProperty, ref UnityEngine.Object asset)
        {
            // Attempt to load via the scene path
            SceneAsset newSceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(pathProperty.stringValue);

            if (newSceneAsset != null)
            {
                Debug.Log("Found missing scene at path " + pathProperty.stringValue);
                asset = newSceneAsset;
                return(true);
            }
            else
            {
                // If we didn't find it this way, search for all scenes in the project and try a name match
                foreach (string sceneGUID in AssetDatabase.FindAssets("t:Scene"))
                {
                    string scenePath = AssetDatabase.GUIDToAssetPath(sceneGUID);
                    string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);

                    if (sceneName == nameProperty.stringValue)
                    {
                        pathProperty.stringValue = scenePath;
                        newSceneAsset            = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath);
                        if (newSceneAsset != null)
                        {
                            Debug.Log("Found missing scene at path " + scenePath);
                            asset = newSceneAsset;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Overrides Unity display of scenes tagged with [Scene].
        /// </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Only override rendering on properties with type of string (otherwise it doesn't work).
            if (property.propertyType == SerializedPropertyType.String)
            {
                // Get currently selected object (generated from previous string value).
                SceneAsset sceneObject = GetSceneObject(property.stringValue);
                // Render a SceneAsset object field, with the previous string value, shown as a SceneAsset.
                Object scene = EditorGUI.ObjectField(position, label, sceneObject, typeof(SceneAsset), true);

                if (scene == null)
                {
                    // We get nulls if the scene asset isn't found so wipe the string value.
                    property.stringValue = "";

                    // If the scene name doesn't match the property they have changed it
                    // either by drag n drop or the object picker.
                }
                else if (scene.name != property.stringValue)
                {
                    // Convert the Object to a SceneAsset.
                    SceneAsset sceneObj = GetSceneObject(scene.name);
                    // If its a valid scene asset we use it, otherwise assume select invalid and ignore.
                    if (sceneObj != null)
                    {
                        property.stringValue = scene.name;
                    }
                }
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use [Scene] with strings.");
            }
        }
        /// <summary>
        /// Creates a new scene with sceneName and saves to path.
        /// </summary>
        public static SceneInfo CreateAndSaveScene(string sceneName, string path = null)
        {
            SceneInfo sceneInfo = default(SceneInfo);

            if (!EditorSceneManager.EnsureUntitledSceneHasBeenSaved("Save untitled scene before proceeding?"))
            {
                return(sceneInfo);
            }

            Scene newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            if (string.IsNullOrEmpty(path))
            {
                path = "Assets/" + sceneName + ".unity";
            }

            if (!EditorSceneManager.SaveScene(newScene, path))
            {
                Debug.LogError("Couldn't create and save scene " + sceneName + " at path " + path);
                return(sceneInfo);
            }

            SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(path);

            sceneInfo.Asset = sceneAsset;
            sceneInfo.Name  = sceneAsset.name;
            sceneInfo.Path  = path;

            return(sceneInfo);
        }
Ejemplo n.º 27
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     if (property.propertyType == SerializedPropertyType.String)
     {
         SceneAsset sceneObject = GetSceneObject(property.stringValue);
         SceneAsset scene       = (SceneAsset)EditorGUI.ObjectField(position, label, sceneObject, typeof(SceneAsset), true);
         if (scene == null)
         {
             property.stringValue = "";
         }
         else if (scene.name != property.stringValue)
         {
             SceneAsset sceneObj = GetSceneObject(scene.name);
             if (sceneObj == null)
             {
                 Debug.LogWarning("The scene " + scene.name + " cannot be used. To use this scene add it to the build settings for the project");
             }
             else
             {
                 property.stringValue = scene.name;
             }
         }
     }
     else
     {
         EditorGUI.LabelField(position, label.text, "Use [Scene] with strings.");
     }
 }
Ejemplo n.º 28
0
    public static void AddAllWorldScenes()
    {
        // Find valid Scene paths and make a list of EditorBuildSettingsScene
        List <EditorBuildSettingsScene> editorBuildSettingsScenes = new List <EditorBuildSettingsScene>();

        List <SceneAsset> m_SceneAssets = new List <SceneAsset>();
        string            folderName    = Application.dataPath + "/Scenes/WorldMap/";
        var dirInfo      = new DirectoryInfo(folderName);
        var allFileInfos = dirInfo.GetFiles("*.unity", SearchOption.AllDirectories);

        foreach (var fileInfo in allFileInfos)
        {
            SceneAsset sa = AssetDatabase.LoadAssetAtPath <SceneAsset>("Assets/Scenes/WorldMap/" + fileInfo.Name);
            m_SceneAssets.Add(sa);
        }

        foreach (var sceneAsset in m_SceneAssets)
        {
            string scenePath = AssetDatabase.GetAssetPath(sceneAsset);
            if (!string.IsNullOrEmpty(scenePath))
            {
                editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(scenePath, true));
            }
        }

        // Set the Build Settings window Scene list
        EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
    }
        /// <summary>
        /// Add the currently loaded scenes to the
        /// </summary>
        private void AddOpenedScenes()
        {
            for (int i = 0; i < EditorSceneManager.sceneCount; i++)
            {
                SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath(EditorSceneManager.GetSceneAt(i).path, typeof(SceneAsset)) as SceneAsset;
                if (SceneAssets.ContainsObjects(sceneAsset))
                {
                    continue;
                }
                if (sceneAsset.IsPersistantScene())
                {
                    continue;
                }

                if (SceneAssets.arraySize > 0)
                {
                    SceneAssets.InsertArrayElementAtIndex(SceneAssets.arraySize - 1);
                }
                else
                {
                    SceneAssets.InsertArrayElementAtIndex(0);
                }

                SceneAssets.GetArrayElementAtIndex(SceneAssets.arraySize - 1).objectReferenceValue = sceneAsset;
                UpdateScenesLabels();
            }
        }
Ejemplo n.º 30
0
    void CreateAndAddNewSceneReference(SceneAsset newSceneReferenceLevel)
    {
        if (newSceneReferenceLevel == null)
        {
            return;
        }

        SceneReference newSceneReference = CreateInstance <SceneReference> ();

        newSceneReference.levelScene = newSceneReferenceLevel;
        newSceneReference.menuScene  = AssetDatabase.LoadAssetAtPath <SceneAsset> (((SceneMenu)target).gameObject.scene.path);

        string newSceneReferencePath = AssetDatabase.GenerateUniqueAssetPath(k_NewSceneReferencePath);

        AssetDatabase.CreateAsset(newSceneReference, newSceneReferencePath);

        string newLevelPath  = AssetDatabase.GetAssetOrScenePath(newSceneReferenceLevel);
        Scene  newLevelScene = EditorSceneManager.OpenScene(newLevelPath, OpenSceneMode.Additive);

        SceneCompletion sceneCompletion = FindObjectOfType <SceneCompletion> ();

        sceneCompletion.sceneReference = newSceneReference;

        EditorUtility.SetDirty(sceneCompletion);
        EditorSceneManager.SaveScene(newLevelScene);
        EditorSceneManager.CloseScene(newLevelScene, true);

        m_LevelsProp.arraySize++;
        m_LevelsProp.GetArrayElementAtIndex(m_LevelsProp.arraySize - 1).FindPropertyRelative("level").objectReferenceValue = newSceneReference;
    }
Ejemplo n.º 31
0
    private void OnLoaded(SceneAsset asset, Object obj)
    {
        //Debug.Log(string.Format("OnLoaded {0} \n", asset.ResName));
        //if (asset.Type != ResourceCenter.AssetType.scene)
        {
            ++mLoadedCount;
            if (asset.Handle != null)
                asset.Handle(obj);

            CheckDone();
        }
        //             else
        //             {
        //                 mAsyncOpt = Application.LoadLevelAsync(asset.ResName);
        //             }
    }
Ejemplo n.º 32
0
	private GameObject FindObject(SceneAsset.SceneObjectType type, int customID)
	{
		for(int i = 0; i < asset.sceneObjects.Length; i++)
		{
			if(asset.sceneObjects[i].type == type || (type == SceneAsset.SceneObjectType.Custom && asset.sceneObjects[i].customID == customID))
			{
				return asset.sceneObjects[i].prefab;
			}
		}

		return null;
	}
Ejemplo n.º 33
0
 private void RequestAsset(SceneAsset asset)
 {
     switch (asset.Type)
     {
         case ResourceCenter.AssetType.normal:
             {
                 ResourceCenter.instance.LoadObject(asset.ResName,
                     (Object obj) =>
                     {
                         OnLoaded(asset, obj);
                     });
                 break;
             }
         case ResourceCenter.AssetType.scene:
             {
                 ResourceCenter.instance.LoadScene(asset.ResName,
                     (Object obj) =>
                     {
                         OnLoaded(asset, obj);
                     });
                 break;
             }
         case ResourceCenter.AssetType.additive_scene:
             {
                 ResourceCenter.instance.LoadAdditiveScene(asset.ResName,
                     (Object obj) =>
                     {
                         OnLoaded(asset, obj);
                     });
                 break;
             }
         case ResourceCenter.AssetType.audio:
             {
                 ResourceCenter.instance.LoadAudio(asset.ResName,
                     (Object obj) =>
                     {
                         OnLoaded(asset, obj);
                     });
                 break;
             }
         case ResourceCenter.AssetType.texture:
             {
                 ResourceCenter.instance.LoadTexture(asset.ResName,
                     (Object obj) =>
                     {
                         OnLoaded(asset, obj);
                     });
                 break;
             }
         default:
             {
                 Logger.instance.Error("Unprocess AssetType : {0} : {1}\n", asset.Type, asset.ResName);
                 break;
             }
     }
 }