private static PropInfo Clone(PropInfo prop, Flag modification, bool isWall) { var gameObject = GameObject.Find("MoreFlags") ?? new GameObject("MoreFlags"); var clone = Util.ClonePrefab(prop, prop.name + $"_{modification.id}", gameObject.transform); PrefabCollection<PropInfo>.InitializePrefabs("MoreFlags", new[] { clone }, null); clone.m_material = Object.Instantiate(prop.m_material); clone.m_material.name = prop.m_material.name + $"_{modification.id}"; clone.m_material.mainTexture = modification.texture; clone.m_lodMaterial = Object.Instantiate(prop.m_lodMaterial); clone.m_lodMaterial.name = prop.m_lodMaterial.name + $"_{modification.id}"; clone.m_lodMaterial.mainTexture = modification.textureLod; clone.m_placementStyle = ItemClass.Placement.Manual; clone.m_createRuining = false; clone.m_Atlas = _atlas; clone.m_InfoTooltipAtlas = _atlas; var thumb = isWall ? modification.thumbWall : modification.thumb; if (thumb != null) { clone.m_Thumbnail = thumb.name; clone.m_InfoTooltipThumbnail = thumb.name; } var locale = (Locale)LocaleField.GetValue(SingletonLite<LocaleManager>.instance); var key = new Locale.Key { m_Identifier = "PROPS_TITLE", m_Key = clone.name }; var versionStr = isWall ? "wall" : "ground"; var extendedDescription = modification.extendedDescripton == string.Empty ? modification.description : modification.extendedDescripton; if (!locale.Exists(key)) { locale.AddLocalizedString(key, $"{modification.description} ({versionStr} version)"); } key = new Locale.Key { m_Identifier = "PROPS_DESC", m_Key = clone.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, $"{extendedDescription} ({versionStr} version)"); } return clone; }
private static void Replace(PropInfo prop, Flag modification) { var material = prop.GetComponent<Renderer>().sharedMaterial; material.mainTexture = modification.texture; var lodMaterial = prop.m_lodObject.GetComponent<Renderer>().sharedMaterial; lodMaterial.mainTexture = modification.textureLod; }
private static PropInfo Clone(PropInfo prop, Flag modification, bool isWall) { var gameObject = GameObject.Find("MoreFlags") ?? new GameObject("MoreFlags"); var collection = gameObject.GetComponent<FlagsCollection>() ?? gameObject.AddComponent<FlagsCollection>(); var instance = Object.Instantiate(prop.gameObject); var clone = instance.GetComponent<PropInfo>(); var name = $"{prop.name}_{modification.id}"; clone.name = name; instance.name = name; instance.transform.parent = gameObject.transform; clone.GetComponent<Renderer>().material.mainTexture = modification.texture; clone.GetComponent<Renderer>().material.name = $"{prop.GetComponent<Renderer>().material.name}_{modification.id}"; // clone.m_lodObject = Object.Instantiate(prop.m_lodObject); // clone.m_lodObject.transform.parent = instance.transform; // clone.m_lodObject.name = prop.m_lodObject.name + $"_{modification.id}"; // var renderer = clone.m_lodObject.GetComponent<MeshRenderer>(); // Object.DestroyImmediate(renderer); // renderer = clone.m_lodObject.AddComponent<MeshRenderer>(); // renderer.material= new Material(prop.m_lodObject.GetComponent<Renderer>().sharedMaterial) // { // mainTexture = modification.textureLod, // name = $"{prop.m_lodObject.GetComponent<Renderer>().sharedMaterial.name}_{modification.id}" // }; clone.m_placementStyle = ItemClass.Placement.Manual; clone.m_createRuining = false; clone.m_Atlas = _atlas; clone.m_InfoTooltipAtlas = _atlas; var thumb = isWall ? modification.thumbWall : modification.thumb; if (thumb != null) { clone.m_Thumbnail = thumb.name; clone.m_InfoTooltipThumbnail = thumb.name; } PrefabCollection<PropInfo>.InitializePrefabs("MoreFlags", new[] { clone }, null); ApplyRenderDistanceHack(clone); AddLocale(modification, isWall, name); collection.flags.Add(clone); return clone; }
private static void AddLocale(Flag modification, bool isWall, string name) { var versionStr = isWall ? "wall" : "ground"; var extendedDescription = modification.extendedDescripton == string.Empty ? modification.description : modification.extendedDescripton; Util.AddLocale("PROPS", name, $"{modification.description} ({versionStr} version)", $"{extendedDescription} ({versionStr} version)"); }
public static List <Flag> CollectFlags(bool ignoreOptions) { var flagsList = (from flag in GetDefaultFlags(ignoreOptions) let id = flag[0] select new Flag { id = id, flagName = id, description = flag[1], extendedDescripton = flag[2], }).ToList(); try { var plugins = PluginManager.instance.GetPluginsInfo(); foreach (var plugin in plugins) { var instances = plugin.GetInstances <IUserMod>(); if (instances.Length != 1) { continue; } var instance = instances[0]; var methodInfo = instance.GetType().GetMethod("CustomFlags"); var customFlags = (string[][])methodInfo?.Invoke(instance, new object[] { }); if (customFlags == null) { continue; } foreach (var flag in customFlags) { if (flag.Length < 2) { continue; } var id = flag[0]; var flagInstance = new Flag { plugin = plugin, id = plugin.publishedFileID + "." + id, flagName = id, description = flag[1] }; if (flag.Length >= 3) { flagInstance.extendedDescripton = flag[2]; } flagsList.Add(flagInstance); } } } catch (Exception e) { Debug.LogException(e); } return(flagsList); }