Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CM3D2.AddModsSlider.Plugin.0.0.0.0 : フリーコメント欄の各modパラメータをスライドバーで操作する UnityInjector 用プラグイン
- // メイドエディット画面中にF5で表示トグル。
- // コメント欄で操作する数値をスライドバーで調整する事が可能。
- // "EYEBALL", "TEST_EYE_RATIO", "TEST_EYE_ANG"
- // "TEST_PELSCL", "TEST_THISCL", "TEST_THIPOS", "SPISCL", "S0ASCL", "S1_SCL", "S1ASCL"
- // に対応。フリーコメント欄にそのmodの有効な書式が在れば、該当するスライドバーが表示される。
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Text.RegularExpressions;
- using UnityEngine;
- using UnityInjector.Attributes;
- namespace CM3D2.AddModsSlider.Plugin
- {
- [PluginFilter("CM3D2x64"),
- PluginFilter("CM3D2x86"),
- PluginFilter("CM3D2VRx64"),
- PluginName("CM3D2 AddModsSlider"),
- PluginVersion("0.0.0.0")]
- public class AddModsSlider : UnityInjector.PluginBase
- {
- private int sceneLevel;
- private bool visible = false;
- private ModsParam mp;
- private float scbarValue = 0f;
- public class ModsParam
- {
- public static string[] sKey = {
- "EYEBALL"
- , "TEST_EYE_RATIO", "TEST_EYE_ANG"
- , "TEST_PELSCL", "TEST_THISCL", "TEST_THIPOS"
- , "SPISCL", "S0ASCL", "S1_SCL", "S1ASCL"
- };
- public static int Count { get{return ModsParam.sKey.Length; } }
- public Dictionary<string, float[]> fValue = new Dictionary<string, float[]>();
- public Dictionary<string, float[]> fVmin = new Dictionary<string, float[]>();
- public Dictionary<string, float[]> fVmax = new Dictionary<string, float[]>();
- public Dictionary<string, string[]> sLabel = new Dictionary<string, string[]>();
- public Dictionary<string, string> sMatchPattern = new Dictionary<string, string>();
- public Dictionary<string, bool> bEnabled = new Dictionary<string, bool>();
- public Dictionary<string, bool> bScale = new Dictionary<string, bool>();
- public ModsParam()
- {
- this.fValue[ModsParam.sKey[0]] = new float[2] {1.0f,1.0f};
- this.fValue[ModsParam.sKey[1]] = new float[1] {1.0f};
- this.fValue[ModsParam.sKey[2]] = new float[3] {0.0f, 0.0f, 0.0f};
- this.fValue[ModsParam.sKey[3]] = new float[3] {1.0f, 1.0f, 1.0f};
- this.fValue[ModsParam.sKey[4]] = new float[2] {1.0f, 1.0f};
- this.fValue[ModsParam.sKey[5]] = new float[2] {0.0f, 0.0f};
- this.fValue[ModsParam.sKey[6]] = new float[3] {1.0f, 1.0f, 1.0f};
- this.fValue[ModsParam.sKey[7]] = new float[3] {1.0f, 1.0f, 1.0f};
- this.fValue[ModsParam.sKey[8]] = new float[3] {1.0f, 1.0f, 1.0f};
- this.fValue[ModsParam.sKey[9]] = new float[3] {1.0f, 1.0f, 1.0f};
- this.fVmin[ModsParam.sKey[0]] = new float[2] {0.1f,0.1f};
- this.fVmin[ModsParam.sKey[1]] = new float[1] {0.1f};
- this.fVmin[ModsParam.sKey[2]] = new float[3] {-60.0f, -100.0f, -100.0f};
- this.fVmin[ModsParam.sKey[3]] = new float[3] {0.1f, 0.1f, 0.1f};
- this.fVmin[ModsParam.sKey[4]] = new float[2] {0.1f, 0.1f};
- this.fVmin[ModsParam.sKey[5]] = new float[2] {-100.0f, -100.0f};
- this.fVmin[ModsParam.sKey[6]] = new float[3] {0.1f, 0.1f, 0.1f};
- this.fVmin[ModsParam.sKey[7]] = new float[3] {0.1f, 0.1f, 0.1f};
- this.fVmin[ModsParam.sKey[8]] = new float[3] {0.1f, 0.1f, 0.1f};
- this.fVmin[ModsParam.sKey[9]] = new float[3] {0.1f, 0.1f, 0.1f};
- this.fVmax[ModsParam.sKey[0]] = new float[2] {2.0f,2.0f};
- this.fVmax[ModsParam.sKey[1]] = new float[1] {2.0f};
- this.fVmax[ModsParam.sKey[2]] = new float[3] {60.0f, 100.0f, 100.0f};
- this.fVmax[ModsParam.sKey[3]] = new float[3] {2.0f, 2.0f, 2.0f};
- this.fVmax[ModsParam.sKey[4]] = new float[2] {2.0f, 2.0f};
- this.fVmax[ModsParam.sKey[5]] = new float[2] {100.0f, 100.0f};
- this.fVmax[ModsParam.sKey[6]] = new float[3] {2.0f, 2.0f, 2.0f};
- this.fVmax[ModsParam.sKey[7]] = new float[3] {2.0f, 2.0f, 2.0f};
- this.fVmax[ModsParam.sKey[8]] = new float[3] {2.0f, 2.0f, 2.0f};
- this.fVmax[ModsParam.sKey[9]] = new float[3] {2.0f, 2.0f, 2.0f};
- this.sLabel[ModsParam.sKey[0]] = new string[2] {"瞳の大きさ(縦): ", "瞳の大きさ(横): "};
- this.sLabel[ModsParam.sKey[1]] = new string[1] {"目の縦横比率 : "};
- this.sLabel[ModsParam.sKey[2]] = new string[3] {"目の角度 : ", "目の横位置 : ", "目の縦位置 : "};
- this.sLabel[ModsParam.sKey[3]] = new string[3] {"骨盤の横幅 : ", "骨盤の奥行き : ", "骨盤の高さ : "};
- this.sLabel[ModsParam.sKey[4]] = new string[2] {"足の横幅 : ", "足の奥行き : "};
- this.sLabel[ModsParam.sKey[5]] = new string[2] {"足の横位置 : ", "足の前後位置 : "};
- this.sLabel[ModsParam.sKey[6]] = new string[3] {"胴(下腹部)の横幅 : ", "胴(下腹部)の奥行き : ", "胴(下腹部)の高さ : "};
- this.sLabel[ModsParam.sKey[7]] = new string[3] {"胴(腹部)の横幅 : ", "胴(腹部)の奥行き : ", "胴(腹部)の高さ : "};
- this.sLabel[ModsParam.sKey[8]] = new string[3] {"胴(みぞおち)の横幅 : ", "胴(みぞおち)の奥行き : ", "胴(みぞおち)の高さ : "};
- this.sLabel[ModsParam.sKey[9]] = new string[3] {"胴(首・肋骨)の横幅 : ", "胴(首・肋骨)の奥行き : ", "胴(首・肋骨)の高さ : "};
- this.sMatchPattern[ModsParam.sKey[0]] = @"#" + ModsParam.sKey[0] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[1]] = @"#" + ModsParam.sKey[1] + @"=([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[2]] = @"#" + ModsParam.sKey[2] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[3]] = @"#" + ModsParam.sKey[3] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[4]] = @"#" + ModsParam.sKey[4] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[5]] = @"#" + ModsParam.sKey[5] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[6]] = @"#" + ModsParam.sKey[6] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[7]] = @"#" + ModsParam.sKey[7] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[8]] = @"#" + ModsParam.sKey[8] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- this.sMatchPattern[ModsParam.sKey[9]] = @"#" + ModsParam.sKey[9] + @"=([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)#";
- for (int i=0; i<ModsParam.Count; i++)
- {
- string key = ModsParam.sKey[i];
- this.bEnabled[key] = false;
- for (int j=0; j<ModsParam.Count; j++)
- {
- if (key == "TEST_EYE_ANG" || key == "TEST_THIPOS")
- {
- this.bScale[key] = false;
- }
- else
- {
- this.bScale[key] = true;
- }
- }
- }
- }
- }
- //----
- public void Awake()
- {
- }
- void OnLevelWasLoaded(int level)
- {
- sceneLevel = level;
- if (sceneLevel == 5)
- {
- this.mp = new ModsParam();
- }
- else
- {
- visible = false;
- }
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.F5))
- {
- visible = !visible;
- }
- }
- void OnGUI()
- {
- if (!visible) return;
- if (sceneLevel != 5) return;
- string freeComment = null;
- CharacterMgr cm = GameMain.Instance.CharacterMgr;
- Maid maid = cm.GetMaid(0);
- if (maid == null) return;
- if (maid.Param != null && maid.Param.status != null && maid.Param.status.free_comment != null)
- {
- freeComment = maid.Param.status.free_comment;
- }
- if (freeComment == null) return;
- CheckModbEnabled(this.mp, freeComment);
- AddSlider(this.mp);
- UpdateFreeComment(maid, this.mp);
- }
- //----
- private void CheckModbEnabled(ModsParam mp, string freeComment)
- {
- for(int i=0; i<ModsParam.Count; i++)
- {
- string key = ModsParam.sKey[i];
- int vnum = mp.fValue[key].Length;
- Match match = Regex.Match(freeComment, mp.sMatchPattern[ModsParam.sKey[i]]);
- if (match.Groups.Count > vnum)
- {
- bool tpf = true;
- for(int j=0; j<vnum; j++)
- {
- mp.bEnabled[key] = true;
- tpf &= Single.TryParse(match.Groups[j + 1].Value, out mp.fValue[key][j]);
- }
- if(!tpf) mp.bEnabled[key] = false;
- }
- }
- }
- private void AddSlider(ModsParam mp)
- {
- int mods_n = ModsParam.Count;
- int margin = 10;
- int menuHeight = 43;
- int okButtonHeight = 90;
- int winTop = margin + menuHeight;
- int winLeft = margin + (int)((Screen.width - margin * 2) * 0.75);
- int winWidth = (int)((Screen.width - margin * 2) * 0.25);
- int winHeight = (int)(Screen.height- winTop - margin - okButtonHeight);
- int conTop = winTop + margin + 30;
- int conWidth = winWidth - margin * 4 ;
- int conHeight = 0;
- int lineH = 22;
- int lineH2 = 24;
- int lineP = conTop;
- int overHeight = 0;
- int outconLine = 0;
- int thrcon = 0;
- bool scrlf = false;
- // 下地のボックス
- GUIStyle bstyle = "box";
- bstyle.fontSize = 18;
- bstyle.alignment = TextAnchor.UpperLeft;
- Rect outRect = new Rect(winLeft, winTop, winWidth, winHeight);
- GUI.Box(outRect, "Mods Slider", bstyle);
- // スクロールバー
- for (int i=0; i<mods_n; i++)
- {
- string key = ModsParam.sKey[i];
- if (!mp.bEnabled[key]) continue;
- int value_n = mp.fValue[key].Length;
- conHeight += lineH2;
- for (int j=0; j<value_n; j++) conHeight += lineH * 2;
- conHeight += (int)(margin*2);
- }
- overHeight = conHeight - (winHeight - conTop - margin);
- if (overHeight > 0)
- {
- outRect.Set(winLeft+winWidth-margin*2, lineP, margin, winHeight-lineP+winTop-margin);
- scbarValue = GUI.VerticalScrollbar(outRect, scbarValue, 20f, 0f, 120f);
- scrlf = true;
- outconLine = (int)(overHeight * scbarValue/100f);
- }
- // ラベルとスライダーバー
- GUIStyle lstyle = "label";
- for (int i=0; i<mods_n; i++)
- {
- if (lineP > winTop + winHeight - lineH * 2) break;
- string key = ModsParam.sKey[i];
- if (!mp.bEnabled[key]) continue;
- int value_n = mp.fValue[key].Length;
- for (int j=0; j<value_n; j++)
- {
- if (scrlf)
- {
- if (thrcon < outconLine)
- {
- thrcon += lineH * 2;
- continue;
- }
- if (lineP > winTop + winHeight - lineH * 2) break;
- }
- if (j == 0)
- {
- lstyle.fontSize = 16;
- outRect.Set(winLeft+10, lineP, conWidth, lineH2);
- GUI.Label(outRect, key, lstyle);
- lineP += lineH2;
- }
- lstyle.fontSize = 14;
- string label = mp.sLabel[key][j];
- float value = mp.fValue[key][j];
- float vmin = mp.fVmin[key][j];
- float vmax = mp.fVmax[key][j];
- bool isScale = mp.bScale[key];
- outRect.Set(winLeft+10, lineP, conWidth, lineH);
- GUI.Label(outRect, label+value.ToString("F"), lstyle);
- lineP += lineH;
- outRect.Set(winLeft+10, lineP, conWidth, lineH);
- if (isScale)
- {
- float tmp = value - 1f;
- tmp = GUI.HorizontalSlider(outRect, tmp, -vmax+1f, vmax-1f);
- mp.fValue[key][j] = 1f + tmp;
- }
- else
- {
- mp.fValue[key][j] = GUI.HorizontalSlider(outRect, value, vmin, vmax);
- }
- lineP += lineH;
- }
- if (scrlf)
- {
- if (thrcon < outconLine)
- {
- thrcon += (int)(margin*2);
- continue;
- }
- if (lineP > winTop + winHeight - lineH * 2) break;
- }
- lineP += (int)(margin*2);
- }
- }
- private void UpdateFreeComment(Maid maid, ModsParam mp)
- {
- string freeComment = maid.Param.status.free_comment;
- for(int i=0; i<ModsParam.Count; i++)
- {
- string key = ModsParam.sKey[i];
- int vnum = mp.fValue[key].Length;
- if (mp.bEnabled[key])
- {
- freeComment = Regex.Replace(freeComment, mp.sMatchPattern[ModsParam.sKey[i]], "");
- string ws = @"#" + ModsParam.sKey[i];
- for(int j=0; j<vnum; j++)
- {
- ws += (j == 0) ? "=" : ",";
- ws += mp.fValue[key][j].ToString("F2");
- }
- ws += "#";
- freeComment += ws;
- }
- }
- maid.Param.SetFreeComment(freeComment);
- }
- private float conRV(float vf)
- {
- return (vf < 0) ? 1f/vf : vf;
- }
- private float decRV(float vf)
- {
- return (vf < 1) ? -1f/vf : vf;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement