/// <summary> /// Upgrades basic brush (v1.x) into an oriented brush (v2.x). /// </summary> /// <remarks> /// <para>The concept of basic brushes was removed in v2.x of Rotorz Tile System. /// Instead the default orientation of an oriented brush can be used.</para> /// </remarks> /// <param name="record">Record for existing v1.x brush.</param> private void UpgradeBasicBrush(RtsBrushAssetRecordWrapper record) { // We need to take a copy of the original brush because that is the // tile prefab, but we'll remove the original brush component. GameObject tilePrefabCopyGO = PrefabUtility.InstantiatePrefab(record.brush.gameObject) as GameObject; GameObject newTilePrefab = null; try { Object.DestroyImmediate(tilePrefabCopyGO.GetComponent(_tyTileBrush)); // Create a new prefab for this prefab. newTilePrefab = PrefabUtility.CreatePrefab(GetUniqueMigratedPath(record.displayName + ".prefab"), tilePrefabCopyGO); } finally { // Destroy the temporary copy. Object.DestroyImmediate(tilePrefabCopyGO); } if (newTilePrefab == null) { Debug.LogError(string.Format("An error occurred whilst upgrading brush '{0}' of type '{1}'.", record.displayName, record.brush.GetType().FullName)); return; } // Basic brushes will now become oriented brushes! OrientedBrush newBrush = BrushUtility.CreateOrientedBrush(record.displayName); newBrush.DefaultOrientation.variations = new Object[] { newTilePrefab }; if (_fiTileBrush_coalesce != null) { newBrush.Coalesce = (Coalesce)_fiTileBrush_coalesce.GetValue(record.brush); } if (_fiTileBrush_coalesceTileGroup != null) { newBrush.CoalesceBrushGroup = (int)_fiTileBrush_coalesceTileGroup.GetValue(record.brush); } FinalizeStandaloneBrush(record, newBrush); // Do not override tag and layer by default. newBrush.overrideTag = false; newBrush.overrideLayer = false; }
/// <summary> /// Upgrades oriented brush (v1.x) into an oriented brush (v2.x). /// </summary> /// <param name="record">Record for existing v1.x brush.</param> private void UpgradeOrientedBrush(RtsBrushAssetRecordWrapper record) { if (useNewAssets) { // Is this the original "Smooth Platform" master brushes? if (record.assetPath == "Assets/Rotorz Tile System/Brushes/Smooth Platform.prefab" || record.assetPath == "Assets/Rotorz Tile System/Brushes/Smooth Platform (Join).prefab" || record.assetPath == "Assets/Rotorz Tile System/Brushes/Smooth Platform (Small).prefab") { // This is a special case that can be switched to new version // if it was imported. OrientedBrush newMasterBrush = AssetDatabase.LoadAssetAtPath("Assets/Rotorz/Tile System/TileBrushes/Master/" + record.displayName + ".brush.asset", typeof(OrientedBrush)) as OrientedBrush; if (newMasterBrush != null) { RtsUpgradedBrushMap.BrushMappings.SetMapping(record.brush, newMasterBrush); return; } // If new version was not found then just proceed to upgrade // existing version. } // Is this one of the original demo brushes? else if (record.assetPath == "Assets/Rotorz Tile System/_Demos/TilePrefabs/Diamond.prefab" || record.assetPath == "Assets/Rotorz Tile System/_Demos/TilePrefabs/Hat Guy.prefab" || record.assetPath == "Assets/Rotorz Tile System/_Demos/TilePrefabs/Steel Brick.prefab") { // This is a special case that can be switched to new version // if it was imported. OrientedBrush newDemoBrush = AssetDatabase.LoadAssetAtPath("Assets/Rotorz/Tile System/Demo/Hat Guy/TileBrushes/" + record.displayName + ".brush.asset", typeof(OrientedBrush)) as OrientedBrush; if (newDemoBrush != null) { RtsUpgradedBrushMap.BrushMappings.SetMapping(record.brush, newDemoBrush); return; } // If new version was not found then just proceed to upgrade // existing version. } } Transform oldBrushTransform = record.brush.transform; OrientedBrush newBrush = BrushUtility.CreateOrientedBrush(record.displayName); newBrush.RemoveOrientation(newBrush.DefaultOrientationMask); List <Object> variations = new List <Object>(); RtsUpgradedBrushMap map = RtsUpgradedBrushMap.BrushMappings; // Copy orientations from old brush. for (int ti = 0; ti < oldBrushTransform.childCount; ++ti) { MonoBehaviour oldOrientation = oldBrushTransform.GetChild(ti).GetComponent(_tyTileBrushOrientation) as MonoBehaviour; if (oldOrientation == null) { continue; } Object[] oldVariations = (Object[])_fiTileBrushOrientation_variations.GetValue(oldOrientation); BrushOrientation newOrientation = newBrush.AddOrientation(OrientationUtility.MaskFromName(oldOrientation.name)); variations.Clear(); for (int i = 0; i < oldVariations.Length; ++i) { if (oldVariations[i] == null) { continue; } Type variationType = oldVariations[i].GetType(); GameObject variationGO = oldVariations[i] as GameObject; Object variationBrush = null; // If game object is nested, check if it is a tile brush prefab! if (variationGO != null) { variationBrush = variationGO.GetComponent(_tyTileBrush); } // If variation is a tile brush then... else if (_tyTileBrush.IsAssignableFrom(variationType)) { variationBrush = oldVariations[i]; } // Need to isolate nested brushes! if (variationBrush != null) { // Note: This only works because oriented brushes are processed last, // and it is not possible to nest oriented brushes. // Use new version of brush! Brush replacementBrush = map.Lookup(variationBrush); if (replacementBrush != null) { variations.Add(replacementBrush); } } else if (variationGO != null) { variations.Add(variationGO); } } newOrientation.variations = variations.ToArray(); } newBrush.DefaultOrientationMask = OrientationUtility.MaskFromName((string)_fiOrientedTileBrush_defaultOrientation.GetValue(record.brush)); newBrush.FallbackMode = (FallbackMode)_fiOrientedTileBrush_fallbackMode.GetValue(record.brush); if (_fiTileBrush_coalesce != null) { newBrush.Coalesce = (Coalesce)_fiTileBrush_coalesce.GetValue(record.brush); } if (_fiTileBrush_coalesceTileGroup != null) { newBrush.CoalesceBrushGroup = (int)_fiTileBrush_coalesceTileGroup.GetValue(record.brush); } if (_fiOrientedTileBrush_forceOverrideFlags != null) { newBrush.forceOverrideFlags = (bool)_fiOrientedTileBrush_forceOverrideFlags.GetValue(record.brush); } FinalizeStandaloneBrush(record, newBrush); }