예제 #1
0
        private void OnDisable()
        {
#if DREAMTECK_SPLINES
            for (int i = 0; i < splines.Length; i++)
            {
                if (splines[i] != null)
                {
                    DSSplineDrawer.UnregisterComputer(splines[i]);
                }
            }
#endif
            if (propertyWindow != null)
            {
                propertyWindow.Close();
            }
        }
예제 #2
0
        void Write(LevelSegment segment, bool forceCopy)
        {
            //Check to see if we are currently editing the prefab and if yes (2018.3), just pack everything without rewriting
            bool   isPrefabInstance = false;
            Object prefabParent     = null;

#if UNITY_2018_3_OR_NEWER
            PrefabInstanceStatus instanceStatus = PrefabUtility.GetPrefabInstanceStatus(segment.gameObject);
            isPrefabInstance = instanceStatus == PrefabInstanceStatus.Connected;
            if (isPrefabInstance)
            {
                prefabParent = PrefabUtility.GetCorrespondingObjectFromSource(segment.gameObject);
            }
#else
            PrefabType prefabType = PrefabUtility.GetPrefabType(segment.gameObject);
            isPrefabInstance = prefabType == PrefabType.PrefabInstance;
            if (isPrefabInstance)
            {
                prefabParent = PrefabUtility.GetPrefabParent(segment.gameObject);
            }
#endif

            if (!forceCopy && prefabParent != null)
            {
                segment.EditorPack();
#if DREAMTECK_SPLINES
                for (int i = 0; i < splines.Length; i++)
                {
                    if (splines[i] != null)
                    {
                        DSSplineDrawer.UnregisterComputer(splines[i]);
                    }
                }
#endif
#if UNITY_2018_3_OR_NEWER
                Selection.activeGameObject = PrefabUtility.SaveAsPrefabAsset(segment.gameObject, AssetDatabase.GetAssetPath(prefabParent));
#else
                PrefabUtility.ReplacePrefab(segment.gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
#endif
                Undo.DestroyObjectImmediate(segment.gameObject);
            }
            else
            {
                relativePath = EditorPrefs.GetString("LevelSegmentEditor.relativePath", "/");
                if (prefabParent != null)
                {
                    relativePath = AssetDatabase.GetAssetPath(prefabParent);
                    if (relativePath.StartsWith("Assets"))
                    {
                        relativePath = relativePath.Substring("Assets".Length);
                    }
                    relativePath = System.IO.Path.GetDirectoryName(relativePath);
                }
                string path = EditorUtility.SaveFilePanel("Save Prefab", Application.dataPath + relativePath, segment.name, "prefab");
                if (path.StartsWith(Application.dataPath) && System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path)))
                {
                    relativePath = path.Substring(Application.dataPath.Length);
                    segment.EditorPack();
#if DREAMTECK_SPLINES
                    for (int i = 0; i < splines.Length; i++)
                    {
                        if (splines[i] != null)
                        {
                            DSSplineDrawer.UnregisterComputer(splines[i]);
                        }
                    }
#endif
#if UNITY_2018_3_OR_NEWER
                    if (isPrefabInstance)
                    {
                        PrefabUtility.UnpackPrefabInstance(segment.gameObject, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);
                    }
                    PrefabUtility.SaveAsPrefabAsset(segment.gameObject, "Assets" + relativePath);
#else
                    if (isPrefabInstance)
                    {
                        PrefabUtility.DisconnectPrefabInstance(segment.gameObject);
                    }
                    PrefabUtility.CreatePrefab("Assets" + relativePath, segment.gameObject);
#endif
                    Undo.DestroyObjectImmediate(segment.gameObject);
                    EditorPrefs.SetString("LevelSegmentEditor.relativePath", System.IO.Path.GetDirectoryName(relativePath));
                }
                else
                {
                    if (path != "" && !path.StartsWith(Application.dataPath))
                    {
                        EditorUtility.DisplayDialog("Path Error", "Please select a path inside this project's Assets folder", "OK");
                    }
                }
            }
        }