示例#1
0
#pragma warning restore 0618 // Type or member is obsolete

        internal static void AddGameObjectsToPrefabAndConnect(GameObject[] gameObjects, Object targetPrefab)
        {
            if (gameObjects == null)
            {
                throw new ArgumentNullException("gameObjects");
            }

            if (gameObjects.Length == 0)
            {
                throw new ArgumentException("gameObjects array is empty");
            }

            if (targetPrefab == null)
            {
                throw new ArgumentNullException("targetPrefab");
            }

            if (!PrefabUtility.IsPartOfPrefabAsset(targetPrefab))
            {
                throw new ArgumentException("Target Prefab has to be a Prefab Asset");
            }

            Object targetPrefabInstance = null;

            var targetPrefabObject = PrefabUtility.GetPrefabAssetHandle(targetPrefab);

            foreach (GameObject go in gameObjects)
            {
                if (go == null)
                {
                    throw new ArgumentException("GameObject in input 'gameObjects' array is null");
                }

                if (EditorUtility.IsPersistent(go))  // Prefab asset
                {
                    throw new ArgumentException("Game object is part of a prefab");
                }

                var parentPrefabInstance = GetParentPrefabInstance(go);
                if (parentPrefabInstance == null)
                {
                    throw new ArgumentException("GameObject is not (directly) parented under a target Prefab instance.");
                }

                if (targetPrefabInstance == null)
                {
                    targetPrefabInstance = parentPrefabInstance;
                    if (!IsPrefabInstanceObjectOf(go.transform.parent, targetPrefabObject))
                    {
                        throw new ArgumentException("GameObject is not parented under a target Prefab instance.");
                    }
                }
                else
                {
                    if (parentPrefabInstance != targetPrefabInstance)
                    {
                        throw new ArgumentException("GameObjects must be parented under the same Prefab instance.");
                    }
                }

                if (PrefabUtility.IsPartOfNonAssetPrefabInstance(go))
                {
                    var correspondingGO             = PrefabUtility.GetCorrespondingObjectFromSource(go);
                    var correspondingGOPrefabObject = PrefabUtility.GetPrefabAssetHandle(correspondingGO);
                    if (targetPrefabObject == correspondingGOPrefabObject)
                    {
                        throw new ArgumentException("GameObject is already part of target prefab");
                    }
                }
            }

            string prefabGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(targetPrefab));

            if (!VerifyNestingFromScript(gameObjects, prefabGUID, null))
            {
                throw new ArgumentException("Cyclic nesting detected");
            }

            AddGameObjectsToPrefabAndConnect_Internal(gameObjects, targetPrefab);
        }
示例#2
0
        public void DoLocalSelectionChange()
        {
            if (this.m_NextSelectionMine)
            {
                this.m_NextSelectionMine = false;
                return;
            }
            UnityEngine.Object[] filtered = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets);
            string[]             array    = new string[0];
            switch (this.m_FileViewWin.SelType)
            {
            case ASHistoryFileView.SelectionType.All:
                if (Selection.objects.Length != 0)
                {
                    Selection.objects        = new UnityEngine.Object[0];
                    this.m_NextSelectionMine = true;
                }
                this.m_SelectedPath = string.Empty;
                this.m_SelectedGUID = string.Empty;
                this.ClearLV();
                break;

            case ASHistoryFileView.SelectionType.Items:
                if (filtered.Length < 1)
                {
                    this.m_SelectedPath = string.Empty;
                    this.m_SelectedGUID = string.Empty;
                    this.ClearLV();
                    return;
                }
                this.m_SelectedPath = AssetDatabase.GetAssetPath(filtered[0]);
                this.m_SelectedGUID = AssetDatabase.AssetPathToGUID(this.m_SelectedPath);
                array = this.m_FileViewWin.GetImplicitProjectViewSelection();
                break;

            case ASHistoryFileView.SelectionType.DeletedItemsRoot:
                if (Selection.objects.Length != 0)
                {
                    Selection.objects        = new UnityEngine.Object[0];
                    this.m_NextSelectionMine = true;
                }
                array = this.m_FileViewWin.GetAllDeletedItemGUIDs();
                if (array.Length == 0)
                {
                    this.ClearLV();
                    return;
                }
                break;

            case ASHistoryFileView.SelectionType.DeletedItems:
                if (Selection.objects.Length != 0)
                {
                    Selection.objects        = new UnityEngine.Object[0];
                    this.m_NextSelectionMine = true;
                }
                array = this.m_FileViewWin.GetSelectedDeletedItemGUIDs();
                break;
            }
            this.m_Changesets = AssetServer.GetHistorySelected(array);
            if (this.m_Changesets != null)
            {
                this.FilterItems(true);
            }
            else
            {
                this.ClearLV();
            }
            if (array != null && this.m_GUIItems != null && array.Length == 1)
            {
                this.MarkBoldItemsByGUID(this.m_SelectedGUID);
            }
            this.m_ParentWindow.Repaint();
        }
            private TreeViewItem EnsureFolderPath(string folderPath, Dictionary <string, AssetsItem> packageFolders, Dictionary <string, PackageImportTreeView.PackageImportTreeViewItem> treeViewFolders, bool initExpandedState)
            {
                TreeViewItem item = TreeViewUtility.FindItem(folderPath.GetHashCode(), base.m_RootItem);

                if (item != null)
                {
                    return(item);
                }
                char[]       separator = new char[] { '/' };
                string[]     strArray  = folderPath.Split(separator);
                string       key       = string.Empty;
                TreeViewItem rootItem  = base.m_RootItem;

                for (int i = 0; i < strArray.Length; i++)
                {
                    string displayName = strArray[i];
                    if (key != string.Empty)
                    {
                        key = key + '/';
                    }
                    key = key + displayName;
                    if (key != "Assets")
                    {
                        PackageImportTreeView.PackageImportTreeViewItem item3;
                        int hashCode = key.GetHashCode();
                        if (treeViewFolders.TryGetValue(key, out item3))
                        {
                            rootItem = item3;
                        }
                        else
                        {
                            AssetsItem item5;
                            int        depth = i - 1;
                            PackageImportTreeView.PackageImportTreeViewItem child = new PackageImportTreeView.PackageImportTreeViewItem(hashCode, depth, rootItem, displayName)
                            {
                                isFolder = true
                            };
                            if (packageFolders.TryGetValue(key, out item5))
                            {
                                child.item = item5;
                            }
                            if (child.item == null)
                            {
                                AssetsItem item6 = new AssetsItem {
                                    assetIsDir        = 1,
                                    pathName          = key,
                                    exportedAssetPath = key,
                                    enabled           = (this.m_EnabledFolders != null) ? (!this.m_EnabledFolders.Contains(key) ? 0 : 1) : 1,
                                    guid        = AssetDatabase.AssetPathToGUID(key),
                                    previewPath = string.Empty
                                };
                                child.item        = item6;
                                child.item.exists = !string.IsNullOrEmpty(child.item.guid) ? 1 : 0;
                            }
                            rootItem.AddChild(child);
                            rootItem = child;
                            if (initExpandedState)
                            {
                                base.m_TreeView.state.expandedIDs.Add(hashCode);
                            }
                            treeViewFolders[key] = child;
                        }
                    }
                }
                return(rootItem);
            }
        static void SaveAssemblyDefinitionState(AssemblyDefinitionState state)
        {
            var references             = state.references;
            var platforms              = CompilationPipeline.GetAssemblyDefinitionPlatforms();
            var OptinalUnityAssemblies = CustomScriptAssembly.OptinalUnityAssemblies;

            CustomScriptAssemblyData data = new CustomScriptAssemblyData();

            data.name = state.assemblyName;

            if (state.useGUIDs)
            {
                data.references = references.Select(r =>
                {
                    var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(r.asset));

                    if (string.IsNullOrEmpty(guid))
                    {
                        return(r.serializedReference);
                    }

                    return(CompilationPipeline.GUIDToAssemblyDefinitionReferenceGUID(guid));
                }).ToArray();
            }
            else
            {
                data.references = references.Select(r => r.name).ToArray();
            }

            data.defineConstraints = state.defineConstraints
                                     .Where(x => !string.IsNullOrEmpty(x.name))
                                     .Select(r => r.name)
                                     .ToArray();

            data.versionDefines = state.versionDefines.Select(x => new UnityEditor.Scripting.ScriptCompilation.VersionDefine
            {
                name       = x.name,
                expression = x.expression,
                define     = x.define,
            }).ToArray();

            data.autoReferenced     = state.autoReferenced;
            data.overrideReferences = state.overrideReferences;

            data.precompiledReferences = state.precompiledReferences
                                         .Select(r => r.name).ToArray();

            List <string> optionalUnityReferences = new List <string>();

            for (int i = 0; i < OptinalUnityAssemblies.Length; i++)
            {
                if (state.optionalUnityReferences[i])
                {
                    optionalUnityReferences.Add(OptinalUnityAssemblies[i].OptionalUnityReferences.ToString());
                }
            }

            data.optionalUnityReferences = optionalUnityReferences.ToArray();

            data.allowUnsafeCode = state.allowUnsafeCode;

            List <string> dataPlatforms = new List <string>();

            for (int i = 0; i < platforms.Length; ++i)
            {
                if (state.platformCompatibility[i])
                {
                    dataPlatforms.Add(platforms[i].Name);
                }
            }

            if (dataPlatforms.Any())
            {
                if (state.compatibleWithAnyPlatform)
                {
                    data.excludePlatforms = dataPlatforms.ToArray();
                }
                else
                {
                    data.includePlatforms = dataPlatforms.ToArray();
                }
            }

            var json = CustomScriptAssemblyData.ToJson(data);

            File.WriteAllText(state.path, json);

            AssetDatabase.ImportAsset(state.path);
        }