Esempio n. 1
0
 public static void ApplyReplacement(ref quest_stuff_data qst, EQuestStuffUI action)
 {
     if (action == EQuestStuffUI.k_EQuestStuffUI_set_pc)
     {
         ApplyReplacement(ref qst, true);
     }
     if (action == EQuestStuffUI.k_EQuestStuffUI_set_quest)
     {
         ApplyReplacement(ref qst, false);
     }
 }
Esempio n. 2
0
    public static EQuestStuffUI DrawQuestStuffGUI(ref quest_stuff_data qst)
    {
        EQuestStuffUI action = EQuestStuffUI.k_EQuestStuffUI_noaction;

        if (qst.replacements == null)
        {
            qst.replacements = new List <mat_replacement>();
        }

        if (qst.objs == null)
        {
            qst.objs = new List <obj_toggly>();
        }

        for (int i = 0; i < qst.replacements.Count; i++)
        {
            mat_replacement replacement = qst.replacements[i];

            replacement.shown = EditorGUILayout.Foldout(replacement.shown, replacement.name, true, EditorStyles.foldout);

            if (replacement.shown)
            {
                EditorGUI.indentLevel++;
                replacement.name = EditorGUILayout.DelayedTextField(replacement.name);

                if (GUILayout.Button("delete"))
                {
                    qst.replacements.RemoveAt(i);
                    continue;
                }

                int newCount = Mathf.Max(0, EditorGUILayout.DelayedIntField("size", replacement.materials.Count));
                while (newCount < replacement.materials.Count)
                {
                    replacement.materials.RemoveAt(replacement.materials.Count - 1);
                }
                while (newCount > replacement.materials.Count)
                {
                    replacement.materials.Add(null);
                }

                replacement.shader_default = (Shader)EditorGUILayout.ObjectField(replacement.shader_default, typeof(Shader), false);
                replacement.shader_quest   = (Shader)EditorGUILayout.ObjectField(replacement.shader_quest, typeof(Shader), false);

                for (int j = 0; j < replacement.materials.Count; j++)
                {
                    replacement.materials[j] = (Material)EditorGUILayout.ObjectField(replacement.materials[j], typeof(Material), false);
                }
                EditorGUI.indentLevel--;
            }
        }

        if (GUILayout.Button("add shader replacement"))
        {
            mat_replacement replacement = new mat_replacement();
            replacement.materials = new List <Material>();
            qst.replacements.Add(replacement);
        }

        for (int i = 0; i < qst.objs.Count; i++)
        {
            obj_toggly toggle = qst.objs[i];

            toggle.shown = EditorGUILayout.Foldout(toggle.shown, toggle.name, true, EditorStyles.foldout);

            if (toggle.shown)
            {
                EditorGUI.indentLevel++;
                toggle.name = EditorGUILayout.DelayedTextField(toggle.name);

                if (GUILayout.Button("delete"))
                {
                    qst.objs.RemoveAt(i);
                    continue;
                }

                int newCount = Mathf.Max(0, EditorGUILayout.DelayedIntField("size", toggle.objs.Count));
                while (newCount < toggle.objs.Count)
                {
                    toggle.objs.RemoveAt(toggle.objs.Count - 1);
                }
                while (newCount > toggle.objs.Count)
                {
                    toggle.objs.Add(null);
                }

                EditorGUILayout.BeginHorizontal();
                toggle.pc    = EditorGUILayout.Toggle("PC", toggle.pc);
                toggle.quest = EditorGUILayout.Toggle("Quest", toggle.quest);
                EditorGUILayout.EndHorizontal();

                for (int j = 0; j < toggle.objs.Count; j++)
                {
                    toggle.objs[j] = (GameObject)EditorGUILayout.ObjectField(toggle.objs[j], typeof(GameObject), true);
                }
                EditorGUI.indentLevel--;
            }
        }

        if (GUILayout.Button("add toggle"))
        {
            obj_toggly toggle = new obj_toggly();
            toggle.objs = new List <GameObject>();
            qst.objs.Add(toggle);
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Set PC"))
        {
            ApplyReplacement(ref qst, true);
            action = EQuestStuffUI.k_EQuestStuffUI_set_pc;
        }

        if (GUILayout.Button("Set Quest"))
        {
            ApplyReplacement(ref qst, false);

            action = EQuestStuffUI.k_EQuestStuffUI_set_quest;
        }

        EditorGUILayout.EndHorizontal();

        return(action);
    }
Esempio n. 3
0
    public override void OnInspectorGUI()
    {
        if (!gui_resource_ready)
        {
            gui_resource_init();
        }

        ht8b_editor _editor = (ht8b_editor)target;

        base.DrawDefaultInspector();

        EditorGUI.BeginChangeCheck();

        ht8b_config cfg = _editor.config;

        if (cfg != null)
        {
            bAllowCompile = true;

            Ht8bUIGroup("Table setup");

            cfg._table_setup_prefab = (GameObject)EditorGUILayout.ObjectField("Table artwork", cfg._table_setup_prefab, typeof(GameObject), false);

            if (cfg._table_setup_prefab)
            {
                if (!Prefab_ht8b_supports(ref cfg._table_setup_prefab))
                {
                    bAllowCompile = false;
                }
            }
            else
            {
                DrawError("Prefab needs to be set to check structure", styleError);
            }

            cfg._table_surface_mat = (Material)EditorGUILayout.ObjectField("Table surface material", cfg._table_surface_mat, typeof(Material), false);
            cfg._ball_mat          = (Material)EditorGUILayout.ObjectField("Ball material", cfg._ball_mat, typeof(Material), false);

            if (cfg._table_surface_mat)
            {
                if (!Material_ht8b_supports(ref cfg._table_surface_mat))
                {
                    bAllowCompile = false;
                }
            }
            else
            {
                DrawError("Material needs to be set to check shader properties", styleError);
            }

            Ht8bUIGroup("Collision info");

            if (!this.cdata_displayTarget)
            {
                this.cdata_displayTarget = _editor.gameObject.transform.Find("intl.balls").Find("__table_refiner__").gameObject.GetComponent <table_configurator>();
            }

            this.bShowCollision = EditorGUILayout.Toggle("Draw collision data", this.cdata_displayTarget.gameObject.activeSelf);
            this.cdata_displayTarget.gameObject.SetActive(this.bShowCollision);

            if (!cfg.cdata.bInit)
            {
                cfg.cdata.init_default();
            }

            cfg.cdata.k_TABLE_WIDTH    = EditorGUILayout.Slider("Width", cfg.cdata.k_TABLE_WIDTH, 0.4f, 2.4f);
            cfg.cdata.k_TABLE_HEIGHT   = EditorGUILayout.Slider("Height", cfg.cdata.k_TABLE_HEIGHT, 0.4f, 2.4f);
            cfg.cdata.k_POCKET_RADIUS  = EditorGUILayout.Slider("Pocket Radius", cfg.cdata.k_POCKET_RADIUS, 0.06f, 0.4f);
            cfg.cdata.k_CUSHION_RADIUS = EditorGUILayout.Slider("Cushion Radius", cfg.cdata.k_CUSHION_RADIUS, 0.01f, 0.4f);
            cfg.cdata.k_INNER_RADIUS   = EditorGUILayout.Slider("Pocket Trigger Radius", cfg.cdata.k_INNER_RADIUS, 0.03f, 0.3f);

            cfg.cdata._cornerpocket = EditorGUILayout.Vector3Field("Corner pocket location", cfg.cdata._cornerpocket);
            cfg.cdata._sidepocket   = EditorGUILayout.Vector3Field("Side pocket location", cfg.cdata._sidepocket);

            this.cdata_displayTarget.cdata = cfg.cdata;

            cfg._collision_data_prefab = (GameObject)EditorGUILayout.ObjectField("(VFX) Collision model", cfg._collision_data_prefab, typeof(GameObject), false);

            if (!cfg._collision_data_prefab)
            {
                DrawError("Without a collision prefab, balls will instantly dissapear when pocketed!", styleWarning);
            }

            Ht8bUIGroupEnd();

            Ht8bUIGroupEnd();

            Ht8bUIGroup("Global");

            cfg._colourDefault = alpha1(EditorGUILayout.ColorField(new GUIContent("Default edge light"), cfg._colourDefault, false, false, false));
            cfg._colourFoul    = alpha1(EditorGUILayout.ColorField(new GUIContent("Foul colour"), cfg._colourFoul, false, false, false));

            Ht8bUIGroupEnd();

            if (Ht8bUIGroupMitButton("8 Ball", "test it"))
            {
                cfg.RenderProcedural_8ball();
                AssetDatabase.Refresh();
                cfg._ball_mat.SetTexture("_MainTex", (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/harry_t/ht8b_materials/procedural/tballs_8ball.png", typeof(Texture2D)));
                cfg._table_surface_mat.SetColor("_EmissionColor", cfg._8ball_team_colour_0 * 1.5f);
                cfg._table_surface_mat.SetColor("_Color", cfg._8ball_fabric_colour);

                balls_showlimited(_editor.gameObject.transform, 0xffffu);

                _editor.transform.Find("intl.table").Find("table_artwork").Find(".4BALL_FILL").gameObject.SetActive(false);
            }

            cfg._8ball_fabric_colour = EditorGUILayout.ColorField(new GUIContent("Surface Colour"), cfg._8ball_fabric_colour, false, true, false);
            cfg._8ball_team_colour_0 = alpha1(EditorGUILayout.ColorField(new GUIContent("Spots Colour"), cfg._8ball_team_colour_0, false, false, false));
            cfg._8ball_team_colour_1 = alpha1(EditorGUILayout.ColorField(new GUIContent("Stripes Colour"), cfg._8ball_team_colour_1, false, false, false));

            Ht8bUIGroupEnd();

            if (Ht8bUIGroupMitButton("9 Ball", "test it"))
            {
                cfg.RenderProcedural_9ball_4ball();
                AssetDatabase.Refresh();
                cfg._ball_mat.SetTexture("_MainTex", (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/harry_t/ht8b_materials/procedural/tballs_9ball.png", typeof(Texture2D)));
                cfg._table_surface_mat.SetColor("_EmissionColor", cfg._colourDefault * 1.5f);
                cfg._table_surface_mat.SetColor("_Color", cfg._9ball_fabric_colour);

                balls_showlimited(_editor.gameObject.transform, 0x03ffu);

                _editor.transform.Find("intl.table").Find("table_artwork").Find(".4BALL_FILL").gameObject.SetActive(false);
            }

            cfg._9ball_fabric_colour = EditorGUILayout.ColorField(new GUIContent("Surface Colour"), cfg._9ball_fabric_colour, false, true, false);
            ui_9x9ColourGrid(cfg._9ball_colours);

            Ht8bUIGroupEnd();

            if (Ht8bUIGroupMitButton("4 Ball", "test it"))
            {
                cfg.RenderProcedural_9ball_4ball();
                AssetDatabase.Refresh();
                cfg._ball_mat.SetTexture("_MainTex", (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/harry_t/ht8b_materials/procedural/tballs_9ball.png", typeof(Texture2D)));
                cfg._table_surface_mat.SetColor("_EmissionColor", cfg._4ball_team_colour_0 * 1.5f);
                cfg._table_surface_mat.SetColor("_Color", cfg._4ball_fabric_colour);

                balls_showlimited(_editor.gameObject.transform, 0xf000u);

                _editor.transform.Find("intl.table").Find("table_artwork").Find(".4BALL_FILL").gameObject.SetActive(true);
            }

            cfg._4ball_fabric_colour    = EditorGUILayout.ColorField(new GUIContent("Surface Colour"), cfg._4ball_fabric_colour, false, true, false);
            cfg._4ball_team_colour_0    = alpha1(EditorGUILayout.ColorField(new GUIContent("Team A Colour"), cfg._4ball_team_colour_0, false, false, false));
            cfg._4ball_team_colour_1    = alpha1(EditorGUILayout.ColorField(new GUIContent("Team B Colour"), cfg._4ball_team_colour_1, false, false, false));
            cfg._4ball_objective_colour = alpha1(EditorGUILayout.ColorField(new GUIContent("Objective colour"), cfg._4ball_objective_colour, false, false, false));

            Ht8bUIGroupEnd();

            Ht8bUIGroup("Quest / shaders");

            EQuestStuffUI switchto = quest_stuff.DrawQuestStuffGUI(ref cfg.quest_switch_data);
            if (switchto != EQuestStuffUI.k_EQuestStuffUI_noaction)
            {
                quest_stuff.ApplyReplacement(ref cfg.quest_switch_data, switchto);

                // Chain replacements switch into internal materials
                quest_stuff intl_replacements = _editor.gameObject.transform.Find("__intl_quest_toggle__").gameObject.GetComponent <quest_stuff>();
                quest_stuff.ApplyReplacement(ref intl_replacements.data, switchto);
            }

            Ht8bUIGroupEnd();

            bShowResource = EditorGUILayout.Foldout(bShowResource, "Texture sources", true, EditorStyles.foldout);

            if (bShowResource)
            {
                cfg._src_ball_content     = (Texture2D)EditorGUILayout.ObjectField("8/9 Ball layout", cfg._src_ball_content, typeof(Texture2D), false);
                cfg._src_ball_spinmarkers = (Texture2D)EditorGUILayout.ObjectField("Ball spin marker", cfg._src_ball_spinmarkers, typeof(Texture2D), false);
            }

            if (!bAllowCompile)
            {
                //GUI.enabled = false;
            }

            if (GUILayout.Button("Compile & Apply config"))
            {
                Debug.Log("Running ht8b config");

                cfg.RenderProceduralTextures();
                cfg.ApplyConfig(_editor.gameObject.transform);
            }

            GUI.enabled = true;

            if (GUI.changed)
            {
                EditorUtility.SetDirty(cfg);
            }
        }
        else
        {
            GUILayout.Label("No config set");
        }

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RegisterCompleteObjectUndo(cfg, "edited ht8b config");
        }
    }