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);
            }
        }
    // Rename multiple entries at once to avoid situations where swapping names of two entries would break references
    static public void RenameMultiple(SerializedObject serializedObject, UnityType type, string[] oldNames, string[] newNames)
    {
        int classID = type.persistentTypeID;

        int left = oldNames.Length;

        SerializedProperty recycleMap = serializedObject.FindProperty("m_InternalIDToNameTable");

        foreach (SerializedProperty element in recycleMap)
        {
            SerializedProperty first = element.FindPropertyRelative("first");
            SerializedProperty cid   = first.FindPropertyRelative("first");
            if (cid.intValue == classID)
            {
                SerializedProperty second = element.FindPropertyRelative("second");
                int idx = Array.IndexOf(oldNames, second.stringValue);
                if (idx >= 0)
                {
                    second.stringValue = newNames[idx];
                    if (--left == 0)
                    {
                        break;
                    }
                }
            }
        }
    }
    static public void RegisterInternalID(SerializedObject serializedObject, UnityType type, ICollection <long> ids, ICollection <string> names)
    {
        if (ids.Count != names.Count)
        {
            return;
        }

        SerializedProperty internalIDMap = serializedObject.FindProperty("m_InternalIDToNameTable");
        var startIdx = internalIDMap.arraySize;

        internalIDMap.arraySize += ids.Count;
        var id = ids.GetEnumerator();

        id.Reset(); id.MoveNext();
        var name = names.GetEnumerator();

        name.Reset(); name.MoveNext();
        if (internalIDMap.arraySize > 0)
        {
            SerializedProperty newEntry = internalIDMap.GetArrayElementAtIndex(startIdx);
            for (int i = 0; i < ids.Count; ++i, id.MoveNext(), name.MoveNext())
            {
                SerializedProperty first = newEntry.FindPropertyRelative("first");
                SerializedProperty cid   = first.FindPropertyRelative("first");
                SerializedProperty lid   = first.FindPropertyRelative("second");
                cid.intValue  = type.persistentTypeID;
                lid.longValue = id.Current;
                SerializedProperty sname = newEntry.FindPropertyRelative("second");
                sname.stringValue = name.Current;
                newEntry.Next(false);
            }
        }
    }
예제 #4
0
 public UnityType CreateOrEditUnityType(UnityType unityType)
 {
     if (unityType.UnityTypeId == 0)
     {
         return(CreateUnityType(unityType));
     }
     return(UpdateUnityType(unityType));
 }
예제 #5
0
 public bool Matches(Object asset, string fullAssetName)
 {
     if (asset == null || !UnityType.IsInstanceOfType(asset))
     {
         return(false);
     }
     return(Extensions == null || Extensions.Length == 0 ||
            Extensions.Any(x => fullAssetName.EndsWith(x, StringComparison.OrdinalIgnoreCase)));
 }
        public ActionResult CreateOrEdit(UnityType unityType)
        {
            if (this.ModelState.IsValid)
            {
                unityType = unityTypeService.CreateOrEditUnityType(unityType);
                return(RedirectToAction("Index"));
            }

            return(View("Form", unityType));
        }
        public UnityType GetById(int unityTypeId)
        {
            var unityType = context.UnityType.Find(unityTypeId);

            if (unityType == null)
            {
                unityType = new UnityType();
            }
            return(unityType);
        }
    static public long MakeInternalID(SerializedObject serializedObject, UnityType type, string name)
    {
        long id = ImportSettingInternalID.FindInternalID(serializedObject, type, name);

        if (id == 0L)
        {
            id = AssetImporter.MakeLocalFileIDWithHash(type.persistentTypeID, name, 0);
            RegisterInternalID(serializedObject, type, id, name);
        }
        return(id);
    }
예제 #9
0
 // Constructor.
 public UnitySerializationHolder(SerializationInfo info,
                                 StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     type     = (UnityType)(info.GetInt32("UnityType"));
     data     = info.GetString("Data");
     assembly = info.GetString("AssemblyName");
 }
	// Constructor.
	public UnitySerializationHolder(SerializationInfo info,
									StreamingContext context)
			{
				if(info == null)
				{
					throw new ArgumentNullException("info");
				}
				type = (UnityType)(info.GetInt32("UnityType"));
				data = info.GetString("Data");
				assembly = info.GetString("AssemblyName");
			}
예제 #11
0
        private static void AddSimpleFoodToMeal(string name, decimal quantity, UnityType unityType, Meal meal, ProductContext productContext)
        {
            Food simpleFood = new Food {
                Name = name, NumberOfPeople = 90
            };

            simpleFood.Ingredients = new List <Ingredient>();
            simpleFood.Ingredients.Add(new Ingredient {
                Product = productContext.Product.FirstOrDefault(p => p.Name == name), Quantity = quantity, UnityType = unityType
            });
            meal.MealFoods.Add(new MealFood {
                Meal = meal, Food = simpleFood
            });
        }
예제 #12
0
        static List <EditorToLinkerData.NativeTypeData> CollectNativeTypeData()
        {
            var items = new List <EditorToLinkerData.NativeTypeData>();

            foreach (var unityType in UnityType.GetTypes())
            {
                items.Add(new EditorToLinkerData.NativeTypeData
                {
                    name   = unityType.name,
                    module = unityType.module
                });
            }

            return(items);
        }
예제 #13
0
 // Serialize a unity object.
 public static void Serialize(SerializationInfo info, UnityType type,
                              String data, Assembly assembly)
 {
     info.SetType(typeof(UnitySerializationHolder));
     info.AddValue("data", data);
     info.AddValue("UnityType", (int)type);
     if (assembly != null)
     {
         info.AddValue("AssemblyName", assembly.FullName);
     }
     else
     {
         info.AddValue("AssemblyName", String.Empty);
     }
 }
	// Serialize a unity object.
	public static void Serialize(SerializationInfo info, UnityType type,
								 String data, Assembly assembly)
			{
				info.SetType(typeof(UnitySerializationHolder));
				info.AddValue("data", data);
				info.AddValue("UnityType", (int)type);
				if(assembly != null)
				{
					info.AddValue("AssemblyName", assembly.FullName);
				}
				else
				{
					info.AddValue("AssemblyName", String.Empty);
				}
			}
    static public void RegisterInternalID(SerializedObject serializedObject, UnityType type, long id, string name)
    {
        SerializedProperty internalIDMap = serializedObject.FindProperty("m_InternalIDToNameTable");

        internalIDMap.arraySize++;
        SerializedProperty newEntry = internalIDMap.GetArrayElementAtIndex(internalIDMap.arraySize - 1);
        SerializedProperty first    = newEntry.FindPropertyRelative("first");
        SerializedProperty cid      = first.FindPropertyRelative("first");
        SerializedProperty lid      = first.FindPropertyRelative("second");

        cid.intValue  = type.persistentTypeID;
        lid.longValue = id;
        SerializedProperty sname = newEntry.FindPropertyRelative("second");

        sname.stringValue = name;
    }
예제 #16
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");
                            }
                        }
                    }
                }
            }
        }
예제 #17
0
        static List <EditorToLinkerData.NativeTypeData> CollectNativeTypeData()
        {
            var items = new List <EditorToLinkerData.NativeTypeData>();

            foreach (var unityType in UnityType.GetTypes())
            {
                items.Add(new EditorToLinkerData.NativeTypeData
                {
                    name       = unityType.name,
                    module     = unityType.module,
                    baseName   = unityType.baseClass != null ? unityType.baseClass.name : null,
                    baseModule = unityType.baseClass != null ? unityType.baseClass.module : null,
                });
            }

            return(items);
        }
예제 #18
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;
        }
    static public long FindInternalID(SerializedObject serializedObject, UnityType type, string name)
    {
        long id = 0;
        SerializedProperty internalIDMap = serializedObject.FindProperty("m_InternalIDToNameTable");

        foreach (SerializedProperty element in internalIDMap)
        {
            SerializedProperty first = element.FindPropertyRelative("first");
            SerializedProperty cid   = first.FindPropertyRelative("first");
            if (cid.intValue == type.persistentTypeID)
            {
                SerializedProperty second = element.FindPropertyRelative("second");
                if (second.stringValue == name)
                {
                    SerializedProperty lid = first.FindPropertyRelative("second");
                    id = lid.longValue;
                    return(id);
                }
            }
        }

        return(id);
    }
 public UnityType Create(UnityType unityType)
 {
     context.Add(unityType);
     context.SaveChanges();
     return(unityType);
 }
 static public void Rename(SerializedObject serializedObject, UnityType type, string oldName, string newName)
 {
     RenameMultiple(serializedObject, type, new string[] { oldName }, new string[] { newName });
 }
예제 #23
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);
        }
    static public bool RemoveEntryFromInternalIDTable(SerializedObject serializedObject, UnityType type, long id,
                                                      string name)
    {
        int classID = type.persistentTypeID;
        SerializedProperty internalIDMap = serializedObject.FindProperty("m_InternalIDToNameTable");
        bool found = false;
        int  index = 0;

        foreach (SerializedProperty element in internalIDMap)
        {
            SerializedProperty first = element.FindPropertyRelative("first");
            SerializedProperty cid   = first.FindPropertyRelative("first");
            if (cid.intValue == classID)
            {
                SerializedProperty second    = element.FindPropertyRelative("second");
                SerializedProperty lid       = first.FindPropertyRelative("second");
                string             foundName = second.stringValue;
                long localid = lid.longValue;

                if (foundName == name && localid == id)
                {
                    found = true;
                    internalIDMap.DeleteArrayElementAtIndex(index);
                    return(found);
                }
            }

            index++;
        }
        return(found);
    }
예제 #25
0
 UnitySerializationHolder(SerializationInfo info, StreamingContext ctx)
 {
     _data         = info.GetString("Data");
     _unityType    = (UnityType)info.GetInt32("UnityType");
     _assemblyName = info.GetString("AssemblyName");
 }
 public UnityType Update(UnityType unityType)
 {
     context.Update(unityType);
     context.SaveChanges();
     return(unityType);
 }
 public void Delete(UnityType unityType)
 {
     context.Remove(unityType);
     context.SaveChanges();
 }
        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);
        }
예제 #29
0
		UnitySerializationHolder (SerializationInfo info, StreamingContext ctx)
		{
			_data = info.GetString ("Data");
			_unityType = (UnityType) info.GetInt32 ("UnityType");
			_assemblyName = info.GetString ("AssemblyName");
		}
예제 #30
0
 public static UnityType[] GetModuleTypes(string moduleName)
 {
     int[] moduleClasses = ModuleMetadata.GetModuleClasses(moduleName);
     return((from id in moduleClasses
             select UnityType.FindTypeByPersistentTypeID(id)).ToArray <UnityType>());
 }
예제 #31
0
 private UnityType CreateUnityType(UnityType unityType)
 {
     return(unityTypeRepository.Create(unityType));
 }
예제 #32
0
 private UnityType UpdateUnityType(UnityType unityType)
 {
     return(unityTypeRepository.Update(unityType));;
 }
 protected void AddNativeClassFromName(string className)
 {
     if (this.objectUnityType == null)
     {
         this.objectUnityType = UnityType.FindTypeByName("Object");
     }
     UnityType type = UnityType.FindTypeByName(className);
     if ((type != null) && (type.persistentTypeID != this.objectUnityType.persistentTypeID))
     {
         this.nativeClasses[type.persistentTypeID] = className;
     }
 }