Advertisement
Guest User

CM3D2.YotogiParamCtrl.Plugin

a guest
Aug 26th, 2015
8,661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.53 KB | None | 0 0
  1. // CM3D2.YotogiParamCtrl.Plugin.0.0.0.1 : 夜伽時のパラメータ(興奮/精神/理性)を固定するUnityInjector用プラグイン
  2.  
  3. // 機能.
  4. // 夜伽画面中にテンキー0で機能有効/無効の切り替え
  5. // テンキー1、2、3を押して興奮・精神・理性に対象を切り替えて、テンキーの+/-で5ずつ増減させる。
  6. // 作成の経緯.
  7. // AddModsSliderの夜伽時のパラメータ固定機能がOculusVRでは動作しないために作成.
  8. // 0.0.0.1 初版(Add Mods Sliderを参考に新規作成)
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Reflection;
  14. using System.Text;
  15. using UnityEngine;
  16. using UnityInjector.Attributes;
  17.  
  18. namespace CM3D2.YotogiParamCtrl.Plugin
  19. {
  20.     [PluginFilter("CM3D2x64"),
  21.     PluginFilter("CM3D2x86"),
  22.     PluginFilter("CM3D2VRx64"),
  23.     PluginName("CM3D2 YotogiParamCtrl"),
  24.     PluginVersion("0.0.0.1")]
  25.     public class YotogiParamCtrl : UnityInjector.PluginBase
  26.     {
  27.         public const string Version = "0.0.0.1";
  28.  
  29.         private const int SCENELEVEL_YOTOGI = 14;    // 夜伽シーンを表す定数
  30.  
  31.         private const int MAID_EXCITE = 0;            // 興奮度
  32.         private const int MAID_MIND = 1;                // 精神
  33.         private const int MAID_REASON = 2;            // 理性
  34.  
  35.         private const float PARAM_STEP = 5f;            // パラメータ増減値
  36.  
  37.         private YotogiParamBasicBar yotogiParamBasicBar;    // 画面上部の夜伽バー(多分)
  38.  
  39.         private int sceneLevel;
  40.         private bool is_enable = false;
  41.         private int param_idx = MAID_EXCITE;    // 初期操作対象は興奮度としておく
  42.         private float[] fYotogiValue = new float[] { 0f, 0f, 0f };
  43.         private float[] fYotogiMinValue = new float[] { -100f, 0f, 0f };
  44.         private float[] fYotogiMaxValue = new float[] { 0f, 0f, 0f };
  45.  
  46.  
  47.  
  48.         // スクリプト起動時に呼ばれるハンドラ
  49.         public void Awake()
  50.         {
  51.             // シーン変更時に破棄されないようにする
  52.             GameObject.DontDestroyOnLoad(this);
  53.  
  54.             return;
  55.         }
  56.  
  57.         // シーンレベルロード完了時に呼ばれるハンドラ
  58.         public void OnLevelWasLoaded(int level)
  59.         {
  60.             // シーンレベルの保存
  61.             sceneLevel = level;
  62.  
  63.             return;
  64.         }
  65.  
  66.         // 毎フレーム呼ばれるハンドラ
  67.         public void Update()
  68.         {
  69.             // 夜伽時、本プラグインのメイン処理
  70.             if (sceneLevel == SCENELEVEL_YOTOGI) {
  71.                 // 夜伽対象のメイドへの参照を取得
  72.                 Maid maid =  GameMain.Instance.CharacterMgr.GetMaid(0);
  73.  
  74.                 // 未取得の場合、夜伽用のUIバーへの参照を取得.
  75.                 if (!this.yotogiParamBasicBar)
  76.                 {
  77.                     this.yotogiParamBasicBar = BaseMgr<YotogiParamBasicBar>.Instance;
  78.                 }
  79.                 // テンキー0で有効/無効の切り替えを制御
  80.                 if (Input.GetKeyDown(KeyCode.Keypad0)) {
  81.                     if (is_enable) {
  82.                         is_enable = false;
  83.                         //Debug.Log("YotogiParamCtrl is Disable");
  84.                     }
  85.                     else {
  86.                         is_enable = true;
  87.                         //Debug.Log("YotogiParamCtrl is Enable");
  88.                     }
  89.                 }
  90.  
  91.                 // 機能有効、かつ夜伽バーの取得に成功、メイドへの参照に成功している場合、処理実行する
  92.                 if ((is_enable == true) && (this.yotogiParamBasicBar != null) && (maid != null)) {
  93.                     // 操作対象切り替え(興奮度)
  94.                     if ( Input.GetKeyDown(KeyCode.Keypad1) ) {
  95.                         param_idx = MAID_EXCITE;
  96.                         //Debug.Log("YotogiParamCtrl Target:Excite");
  97.                     }
  98.                     // 操作対象切り替え(精神)
  99.                     else if ( Input.GetKeyDown(KeyCode.Keypad2) ) {
  100.                         param_idx = MAID_MIND;
  101.                         //Debug.Log("YotogiParamCtrl Target:Mind");
  102.                     }
  103.                     // 操作対象切り替え(理性)
  104.                     else if ( Input.GetKeyDown(KeyCode.Keypad3) ) {
  105.                         param_idx = MAID_REASON;
  106.                         //Debug.Log("YotogiParamCtrl Target:Reason");
  107.                     }
  108.  
  109.                     // 現在値を取得
  110.                     fYotogiValue[MAID_EXCITE] = maid.Param.status.cur_excite;    // 興奮度
  111.                     fYotogiValue[MAID_MIND] = maid.Param.status.cur_mind;        // 精神
  112.                     fYotogiValue[MAID_REASON] = maid.Param.status.cur_reason;    // 理性
  113.  
  114.                     // 最大値を取得
  115.                     fYotogiMaxValue[MAID_EXCITE] = 300;                            // 興奮度
  116.                     fYotogiMaxValue[MAID_MIND] = maid.Param.status.mind + maid.Param.status.maid_class_bonus_status.mind;    // 精神
  117.                     fYotogiMaxValue[MAID_REASON] = maid.Param.status.reason;    // 理性
  118.  
  119.                     // 最小値を取得(コードとしてはは不要だが、修正しやすいように)
  120.                     fYotogiMinValue[MAID_EXCITE] = -100;                            // 興奮度
  121.                     fYotogiMinValue[MAID_MIND] = 0;                                    // 精神
  122.                     fYotogiMinValue[MAID_REASON] = 0;                                // 理性
  123.  
  124.                     // テンキー「+」で増加
  125.                     if ( Input.GetKeyDown(KeyCode.KeypadPlus) ) {
  126.                         fYotogiValue[param_idx] += PARAM_STEP;
  127.                         //Debug.Log("YotogiParamCtrl Paramater Plus");
  128.                     }
  129.                     // テンキー「-」で減少
  130.                     else if ( Input.GetKeyDown(KeyCode.KeypadMinus) ) {
  131.                         fYotogiValue[param_idx] -= PARAM_STEP;
  132.                         //Debug.Log("YotogiParamCtrl Paramater Minus");
  133.                     }
  134.  
  135.                     // 最大値、最小値へのクリッピング
  136.                     if (fYotogiValue[param_idx] > fYotogiMaxValue[param_idx]) {
  137.                         fYotogiValue[param_idx] = fYotogiMaxValue[param_idx];
  138.                         //Debug.Log("YotogiParamCtrl Max Value");
  139.                     }
  140.                     else if (fYotogiValue[param_idx] < fYotogiMinValue[param_idx]) {
  141.                         fYotogiValue[param_idx] = fYotogiMinValue[param_idx];
  142.                         //Debug.Log("YotogiParamCtrl Min Value");
  143.                     }
  144.  
  145.                     // メイドのパラメータ更新
  146.                     maid.Param.SetCurExcite((int)fYotogiValue[MAID_EXCITE]);
  147.                     maid.Param.SetCurMind((int)fYotogiValue[MAID_MIND]);
  148.                     maid.Param.SetCurReason((int)fYotogiValue[MAID_REASON]);
  149.  
  150.                     // 夜伽バーの更新
  151.                     this.yotogiParamBasicBar.SetCurrentExcite((int)this.fYotogiValue[MAID_EXCITE], true);
  152.                     this.yotogiParamBasicBar.SetCurrentMind((int)this.fYotogiValue[MAID_MIND], true);
  153.                     this.yotogiParamBasicBar.SetCurrentReason((int)this.fYotogiValue[MAID_REASON], true);
  154.                 }
  155.  
  156.             }
  157.             else
  158.             {
  159.                 // 夜伽シーン以外では、誤動作防止のため無効化
  160.                 is_enable = false;
  161.             }
  162.         }
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement