/// <summary> /// Initializzation that happens the first time the window is created /// </summary> /// <param name="materialEditor">Material editor provided by the custom inspector</param> /// <param name="properties">Array of materialProperties provided by the custom inspector</param> public void Start(MaterialEditor materialEditor, MaterialProperty[] properties) { //Temporary code for transitioning between 2017 to 2018 if (FindProperty("_NeedsFix", properties).floatValue == 0.5) { #if UNITY_2018_1_OR_NEWER FindProperty("_NeedsFix", properties).floatValue = 0; #else FindProperty("_NeedsFix", properties).floatValue = 1; #endif } EditorGUIUtility.labelWidth = 0f; //material = materialEditor.target as Material; //Initialize properties FindProperties(properties); //Initializes the ramp section based on the inspector level inspectorLevel = (InspectorLevel)EditorPrefs.GetInt("TSInspectorLevel"); switch (inspectorLevel) { case InspectorLevel.Basic: basicMain = new BasicMainSection(properties); break; case InspectorLevel.Normal: packer = new TexturePacker(TexturePacker.Resolution.M_512x512, new string[] { "Metallic", "Smoothness", "Ambient occlusion", "Thickness map" }, GetTextureDestinationPath((Material)_RampOn.targets[0], "MSOT.png")); main = new MainSection(properties, inspectorLevel, packer, this); Selection.selectionChanged += SetMSOT; break; case InspectorLevel.Expert: packer = new TexturePacker(TexturePacker.Resolution.M_512x512, new string[] { "Metallic", "Smoothness", "Ambient occlusion", "Thickness map" }, GetTextureDestinationPath((Material)_RampOn.targets[0], "MSOT.png")); main = new MainSection(properties, inspectorLevel, packer, this); break; } foreach (Material mat in FindProperty("_Mode", properties).targets) { //remove keywords not used in Toony Standard RemoveUnwantedKeywords(mat); // Setup various keyword based settings SetupMaterialWithBlendMode(mat, (BlendMode)mat.GetFloat("_Mode"), mat.GetFloat("_OutlineOn") > 0); // Setup emission MaterialEditor.FixupEmissiveFlag(mat); bool shouldEmissionBeEnabled = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0; TSFunctions.SetKeyword(mat, "_EMISSION", shouldEmissionBeEnabled); if (shouldEmissionBeEnabled) { mat.SetOverrideTag("IsEmissive", "true"); } else { mat.SetOverrideTag("IsEmissive", "false"); } } GenerateRampMinMax(properties); // Add sections based on the inspector level group = new OrderedSectionGroup(); if (inspectorLevel == InspectorLevel.Basic) { group.addSection(new BasicSpecularSection(properties, TSFunctions.BooleanFloat(_SpecularBox.floatValue), TSFunctions.BooleanFloat(_SpecularOn.floatValue))); group.addSection(new OutlineSection(properties, TSFunctions.BooleanFloat(_OutlineBox.floatValue), TSFunctions.BooleanFloat(_OutlineOn.floatValue))); } else { group.addSection(new RampSection(this, properties, TSFunctions.BooleanFloat(_ToonRampBox.floatValue), TSFunctions.BooleanFloat(_RampOn.floatValue))); group.addSection(new RimLightSection(properties, TSFunctions.BooleanFloat(_RimLightBox.floatValue), TSFunctions.BooleanFloat(_RimLightOn.floatValue))); group.addSection(new SpecularSection(properties, inspectorLevel, this, TSFunctions.BooleanFloat(_SpecularBox.floatValue), TSFunctions.BooleanFloat(_SpecularOn.floatValue))); group.addSection(new DetailSection(properties, TSFunctions.BooleanFloat(_DetailBox.floatValue), TSFunctions.BooleanFloat(_DetailMapOn.floatValue))); group.addSection(new SubsurfaceSection(properties, inspectorLevel, this, TSFunctions.BooleanFloat(_SSSBox.floatValue), TSFunctions.BooleanFloat(_SSSOn.floatValue))); group.addSection(new OutlineSection(properties, TSFunctions.BooleanFloat(_OutlineBox.floatValue), TSFunctions.BooleanFloat(_OutlineOn.floatValue))); } if (inspectorLevel == InspectorLevel.Expert) { group.addSection(new StencilSection(properties, TSFunctions.BooleanFloat(_StencilBox.floatValue), TSFunctions.BooleanFloat(_StencilOn.floatValue))); } else { FindProperty("_StencilID", properties).floatValue = 0; FindProperty("_StencilComp", properties).floatValue = 0; FindProperty("_StencilOp", properties).floatValue = 0; } }
/// <summary> /// Initializzation that happens the first time the window is created /// </summary> /// <param name="materialEditor">Material editor provided by the custom inspector</param> /// <param name="properties">Array of materialProperties provided by the custom inspector</param> public void Start(MaterialEditor materialEditor, MaterialProperty[] properties) { //Temporary code for transitioning between 2017 to 2018 if (FindProperty("_NeedsFix", properties).floatValue == 0.5) { #if UNITY_2018_1_OR_NEWER FindProperty("_NeedsFix", properties).floatValue = 0; #else FindProperty("_NeedsFix", properties).floatValue = 1; #endif } EditorGUIUtility.labelWidth = 0f; material = materialEditor.target as Material; //Initialize properties FindProperties(properties); //Set some values based on the inspector level setting inspectorLevel = (InspectorLevel)EditorPrefs.GetInt("TSInspectorLevel"); switch (inspectorLevel) { case InspectorLevel.Basic: _Occlusion.floatValue = 0f; _FakeLight.floatValue = 0f; _RimLightOn.floatValue = 0; _workflow.floatValue = (float)Workflow.Metallic; _MetallicMap.textureValue = null; _GlossinessMap.textureValue = null; _SpMode.floatValue = (float)SpMode.Standard; _indirectSpecular.floatValue = (float)IndirectSpecular.Probe; _HighlightRamp.textureValue = TSConstants.DefaultRamp; _HighlightRampOffset.floatValue = 0f; _DetailMapOn.floatValue = 0f; break; case InspectorLevel.Normal: break; case InspectorLevel.Expert: break; } foreach (Material mat in _SpecularOn.targets) { TSFunctions.SetKeyword(mat, "_ENABLE_SPECULAR", mat.GetFloat(_SpecularOn.name) != 0); TSFunctions.SetKeyword(mat, "_DETAIL_MAP", mat.GetFloat(_DetailMapOn.name) != 0); } // Setup various keyword based settings SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode")); SetupIndirectSource(material, (IndirectSpecular)material.GetFloat("_IndirectSpecular")); SetupWorkflow(material, (Workflow)material.GetFloat("_Workflow")); SetupSpMode(material, (SpMode)_SpMode.floatValue); // Setup emission MaterialEditor.FixupEmissiveFlag(material); bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0; TSFunctions.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled); if (shouldEmissionBeEnabled) { material.SetOverrideTag("IsEmissive", "true"); } else { material.SetOverrideTag("IsEmissive", "false"); } // Add sections based on the inspector level group = new OrderedSectionGroup(); if (inspectorLevel == InspectorLevel.Basic) { group.addSection(new OrderedSection(Styles.specularOptions, DrawBasicSpecularOptionsSection, CheckBasicSpecularOptionsSection, SpecularOptionsIndex)); } else { group.addSection(new OrderedSection(Styles.rampOptions, DrawRampOptionsSection, CheckRampOptionsChanges, RampOptionsIndex)); group.addSection(new OrderedSection(Styles.rimOptions, DrawRimLightOptionsSection, CheckRimLightOptionsSection, RimLightOptionsIndex)); group.addSection(new OrderedSection(Styles.specularOptions, DrawSpecularOptionsSection, CheckSpecularOptionsSection, SpecularOptionsIndex)); group.addSection(new OrderedSection(Styles.detailOptions, DrawDetailOptionsSection, CheckDrawDetailOptionsSection, DetailOptionsIndex)); } }