Skip to content

Instantly share code, notes, and snippets.

@neguse11
Created September 6, 2015 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neguse11/8ed6a98c91b511e5bb38 to your computer and use it in GitHub Desktop.
Save neguse11/8ed6a98c91b511e5bb38 to your computer and use it in GitHub Desktop.
オートロードプラグイン
/*
オートロードを行うUnityInjector用プラグイン
起動後に、自動的に最新のセーブデーターをロードします。
コンパイル方法
cd /d C:\KISS\CM3D2_KAIZOU\UnityInjector
C:\Windows\Microsoft.NET\Framework\v3.5\csc /t:library /lib:..\CM3D2x64_Data\Managed /r:Assembly-CSharp.dll /r:UnityEngine.dll /r:UnityInjector.dll CM3D2.AutoLoad.Plugin.cs
コマンドラインオプション
--AutoLoadPlugin-auto-edit
自動ロード後に「メイド管理」→「エディット」を実行します。メイド長がいる場合は常にメイド長をエディット対象とします。
*/
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityInjector;
using UnityInjector.Attributes;
namespace CM3D2.AutoLoad.Plugin
{
[PluginFilter("CM3D2x64"),
PluginFilter("CM3D2x86"),
PluginFilter("CM3D2VRx64"),
PluginName("CM3D2 AutoLoad"),
PluginVersion("0.1.0.0")]
public class AutoLoadPlugin : PluginBase
{
bool firstTitleScreen = true;
bool firstDailyScreen = true;
bool firstMaidManagementScreen = true;
bool bAutoLoad = true;
bool bAutoEdit = false;
Coroutine cor = null;
void Awake()
{
GameObject.DontDestroyOnLoad(this);
foreach (string arg in System.Environment.GetCommandLineArgs())
{
if (arg == "--AutoLoadPlugin-no-auto-load")
{
bAutoLoad = false;
}
if (arg == "--AutoLoadPlugin-auto-edit")
{
bAutoLoad = true;
bAutoEdit = true;
}
}
}
void OnLevelWasLoaded(int level)
{
if (cor != null)
{
StopCoroutine(cor);
cor = null;
}
switch(level) {
default:
break;
case 9:
if (firstTitleScreen && bAutoLoad)
{
firstTitleScreen = false;
cor = StartCoroutine(AutoClickCoroutine());
}
break;
case 3:
if (firstDailyScreen && bAutoEdit)
{
firstDailyScreen = false;
cor = StartCoroutine(AutoDailyClickCoroutine());
}
break;
case 7:
if (firstMaidManagementScreen && bAutoEdit)
{
firstMaidManagementScreen = false;
cor = StartCoroutine(AutoMaidManagementClickCoroutine());
}
break;
}
}
IEnumerator AutoClickCoroutine()
{
yield return StartCoroutine(WaitForFade());
// タイトル画面での「Continue」クリック
while (! ClickGameObject("/UI Root/TitlePanel/ButtonGroup/ContinueGroup/Continue"))
{
yield return null;
}
// ロード画面での「New」ファイルクリック
while (true)
{
yield return null;
if (IsActive("SaveAndLoadPanel"))
{
GameObject go = GameObject.Find("NewLabel");
if (go != null)
{
GameObject parent = go.transform.parent.gameObject;
UICamera.currentTouchID = -1; // 擬似左クリック。ロード画面ではこれが必要
if (ClickGameObject(parent))
{
break;
}
}
}
}
// ロード確認ダイアログの「OK」クリック
while (! ClickGameObject("/__GameMain__/SystemUI Root/SystemDialog/Base/Ok"))
{
yield return null;
}
yield break;
}
IEnumerator AutoDailyClickCoroutine()
{
yield return StartCoroutine(WaitForFade());
// デイリー画面での「メイド管理」クリック
while (! ClickGameObject("/UI Root/DailyPanel/DailyButtonGroup/MaidManagement"))
{
yield return null;
}
yield break;
}
IEnumerator AutoMaidManagementClickCoroutine()
{
yield return StartCoroutine(WaitForFade());
// メイド管理画面での「エディット」クリック
while (! ClickGameObject("/UI Root/Parent/ButtonParent/Tower/Grid/エディット"))
{
yield return null;
}
yield break;
}
// フェードイン待ち
static IEnumerator WaitForFade()
{
// WfScreenChildrenが出揃うのを待つ
yield return null;
WfScreenChildren[] wscs = FindObjectsOfType<WfScreenChildren>();
while (wscs.Any(wsc => IsFading(wsc)))
{
yield return null;
}
yield break;
}
static bool IsFading(WfScreenChildren wsc)
{
WfScreenChildren.FadeStatus fs = wsc.fade_status;
return fs != WfScreenChildren.FadeStatus.FadeEnd &&
fs != WfScreenChildren.FadeStatus.Null &&
fs != WfScreenChildren.FadeStatus.Wait;
}
static bool IsActive(string name)
{
return IsActive(GameObject.Find(name));
}
static bool IsActive(GameObject go)
{
return go != null && go.activeInHierarchy;
}
static bool ClickGameObject(string name)
{
return ClickGameObject(GameObject.Find(name));
}
static bool ClickGameObject(GameObject go)
{
if (go != null)
{
UIButton uiButton = go.GetComponent<UIButton>();
if (uiButton != null && uiButton.isEnabled)
{
uiButton.SendMessage("OnClick");
return true;
}
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment