public void SetDisplay(AssetHandlerWidget displayWidget) { if (displayWidget is IModelWidget) { m_display = displayWidget; } else { Debug.LogWarning(this.name + " [Incompatible Display] " + displayWidget.name + " cannot be initialized as a display."); return; } if (m_display) { if (((IModelWidget)m_display).GetRenderedObjects().Length > 0) { waitingOnDisplay = false; if (!waitingOnAsset) { UpdateDisplay(); } } else { waitingOnDisplay = true; ((IModelWidget)m_display).SubscribeForInstancing(OnDisplayReady); } } }
public void SetDisplay(AssetHandlerWidget displayWidget) { if (displayWidget is IModelWidget || displayWidget is SkyboxWidget || displayWidget is ParticleWidget) { m_display = displayWidget; } else { Debug.LogWarning(this.name + " [Incompatible Surface] " + displayWidget.name + " cannot be initialized to display " + this.name + "."); return; } //if (m_display && !m_material) //{ // if (m_display is IModelWidget) // { // //TODO: Address issue of multiple materials // if (((IModelWidget)m_display).GetRenderedObjects().Length > 0) // { // waitingOnDisplay = false; // //GetMaterial(); // GenerateMaterialWidgets(m_display); // } // else // { // waitingOnDisplay = true; // ((IModelWidget)m_display).SubscribeForInstancing(OnDisplayReady); // } // } //} }
public void SetDisplay(AssetHandlerWidget displayWidget) { if (displayWidget is IModelWidget) { m_display = displayWidget; } else { Debug.LogWarning(this.name + " [Incompatible Display] " + displayWidget.name + " cannot be initialized as a display."); return; } if (m_display) { //TODO: Verify this solution is workable in a compiled build. //if (!displayMat) // displayMat = new Material(Shader.Find("Unlit/Texture")); if (((IModelWidget)m_display).GetRenderedObjects().Length > 0) { waitingOnDisplay = false; //var renderer = m_display.GetComponentInChildren<Renderer>(); //displayMat = renderer ? renderer.material : new Material(Shader.Find("Unlit/Texture")); ; if (!waitingOnAsset) { UpdateDisplay(); } } else { waitingOnDisplay = true; ((IModelWidget)m_display).SubscribeForInstancing(OnDisplayReady); } } }
public static List <MaterialWidget> GenerateMaterialWidgets(AssetHandlerWidget displayWidget) { List <MaterialWidget> matWidgets = displayWidget.GetComponents <MaterialWidget>().ToList(); List <MaterialWidget> usedMatWidgets = new List <MaterialWidget>(); // TODO: Implement cleanup to destroy materials when disposing of this stuff. if (displayWidget is SkyboxWidget) { if (((SkyboxWidget)displayWidget).stereo) { string shaderType = InternalShaders.Skybox; if (((SkyboxWidget)displayWidget).type == SkyboxWidget.SkyboxType.Cubemap) { shaderType = InternalShaders.Skybox; } var leftMatWidget = matWidgets.FirstOrDefault(w => w.materialName == "left eye"); if (!leftMatWidget) { leftMatWidget = displayWidget.gameObject.AddComponent <MaterialWidget>(); leftMatWidget.materialName = "left eye"; } leftMatWidget.defaultShader = shaderType; leftMatWidget.Initialize(leftMatWidget.m_material); leftMatWidget.UpdateMaterial(); var rightMatWidget = matWidgets.FirstOrDefault(w => w.materialName == "right eye"); if (!rightMatWidget) { rightMatWidget = displayWidget.gameObject.AddComponent <MaterialWidget>(); rightMatWidget.materialName = "right eye"; } rightMatWidget.defaultShader = shaderType; rightMatWidget.Initialize(rightMatWidget.m_material); rightMatWidget.UpdateMaterial(); usedMatWidgets.Add(leftMatWidget); usedMatWidgets.Add(rightMatWidget); } else { var materialWidget = matWidgets.FirstOrDefault(); if (!materialWidget) { materialWidget = displayWidget.gameObject.AddComponent <MaterialWidget>(); materialWidget.materialName = "skybox"; } switch (((SkyboxWidget)displayWidget).type) { case SkyboxWidget.SkyboxType.SixSided: materialWidget.defaultShader = InternalShaders.Skybox; break; case SkyboxWidget.SkyboxType.Cubemap: materialWidget.defaultShader = InternalShaders.SkyboxCubemap; break; case SkyboxWidget.SkyboxType.Procedural: materialWidget.defaultShader = InternalShaders.SkyboxProcedural; break; default: break; } materialWidget.Initialize(materialWidget.m_material); materialWidget.UpdateMaterial(); usedMatWidgets.Add(materialWidget); } } else { var renderers = new List <Renderer>(); if (displayWidget is ModelWidget) { foreach (var go in displayWidget.GetComponentsInChildren <InstancedAssetWidget>()) { renderers.AddRange(go.GetComponentsInChildren <Renderer>()); } } else { renderers.AddRange(displayWidget.GetComponentsInChildren <Renderer>()); } for (int r = 0; r < renderers.Count; r++) { for (int i = 0; i < renderers[r].materials.Length; i++) { string materialName = renderers[r].materials[i].name + "[" + r + "]"; if (displayWidget is ParticleWidget) { //TODO: This needs better handling to facilitate possible future subemitter support if (i == 0) { materialName = "Particle_Material"; } else { materialName = "Trail_Material"; } } var matWidget = matWidgets.FirstOrDefault(m => !usedMatWidgets.Contains(m) && (m.materialName.Contains(materialName) || m.materialName.Contains(renderers[r].materials[i].name))); if (matWidget) { if (displayWidget is ModelWidget) { renderers[r].materials[i].name = materialName; } usedMatWidgets.Add(matWidget); matWidget.Initialize(renderers[r].materials[i]); matWidget.UpdateMaterial(); } else { matWidget = displayWidget.gameObject.AddComponent <MaterialWidget>(); if (displayWidget is ParticleWidget) { //TODO: This needs better handling to facilitate possible future subemitter support if (i == 0) { renderers[r].materials[i].name = "Particle_Material"; } else { renderers[r].materials[i].name = "Trail_Material"; } renderers[r].materials[i].shader = Shader.Find(ShaderInterface.GetInterface(InternalShaders.Particles).shaderName); } else { renderers[r].materials[i].name = materialName; } matWidget.Initialize(renderers[r].materials[i]); matWidget.UpdateWidgetState(); usedMatWidgets.Add(matWidget); } } } } matWidgets.ForEach(m => { if (!usedMatWidgets.Contains(m)) { GameObject.Destroy(m); } }); return(usedMatWidgets); }
protected virtual void GetAssetHandler(Asset asset) { UnSubscribeFromAsset(); if (asset != null && asset.metadata != null && asset.metadata.node != null && asset.metadata.node.localScale != Vector3.zero && !GraphSetBySpace) { // TODO: work out a better identification for legit Nodes than id == 0 if (asset.metadata.node.id != 0) { asset.metadata.node.RenderToGameObjectHierarchy(gameObject); } if (string.IsNullOrEmpty(gameObject.name)) { gameObject.name = asset.name; } } //TODO: decide whether assetType should override existing type. if (gameObject && !m_handler && asset != null && !string.IsNullOrEmpty(asset.assetType)) { switch (asset.assetType.ToLower()) { case "model": case "fbx": var modelWidget = gameObject.GetComponent <ModelWidget>() ? gameObject.GetComponent <ModelWidget>() : gameObject.AddComponent <ModelWidget>(); modelWidget.Initialize(this); m_handler = modelWidget; break; case "audio": var soundWidget = gameObject.GetComponent <SoundWidget>() ? gameObject.GetComponent <SoundWidget>() : gameObject.AddComponent <SoundWidget>(); soundWidget.Initialize(this); m_handler = soundWidget; break; case "movfile": case "video": var videoWidget = gameObject.GetComponent <VideoWidget>() ? gameObject.GetComponent <VideoWidget>() : gameObject.AddComponent <VideoWidget>(); videoWidget.Initialize(this); m_handler = videoWidget; break; case "image": case "jpg": case "jpeg": var imageWidget = gameObject.GetComponent <ImageWidget>() ? gameObject.GetComponent <ImageWidget>() : gameObject.AddComponent <ImageWidget>(); imageWidget.Initialize(this); m_handler = imageWidget; break; case "text": var textWidget = gameObject.GetComponent <TextWidget>() ? gameObject.GetComponent <TextWidget>() : gameObject.AddComponent <TextWidget>(); textWidget.Initialize(this); m_handler = textWidget; break; case "material": //var materialWidget = gameObject.GetComponent<MaterialWidget>() ? gameObject.GetComponent<MaterialWidget>() : gameObject.AddComponent<MaterialWidget>(); //materialWidget.Initialize(this); //m_handler = materialWidget; break; case "shader": // Do something different here. var shaderHandler = gameObject.GetComponent <MaterialWidget>() ? gameObject.GetComponent <MaterialWidget>() : gameObject.AddComponent <MaterialWidget>(); m_handler = shaderHandler; break; case "skybox": var skyboxWidget = gameObject.GetComponent <SkyboxWidget>() ? gameObject.GetComponent <SkyboxWidget>() : gameObject.AddComponent <SkyboxWidget>(); skyboxWidget.Initialize(this); m_handler = skyboxWidget; break; case "compound": case "assetbundle": case "scene": break; default: break; } } if (asset != null && !asset.InProcess(Asset.Process.Error) && m_handler) { asset.EnqueueHandlerRequest(m_handler); } else { if (!m_handler) { var modelWidget = gameObject.AddComponent <ModelWidget>(); modelWidget.Initialize(this); m_handler = modelWidget; } var placeholder = m_handler.InstancePlaceholder(); AddAssetInstance(placeholder.transform); placeholder.AddComponent <InstancedAssetWidget>(); } }