Beispiel #1
0
        /// <summary>
        /// Sorts the Material Remaps by names.
        /// </summary>
        /// <param name="syncPrefabImporter"></param>
        public static void SortRemaps(this SyncPrefabScriptedImporter syncPrefabImporter)
        {
            var so = new SerializedObject(syncPrefabImporter);

            var sourceRemaps = so.FindProperty("m_MaterialRemaps");
            var unsortedList = new List <string>();

            for (int i = 0; i < sourceRemaps.arraySize; i++)
            {
                SerializedProperty item = sourceRemaps.GetArrayElementAtIndex(i);
                unsortedList.Add(item.FindPropertyRelative("syncMaterialName").stringValue);
            }

            var sortedList = new List <string>(unsortedList);

            sortedList.Sort();

            for (int destinationIndex = 0; destinationIndex < sortedList.Count; destinationIndex++)
            {
                var sourceIndex = unsortedList.FindIndex(x => x == sortedList[destinationIndex]);
                sourceRemaps.MoveArrayElement(sourceIndex, destinationIndex);

                var item = unsortedList[sourceIndex];
                unsortedList.RemoveAt(sourceIndex);
                if (destinationIndex > sourceIndex)
                {
                    destinationIndex--;
                }
                unsortedList.Insert(destinationIndex, item);
            }

            so.ApplyModifiedProperties();
            syncPrefabImporter.SaveAndReimport();
        }
Beispiel #2
0
        /// <summary>
        /// Resets the Material Remaps.
        /// </summary>
        /// <param name="syncPrefabImporter"></param>
        public static void ResetRemaps(this SyncPrefabScriptedImporter syncPrefabImporter)
        {
            var so = new SerializedObject(syncPrefabImporter);

            var sourceRemaps = so.FindProperty("m_MaterialRemaps");

            for (int i = 0; i < sourceRemaps.arraySize; i++)
            {
                SerializedProperty item = sourceRemaps.GetArrayElementAtIndex(i);
                item.FindPropertyRelative("remappedMaterial").objectReferenceValue = null;
            }

            so.ApplyModifiedProperties();
            syncPrefabImporter.SaveAndReimport();
        }
Beispiel #3
0
        /// <summary>
        /// Assign a Dictionary of Material Remapping Names and Materials to Material Remaps
        /// </summary>
        /// <param name="syncPrefabImporter"></param>
        /// <param name="remaps"></param>
        public static void SetRemaps(this SyncPrefabScriptedImporter syncPrefabImporter, Dictionary <string, Material> remaps)
        {
            var so = new SerializedObject(syncPrefabImporter);

            var targetRemaps = so.FindProperty("m_MaterialRemaps");

            targetRemaps.arraySize = remaps.Count;

            var list = remaps.Keys.ToList();

            //list.Sort(); // FIXME : why does this screw up the importer ?

            for (int i = 0; i < list.Count; i++)
            {
                SerializedProperty item = targetRemaps.GetArrayElementAtIndex(i);
                item.FindPropertyRelative("syncMaterialName").stringValue          = list[i];
                item.FindPropertyRelative("remappedMaterial").objectReferenceValue = remaps[list[i]];
            }

            so.ApplyModifiedProperties();
            syncPrefabImporter.SaveAndReimport();
        }