public void generate(List <AreaSet> areaSet) { buildings = PrefabLoader.LoadAllPrefabs("Assets/Resources/Prefab/Building"); buildings.Sort(SortBySize); /* clipping regions * Rect centralPart1 = new Rect(0, -200, 20, 400); * Rect centralPart2 = new Rect(-300, -300, 80, 600); * Rect centralPart3 = new Rect(250, -300, 80, 600); */ for (int i = 0; i < areaSet.Count; i++) { /* clipping regions * if ((areaSet[i].region.Overlaps(centralPart1) || areaSet[i].region.Overlaps(centralPart2) || areaSet[i].region.Overlaps(centralPart3))) * continue; */ // first we build buildings for each four corner List <GameObject> buildingOnArea = new List <GameObject>(); createABuilding(areaSet[i].region, ref buildingOnArea, AreaPosition.NW); createABuilding(areaSet[i].region, ref buildingOnArea, AreaPosition.NE); createABuilding(areaSet[i].region, ref buildingOnArea, AreaPosition.SE); createABuilding(areaSet[i].region, ref buildingOnArea, AreaPosition.SW); // then build other buidings between the corner buildings createBtwBuilding(buildingOnArea[0], buildingOnArea[1], areaSet[i].region, ref buildingOnArea, AbsDirection.N); createBtwBuilding(buildingOnArea[1], buildingOnArea[2], areaSet[i].region, ref buildingOnArea, AbsDirection.E); createBtwBuilding(buildingOnArea[0], buildingOnArea[3], areaSet[i].region, ref buildingOnArea, AbsDirection.W); createBtwBuilding(buildingOnArea[3], buildingOnArea[2], areaSet[i].region, ref buildingOnArea, AbsDirection.S); } }
public static void ProcessAllPrefabs() { int languageIndex = GetEnglishLanguageIndex(); if (languageIndex == -1) { return; } List <GameObject> allPrefabs = PrefabLoader.LoadAllPrefabs("Assets/Prefabs"); foreach (GameObject prefab in allPrefabs) { MonoBehaviour[] monoBehaviours = prefab.GetComponentsInChildren <MonoBehaviour>(); foreach (MonoBehaviour mb in monoBehaviours) { if (mb == null) { Debug.Log(prefab.name + " referencing dead component", prefab); continue; } string chunks = string.Empty; SerializedObject mbSO = new SerializedObject(mb); SerializedProperty propIter = mbSO.GetIterator(); propIter.Next(true); bool anyChanged = false; while (propIter.Next(true)) { if (propIter.type == typeof(DialogueChunk).ToString() && propIter.isArray) { for (int j = 0; j < propIter.arraySize; j++) { SerializedProperty chunkProp = propIter.GetArrayElementAtIndex(j); SerializedProperty dialogueTermProp = chunkProp.FindPropertyRelative("dialogueTerm"); string displayPropPath = chunkProp.propertyPath .Replace("_", "") .Replace(".Array.data", "") .Replace("[", "-") .Replace("]", ""); displayPropPath = char.ToUpper(displayPropPath[0]) + displayPropPath.Substring(1); string termName = string.Format("Dialogue/{0}_{1}", prefab.name, displayPropPath); TermData termData = LocalizationManager.GetTermData(termName); if (termData == null) { termData = LocalizationManager.Sources[0].AddTerm(termName); chunks += termName + "\n"; } string prevTranslation = termData.GetTranslation(languageIndex); string newTranslation = chunkProp.FindPropertyRelative("dialogue").stringValue; if (prevTranslation == string.Empty || newTranslation != prevTranslation || dialogueTermProp.stringValue != termName) { termData.SetTranslation(languageIndex, newTranslation); dialogueTermProp.stringValue = termName; anyChanged = true; } } } } if (anyChanged) { mbSO.ApplyModifiedProperties(); EditorUtility.SetDirty(LocalizationManager.Sources[0]); } if (chunks != string.Empty) { Debug.Log(prefab.name + ":\n" + chunks); } } } AssetDatabase.SaveAssets(); }
public static void FixBrokenTermPopups() { // Iterate over all prefabs, find TermPopup attributed properties, check if valid term, if not try to fix by adding category int languageIndex = GetEnglishLanguageIndex(); if (languageIndex == -1) { return; } string fixedProperties = string.Empty; List <GameObject> allPrefabs = PrefabLoader.LoadAllPrefabs("Assets/Prefabs"); foreach (GameObject prefab in allPrefabs) { MonoBehaviour[] monoBehaviours = prefab.GetComponentsInChildren <MonoBehaviour>(); foreach (MonoBehaviour mb in monoBehaviours) { if (mb == null) { Debug.Log(prefab.name + " referencing dead component", prefab); continue; } SerializedObject mbSO = new SerializedObject(mb); bool anyChanged = false; FieldInfo[] fieldInfos = mb.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fieldInfos) { object[] attributes = fieldInfo.GetCustomAttributes(true); foreach (object attribute in attributes) { TermsPopup termsPopup = attribute as TermsPopup; if (termsPopup != null) { SerializedProperty termProp = mbSO.FindProperty(fieldInfo.Name); string termName = termProp.stringValue; TermData termData = LocalizationManager.GetTermData(termName); if (termData == null) { foreach (var kvp in LocalizationManager.Sources[0].mDictionary) { if (kvp.Value.IsTerm(termName, true)) { termData = kvp.Value; termProp.stringValue = termData.Term; fixedProperties += termProp.propertyPath + "\n"; anyChanged = true; break; } } break; } } } } if (anyChanged) { mbSO.ApplyModifiedProperties(); } } } if (fixedProperties != string.Empty) { Debug.Log("Fixed Properties:\n" + fixedProperties); AssetDatabase.SaveAssets(); } }