コード例 #1
0
        public static void CreateNewTranslationDefinition()
        {
            ShaderTranslator shaderTranslator = CreateInstance <ShaderTranslator>();
            string           path             = UnityHelper.GetCurrentAssetExplorerFolder() + "/shaderTranslationDefinition.asset";

            AssetDatabase.CreateAsset(shaderTranslator, path);
            EditorGUIUtility.PingObject(shaderTranslator);
            TranslationDefinitions.Add(shaderTranslator);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            ShaderTranslator translator = serializedObject.targetObject as ShaderTranslator;

            translator.Name = EditorGUILayout.TextField("Translation File Name: ", translator.Name);

            GUILayout.Space(10);

            string[] shaders = AssetDatabase.FindAssets("t:shader").Select(g => AssetDatabase.LoadAssetAtPath <Shader>(AssetDatabase.GUIDToAssetPath(g)).name).
                               Where(s => s.StartsWith("Hidden") == false).ToArray();

            EditorGUI.BeginChangeCheck();
            int originIndex = EditorGUILayout.Popup("From Shader", Array.IndexOf(shaders, translator.OriginShader), shaders);

            if (EditorGUI.EndChangeCheck())
            {
                translator.OriginShader = shaders[originIndex];
            }

            EditorGUI.BeginChangeCheck();
            int targetIndex = EditorGUILayout.Popup("To Shader", Array.IndexOf(shaders, translator.TargetShader), shaders);

            if (EditorGUI.EndChangeCheck())
            {
                translator.TargetShader = shaders[targetIndex];
            }

            translator.MatchOriginShaderBasedOnRegex = EditorGUILayout.ToggleLeft(new GUIContent("Match Origin Shader Using Regex",
                                                                                                 "Match the origin shader for suggestions based on a regex definition."), translator.MatchOriginShaderBasedOnRegex);
            if (translator.MatchOriginShaderBasedOnRegex)
            {
                translator.OriginShaderRegex = EditorGUILayout.TextField("Origin Shader Regex", translator.OriginShaderRegex);
            }
            translator.MatchTargetShaderBasedOnRegex = EditorGUILayout.ToggleLeft(new GUIContent("Match Target Shader Using Regex",
                                                                                                 "Match the target shader for suggestions based on a regex definition."), translator.MatchTargetShaderBasedOnRegex);
            if (translator.MatchTargetShaderBasedOnRegex)
            {
                translator.TargetShaderRegex = EditorGUILayout.TextField("Target Shader Regex", translator.TargetShaderRegex);
            }

            if (originIndex < 0 || targetIndex < 0)
            {
                EditorGUILayout.HelpBox("Could not find origin or target shader.", MessageType.Error);
                return;
            }

            Shader origin = Shader.Find(shaders[originIndex]);
            Shader target = Shader.Find(shaders[targetIndex]);

            GUILayout.Space(10);

            using (new GUILayout.VerticalScope("box"))
            {
                GUILayout.Label("Property Translation", EditorStyles.boldLabel);
                GUILayout.BeginHorizontal();
                GUILayout.Label("From");
                GUILayout.Label("To");
                GUILayout.Label("Math");
                GUILayout.EndHorizontal();
                List <PropertyTranslation> remove = new List <PropertyTranslation>();
                foreach (PropertyTranslation trans in translator.PropertyTranslations)
                {
                    Rect fullWidth = EditorGUILayout.GetControlRect();
                    Rect r         = fullWidth;
                    r.width = (r.width - 20) / 3;
                    if (GUI.Button(r, trans.Origin))
                    {
                        GuiHelper.SearchableEnumPopup.CreateSearchableEnumPopup(
                            MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { new Material(origin) }).Select(p => p.name).ToArray(), trans.Origin,
                            (newValue) => trans.Origin = newValue);
                    }
                    r.x += r.width;
                    if (GUI.Button(r, trans.Target))
                    {
                        GuiHelper.SearchableEnumPopup.CreateSearchableEnumPopup(
                            MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { new Material(target) }).Select(p => p.name).ToArray(), trans.Target,
                            (newValue) => trans.Target = newValue);
                    }
                    r.x       += r.width;
                    trans.Math = EditorGUI.TextField(r, trans.Math);
                    r.x       += r.width;
                    r.width    = 20;
                    if (GUI.Button(r, GUIContent.none, Styles.icon_style_remove))
                    {
                        remove.Add(trans);
                    }
                }

                foreach (PropertyTranslation r in remove)
                {
                    translator.PropertyTranslations.Remove(r);
                }

                Rect buttonRect = EditorGUILayout.GetControlRect();
                buttonRect.x     = buttonRect.width - 20;
                buttonRect.width = 20;
                if (GUI.Button(buttonRect, GUIContent.none, Styles.icon_style_add))
                {
                    translator.PropertyTranslations.Add(new PropertyTranslation());
                }
            }

            serializedObject.Update();
            EditorUtility.SetDirty(serializedObject.targetObject);
        }