public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (!sb) { sb = ScriptableObject.CreateInstance <SubstanceBaker>(); } this.m_MaterialEditor = materialEditor; this.substance = m_MaterialEditor.target as ProceduralMaterial; this.FindProperties(props); //Style similar to Standard shader m_MaterialEditor.SetDefaultGUIWidths(); m_MaterialEditor.UseDefaultMargins(); EditorGUIUtility.labelWidth = 0f; EditorGUI.BeginChangeCheck(); //Draw fields DoHeader(); DrawFields(); if (!substance || substance.GetType() != typeof(ProceduralMaterial)) { EditorGUILayout.HelpBox("This is material is not a Substance material\n\nSubstances can be recognized by a small red flame in the icon", MessageType.Error); } else { //Retreive the last used folder in the registry savedTargetFolder = EditorPrefs.GetString("FAE_S2T_TARGETFOLDER"); if (targetFolder == null) { targetFolder = savedTargetFolder; } if (targetFolder == null) { targetFolder = "Assets/Fantasy Adventure Environment/Terrain/Textures"; } EditorGUILayout.LabelField("Target folder: ", EditorStyles.boldLabel); targetFolder = EditorGUILayout.TextField(targetFolder); if (targetFolder == null) { EditorGUILayout.HelpBox("This field cannot be empty", MessageType.Error); } if (showHelp) { EditorGUILayout.HelpBox("A separate folder will be created with the name of the current Substance material\n\nExample: /" + substance.name + "/texture_name.png", MessageType.Info); } if (GUILayout.Button("Bake textures") && targetFolder != null) { sb.BakeSubstance(substance, targetFolder); } } DoFooter(); }
public bool FindMaterial(JsonData cityMatJson, out ProceduralMaterial outMat) { return(FindMaterial(CityMaterial.CreateFromJClass(cityMatJson), out outMat)); }
//Esta funcion se llama cada que se crea un objeto nuevo public void LoadNewObject(GameObject parentOfSubstances) { //borrar lo que ya haya en la ui para las variables expuestas ClearUI(); target = parentOfSubstances; if (objectWithMaterials != null) { objectWithMaterials.Clear(); } else { objectWithMaterials = new List <MatClass>(); } //Sacar cada objeto hijo con materiales foreach (Transform child in parentOfSubstances.transform) { //de cada hijo sacar todos sus materiales Debug.Log("Shared MAterials: " + child.GetComponent <Renderer>().sharedMaterials.Length); MatClass objMaterial = new MatClass(); objMaterial.Init(); foreach (Material mat in child.GetComponent <Renderer>().sharedMaterials) { //Tomar el susbtance como material procedural y agregarlo a lista ProceduralMaterial tempSubstance = mat as ProceduralMaterial; ProceduralMaterial.substanceProcessorUsage = ProceduralProcessorUsage.All; if (tempSubstance != null) { tempSubstance.CacheProceduralProperty("_MainTex", true); //Solo se va a checar el workflow con el primer objeto que tenga material if (child.GetSiblingIndex() == 0) { //Display Material Name DisplayMaterialName(tempSubstance, target.name); } //Guardar el material objMaterial.baseMaterial.Add(mat); //Creaete albedo Mat Material tempMat; CreateMaterialFrom("_MainTex", out tempMat, child, tempSubstance); objMaterial.albedoMaterial.Add(tempMat); //Create Normal Mat tempMat = null; CreateMaterialFrom("_BumpMap", out tempMat, child, tempSubstance, true); //_BumpMap objMaterial.normalMaterial.Add(tempMat); if (isMetallicWorkflow) { //Create Metallic Mat tempMat = null; CreateMaterialFrom("_MetallicGlossMap", out tempMat, child, tempSubstance); objMaterial.metallicSpecMaterial.Add(tempMat); //Create Roughness Mat tempMat = null; CreateMaterialFrom("_RoughnessMap", out tempMat, child, tempSubstance); //CHECAR QUE ASI SE LLAME EN SHADER objMaterial.roughnessGlossinesMaterial.Add(tempMat); } else { tempMat = null; CreateMaterialFrom("_SpecGlossMap", out tempMat, child, tempSubstance); objMaterial.metallicSpecMaterial.Add(tempMat); //Create Roughness Mat tempMat = null; CreateMaterialFrom("_GloosMap", out tempMat, child, tempSubstance); objMaterial.roughnessGlossinesMaterial.Add(tempMat); } //Create Height Map tempMat = null; CreateMaterialFrom("_ParallaxMap", out tempMat, child, tempSubstance); objMaterial.heightMaterial.Add(tempMat); //Create Alpha Map tempMat = null; CreateMaterialFrom("_AlphaMap", out tempMat, child, tempSubstance); //CONFIRMAR QU ESTE SEA EL NOMBRE EN EL SHADER objMaterial.alphaMaterial.Add(tempMat); tempMat = null; //Create S CreateMaterialFrom("_EmissionMap", out tempMat, child, tempSubstance); objMaterial.emissionMaterial.Add(tempMat); //Agregar a la UI if (tempSubstance != null) { DisplaySubstanceMaterialProperties(tempSubstance); } //Agregar el substance a la lista objMaterial.substance.Add(tempSubstance); Debug.Log("Albedos: " + objMaterial.albedoMaterial.Count); } objectWithMaterials.Add(objMaterial); Debug.Log("Materiales: " + objectWithMaterials.Count); } //fin foreach material } // fin foreach child }
public override void Draw(DrawInfo drawInfo) { base.Draw(drawInfo); if (m_editing) { m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; if (GUI.Button(m_pickerArea, string.Empty, GUIStyle.none)) { int controlID = EditorGUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.ShowObjectPicker <ProceduralMaterial>(m_proceduralMaterial, false, "", controlID); } string commandName = Event.current.commandName; UnityEngine.Object newValue = null; if (commandName == "ObjectSelectorUpdated") { newValue = EditorGUIUtility.GetObjectPickerObject(); if (newValue != (UnityEngine.Object)m_proceduralMaterial) { UndoRecordObject(this, "Changing value EditorGUIObjectField on node Substance Sample"); m_proceduralMaterial = newValue != null ? ( ProceduralMaterial )newValue : null; m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; OnNewSubstanceSelected(m_textures); } } else if (commandName == "ObjectSelectorClosed") { newValue = EditorGUIUtility.GetObjectPickerObject(); if (newValue != (UnityEngine.Object)m_proceduralMaterial) { UndoRecordObject(this, "Changing value EditorGUIObjectField on node Substance Sample"); m_proceduralMaterial = newValue != null ? ( ProceduralMaterial )newValue : null; m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; OnNewSubstanceSelected(m_textures); } m_editing = false; } if (GUI.Button(m_previewArea, string.Empty, GUIStyle.none)) { if (m_proceduralMaterial != null) { Selection.activeObject = m_proceduralMaterial; EditorGUIUtility.PingObject(Selection.activeObject); } m_editing = false; } } if (drawInfo.CurrentEventType == EventType.Repaint) { if (!m_editing) { m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; } if (m_textures != null) { if (m_firstOutputConnected < 0) { CalculateFirstOutputConnected(); } else if (m_textures.Length != m_textureTypes.Length) { OnNewSubstanceSelected(m_textures); } int texCount = m_outputConns.Count; Rect individuals = m_previewArea; individuals.height /= texCount; for (int i = 0; i < texCount; i++) { EditorGUI.DrawPreviewTexture(individuals, m_textures[m_outputConns[i]], null, ScaleMode.ScaleAndCrop); individuals.y += individuals.height; } } else { GUI.Label(m_previewArea, string.Empty, UIUtils.ObjectFieldThumb); } if (ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2) { Rect smallButton = m_previewArea; smallButton.height = 14 * drawInfo.InvertedZoom; smallButton.y = m_previewArea.yMax - smallButton.height - 2; smallButton.width = 40 * drawInfo.InvertedZoom; smallButton.x = m_previewArea.xMax - smallButton.width - 2; if (m_textures == null) { GUI.Label(m_previewArea, "None (Procedural Material)", UIUtils.ObjectFieldThumbOverlay); } GUI.Label(m_pickerArea, "Select", UIUtils.GetCustomStyle(CustomStyle.SamplerButton)); } GUI.Label(m_previewArea, string.Empty, UIUtils.GetCustomStyle(CustomStyle.SamplerFrame)); } }
void AddSetProceduralVariablesBeforeChangeToKeyValue(ProceduralMaterial inputMaterialBeforeChange, ProceduralPropertyDescription[] materialVariablesListBeforeChange, List <string> keysList, List <string> valuesList) { // Specify current material variables as the 'beforeChange' material and what to check against after a change happens if (keysList.Count > 0) { keysList.Clear(); } if (valuesList.Count > 0) { valuesList.Clear(); } for (int i = 0; i < materialVariablesBeforeChange.Length; i++)//loop through properties and make them the default properties for this object { ProceduralPropertyDescription materialVariable = materialVariablesBeforeChange[i]; ProceduralPropertyType propType = materialVariablesBeforeChange[i].type; if (propType == ProceduralPropertyType.Float /*&& (materialVariable.hasRange )*/) { float propFloat = inputMaterialBeforeChange.GetProceduralFloat(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add(propFloat.ToString()); } if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4) { Color propColor = inputMaterialBeforeChange.GetProceduralColor(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add("#" + ColorUtility.ToHtmlStringRGBA(propColor)); } if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) /* && (objProperty.hasRange || (saveParametersWithoutRange && !objProperty.hasRange))*/) { if (propType == ProceduralPropertyType.Vector4) { Vector4 propVector4 = inputMaterialBeforeChange.GetProceduralVector(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add(propVector4.ToString()); } else if (propType == ProceduralPropertyType.Vector3) { Vector3 propVector3 = inputMaterialBeforeChange.GetProceduralVector(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add(propVector3.ToString()); } else if (propType == ProceduralPropertyType.Vector2) { Vector2 propVector2 = inputMaterialBeforeChange.GetProceduralVector(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add(propVector2.ToString()); } } else if (propType == ProceduralPropertyType.Enum) { int propEnum = inputMaterialBeforeChange.GetProceduralEnum(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add(propEnum.ToString()); } else if (propType == ProceduralPropertyType.Boolean) { bool propBoolean = inputMaterialBeforeChange.GetProceduralBoolean(materialVariable.name); keysList.Add(materialVariable.name); valuesList.Add(propBoolean.ToString()); } } // materialVariables.animationTime = animationTime; // sets a procedural material based on custom dictionary. I do this because copies of Procedural Materials get changed with their originals. This does not happen if i set values based on parsed values. for (int i = 0; i < materialVariablesBeforeChange.Length; i++) { ProceduralPropertyDescription materialVariables = materialVariablesBeforeChange[i]; ProceduralPropertyType propType = materialVariablesBeforeChange[i].type; if (propType == ProceduralPropertyType.Float && (materialVariables.hasRange /*|| (saveParametersWithoutRange && !materialVariables.hasRange) || resettingValuesToDefault)*/)) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { if (keysList[j] == materialVariables.name) { inputMaterialBeforeChange.SetProceduralFloat(materialVariables.name, float.Parse(valuesList[j])); } } } } else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { Color curColor; ColorUtility.TryParseHtmlString(valuesList[j], out curColor); inputMaterialBeforeChange.SetProceduralColor(materialVariables.name, curColor); } } } else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) && (materialVariables.hasRange /*|| (saveParametersWithoutRange && !materialVariables.hasRange) || resettingValuesToDefault)*/)) { if (propType == ProceduralPropertyType.Vector4) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { Vector4 curVector4 = StringToVector(valuesList[j], 4); inputMaterialBeforeChange.SetProceduralVector(materialVariables.name, curVector4); } } } else if (propType == ProceduralPropertyType.Vector3) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { Vector3 curVector3 = StringToVector(valuesList[j], 3); inputMaterialBeforeChange.SetProceduralVector(materialVariables.name, curVector3); } } } else if (propType == ProceduralPropertyType.Vector2) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { Vector2 curVector2 = StringToVector(valuesList[j], 2); inputMaterialBeforeChange.SetProceduralVector(materialVariables.name, curVector2); } } } } else if (propType == ProceduralPropertyType.Enum) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { int curEnum = int.Parse(valuesList[j]); inputMaterialBeforeChange.SetProceduralEnum(materialVariables.name, curEnum); } } } else if (propType == ProceduralPropertyType.Boolean) { for (int j = 0; j < keysList.Count; j++) { if (keysList[j] == materialVariables.name) { bool curBool = bool.Parse(valuesList[j]); inputMaterialBeforeChange.SetProceduralBoolean(materialVariables.name, curBool); } } } } }
public void SlideSubstanceProperty(ProceduralPropertyDescription input, Slider slider, ProceduralMaterial mySubstance) { float inputFloat = mySubstance.GetProceduralFloat(input.name); float oldInputFloat = inputFloat; //print("VALUE CHANGED!" + inputFloat + " SLIDER VAL " + slider.value); inputFloat = slider.value;//GUILayout.HorizontalSlider(inputFloat, input.minimum, input.maximum); if (inputFloat != oldInputFloat) { mySubstance.SetProceduralFloat(input.name, inputFloat); mySubstance.RebuildTextures(); } }
public virtual void FromXML(XmlNode node) { material = new Material(Shader.Find("Diffuse")); if (node["customName"] != null) { customName = node["customName"].FirstChild.Value; } tiled = bool.Parse(node["tiled"].FirstChild.Value); patterned = bool.Parse(node["patterned"].FirstChild.Value); flipped = bool.Parse(node["flipped"].FirstChild.Value); if (node["type"] != null) { type = (Types)System.Enum.Parse(typeof(Types), node["type"].FirstChild.Value); } _tileUnitUV = XMLVariableConverter.FromXMLVector2(node["_tileUnitUV"]); _textureUnitSize = XMLVariableConverter.FromXMLVector2(node["_textureUnitSize"]); tiledX = int.Parse(node["tiledX"].FirstChild.Value); tiledY = int.Parse(node["tiledY"].FirstChild.Value); maxUVTile = XMLVariableConverter.FromXMLVector2(node["maxUVTile"]); minWorldUnits = XMLVariableConverter.FromXMLVector2(node["minWorldUnits"]); maxWorldUnits = XMLVariableConverter.FromXMLVector2(node["maxWorldUnits"]); ProceduralMaterial loadedProcedualMaterial = null; if (node["_proceduralMaterial"] != null) { if (node["_proceduralMaterial"].HasChildNodes) { loadedProcedualMaterial = (ProceduralMaterial)AssetDatabase.LoadAssetAtPath(node["_proceduralMaterial"].FirstChild.Value, typeof(ProceduralMaterial)); } } if (loadedProcedualMaterial != null) { _proceduralMaterial = loadedProcedualMaterial; } Material loadedMaterial = null; if (node["_userMaterial"] != null) { if (node["_userMaterial"].HasChildNodes) { loadedMaterial = (Material)AssetDatabase.LoadAssetAtPath(node["_userMaterial"].FirstChild.Value, typeof(Material)); } } if (loadedMaterial != null) { _userMaterial = loadedMaterial; } if (node["texture"].HasChildNodes) { material.mainTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(node["texture"].FirstChild.Value, typeof(Texture2D)); } if (node["color"].HasChildNodes) { material.color = XMLVariableConverter.FromXMLtoColour(node["color"]); } }
private void MaterialListing() { ProceduralMaterial[] sortedMaterials = this.GetSortedMaterials(); foreach (ProceduralMaterial material in sortedMaterials) { if (material.isProcessing) { base.Repaint(); SceneView.RepaintAll(); GameView.RepaintAll(); break; } } int length = sortedMaterials.Length; float num3 = ((GUIView.current.position.width - 16f) - 18f) - 2f; if ((num3 * 2f) < (length * 60f)) { num3 -= 16f; } int num4 = Mathf.Max(1, Mathf.FloorToInt(num3 / 60f)); int num5 = Mathf.CeilToInt(((float)length) / ((float)num4)); Rect viewRect = new Rect(0f, 0f, num4 * 60f, num5 * 76f); Rect rect = GUILayoutUtility.GetRect(viewRect.width, Mathf.Clamp(viewRect.height, 76f, 152f) + 1f); Rect position = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 1f); GUI.Box(rect, GUIContent.none, this.m_SubstanceStyles.gridBackground); GUI.Box(position, GUIContent.none, this.m_SubstanceStyles.background); this.m_ListScroll = GUI.BeginScrollView(position, this.m_ListScroll, viewRect, false, false); if (this.m_EditorCache == null) { this.m_EditorCache = new EditorCache(EditorFeatures.PreviewGUI); } for (int i = 0; i < sortedMaterials.Length; i++) { ProceduralMaterial target = sortedMaterials[i]; if (target != null) { float x = (i % num4) * 60f; float y = (i / num4) * 76f; Rect rect5 = new Rect(x, y, 60f, 76f); bool on = target.name == this.m_SelectedMaterialInstanceName; Event current = Event.current; int controlID = GUIUtility.GetControlID(previewNoDragDropHash, FocusType.Passive, rect5); switch (current.GetTypeForControl(controlID)) { case EventType.Repaint: { Rect rect6 = rect5; rect6.y = rect5.yMax - 16f; rect6.height = 16f; this.m_SubstanceStyles.resultsGridLabel.Draw(rect6, EditorGUIUtility.TempContent(target.name), false, false, on, on); break; } case EventType.MouseDown: if ((current.button == 0) && rect5.Contains(current.mousePosition)) { if (current.clickCount == 1) { this.m_SelectedMaterialInstanceName = target.name; current.Use(); } else if (current.clickCount == 2) { AssetDatabase.OpenAsset(target); GUIUtility.ExitGUI(); current.Use(); } } break; } rect5.height -= 16f; this.m_EditorCache[target].OnPreviewGUI(rect5, this.m_SubstanceStyles.background); } } GUI.EndScrollView(); }
public bool GetGenerateMipMaps(ProceduralMaterial material) { return(this.GetMaterialInformation(material).generateMipMaps); }
void getProcedualPropertices( ) { lightcapSubstance = lightcapTransform.renderer.sharedMaterial as ProceduralMaterial; curProperties = lightcapSubstance.GetProceduralPropertyDescriptions(); }
public int GetAnimationUpdateRate(ProceduralMaterial material) { return(this.GetMaterialInformation(material).animationUpdateRate); }
public bool GetGenerateAllOutputs(ProceduralMaterial material) { return(this.GetMaterialInformation(material).generateAllOutputs); }
public Vector2 GetMaterialScale(ProceduralMaterial material) { return(this.GetMaterialInformation(material).scale); }
public Vector2 GetMaterialOffset(ProceduralMaterial material) { return(this.GetMaterialInformation(material).offset); }
private static Material CreateMaterialFromMaps(BakerProfile profile, string name) { AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Assert.IsNotNull(profile.shader); ProceduralMaterial pm = bakingMaterials[name]; bakingMaterials.Remove(name); Material mat; if (profile.shader != pm.shader) { mat = new Material(profile.shader); foreach (var field in profile.AdditionFields) { try { switch (field.FieldType) { case (MappableFields.Color): { mat.SetColor(field.To, pm.GetColor(field.From)); break; } case (MappableFields.Float): { mat.SetFloat(field.To, pm.GetFloat(field.From)); break; } case (MappableFields.Texture): { mat.SetTexture(field.To, pm.GetTexture(field.From)); break; } case (MappableFields.Int): { mat.SetInt(field.To, pm.GetInt(field.From)); break; } } } catch (Exception e) { Debug.LogError("Additional fields " + field.From + " fialed to set, Skipping field."); Debug.LogException(e); continue; } } } else { mat = new Material(pm); } var path = UnityPath(Path.Combine(profile.materialFolder, name)); var mats = Baker.LoadAllAssetsAtPath <Texture>(path); foreach (Texture2D tex in mats) { if (tex.name.ToLower().Contains("ambient_occlusion")) { mat.SetTexture(profile.AOName, tex); } else if (tex.name.ToLower().Contains("basecolor") || tex.name.ToLower().Contains("diffuse")) { mat.SetTexture(profile.albedoName, tex); } else if (tex.name.ToLower().Contains("roughness")) { mat.SetTexture(profile.roughnessName, tex); } else if (tex.name.ToLower().Contains("height")) { mat.SetTexture(profile.heightName, tex); } else if (tex.name.ToLower().Contains("normal")) { mat.SetTexture(profile.normalName, tex); } else if (tex.name.ToLower().Contains("specular")) { mat.SetTexture(profile.specularName, tex); } else if (tex.name.ToLower().Contains("glossiness")) { mat.SetTexture(profile.glossinessName, tex); } } if (profile.removeSubstance) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(pm)); } AssetDatabase.CreateAsset(mat, path + "/" + name + ".mat"); Material mat2 = new Material(pm); AssetDatabase.CreateAsset(mat2, path + "/" + name + "2.mat"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Resources.UnloadUnusedAssets(); return(mat); }
private static void INTERNAL_CALL_SetProceduralColor(ProceduralMaterial self, string inputName, ref Color value){}
public static void ApplySettings(BakerProfile profile, ProceduralMaterial proceduralMaterial) { ApplySettings(profile, proceduralMaterial, AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(proceduralMaterial)) as SubstanceImporter); }
void CheckForNoChangeInMaterialParams(ProceduralMaterial inputMaterialBeforeChange, ProceduralPropertyDescription[] materialVariablesListBeforeChange, List <string> keysList, List <string> valuesList) {// checks if the material variables have not changed from a given material. int variablesChanged = 0; for (int i = 0; i <= materialVariablesListBeforeChange.Count() - 1; i++) { ProceduralPropertyDescription materialVariableCurrent = testingScript.substanceMaterialParams.materialVariables[i]; ProceduralPropertyDescription materialVariableBeforeChange = materialVariablesListBeforeChange[i]; ProceduralPropertyType propType = testingScript.substanceMaterialParams.materialVariables[i].type; if (propType == ProceduralPropertyType.Float) { float propFloatCurrent = testingScript.substanceMaterialParams.substance.GetProceduralFloat(materialVariableCurrent.name); float propFloatBeforeChange = float.Parse(valuesList[keysList.IndexOf(materialVariableCurrent.name)]); if (propFloatCurrent != propFloatBeforeChange) { variablesChanged++; } } else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4) { Color propColorCurrent = testingScript.substanceMaterialParams.substance.GetProceduralColor(materialVariableCurrent.name); Color curColor; ColorUtility.TryParseHtmlString(valuesList[keysList.IndexOf(materialVariableCurrent.name)], out curColor); Color propColorBeforeChange = curColor; if (propColorCurrent != propColorBeforeChange) { variablesChanged++; } } else if ((propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4)) { if (propType == ProceduralPropertyType.Vector4) { Vector4 propVector4Current = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name); Vector4 propVector4BeforeChange = StringToVector(valuesList[keysList.IndexOf(materialVariableCurrent.name)], 4); if (propVector4Current != propVector4BeforeChange) { variablesChanged++; } } else if (propType == ProceduralPropertyType.Vector3) { Vector3 propVector3Current = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name); Vector3 propVector3BeforeChange = StringToVector(valuesList[keysList.IndexOf(materialVariableCurrent.name)], 3); if (propVector3Current != propVector3BeforeChange) { variablesChanged++; } } else if (propType == ProceduralPropertyType.Vector2) { Vector2 propVector2Current = testingScript.substanceMaterialParams.substance.GetProceduralVector(materialVariableCurrent.name); Vector2 propVector2BeforeChange = StringToVector(valuesList[keysList.IndexOf(materialVariableCurrent.name)], 2); if (propVector2Current != propVector2BeforeChange) { variablesChanged++; } } } else if (propType == ProceduralPropertyType.Enum) { int propEnumCurrent = testingScript.substanceMaterialParams.substance.GetProceduralEnum(materialVariableCurrent.name); int propEnumBeforeChange = int.Parse(valuesList[keysList.IndexOf(materialVariableCurrent.name)]); if (propEnumCurrent != propEnumBeforeChange) { variablesChanged++; } } else if (propType == ProceduralPropertyType.Boolean) { bool propBoolCurrent = testingScript.substanceMaterialParams.substance.GetProceduralBoolean(materialVariableCurrent.name); bool propBoolBeforeChange = materialBeforeChange.GetProceduralBoolean(materialVariableBeforeChange.name); if (propBoolCurrent != propBoolBeforeChange) { variablesChanged++; } } if (variablesChanged > 0) { Assert.Fail("Material not the same as original"); break; } if (i == materialVariablesBeforeChange.Count() - 1 && variablesChanged == 0) { Debug.Log("Material same as original, Success?"); } } }
public static void Bake(BakerProfile profile, ProceduralMaterial proceduralMaterial) { isBaking = true; Bake(profile, proceduralMaterial, AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(proceduralMaterial)) as SubstanceImporter); }
private void CreateMaterialFrom(string property, out Material _toAssing, Transform _child, ProceduralMaterial mySubstance, bool _isNormal = false) { _toAssing = new Material(Shader.Find("Standard")); try { _toAssing.mainTexture = mySubstance.GetTexture(Shader.PropertyToID(property)); } catch { Debug.Log("Objeto no tiene propiedad."); } if (_isNormal) { _toAssing.SetTexture("_BumpMap", mySubstance.GetTexture(Shader.PropertyToID("_BumpMap"))); _toAssing.mainTexture = ToNormalMap(mySubstance.GetTexture(Shader.PropertyToID("_BumpMap"))); } }
void SetTextureCharacter() { if (Ag.mgIsKick) { mProcedureMat = (ProceduralMaterial)subKickerShirts [Ag.NodeObj.MyUser.arrUniform [0].Kick.Shirt.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.MyUser.arrUniform [0].Kick.Shirt.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.MyUser.arrUniform [0].Kick.Shirt.ColSub); KickermShirts = mProcedureMat.mainTexture; mPlayerKicker.transform.FindChild("Clothes").renderer.sharedMaterials [0].mainTexture = KickermShirts; mProcedureMat = (ProceduralMaterial)subPants [Ag.NodeObj.MyUser.arrUniform [0].Kick.Pants.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.MyUser.arrUniform [0].Kick.Pants.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.MyUser.arrUniform [0].Kick.Pants.ColSub); KickerPants = mProcedureMat.mainTexture; mPlayerKicker.transform.FindChild("Clothes").renderer.sharedMaterials [1].mainTexture = KickerPants; mProcedureMat = (ProceduralMaterial)subSocks [Ag.NodeObj.MyUser.arrUniform [0].Kick.Socks.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.MyUser.arrUniform [0].Kick.Socks.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.MyUser.arrUniform [0].Kick.Socks.ColSub); KickermSocks = mProcedureMat.mainTexture; mPlayerKicker.transform.FindChild("Clothes").renderer.sharedMaterials [2].mainTexture = KickermSocks; mProcedureMat = (ProceduralMaterial)subKeeperShirts [Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Shirt.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Shirt.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Shirt.ColSub); KeeperShirts = mProcedureMat.mainTexture; mPlayerKeeper.transform.FindChild("uniform").renderer.sharedMaterials [0].mainTexture = KeeperShirts; mProcedureMat = (ProceduralMaterial)EnemysubPants [Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Pants.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Pants.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Pants.ColSub); KeeperPants = mProcedureMat.mainTexture; mPlayerKeeper.transform.FindChild("uniform").renderer.sharedMaterials [1].mainTexture = KeeperPants; mProcedureMat = (ProceduralMaterial)EnemysubSocks [Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Socks.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Socks.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.EnemyUser.arrUniform [0].Keep.Socks.ColSub); KeeperSocks = mProcedureMat.mainTexture; mPlayerKeeper.transform.FindChild("uniform").renderer.sharedMaterials [2].mainTexture = KeeperSocks; } else { mProcedureMat = (ProceduralMaterial)subKeeperShirts [Ag.NodeObj.MyUser.arrUniform [0].Keep.Shirt.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.MyUser.arrUniform [0].Keep.Shirt.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.MyUser.arrUniform [0].Keep.Shirt.ColSub); KeeperShirts = mProcedureMat.mainTexture; mPlayerKeeper.transform.FindChild("uniform").renderer.sharedMaterials [0].mainTexture = KeeperShirts; mProcedureMat = (ProceduralMaterial)subPants [Ag.NodeObj.MyUser.arrUniform [0].Keep.Pants.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.MyUser.arrUniform [0].Keep.Pants.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.MyUser.arrUniform [0].Keep.Pants.ColSub); KeeperPants = mProcedureMat.mainTexture; mPlayerKeeper.transform.FindChild("uniform").renderer.sharedMaterials [1].mainTexture = KeeperPants; mProcedureMat = (ProceduralMaterial)subSocks [Ag.NodeObj.MyUser.arrUniform [0].Keep.Socks.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.MyUser.arrUniform [0].Keep.Socks.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.MyUser.arrUniform [0].Keep.Socks.ColSub); KeeperSocks = mProcedureMat.mainTexture; mPlayerKeeper.transform.FindChild("uniform").renderer.sharedMaterials [2].mainTexture = KeeperSocks; mProcedureMat = (ProceduralMaterial)subKickerShirts [Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Shirt.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Shirt.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Shirt.ColSub); KickermShirts = mProcedureMat.mainTexture; mPlayerKicker.transform.FindChild("Clothes").renderer.sharedMaterials [0].mainTexture = KickermShirts; mProcedureMat = (ProceduralMaterial)EnemysubPants [Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Pants.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Pants.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Pants.ColSub); KickerPants = mProcedureMat.mainTexture; mPlayerKicker.transform.FindChild("Clothes").renderer.sharedMaterials [1].mainTexture = KickerPants; mProcedureMat = (ProceduralMaterial)EnemysubSocks [Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Socks.Texture - 1]; UNiformSetColorColor("outputcolor", Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Socks.ColMain); UNiformSetColorColor("outputcolor_1", Ag.NodeObj.EnemyUser.arrUniform [0].Kick.Socks.ColSub); KickermSocks = mProcedureMat.mainTexture; mPlayerKicker.transform.FindChild("Clothes").renderer.sharedMaterials [2].mainTexture = KickermSocks; } }
public void DisplaySubstanceMaterialProperties(ProceduralMaterial mySubstance) { ProceduralPropertyDescription[] inputs = mySubstance.GetProceduralPropertyDescriptions(); int i = 0; while (i < inputs.Length) { ProceduralPropertyDescription input = inputs[i]; ProceduralPropertyType type = input.type; //Para variables booleanas if (type == ProceduralPropertyType.Boolean) { GameObject holder = GameObject.Instantiate(propertyHolderTogglePrefab, propertyParent.transform); holder.GetComponentInChildren <Toggle>().GetComponentInChildren <Text>().text = input.label; holder.GetComponentInChildren <Toggle>().onValueChanged.AddListener(delegate { ToggleSubtanceProperty(input.name, mySubstance, holder.GetComponentInChildren <Toggle>()); }); } //Para variables expuestas flotantes else if (type == ProceduralPropertyType.Float) { if (input.hasRange) { GameObject holder = GameObject.Instantiate(propertyHoldeSliderPrefab, propertyParent.transform); holder.transform.Find("txt").GetComponent <Text>().text = input.label; holder.GetComponentInChildren <Slider>().onValueChanged.AddListener(delegate { SlideSubstanceProperty(input, holder.GetComponentInChildren <Slider>(), mySubstance); }); } else if (type == ProceduralPropertyType.Vector2 || type == ProceduralPropertyType.Vector3 || type == ProceduralPropertyType.Vector4) { if (input.hasRange) { GUILayout.Label(input.name); int vectorComponentAmount = 4; if (type == ProceduralPropertyType.Vector2) { vectorComponentAmount = 2; } if (type == ProceduralPropertyType.Vector3) { vectorComponentAmount = 3; } Vector4 inputVector = mySubstance.GetProceduralVector(input.name); Vector4 oldInputVector = inputVector; int c = 0; while (c < vectorComponentAmount) { inputVector[c] = GUILayout.HorizontalSlider(inputVector[c], input.minimum, input.maximum); c++; } if (inputVector != oldInputVector) { mySubstance.SetProceduralVector(input.name, inputVector); } } else if (type == ProceduralPropertyType.Color3 || type == ProceduralPropertyType.Color4) { GUILayout.Label(input.label); int colorComponentAmount = ((type == ProceduralPropertyType.Color3) ? 3 : 4); Color colorInput = mySubstance.GetProceduralColor(input.name); Color oldColorInput = colorInput; int d = 0; while (d < colorComponentAmount) { colorInput[d] = GUILayout.HorizontalSlider(colorInput[d], 0, 1); d++; } if (colorInput != oldColorInput) { mySubstance.SetProceduralColor(input.name, colorInput); } } else if (type == ProceduralPropertyType.Enum) { GUILayout.Label(input.label); int enumInput = mySubstance.GetProceduralEnum(input.name); int oldEnumInput = enumInput; string[] enumOptions = input.enumOptions; enumInput = GUILayout.SelectionGrid(enumInput, enumOptions, 1); if (enumInput != oldEnumInput) { mySubstance.SetProceduralEnum(input.name, enumInput); } } } } i++; } mySubstance.RebuildTextures(); }
public static void InspectorGUI(BuildrEditMode _editMode, BuildrData _data) { data = _data; BuildrTexture[] textures = data.textures.ToArray(); int numberOfTextures = textures.Length; selectedTexture = Mathf.Clamp(selectedTexture, 0, numberOfTextures - 1); int currentSelectedTexture = selectedTexture;//keep tack of what we had selected to reset fields if changed Undo.RecordObject(data, "Texture Modified"); if (numberOfTextures == 0) { EditorGUILayout.HelpBox("There are no textures to show", MessageType.Info); if (GUILayout.Button("Add New")) { data.textures.Add(new BuildrTexture("new texture " + numberOfTextures)); numberOfTextures++; selectedTexture = numberOfTextures - 1; } return; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Texture", GUILayout.Width(75)); string[] textureNames = new string[numberOfTextures]; for (int t = 0; t < numberOfTextures; t++) { textureNames[t] = textures[t].name; } selectedTexture = EditorGUILayout.Popup(selectedTexture, textureNames); EditorGUILayout.EndHorizontal(); BuildrTexture bTexture = textures[selectedTexture]; EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Add New", GUILayout.Width(81))) { data.textures.Add(new BuildrTexture("new texture " + numberOfTextures)); numberOfTextures++; selectedTexture = numberOfTextures - 1; } if (GUILayout.Button("Duplicate", GUILayout.Width(90))) { data.textures.Add(bTexture.Duplicate()); numberOfTextures++; selectedTexture = numberOfTextures - 1; } if (GUILayout.Button("Delete", GUILayout.Width(71))) { if (EditorUtility.DisplayDialog("Deleting Texture Entry", "Are you sure you want to delete this texture?", "Delete", "Cancel")) { data.RemoveTexture(bTexture); selectedTexture = 0; GUI.changed = true; return; } } if (GUILayout.Button("Import", GUILayout.Width(71))) { string xmlPath = EditorUtility.OpenFilePanel("Select the XML file...", "Assets/BuildR/Exported/", "xml"); if (xmlPath == "") { return; } BuildrXMLImporter.ImportTextures(xmlPath, _data); textures = data.textures.ToArray(); selectedTexture = 0; GUI.changed = true; } if (GUILayout.Button("Export", GUILayout.Width(71))) { string xmlPath = EditorUtility.SaveFilePanel("Export as...", "Assets/BuildR/Exported/", _data.name + "_textureLibrary", "xml"); if (xmlPath == "") { return; } BuildrXMLExporter.ExportTextures(xmlPath, _data); GUI.changed = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); textures = data.textures.ToArray(); textureNames = new string[numberOfTextures]; for (int t = 0; t < numberOfTextures; t++) { textureNames[t] = textures[t].name; } bTexture = textures[selectedTexture];//reassign string textureName = bTexture.name; GUIStyle redText = new GUIStyle(GUI.skin.textField); if (textureName.Contains(" ")) { redText.focused.textColor = Color.red; textureName = EditorGUILayout.TextField("Name", textureName, redText); } else { redText.focused.textColor = defaultCol; textureName = EditorGUILayout.TextField("Name", textureName, redText); } bTexture.name = textureName; bool conflictingName = false; for (int i = 0; i < textureNames.Length; i++) { if (selectedTexture != i) { if (textureNames[i] == bTexture.name) { conflictingName = true; } } } if (conflictingName) { EditorGUILayout.HelpBox("You have named this texture the same as another.", MessageType.Warning); } if (currentSelectedTexture != selectedTexture) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } bTexture.type = (BuildrTexture.Types)EditorGUILayout.EnumPopup("Type", bTexture.type); switch (bTexture.type) { case BuildrTexture.Types.Basic: if (bTexture.texture != null) { string texturePath = AssetDatabase.GetAssetPath(bTexture.texture); TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(texturePath); if (!textureImporter.isReadable) { EditorGUILayout.HelpBox("The texture you have selected is not readable." + "\nPlease select the readable checkbox under advanced texture settings." + "\nOr move this texture to the BuildR texture folder and reimport.", MessageType.Error); } } //Shader Time Shader[] tempshaders = (Shader[])Resources.FindObjectsOfTypeAll(typeof(Shader)); List <string> shaderNames = new List <string>(ShaderProperties.NAMES); foreach (Shader shader in tempshaders) { if (!string.IsNullOrEmpty(shader.name) && !shader.name.StartsWith("__") && !shader.name.Contains("hidden")) { shaderNames.Add(shader.name); } } int selectedShaderIndex = shaderNames.IndexOf(bTexture.material.shader.name); int newSelectedShaderIndex = EditorGUILayout.Popup("Shader", selectedShaderIndex, shaderNames.ToArray()); if (selectedShaderIndex != newSelectedShaderIndex) { bTexture.material.shader = Shader.Find(shaderNames[newSelectedShaderIndex]); } Shader selectedShader = bTexture.material.shader; int propertyCount = ShaderUtil.GetPropertyCount(selectedShader); for (int s = 0; s < propertyCount; s++) { ShaderUtil.ShaderPropertyType propertyTpe = ShaderUtil.GetPropertyType(selectedShader, s); string shaderPropertyName = ShaderUtil.GetPropertyName(selectedShader, s); switch (propertyTpe) { case ShaderUtil.ShaderPropertyType.TexEnv: Texture shaderTexture = bTexture.material.GetTexture(shaderPropertyName); Texture newShaderTexture = (Texture)EditorGUILayout.ObjectField(shaderPropertyName, shaderTexture, typeof(Texture), false); if (shaderTexture != newShaderTexture) { bTexture.material.SetTexture(shaderPropertyName, newShaderTexture); } break; case ShaderUtil.ShaderPropertyType.Color: Color shaderColor = bTexture.material.GetColor(shaderPropertyName); Color newShaderColor = EditorGUILayout.ColorField(shaderPropertyName, shaderColor); if (shaderColor != newShaderColor) { bTexture.material.SetColor(shaderPropertyName, newShaderColor); } break; case ShaderUtil.ShaderPropertyType.Float: float shaderFloat = bTexture.material.GetFloat(shaderPropertyName); float newShaderFloat = EditorGUILayout.FloatField(shaderPropertyName, shaderFloat); if (shaderFloat != newShaderFloat) { bTexture.material.SetFloat(shaderPropertyName, newShaderFloat); } break; case ShaderUtil.ShaderPropertyType.Range: float shaderRange = bTexture.material.GetFloat(shaderPropertyName); float rangeMin = ShaderUtil.GetRangeLimits(selectedShader, s, 1); float rangeMax = ShaderUtil.GetRangeLimits(selectedShader, s, 2); float newShaderRange = EditorGUILayout.Slider(shaderPropertyName, shaderRange, rangeMin, rangeMax); if (shaderRange != newShaderRange) { bTexture.material.SetFloat(shaderPropertyName, newShaderRange); } break; case ShaderUtil.ShaderPropertyType.Vector: Vector3 shaderVector = bTexture.material.GetVector(shaderPropertyName); Vector3 newShaderVector = EditorGUILayout.Vector3Field(shaderPropertyName, shaderVector); if (shaderVector != newShaderVector) { bTexture.material.SetVector(shaderPropertyName, newShaderVector); } break; } } bool tiled = EditorGUILayout.Toggle("Is Tiled", bTexture.tiled); if (tiled != bTexture.tiled) { bTexture.tiled = tiled; } if (bTexture.tiled) { bool patterned = EditorGUILayout.Toggle("Has Pattern", bTexture.patterned); if (patterned != bTexture.patterned) { bTexture.patterned = patterned; } } else { bTexture.patterned = false; } if (bTexture.texture == null) { return; } Vector2 textureUnitSize = bTexture.textureUnitSize; if (bTexture.tiled) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("texture width", GUILayout.Width(75)); //, GUILayout.Width(42)); textureUnitSize.x = EditorGUILayout.FloatField(bTexture.textureUnitSize.x, GUILayout.Width(25)); EditorGUILayout.LabelField("metres", GUILayout.Width(40)); //, GUILayout.Width(42)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("texture height", GUILayout.Width(75));//, GUILayout.Width(42)); textureUnitSize.y = EditorGUILayout.FloatField(bTexture.textureUnitSize.y, GUILayout.Width(25)); EditorGUILayout.LabelField("metres", GUILayout.Width(40)); EditorGUILayout.EndHorizontal(); if (bTexture.textureUnitSize != textureUnitSize) { bTexture.textureUnitSize = textureUnitSize; } } Vector2 tileUnitSize = bTexture.tileUnitUV; if (bTexture.patterned) { float minWidth = 2 / bTexture.texture.width; float minHeight = 2 / bTexture.texture.height; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("unit width", GUILayout.Width(75)); float tileUnitSizex = EditorGUILayout.Slider(tileUnitSize.x, minWidth, 1.0f); if (tileUnitSizex != tileUnitSize.x) { tileUnitSize.x = tileUnitSizex; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("unit height", GUILayout.Width(75)); float tileUnitSizey = EditorGUILayout.Slider(tileUnitSize.y, minHeight, 1.0f); if (tileUnitSizey != tileUnitSize.y) { tileUnitSize.y = tileUnitSizey; } EditorGUILayout.EndHorizontal(); bTexture.tileUnitUV = tileUnitSize; EditorGUILayout.Space(); } const int previewTextureUnitSize = 120; const int previewTileUnitSize = 59; const int previewTileUnitPadding = 2; const int previewPadding = 25; EditorGUILayout.BeginHorizontal(); if (bTexture.tiled) { EditorGUILayout.LabelField("1 Metre Squared", GUILayout.Width(previewTextureUnitSize)); } GUILayout.Space(previewPadding); if (bTexture.patterned) { EditorGUILayout.LabelField("Texture Pattern Units", GUILayout.Width(previewTileUnitSize * 2)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (Event.current.type == EventType.Repaint) { texturePreviewPostion = GUILayoutUtility.GetLastRect(); } if (bTexture.tiled) { Rect previewRect = new Rect(texturePreviewPostion.x, texturePreviewPostion.y, previewTextureUnitSize, previewTextureUnitSize); Rect sourceRect = new Rect(0, 0, (1.0f / textureUnitSize.x), (1.0f / textureUnitSize.y)); Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0); } if (bTexture.patterned) { Rect previewRect = new Rect(previewTextureUnitSize + previewPadding, 0, previewTileUnitSize, previewTileUnitSize); Rect sourceRect = new Rect(0, tileUnitSize.y, tileUnitSize.x, tileUnitSize.y); previewRect.x += texturePreviewPostion.x; previewRect.y += texturePreviewPostion.y; Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0); sourceRect.x += tileUnitSize.x; previewRect.x += previewTileUnitSize + previewTileUnitPadding; Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0); sourceRect.x += -tileUnitSize.x; sourceRect.y += -tileUnitSize.y; previewRect.x += -(previewTileUnitSize + previewTileUnitPadding); previewRect.y += previewTileUnitSize + previewTileUnitPadding; Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0); sourceRect.x += tileUnitSize.x; previewRect.x += previewTileUnitSize + previewTileUnitPadding; Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0); } if (!bTexture.tiled) { EditorGUILayout.LabelField("Tile texture"); EditorGUILayout.BeginHorizontal(); int currentXTiles = bTexture.tiledX; GUILayout.Label("tile x", GUILayout.Width(38)); currentXTiles = EditorGUILayout.IntField(currentXTiles, GUILayout.Width(20)); if (GUILayout.Button("+", GUILayout.Width(25))) { currentXTiles++; } EditorGUI.BeginDisabledGroup(currentXTiles < 2); if (GUILayout.Button("-", GUILayout.Width(25))) { currentXTiles--; } EditorGUI.EndDisabledGroup(); bTexture.tiledX = currentXTiles; int currentYTiles = bTexture.tiledY; GUILayout.Label("tile y", GUILayout.Width(38)); currentYTiles = EditorGUILayout.IntField(currentYTiles, GUILayout.Width(20)); if (GUILayout.Button("+", GUILayout.Width(25))) { currentYTiles++; } EditorGUI.BeginDisabledGroup(currentYTiles < 2); if (GUILayout.Button("-", GUILayout.Width(25))) { currentYTiles--; } EditorGUI.EndDisabledGroup(); bTexture.tiledY = currentYTiles; EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.Space(); if (Event.current.type == EventType.Repaint) { texturePreviewPostion = GUILayoutUtility.GetLastRect(); } Rect previewRect = new Rect(texturePreviewPostion.x, texturePreviewPostion.y, previewTextureUnitSize, previewTextureUnitSize); Rect sourceRect = new Rect(0, 0, currentXTiles, currentYTiles); Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0); } GUILayout.Space(previewTextureUnitSize); break; case BuildrTexture.Types.Substance: bTexture.proceduralMaterial = (ProceduralMaterial)EditorGUILayout.ObjectField("Procedural Material", bTexture.proceduralMaterial, typeof(ProceduralMaterial), false); if (bTexture.proceduralMaterial != null) { ProceduralMaterial pMat = bTexture.proceduralMaterial; GUILayout.Label(pMat.GetGeneratedTexture(pMat.mainTexture.name), GUILayout.Width(400)); } else { EditorGUILayout.HelpBox("There is no substance material set.", MessageType.Error); } break; case BuildrTexture.Types.User: bTexture.userMaterial = (Material)EditorGUILayout.ObjectField("User Material", bTexture.userMaterial, typeof(Material), false); if (bTexture.userMaterial != null) { Material mat = bTexture.userMaterial; GUILayout.Label(mat.mainTexture, GUILayout.Width(400)); } else { EditorGUILayout.HelpBox("There is no substance material set.", MessageType.Error); } break; } }
private void MaterialListing() { ProceduralMaterial[] sortedMaterials = this.GetSortedMaterials(); ProceduralMaterial[] array = sortedMaterials; for (int i = 0; i < array.Length; i++) { ProceduralMaterial proceduralMaterial = array[i]; if (proceduralMaterial.isProcessing) { base.Repaint(); SceneView.RepaintAll(); GameView.RepaintAll(); break; } } int num = sortedMaterials.Length; float num2 = GUIView.current.position.width - 16f - 18f - 2f; if (num2 * 2f < (float)num * 60f) { num2 -= 16f; } int num3 = Mathf.Max(1, Mathf.FloorToInt(num2 / 60f)); int num4 = Mathf.CeilToInt((float)num / (float)num3); Rect viewRect = new Rect(0f, 0f, (float)num3 * 60f, (float)num4 * 76f); Rect rect = GUILayoutUtility.GetRect(viewRect.width, Mathf.Clamp(viewRect.height, 76f, 152f) + 1f); Rect position = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 1f); GUI.Box(rect, GUIContent.none, this.m_SubstanceStyles.gridBackground); GUI.Box(position, GUIContent.none, this.m_SubstanceStyles.background); this.m_ListScroll = GUI.BeginScrollView(position, this.m_ListScroll, viewRect, false, false); if (this.m_EditorCache == null) { this.m_EditorCache = new EditorCache(EditorFeatures.PreviewGUI); } for (int j = 0; j < sortedMaterials.Length; j++) { ProceduralMaterial proceduralMaterial2 = sortedMaterials[j]; if (!(proceduralMaterial2 == null)) { float x = (float)(j % num3) * 60f; float y = (float)(j / num3) * 76f; Rect rect2 = new Rect(x, y, 60f, 76f); bool flag = proceduralMaterial2.name == this.m_SelectedMaterialInstanceName; Event current = Event.current; int controlID = GUIUtility.GetControlID(SubstanceImporterInspector.previewNoDragDropHash, FocusType.Passive, rect2); EventType typeForControl = current.GetTypeForControl(controlID); if (typeForControl != EventType.Repaint) { if (typeForControl == EventType.MouseDown) { if (current.button == 0) { if (rect2.Contains(current.mousePosition)) { if (current.clickCount == 1) { this.m_SelectedMaterialInstanceName = proceduralMaterial2.name; current.Use(); } else if (current.clickCount == 2) { AssetDatabase.OpenAsset(proceduralMaterial2); GUIUtility.ExitGUI(); current.Use(); } } } } } else { Rect position2 = rect2; position2.y = rect2.yMax - 16f; position2.height = 16f; this.m_SubstanceStyles.resultsGridLabel.Draw(position2, EditorGUIUtility.TempContent(proceduralMaterial2.name), false, false, flag, flag); } rect2.height -= 16f; EditorWrapper editorWrapper = this.m_EditorCache[proceduralMaterial2]; editorWrapper.OnPreviewGUI(rect2, this.m_SubstanceStyles.background); } } GUI.EndScrollView(); }
public static void OnInspectorGUI_SM(Surface surface) { int selectedType = (int)surface.surfaceType; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Type", GUILayout.Width(LABEL_WIDTH)); int toolbarSelection = GUILayout.Toolbar(selectedType, TYPE_STRINGS); if (toolbarSelection != selectedType) { surface.material = null; #if !UNITY_2017_3_OR_NEWER surface.substance = null; #endif surface.surfaceType = (Surface.SurfaceTypes)toolbarSelection; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Material", GUILayout.Width(LABEL_WIDTH)); switch (surface.surfaceType) { case Surface.SurfaceTypes.Material: Material newMat = EditorGUILayout.ObjectField(surface.material, typeof(Material), false) as Material; if (newMat != surface.material) { surface.material = newMat; } break; #if !UNITY_2017_3_OR_NEWER case Surface.SurfaceTypes.Substance: ProceduralMaterial newSub = EditorGUILayout.ObjectField(surface.substance, typeof(ProceduralMaterial), false) as ProceduralMaterial; surface.substance = newSub; break; #endif } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Texture is Tiled", GUILayout.Width(LABEL_WIDTH)); bool tiledValue = EditorGUILayout.Toggle(surface.tiled); if (tiledValue != surface.tiled) { surface.tiled = tiledValue; } EditorGUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(tiledValue); int tileX = surface.tiledX; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Repeat X", GUILayout.Width(LABEL_WIDTH)); EditorGUI.BeginDisabledGroup(tileX <= 1); if (GUILayout.Button("-")) { tileX--; } EditorGUI.EndDisabledGroup(); EditorGUILayout.IntField(tileX); if (GUILayout.Button("+")) { tileX++; } if (tileX != surface.tiledX) { surface.tiledX = tileX; } EditorGUILayout.EndHorizontal(); int tileY = surface.tiledY; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Repeat Y", GUILayout.Width(LABEL_WIDTH)); EditorGUI.BeginDisabledGroup(tileY <= 1); if (GUILayout.Button("-")) { tileY--; } EditorGUI.EndDisabledGroup(); EditorGUILayout.IntField(tileY); if (GUILayout.Button("+")) { tileY++; } if (tileY != surface.tiledY) { surface.tiledY = tileY; } EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); Vector2 textureUnitSize = surface.textureUnitSize; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Texture Unit Size", GUILayout.Width(LABEL_WIDTH)); textureUnitSize = EditorGUILayout.Vector2Field("", textureUnitSize); if (textureUnitSize != surface.textureUnitSize) { surface.textureUnitSize = textureUnitSize; } EditorGUILayout.EndHorizontal(); if (surface.previewTexture != null) { GUILayout.Label(surface.previewTexture, GUILayout.Width(BuildingEditor.MAIN_GUI_WIDTH), GUILayout.Height(BuildingEditor.MAIN_GUI_WIDTH)); } }
// Use this for initialization void Start() { creatureSubstance = creature.GetComponent <Renderer>().sharedMaterial as ProceduralMaterial; creatureProperties = creatureSubstance.GetProceduralPropertyDescriptions(); }
private void MaterialListing() { ProceduralMaterial[] sortedMaterials = this.GetSortedMaterials(); foreach (ProceduralMaterial proceduralMaterial in sortedMaterials) { if (proceduralMaterial.isProcessing) { this.Repaint(); SceneView.RepaintAll(); GameView.RepaintAll(); break; } } int length = sortedMaterials.Length; float num1 = (float)((double)GUIView.current.position.width - 16.0 - 18.0 - 2.0); if ((double)num1 * 2.0 < (double)length * 60.0) { num1 -= 16f; } int num2 = Mathf.Max(1, Mathf.FloorToInt(num1 / 60f)); int num3 = Mathf.CeilToInt((float)length / (float)num2); Rect viewRect = new Rect(0.0f, 0.0f, (float)num2 * 60f, (float)num3 * 76f); Rect rect = GUILayoutUtility.GetRect(viewRect.width, Mathf.Clamp(viewRect.height, 76f, 152f) + 1f); Rect position1 = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 1f); GUI.Box(rect, GUIContent.none, this.m_SubstanceStyles.gridBackground); GUI.Box(position1, GUIContent.none, this.m_SubstanceStyles.background); this.m_ListScroll = GUI.BeginScrollView(position1, this.m_ListScroll, viewRect, false, false); if (this.m_EditorCache == null) { this.m_EditorCache = new EditorCache(EditorFeatures.PreviewGUI); } for (int index = 0; index < sortedMaterials.Length; ++index) { ProceduralMaterial proceduralMaterial = sortedMaterials[index]; if (!((UnityEngine.Object)proceduralMaterial == (UnityEngine.Object)null)) { Rect position2 = new Rect((float)(index % num2) * 60f, (float)(index / num2) * 76f, 60f, 76f); bool flag = proceduralMaterial.name == this.m_SelectedMaterialInstanceName; Event current = Event.current; int controlId = GUIUtility.GetControlID(SubstanceImporterInspector.previewNoDragDropHash, FocusType.Native, position2); switch (current.GetTypeForControl(controlId)) { case EventType.MouseDown: if (current.button == 0 && position2.Contains(current.mousePosition)) { if (current.clickCount == 1) { this.m_SelectedMaterialInstanceName = proceduralMaterial.name; current.Use(); break; } if (current.clickCount == 2) { AssetDatabase.OpenAsset((UnityEngine.Object)proceduralMaterial); GUIUtility.ExitGUI(); current.Use(); break; } break; } break; case EventType.Repaint: Rect position3 = position2; position3.y = position2.yMax - 16f; position3.height = 16f; this.m_SubstanceStyles.resultsGridLabel.Draw(position3, EditorGUIUtility.TempContent(proceduralMaterial.name), false, false, flag, flag); break; } position2.height -= 16f; this.m_EditorCache[(UnityEngine.Object)proceduralMaterial].OnPreviewGUI(position2, this.m_SubstanceStyles.background); } } GUI.EndScrollView(); }
public void AddMaterial(ProceduralMaterial pm) { matList.Add(pm); }
public void ConvertAnimatedListToDictionaryandSet() { if (gameObject.GetComponent <PrefabProperties>().enabled) { rend = GetComponent <Renderer>(); #if UNITY_EDITOR if (UnityEditor.Selection.activeGameObject != null && UnityEditor.Selection.activeGameObject.GetComponent <SubstanceTool>() != null) { useSharedMaterial = true; } if (UnityEditor.PrefabUtility.GetPrefabType(this) == UnityEditor.PrefabType.Prefab) { Debug.Log("object is in project view"); return; } #endif if (useSharedMaterial && this.GetComponent <Renderer>() != null) { substance = rend.sharedMaterial as ProceduralMaterial; } else if (!useSharedMaterial && this.GetComponent <Renderer>() != null) { substance = rend.material as ProceduralMaterial; } else { Debug.LogWarning("No Renderer on " + this.name); } if (useSharedMaterial) { emissionInput = rend.sharedMaterial.GetColor("_EmissionColor"); } else { emissionInput = rend.material.GetColor("_EmissionColor"); } if (substance) { substance.cacheSize = (ProceduralCacheSize)myProceduralCacheSize; ProceduralMaterial.substanceProcessorUsage = (ProceduralProcessorUsage)mySubstanceProcessorUsage; substance.enableInstancing = true; materialVariables = substance.GetProceduralPropertyDescriptions(); if (MaterialVariableKeyframeList.Count > 0) { for (int i = 0; i <= MaterialVariableKeyframeList.Count - 1; i++) { int index; MaterialVariableKeyframeDictionaryList.Add(new MaterialVariableDictionaryHolder()); MaterialVariableKeyframeDictionaryList[i].PropertyMaterialName = MaterialVariableKeyframeList[0].PropertyMaterialName; for (int j = 0; j < materialVariables.Length; j++) { ProceduralPropertyDescription materialVariable = materialVariables[j]; ProceduralPropertyType propType = materialVariables[j].type; if (i == 0 && animatedParameterNames.Contains(materialVariable.name)) { substance.CacheProceduralProperty(materialVariable.name, true); } if (propType == ProceduralPropertyType.Float) { if (MaterialVariableKeyframeList[i].myFloatKeys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myFloatKeys.IndexOf(materialVariable.name); float curFloat = MaterialVariableKeyframeList[i].myFloatValues[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curFloat); MaterialVariableKeyframeDictionaryList[i].PropertyFloatDictionary.Add(materialVariable.name, curFloat); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } if (i == 0) { substance.SetProceduralFloat(materialVariable.name, MaterialVariableKeyframeList[0].myFloatValues[MaterialVariableKeyframeList[0].myFloatKeys.IndexOf(materialVariable.name)]); } } } else if (propType == ProceduralPropertyType.Color3 || propType == ProceduralPropertyType.Color4) { if (MaterialVariableKeyframeList[i].myColorKeys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myColorKeys.IndexOf(materialVariable.name); Color curColor = MaterialVariableKeyframeList[i].myColorValues[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curColor); MaterialVariableKeyframeDictionaryList[i].PropertyColorDictionary.Add(materialVariable.name, curColor); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } if (i == 0) { substance.SetProceduralColor(materialVariable.name, MaterialVariableKeyframeList[0].myColorValues[MaterialVariableKeyframeList[0].myColorKeys.IndexOf(materialVariable.name)]); } } } else if (propType == ProceduralPropertyType.Vector2 || propType == ProceduralPropertyType.Vector3 || propType == ProceduralPropertyType.Vector4) { if (propType == ProceduralPropertyType.Vector4) { if (MaterialVariableKeyframeList[i].myVector4Keys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myVector4Keys.IndexOf(materialVariable.name); Vector4 curVector4 = MaterialVariableKeyframeList[i].myVector4Values[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector4); MaterialVariableKeyframeDictionaryList[i].PropertyVector4Dictionary.Add(materialVariable.name, curVector4); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } } if (i == 0) { substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector4Values[MaterialVariableKeyframeList[0].myVector4Keys.IndexOf(materialVariable.name)]); } } else if (propType == ProceduralPropertyType.Vector3) { if (MaterialVariableKeyframeList[i].myVector3Keys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myVector3Keys.IndexOf(materialVariable.name); Vector3 curVector3 = MaterialVariableKeyframeList[i].myVector3Values[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector3); MaterialVariableKeyframeDictionaryList[i].PropertyVector3Dictionary.Add(materialVariable.name, curVector3); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } } if (i == 0) { substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector3Values[MaterialVariableKeyframeList[0].myVector3Keys.IndexOf(materialVariable.name)]); } } else if (propType == ProceduralPropertyType.Vector2) { if (MaterialVariableKeyframeList[i].myVector2Keys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myVector2Keys.IndexOf(materialVariable.name); Vector2 curVector2 = MaterialVariableKeyframeList[i].myVector2Values[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curVector2); MaterialVariableKeyframeDictionaryList[i].PropertyVector2Dictionary.Add(materialVariable.name, curVector2); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } } if (i == 0) { substance.SetProceduralVector(materialVariable.name, MaterialVariableKeyframeList[0].myVector2Values[MaterialVariableKeyframeList[0].myVector2Keys.IndexOf(materialVariable.name)]); } } } else if (propType == ProceduralPropertyType.Enum) { if (MaterialVariableKeyframeList[i].myEnumKeys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myEnumKeys.IndexOf(materialVariable.name); int curEnum = MaterialVariableKeyframeList[i].myEnumValues[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curEnum); MaterialVariableKeyframeDictionaryList[i].PropertyEnumDictionary.Add(materialVariable.name, curEnum); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } } if (i == 0) { substance.SetProceduralEnum(materialVariable.name, MaterialVariableKeyframeList[0].myEnumValues[MaterialVariableKeyframeList[0].myEnumKeys.IndexOf(materialVariable.name)]); } } else if (propType == ProceduralPropertyType.Boolean) { if (MaterialVariableKeyframeList[i].myBooleanKeys.Contains(materialVariable.name)) { if (animatedParameterNames.Contains(materialVariable.name)) { index = MaterialVariableKeyframeList[i].myBooleanKeys.IndexOf(materialVariable.name); bool curBool = MaterialVariableKeyframeList[i].myBooleanValues[index]; MaterialVariableKeyframeDictionaryList[i].PropertyDictionary.Add(materialVariable.name, curBool); MaterialVariableKeyframeDictionaryList[i].PropertyBoolDictionary.Add(materialVariable.name, curBool); if (i == 0) { animatedMaterialVariables.Add(materialVariable); } } } if (i == 0) { substance.SetProceduralBoolean(materialVariable.name, MaterialVariableKeyframeList[0].myBooleanValues[MaterialVariableKeyframeList[0].myBooleanKeys.IndexOf(materialVariable.name)]); } } } MaterialVariableKeyframeDictionaryList[i].MainTex = MaterialVariableKeyframeList[i].MainTex; MaterialVariableKeyframeDictionaryList[i].emissionColor = MaterialVariableKeyframeList[i].emissionColor; } } } if (deleteOldListValuesOnStart) { MaterialVariableKeyframeList.Clear(); } } }
void Awake() { substance = gameObject.GetComponent <MeshRenderer>().sharedMaterial as ProceduralMaterial; }
public extern void OnShaderModified(ProceduralMaterial material);