Skip to content

Commit

Permalink
Merge pull request #18 from Masterexa/develop
Browse files Browse the repository at this point in the history
update v7
  • Loading branch information
Masterexa authored Jan 15, 2020
2 parents d692926 + cf35795 commit e02b852
Show file tree
Hide file tree
Showing 103 changed files with 4,249 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"m_Tooltip": "陰影の設定"
},
"rampDirectionalText": {
"m_Text": "ディレクショナル",
"m_Text": "平行光源",
"m_Image": { "instanceID": 0 },
"m_Tooltip": "ディレクショナルライトのランプテクスチャ"
},
"rampPointText": {
"m_Text": "ポイント",
"m_Text": "点光源",
"m_Image": { "instanceID": 0 },
"m_Tooltip": "ポイントライトのランプテクスチャ"
},
Expand All @@ -50,7 +50,7 @@
"m_Tooltip": "色(RGB)と不透明度(A)の設定"
},
"standardGIText": {
"m_Text": "標準のGIを使う",
"m_Text": "単色GIを無効にする",
"m_Image": { "instanceID": 0 },
"m_Tooltip": "Unityの標準的なGIを利用する"
},
Expand Down
9 changes: 9 additions & 0 deletions Assets/HoshiyukiToonGit/Utility.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/HoshiyukiToonGit/Utility/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/HoshiyukiToonGit/Utility/Editor/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 146 additions & 0 deletions Assets/HoshiyukiToonGit/Utility/Editor/Scripts/ScreenShotWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using NowhereUnity.Utility;

namespace ProjectNameEditor{


/* --- WARNING ---
Create this only in under the 'Editor' directory.
*/

///<summary>ScreenShotWindow</summary>
///<remarks>
///A Editor Window class.
///</remarks>
public class ScreenShotWindow : EditorWindow{

enum ImageFormat {
JPG,
PNG,
DXR
}

[MenuItem("Window/ScreenShotWindow")]
static void Init(){
var wnd = EditorWindow.GetWindow(typeof(ScreenShotWindow));
wnd.Show();
}


#region Instance
#region Fields
[SerializeField]ImageFormat m_format;
[SerializeField]bool m_customResolution = false;
[SerializeField]int m_imageWidth = 1920;
[SerializeField]int m_imageHeight = 1080;
#endregion

#region Properties
#endregion

#region Events
///<summary>
///Use this for initialization.
///</summary>
void OnEnable() {

}

///<summary>
///Use this for draw window.
///</summary>
void OnGUI(){

m_format = (ImageFormat)EditorGUILayout.EnumPopup("Format",m_format);

m_customResolution = EditorGUILayout.ToggleLeft("Custom Resolution", m_customResolution);
using(var hz = new GUILayout.HorizontalScope())
{
EditorGUI.indentLevel++;

m_imageWidth = EditorGUILayout.IntField(m_imageWidth);
GUILayout.Label("x", GUILayout.ExpandWidth(false));
m_imageHeight = EditorGUILayout.IntField(m_imageHeight);

EditorGUI.indentLevel--;
}


if(GUILayout.Button("Take"))
{
string path = ChooseSavePath();

if( !string.IsNullOrEmpty(path) )
{
var tex = CreateTexture();

ScreenShot.TakeCameraImage(Camera.main, tex);

var bytes = EncodeImage(tex);
SafeDestroy(tex);
System.IO.File.WriteAllBytes(path, bytes);
}
}
}
#endregion

#region Pipeline
void SafeDestroy(UnityEngine.Object obj) {

if( Application.isPlaying )
{
UnityEngine.Object.Destroy(obj);
}
else
{
UnityEngine.Object.DestroyImmediate(obj);
}
}

string ChooseSavePath() {
var ext = (m_format==ImageFormat.JPG) ? "jpg" : (m_format==ImageFormat.PNG) ? "png" : "exr";

return EditorUtility.SaveFilePanel("Save Screenshot", EditorApplication.applicationPath, "", ext);
}

Texture2D CreateTexture() {

int w = Camera.main.pixelWidth, h=Camera.main.pixelHeight;
if( m_customResolution )
{
w = m_imageWidth;
h = m_imageHeight;
}
return new Texture2D(w, h, (m_format==ImageFormat.DXR) ? TextureFormat.RGBAHalf : TextureFormat.ARGB32, false );
}

byte[] EncodeImage(Texture2D tex) {

byte[] bytes = null;

switch(m_format)
{
case ImageFormat.JPG:
bytes = tex.EncodeToJPG();
break;
case ImageFormat.PNG:
bytes = tex.EncodeToPNG();
break;
case ImageFormat.DXR:
bytes = tex.EncodeToEXR();
break;
default:
break;
}
return bytes;
}
#endregion
#endregion
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/HoshiyukiToonGit/Utility/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions Assets/HoshiyukiToonGit/Utility/Scripts/EnvironmentChange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace NowhereUnity.Utility{

///<summary>EnvironmentChange</summary>
///<remarks>
///Use this for control objects in a scene.
///</remarks>
public class EnvironmentChange : MonoBehaviour {
#region Instance
#region Fields
public ReflectionProbe reflectionProbe;
public Material[] materials = new Material[0];

Rect m_rect;
Vector2 m_scroll;
int m_index=-1;
#endregion

#region Properties
#endregion

#region Events
///<summary>
///Use this for initialization.
///</summary>
void Start () {
m_rect = new Rect(Screen.width-410, 10, 250, 400);
}

private void OnGUI() {

m_rect.x = Mathf.Clamp(m_rect.x, 30f-m_rect.width, (float)Screen.width-30f);
m_rect.y = Mathf.Clamp(m_rect.y, 30f-m_rect.height, (float)Screen.height-30f);

m_rect = GUI.Window(0, m_rect, (id) =>
{
var sun = RenderSettings.sun;
bool sunEnabled = (sun!=null) ? sun.enabled : false;
int index = m_index;

GUI.enabled = sun!=null;
sunEnabled = GUILayout.Toggle(sunEnabled,"Sun");

GUI.enabled = true;
m_scroll = GUILayout.BeginScrollView(m_scroll, GUI.skin.textArea);
{
for(int i=0; i<materials.Length; i++)
{
var it = materials[i];
bool isActived = i==index;
bool choosen = GUILayout.Toggle(isActived, it.name);

if( !isActived && choosen )
{
index = i;
}
}
}
GUILayout.EndScrollView();
GUI.DragWindow();

// Ref
if(sun!=null)
{
sun.enabled = sunEnabled;
}
if( m_index!=index )
{
m_index = index;
RenderSettings.skybox = materials[m_index];
DynamicGI.UpdateEnvironment();
if( reflectionProbe )
{
reflectionProbe.RenderProbe();
}
}
}, "Environment");
}
#endregion

#region Pipeline
#endregion

#region Methods
#endregion
#endregion
}
}
12 changes: 12 additions & 0 deletions Assets/HoshiyukiToonGit/Utility/Scripts/EnvironmentChange.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e02b852

Please sign in to comment.