Last active
September 11, 2015 14:12
-
-
Save asm256/4013bfc9de412d62b670 to your computer and use it in GitHub Desktop.
CM3D2.CharacterShot.Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$build_base = 'https://gist.github.com/asm256/4013bfc9de412d62b670/raw/' | |
$build_script = 'build.ps1' | |
$build_lib = 'https://gist.github.com/asm256/ed75d84a9e89802821f8/raw/4232d16dc57b25e1fbd94382c883e2121e0e1534/build_lib.ps1' | |
$web = new-object net.webclient | |
[Text.Encoding]::UTF8.GetString($web.DownloadData("$build_lib")) | iex | |
(WebDownloadString $web "$build_base$build_script")| iex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#改変再配布自由 | |
#大抵の場合ここから | |
$prjName = 'CharacterShot' | |
$base = 'https://gist.github.com/asm256/4013bfc9de412d62b670/raw/' | |
$srcs = @('CM3D2.CharacterShot.Plugin.cs') | |
#ここまで | |
Init($prjName) | |
pushd -LiteralPath $prjDir | |
$web = new-object net.webclient | |
$web.BaseAddress = $base | |
Write-Host "ダウンロード" | |
foreach($s in $srcs){ | |
WebDownload $web $s | |
} | |
Write-Host "レシピ作成" | |
$recipe = foreach( $s in $srcs){ | |
make_recipe $s | |
} | |
Write-Host "コンパイル" | |
foreach($r in $recipe){ | |
make_batch $r | |
compile $r | |
} | |
Write-Host "インストール" | |
foreach($r in $recipe){ | |
install $r | |
} | |
Write-Host "おわり" | |
#パッチ当ては各自で | |
Pop-Location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// == Compile Options == | |
// csc /t:library /lib:..\CM3D2x64_Data\Managed /r:UnityEngine.dll /r:UnityInjector.dll /r:Assembly-CSharp.dll CM3D2.CharacterShot.Plugin.cs | |
// @AB_addarg /lib:%managed% | |
// @AB_addarg /r:UnityEngine.dll | |
// @AB_addarg /r:UnityInjector.dll | |
// @AB_addarg /r:Assembly-CSharp.dll | |
// @AB_install %uinjector% | |
// ==/Compile Options == | |
// == History == | |
// wip とりあえず実装 | |
// 15.9.10.0 ブラッシュアップした | |
// - コンパイル通らなかったバグ | |
// - スーパーサイズの実装 | |
// - ScreenShotフォルダへ | |
// 15.9.11.0 名前変更 | |
// - CharacterShot へと名前を変更 | |
// ==/History == | |
// == Description == | |
// Kを押すと背景を黒い完全透過色に変えます | |
// 右Alt+Sを押すと透過pngで保存します | |
// | |
// ブルーム0で謎の現象が起きます | |
// ブルームが大きいと影というか背景漏れ?が目立ちます | |
// ブルーム1か2だと綺麗に抜けます | |
// ==/Description == | |
using System; | |
using System.IO; | |
using System.Collections; | |
using UnityEngine; | |
using UnityInjector; | |
using UnityInjector.Attributes; | |
namespace CM3D2.CharacterShot.Plugin | |
{ | |
[PluginFilter("CM3D2x64"), | |
PluginFilter("CM3D2x86"), | |
PluginFilter("CM3D2VRx64"), | |
PluginName("CharacterShot"), | |
PluginVersion("15.9.11.0")] | |
public class CharacterShot : PluginBase | |
{ | |
private void Awake() | |
{ | |
GameObject.DontDestroyOnLoad(this); | |
} | |
private void Update() | |
{ | |
if (Application.loadedLevel != 5) | |
{ | |
return; | |
} | |
if (Input.GetKey(KeyCode.RightAlt) && Input.GetKeyDown(KeyCode.S)) | |
{ | |
Camera.main.backgroundColor = Color.clear; | |
gameObject.AddComponent<SuperSizeAlphaSS>().filename = "ScreenShot/" + System.DateTime.Now.ToString("yyyyMMdd_HHmmssFFFF") + ".png"; | |
} | |
if (Input.GetKeyDown(KeyCode.K)) | |
{ | |
GameMain.Instance.BgMgr.ChangeBg(null); | |
Camera.main.backgroundColor = Color.clear; | |
} | |
} | |
} | |
public class SuperSizeAlphaSS : MonoBehaviour{ | |
IEnumerator Start(){ | |
return take(); | |
} | |
public string filename; | |
IEnumerator take(){ | |
yield return new WaitForEndOfFrame(); | |
if(String.IsNullOrEmpty(filename))filename = "test_ss.png"; | |
Console.Out.Write("ScreenShot Take\n"); | |
int scale = new int[]{1,2,4}[(int)GameMain.Instance.CMSystem.ScreenShotSuperSize]; | |
int width = Screen.width * scale; | |
int height= Screen.height * scale; | |
var rt = RenderTexture.GetTemporary(width, height); | |
var tex = new Texture2D (width, height, TextureFormat.ARGB32, false,false); | |
var prevtT = Camera.main.targetTexture; | |
var prevact= RenderTexture.active; | |
Camera.main.targetTexture = rt; | |
Camera.main.Render(); | |
RenderTexture.active = rt; | |
tex.ReadPixels ( new Rect(0, 0, width, height), 0, 0); | |
tex.Apply (); | |
Camera.main.targetTexture = prevtT; | |
RenderTexture.active = prevact; | |
// Encode texture into PNG | |
var bytes = tex.EncodeToPNG(); | |
File.WriteAllBytes(filename, bytes); | |
Destroy(tex); | |
Destroy(rt); | |
Destroy(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment