internal static void PatchSceneDecals() { GameObject[] rObjs = RCUtils.GetRootObjects().ToArray(); foreach (GameObject rootObj in rObjs) { MeshRenderer childRenderer = rootObj.GetComponent <MeshRenderer>(); MeshRenderer[] allRenderers = rootObj.GetComponentsInChildren <MeshRenderer>(); allRenderers.Add(childRenderer); foreach (MeshRenderer renderer in allRenderers) { if (renderer.gameObject.name.ToLower().Contains("decal-")) { renderer.receiveShadows = true; qd_Decal decal = renderer.GetComponent <qd_Decal>(); if (decal != null && (decal.texture.name.StartsWith("FX_DebrisPaper") || decal.texture.name.StartsWith("FX_DebrisMail") || decal.texture.name.StartsWith("FX_DebriPaper"))) { BreakDownDefinition bdDef = new BreakDownDefinition { filter = "Paper", minutesToHarvest = 1f, sound = "Paper" }; PrepareGameObject(renderer.gameObject, bdDef); } continue; } } } //BreakDown.DeserializeAllAdditive(sceneBreakDownData); }
public override SearchResult Filter(GameObject gameObject) { if (!gameObject.activeInHierarchy || gameObject.layer == vp_Layer.Gear) { return(SearchResult.SKIP_CHILDREN); } if (gameObject.name.StartsWith("OBJ_PaperDebris") || gameObject.name.StartsWith("OBJ_PaperDeco") || gameObject.name.StartsWith("OBJ_WallDecoPatterned") || gameObject.name.StartsWith("OBJ_CalendarDeco")) { return(SearchResult.INCLUDE_SKIP_CHILDREN); } qd_Decal decal = gameObject.GetComponent <qd_Decal>(); if (decal) { if (decal.texture.name.StartsWith("FX_DebrisPaper") || decal.texture.name.StartsWith("FX_DebrisMail")) { return(SearchResult.INCLUDE_SKIP_CHILDREN); } } return(SearchResult.CONTINUE); }
void OnSceneGUI(SceneView sceneView) { Event e = Event.current; #if UNITY_STANDALONE_OSX EventModifiers em = e.modifiers; // Took me longer than I care to admit to figure out that the `&=` was eating the event. if ((em &= EventModifiers.Shift) != EventModifiers.Shift) { return; } int controlID = EditorGUIUtility.GetControlID(FocusType.Passive); HandleUtility.AddDefaultControl(controlID); #endif #if UNITY_STANDALONE_OSX if (e.type == EventType.MouseUp && ((e.button == RIGHT_MOUSE_BUTTON && e.modifiers == EventModifiers.Shift) || (e.modifiers == (EventModifiers.Shift | EventModifiers.Control)))) #else if (e.type == EventType.MouseUp && e.button == RIGHT_MOUSE_BUTTON && e.modifiers == EventModifiers.Shift) #endif { if (selected.Count < 1 || decalView == DecalView.Atlas) { return; } int key = selected.Keys.ToList()[(int)Random.Range(0, selected.Count)]; if (selected[key].Count < 1) { return; } int val = (int)Random.Range(0, selected[key].Count); int grpIndex = key; int texIndex = selected[key][val]; Material mat = decalGroups[grpIndex].isPacked ? decalGroups[grpIndex].material : null; Decal decal = decalGroups[grpIndex].decals[texIndex]; Rect r = decalGroups[grpIndex].isPacked ? decal.atlasRect : new Rect(0f, 0f, 1f, 1f); Texture2D tex = decal.texture; if (mat == null) { GameObject[] existingDecals = qdUtil.FindDecalsWithTexture(tex); if (existingDecals == null || existingDecals.Length < 1) { mat = new Material(decalGroups[grpIndex].shader); mat.mainTexture = tex; } else { mat = existingDecals[0].GetComponent <MeshRenderer>().sharedMaterial; } } GameObject decalGo; if (PlaceDecal(e.mousePosition, mat, r, decal.rotationPlacement == Placement.Random ? Random.Range(decal.rotation.x, decal.rotation.y) : decal.rotation.z, decal.scalePlacement == Placement.Random ? Random.Range(decal.scale.x, decal.scale.y) : decal.scale.z, out decalGo)) { decalGo.transform.parent = DecalParent.transform; Selection.objects = new Object[1] { decalGo }; SceneView.RepaintAll(); qd_Decal decalComponent = decalGo.AddComponent <qd_Decal>(); decalComponent.SetTexture(tex); decalComponent.SetUVRect(r); // DO NOT USE THE EVENT // unitay needs shift clicks to register in order // to release the view mode shortcut } } }
/****** SCENE *****/ internal static void PrepareSceneShadows() { GameObject[] rObjs = ALUtils.GetRootObjects().ToArray(); foreach (GameObject rootObj in rObjs) { MeshRenderer childRenderer = rootObj.GetComponent <MeshRenderer>(); MeshRenderer[] allRenderers = rootObj.GetComponentsInChildren <MeshRenderer>(); //allRenderers.Add(childRenderer); allRenderers.AddItem(childRenderer); foreach (MeshRenderer renderer in allRenderers) { //Remove glass from sun layer Material[] mats = renderer.materials; foreach (Material mat in mats) { if (mat.name.ToLower().Contains("glass")) { renderer.gameObject.layer = 7; continue; } } //Ignore if (renderer == null || renderer.gameObject.name.Contains("XPZ_Wall") || renderer.gameObject.name.Contains("XPZ_BaseWindow") || (renderer.gameObject.name.StartsWith("OBJ_") && !renderer.gameObject.name.ToLower().Contains("door") && !renderer.gameObject.name.ToLower().Contains("curtain") && !renderer.gameObject.name.ToLower().Contains("car")) || renderer.gameObject.name.StartsWith("GEAR_") || renderer.gameObject.name.StartsWith("FX_") || renderer.gameObject.name.StartsWith("CONTAINER_") || renderer.gameObject.name.StartsWith("INTERACTIVE_") ) { continue; } //Hide if (renderer.gameObject.name.ToLower().Contains("shadow_caster") || (renderer.gameObject.name.ToLower().Contains("cylinder") && !renderer.material.name.StartsWith("FX_")) || renderer.gameObject.name.ToLower().Contains("sphere") ) { renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; renderer.gameObject.SetActive(false); continue; } //Glass-Glow if ((renderer.gameObject.name.ToLower().Contains("glass") || renderer.gameObject.name.ToLower().Contains("glow")) && (!renderer.gameObject.name.ToLower().Contains("shadow") && !renderer.gameObject.name.ToLower().Contains("truck") && !renderer.gameObject.name.ToLower().Contains("car") && !renderer.gameObject.name.ToLower().Contains("xpz_window"))) { renderer.gameObject.name += "_XPZ_BaseWindow"; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; continue; } else if (renderer.gameObject.name.ToLower().Contains("glow") && renderer.gameObject.name.ToLower().Contains("shadow")) { renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; renderer.gameObject.SetActive(false); continue; } if (renderer.gameObject.name.ToLower().Contains("decal")) { renderer.receiveShadows = true; qd_Decal decalInst = renderer.GetComponent <qd_Decal>(); vp_Layer.Set(renderer.gameObject, 7, false); continue; } //Rest - Cast shadows if not transparent if (renderer.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.Off || renderer.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.On) { //Material[] mats = renderer.materials; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.TwoSided; /*foreach (Material mat in mats) * { * if (mat.name.ToLower().Contains("glass")) * { * renderer.gameObject.layer = 7; * continue; * } * }*/ } else if (renderer.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly) { FlipMesh(renderer.gameObject); } } } }