private static void Replace(PropInfo prop, Flag modification) { var material = prop.GetComponent <Renderer>().material; material.mainTexture = modification.texture; var lodMaterial = prop.m_lodObject.GetComponent <Renderer>().material; lodMaterial.mainTexture = modification.textureLod; }
private static void SetupMainMaterial(PropInfo prop, Flag modification, PropInfo clone) { var renderer = clone.GetComponent <Renderer>(); var material = renderer.material; material.mainTexture = modification.texture; //TODO: is this needed at all? // material.SetTexture("_XYSMap", Util.CloneTexture(material, "_XYSMap")); // material.SetTexture("_ACIMap", Util.CloneTexture(material, "_ACIMap")); material.name = $"{prop.GetComponent<Renderer>().material.name}_{modification.id}"; }
/// <summary> /// Creates and instantiates a copy of a PropInfo /// </summary> public static PropInfo InstantiatePropCopy(PropInfo template) { if (template == null) { return(null); } PropInfo copyInfo = GameObject.Instantiate(template); copyInfo.name = template.name; copyInfo.gameObject.SetActive(false); // Create generated info copyInfo.m_generatedInfo = ScriptableObject.CreateInstance <PropInfoGen>(); copyInfo.m_generatedInfo.name = copyInfo.name; copyInfo.m_generatedInfo.m_propInfo = copyInfo; copyInfo.CalculateGeneratedInfo(); // Create LOD object if (template.m_lodObject != null) { GameObject copyLod = GameObject.Instantiate(template.m_lodObject); copyLod.SetActive(false); // Set sharedmaterial Renderer lodRenderer = copyLod.GetComponent <Renderer>(); if (lodRenderer != null) { lodRenderer.sharedMaterial = lodRenderer.material; } copyInfo.m_lodObject = copyLod; } // Set sharedmaterial Renderer r = copyInfo.GetComponent <Renderer>(); if (r != null) { r.sharedMaterial = r.material; } copyInfo.InitializePrefab(); copyInfo.m_prefabInitialized = true; return(copyInfo); }
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 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; }