public override bool Equals(object obj)
        {
            if (!(obj is NameClashKey))
            {
                return(false);
            }
            NameClashKey other = (NameClashKey)obj;

            return((name == other.name) && (parentId == other.parentId));
        }
Exemple #2
0
        public void fixNameClashes()
        {
            var nameClashes = new Dictionary <NameClashKey, List <ResId> >();

            for (int i = 0; i < objects.Count; i++)
            {
                var cur    = objects[i];
                var key    = new NameClashKey(cur.name, cur.parent);
                var idList = nameClashes.getValOrGenerate(key, (parId_) => new List <ResId>());
                idList.Add(cur.id);
            }

            foreach (var entry in nameClashes)
            {
                var key  = entry.Key;
                var list = entry.Value;
                if ((list == null) || (list.Count <= 1))
                {
                    continue;
                }

                for (int i = 1; i < list.Count; i++)
                {
                    var curId = list[i];
                    //if ((curId <= 0) || (curId >= objects.Count)){
                    if (!curId.isValid || (curId.objectIndex > objects.Count))
                    {
                        Debug.LogErrorFormat("Invalid object id {0}, while processing name clash {1};\"{2}\"",
                                             curId, key.parentId, key.name);
                        continue;
                    }

                    var curObj  = objects[curId.objectIndex];
                    var altName = string.Format("{0}-#{1}", key.name, i);
                    while (nameClashes.ContainsKey(new NameClashKey(altName, key.parentId)))
                    {
                        altName = string.Format("{0}-#{1}({2})",
                                                key.name, i, System.Guid.NewGuid().ToString("n"));
                        //break;
                    }
                    curObj.nameClash  = true;
                    curObj.uniqueName = altName;
                }
            }
        }