public void Apply(SerializedProperty sp)
        {
            sp.FindPropertyRelative("m_Rect").rectValue                = rect;
            sp.FindPropertyRelative("m_Name").stringValue              = name;
            sp.FindPropertyRelative("m_Border").vector4Value           = border;
            sp.FindPropertyRelative("m_Alignment").intValue            = (int)alignment;
            sp.FindPropertyRelative("m_Pivot").vector2Value            = pivot;
            sp.FindPropertyRelative("m_TessellationDetail").floatValue = tessellationDetail;
            sp.FindPropertyRelative("m_SpriteID").stringValue          = spriteID.ToString();
            if (internalID == 0L)
            {
                UnityType spriteType = UnityType.FindTypeByName("Sprite");
                internalID = ImportSettingInternalID.MakeInternalID(sp.serializedObject, spriteType, name);
            }

            sp.FindPropertyRelative("m_InternalID").longValue = internalID;

            if (spriteBone != null)
            {
                SpriteBoneDataTransfer.Apply(sp, spriteBone);
            }
            if (spriteOutline != null)
            {
                SpriteOutlineDataTransfer.Apply(sp, spriteOutline);
            }
            if (spritePhysicsOutline != null)
            {
                SpritePhysicsOutlineDataTransfer.Apply(sp, spritePhysicsOutline);
            }
            if (vertices != null)
            {
                SpriteMeshDataTransfer.Apply(sp, vertices, indices, edges);
            }
        }
예제 #2
0
        private static void UpdateBuildReport(LinkerToEditorData dataFromLinker, IIl2CppPlatformProvider platformProvider)
        {
            var strippingInfo = platformProvider == null ? null : StrippingInfo.GetBuildReportData(platformProvider.buildReport);

            if (strippingInfo == null)
            {
                return;
            }

            foreach (var moduleInfo in dataFromLinker.report.modules)
            {
                strippingInfo.AddModule(moduleInfo.name);
                foreach (var moduleDependency in moduleInfo.dependencies)
                {
                    strippingInfo.RegisterDependency(StrippingInfo.ModuleName(moduleInfo.name), moduleDependency.name);

                    if (!string.IsNullOrEmpty(moduleDependency.icon))
                    {
                        strippingInfo.SetIcon(moduleDependency.name, moduleDependency.icon);
                    }

                    // Hacky way to match the existing behavior
                    if (moduleDependency.name == "UnityConnectSettings")
                    {
                        strippingInfo.RegisterDependency(moduleDependency.name, "Required by UnityAnalytics");
                    }

                    foreach (var scene in moduleDependency.scenes)
                    {
                        strippingInfo.RegisterDependency(moduleDependency.name, scene);

                        var klass = UnityType.FindTypeByName(moduleDependency.name);
                        if (klass != null && !klass.IsDerivedFrom(CodeStrippingUtils.GameManagerTypeInfo))
                        {
                            if (scene.EndsWith(".unity"))
                            {
                                strippingInfo.SetIcon(scene, "class/SceneAsset");
                            }
                            else
                            {
                                strippingInfo.SetIcon(scene, "class/AssetBundle");
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        static List <EditorToLinkerData.TypeInSceneData> GetTypesInScenesInformation(string managedAssemblyDirectory, RuntimeClassRegistry rcr)
        {
            var items = new List <EditorToLinkerData.TypeInSceneData>();

            foreach (var nativeClass in rcr.GetAllNativeClassesIncludingManagersAsString())
            {
                var unityType = UnityType.FindTypeByName(nativeClass);

                var managedName  = RuntimeClassMetadataUtils.ScriptingWrapperTypeNameForNativeID(unityType.persistentTypeID);
                var usedInScenes = rcr.GetScenesForClass(unityType.persistentTypeID);

                bool noManagedType = unityType.persistentTypeID != 0 && managedName == "UnityEngine.Object";
                var  information   = new EditorToLinkerData.TypeInSceneData(
                    noManagedType ? null : "UnityEngine.dll",
                    noManagedType ? null : managedName,
                    nativeClass,
                    unityType.module,
                    usedInScenes != null ? usedInScenes.ToArray() : null);

                items.Add(information);
            }

            foreach (var userAssembly in rcr.UsedTypePerUserAssembly)
            {
                // Some how stuff for assemblies that will not be in the build make it into UsedTypePerUserAssembly such as
                // ex: [UnityEditor.TestRunner.dll] UnityEditor.TestTools.TestRunner.TestListCacheData
                //
                // Filter anything out where the assembly doesn't exist so that UnityLinker can be strict about being able to find
                // all of the types that are reported as being in the scene.
                if (!File.Exists(Path.Combine(managedAssemblyDirectory, userAssembly.Key)))
                {
                    continue;
                }

                foreach (var type in userAssembly.Value)
                {
                    items.Add(new EditorToLinkerData.TypeInSceneData(userAssembly.Key, type, null, null, null));
                }
            }

            return(items);
        }
        private void RegisterEventHandlers()
        {
            if (m_RegisteredEventHandlers)
            {
                return;
            }

            SceneView.duringSceneGui           += OnSceneGuiDelegate;
            Selection.selectionChanged         += UpdateCache;
            EditorApplication.hierarchyChanged += UpdateCache;
            UnityEditor.EditorTools.ToolManager.activeToolChanged += ActiveToolChanged;
            EditorApplication.quitting                += EditorQuitting;
            GridPaintingState.brushChanged            += OnBrushChanged;
            GridPaintingState.scenePaintTargetChanged += OnScenePaintTargetChanged;
            GridSnapping.snapPosition = OnSnapPosition;
            GridSnapping.activeFunc   = GetActive;

            m_GridType = UnityType.FindTypeByName("Grid");

            m_RegisteredEventHandlers = true;
        }
예제 #5
0
        protected AdvancedDropdownItem RebuildTree()
        {
            m_SearchableElements = new List <AdvancedDropdownItem>();
            AdvancedDropdownItem root = new PresetTypeDropdownItem(L10n.Tr("Add Default Type"));

            var type        = UnityType.FindTypeByName("AssetImporter");
            var presetTypes = UnityType.GetTypes()
                              .Where(t => t.IsDerivedFrom(type) && !t.isAbstract)
                              .Select(t => new PresetType(t.persistentTypeID))
                              .Union(
                TypeCache.GetTypesDerivedFrom <ScriptedImporter>()
                .Where(t => !t.IsAbstract)
                .Select(t => new PresetType(t))
                )
                              .Distinct()
                              .Where(pt => pt.IsValidDefault());

            // Add Importers
            var importersRoot = new PresetTypeDropdownItem(L10n.Tr("Importer"));

            root.AddChild(importersRoot);
            foreach (var presetType in presetTypes)
            {
                var menuPath = presetType.GetManagedTypeName();
                var paths    = menuPath.Split('.').Last();
                var element  = new PresetTypeDropdownItem(paths, presetType);
                importersRoot.AddChild(element);
                m_SearchableElements.Add(element);
            }

            // Add Components
            var menuDictionary = GetMenuDictionary();

            menuDictionary.Sort(CompareItems);
            for (var i = 0; i < menuDictionary.Count; i++)
            {
                var menu = menuDictionary[i];
                if (menu.Value == "ADD")
                {
                    continue;
                }

                var menuPath = menu.Key;
                var paths    = menuPath.Split('/');

                var parent = root;
                for (var j = 0; j < paths.Length; j++)
                {
                    var path = paths[j];
                    if (j == paths.Length - 1)
                    {
                        var element = new PresetTypeDropdownItem(path, menu.Value);
                        parent.AddChild(element);
                        m_SearchableElements.Add(element);
                        continue;
                    }
                    var group = (PresetTypeDropdownItem)parent.children.SingleOrDefault(c => c.name == path);
                    if (group == null)
                    {
                        group = new PresetTypeDropdownItem(path);
                        parent.AddChild(group);
                    }
                    parent = group;
                }
            }

            // Add ScriptableObjects
            var scriptableObjectRoot = new PresetTypeDropdownItem(L10n.Tr("ScriptableObject"));

            root.AddChild(scriptableObjectRoot);
            foreach (var entry in GetScriptableObjectMenuItem())
            {
                var menuPath = entry.Item2;
                var paths    = menuPath.Split('/');

                AdvancedDropdownItem parent = scriptableObjectRoot;
                for (var j = 0; j < paths.Length; j++)
                {
                    var path = paths[j];
                    if (j == paths.Length - 1)
                    {
                        var presetType = new PresetType(entry.Item1);
                        var element    = new PresetTypeDropdownItem(path, presetType);
                        parent.AddChild(element);
                        m_SearchableElements.Add(element);
                        continue;
                    }
                    var group = parent.children.SingleOrDefault(c => c.name == path);
                    if (group == null)
                    {
                        group = new PresetTypeDropdownItem(path);
                        parent.AddChild(group);
                    }
                    parent = group;
                }
            }

            return(root);
        }
        public override bool ApplyRevert(bool apply)
        {
            if (apply)
            {
                if (containsMultipleSprites)
                {
                    var oldNames = new List <string>();
                    var newNames = new List <string>();

                    for (int i = 0; i < m_RectsCache.spriteRects.Count; i++)
                    {
                        SpriteRect spriteRect = (SpriteRect)m_RectsCache.spriteRects[i];

                        if (string.IsNullOrEmpty(spriteRect.name))
                        {
                            spriteRect.name = "Empty";
                        }

                        if (!string.IsNullOrEmpty(spriteRect.originalName))
                        {
                            oldNames.Add(spriteRect.originalName);
                            newNames.Add(spriteRect.name);
                        }
                    }
                    var so = new SerializedObject(m_SpriteDataProvider.targetObject);
                    if (oldNames.Count > 0)
                    {
                        AssetImporter assetImporter = m_SpriteDataProvider.targetObject as AssetImporter;

                        if (assetImporter != null)
                        {
                            UnityType spriteType = UnityType.FindTypeByName("Sprite");
                            assetImporter.RenameSubAssets(spriteType.persistentTypeID, oldNames.ToArray(), newNames.ToArray());
                        }
                    }

                    so.ApplyModifiedPropertiesWithoutUndo();
                }
                var array = m_RectsCache != null?m_RectsCache.spriteRects.ToArray() : null;

                m_SpriteDataProvider.SetSpriteRects(array);
                if (m_RectsCache != null)
                {
                    undoSystem.ClearUndo(m_RectsCache);
                }
            }
            else
            {
                if (m_RectsCache != null)
                {
                    undoSystem.ClearUndo(m_RectsCache);
                    m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList();
                    spriteEditor.spriteRects = m_RectsCache.spriteRects;
                    if (spriteEditor.selectedSpriteRect != null)
                    {
                        spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID);
                    }
                }
            }

            return(true);
        }