generated from max/template-unity-project
	- Object and prefab file id loading - Generate grid update - Switched uint to long but should probably be ulong!
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Collections.Generic;
 | 
						|
using System.IO;
 | 
						|
using System.Text.RegularExpressions;
 | 
						|
 | 
						|
namespace VertexColor.ScenePartition
 | 
						|
{
 | 
						|
    public class SceneIdComparer : IComparer<ScenePartition>
 | 
						|
    {
 | 
						|
        public int Compare(ScenePartition x, ScenePartition y)
 | 
						|
        {
 | 
						|
            if (x.id == y.id)
 | 
						|
            {
 | 
						|
                return 0;
 | 
						|
            }
 | 
						|
            if (x.id < y.id)
 | 
						|
            {
 | 
						|
                return -1;
 | 
						|
            }
 | 
						|
 | 
						|
            return 1;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    [System.Serializable]
 | 
						|
    public class ScenePartition
 | 
						|
    {
 | 
						|
        public long id = 0;
 | 
						|
        //public long classId = 0;
 | 
						|
        public string filePath = null;
 | 
						|
        //public string[] data = null;
 | 
						|
        public LongSortedSet references = new LongSortedSet();
 | 
						|
 | 
						|
        public ScenePartition(string filePath)
 | 
						|
        {
 | 
						|
            this.filePath = filePath;
 | 
						|
 | 
						|
            string[] data = File.ReadAllLines(filePath);
 | 
						|
 | 
						|
            if (data == null || data.Length == 0) return;
 | 
						|
 | 
						|
            {   // Get id.
 | 
						|
                string pattern = @"&(\d+)";
 | 
						|
 | 
						|
                // Find all matches using regex
 | 
						|
                Match match = Regex.Match(data[0], pattern);
 | 
						|
 | 
						|
                if (!match.Success) return;
 | 
						|
                if (!long.TryParse(match.Groups[1].Value, out id)) return;
 | 
						|
            }
 | 
						|
 | 
						|
            //{   // Get class id.
 | 
						|
            //    string pattern = @"!u!(\d+)";
 | 
						|
 | 
						|
            //    // Find all matches using regex
 | 
						|
            //    Match match = Regex.Match(data[0], pattern);
 | 
						|
 | 
						|
            //    if (!match.Success) return;
 | 
						|
            //    if (!long.TryParse(match.Groups[1].Value, out classId)) return;
 | 
						|
            //}
 | 
						|
 | 
						|
            {   // Get references.
 | 
						|
                string pattern = @"fileID:\s(\d+)";
 | 
						|
 | 
						|
                for (int i = 0; i < data.Length; i++)
 | 
						|
                {
 | 
						|
                    // Find the match using regex
 | 
						|
                    Match match = Regex.Match(data[i], pattern);
 | 
						|
 | 
						|
                    if (!match.Success) continue;
 | 
						|
 | 
						|
                    if (long.TryParse(match.Groups[1].Value, out long fileNumber))
 | 
						|
                    {
 | 
						|
                        if (fileNumber == 0) continue; // 0 == nothing.
 | 
						|
 | 
						|
                        references.Add(fileNumber);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |