Import AllIn1SpriteShader
This commit is contained in:
parent
73557e3bbe
commit
4d817ea88a
87 changed files with 8553 additions and 0 deletions
383
Assets/AllIn1SpriteShader/Scripts/AllIn1Shader.cs
Normal file
383
Assets/AllIn1SpriteShader/Scripts/AllIn1Shader.cs
Normal file
|
|
@ -0,0 +1,383 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("AllIn1SpriteShader/AddAllIn1Shader")]
|
||||
public class AllIn1Shader : MonoBehaviour
|
||||
{
|
||||
private Material currMaterial, prevMaterial;
|
||||
private bool matAssigned = false, destroyed = false;
|
||||
private enum AfterSetAction { Clear, CopyMaterial, Reset};
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private static float timeLastReload = -1f;
|
||||
private void Start()
|
||||
{
|
||||
if(timeLastReload < 0) timeLastReload = Time.time;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (matAssigned || Application.isPlaying || !gameObject.activeSelf) return;
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
Renderer r = GetComponent<Renderer>();
|
||||
if (r.sharedMaterial == null) return;
|
||||
if (r.sharedMaterial.name.Contains("Default")) MakeNewMaterial();
|
||||
else matAssigned = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
if (img.material.name.Contains("Default")) MakeNewMaterial();
|
||||
else matAssigned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void MakeNewMaterial()
|
||||
{
|
||||
SetMaterial(AfterSetAction.Clear);
|
||||
}
|
||||
|
||||
public void MakeCopy()
|
||||
{
|
||||
SetMaterial(AfterSetAction.CopyMaterial);
|
||||
}
|
||||
|
||||
private void ResetAllProperties()
|
||||
{
|
||||
SetMaterial(AfterSetAction.Reset);
|
||||
}
|
||||
|
||||
private void SetMaterial(AfterSetAction action)
|
||||
{
|
||||
Shader allIn1Shader = Resources.Load("AllIn1SpriteShader", typeof(Shader)) as Shader;
|
||||
if (!Application.isPlaying && Application.isEditor && allIn1Shader != null)
|
||||
{
|
||||
bool rendererExists = false;
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
rendererExists = true;
|
||||
prevMaterial = new Material(GetComponent<Renderer>().sharedMaterial);
|
||||
currMaterial = new Material(allIn1Shader);
|
||||
GetComponent<Renderer>().sharedMaterial = currMaterial;
|
||||
GetComponent<Renderer>().sharedMaterial.hideFlags = HideFlags.None;
|
||||
matAssigned = true;
|
||||
DoAfterSetAction(action);
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
rendererExists = true;
|
||||
prevMaterial = new Material(img.material);
|
||||
currMaterial = new Material(allIn1Shader);
|
||||
img.material = currMaterial;
|
||||
img.material.hideFlags = HideFlags.None;
|
||||
matAssigned = true;
|
||||
DoAfterSetAction(action);
|
||||
}
|
||||
}
|
||||
if (!rendererExists)
|
||||
{
|
||||
MissingRenderer();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSceneDirty();
|
||||
}
|
||||
}
|
||||
else if (allIn1Shader == null)
|
||||
{
|
||||
Debug.LogError("Make sure the AllIn1SpriteShader file is inside the Resource folder!");
|
||||
}
|
||||
}
|
||||
|
||||
private void DoAfterSetAction(AfterSetAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case AfterSetAction.Clear:
|
||||
ClearAllKeywords();
|
||||
break;
|
||||
case AfterSetAction.CopyMaterial:
|
||||
currMaterial.CopyPropertiesFromMaterial(prevMaterial);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void TryCreateNew()
|
||||
{
|
||||
bool rendererExists = false;
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
rendererExists = true;
|
||||
Renderer r = GetComponent<Renderer>();
|
||||
if (r != null && r.sharedMaterial != null && r.sharedMaterial.name.Contains("AllIn1"))
|
||||
{
|
||||
ResetAllProperties();
|
||||
ClearAllKeywords();
|
||||
}
|
||||
else
|
||||
{
|
||||
CleanMaterial();
|
||||
MakeNewMaterial();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
rendererExists = true;
|
||||
if (img.material.name.Contains("AllIn1"))
|
||||
{
|
||||
ResetAllProperties();
|
||||
ClearAllKeywords();
|
||||
}
|
||||
else MakeNewMaterial();
|
||||
}
|
||||
}
|
||||
if (!rendererExists)
|
||||
{
|
||||
MissingRenderer();
|
||||
}
|
||||
SetSceneDirty();
|
||||
}
|
||||
|
||||
public void ClearAllKeywords()
|
||||
{
|
||||
SetKeyword("RECTSIZE_ON");
|
||||
SetKeyword("OFFSETUV_ON");
|
||||
SetKeyword("CLIPPING_ON");
|
||||
SetKeyword("POLARUV_ON");
|
||||
SetKeyword("TWISTUV_ON");
|
||||
SetKeyword("ROTATEUV_ON");
|
||||
SetKeyword("FISHEYE_ON");
|
||||
SetKeyword("PINCH_ON");
|
||||
SetKeyword("SHAKEUV_ON");
|
||||
SetKeyword("WAVEUV_ON");
|
||||
SetKeyword("ROUNDWAVEUV_ON");
|
||||
SetKeyword("DOODLE_ON");
|
||||
SetKeyword("ZOOMUV_ON");
|
||||
SetKeyword("FADE_ON");
|
||||
SetKeyword("TEXTURESCROLL_ON");
|
||||
SetKeyword("GLOW_ON");
|
||||
SetKeyword("OUTBASE_ON");
|
||||
SetKeyword("ONLYOUTLINE_ON");
|
||||
SetKeyword("OUTTEX_ON");
|
||||
SetKeyword("OUTDIST_ON");
|
||||
SetKeyword("DISTORT_ON");
|
||||
SetKeyword("WIND_ON");
|
||||
SetKeyword("GRADIENT_ON");
|
||||
SetKeyword("COLORSWAP_ON");
|
||||
SetKeyword("HSV_ON");
|
||||
SetKeyword("HITEFFECT_ON");
|
||||
SetKeyword("PIXELATE_ON");
|
||||
SetKeyword("NEGATIVE_ON");
|
||||
SetKeyword("COLORRAMP_ON");
|
||||
SetKeyword("GREYSCALE_ON");
|
||||
SetKeyword("POSTERIZE_ON");
|
||||
SetKeyword("BLUR_ON");
|
||||
SetKeyword("MOTIONBLUR_ON");
|
||||
SetKeyword("GHOST_ON");
|
||||
SetKeyword("INNEROUTLINE_ON");
|
||||
SetKeyword("ONLYINNEROUTLINE_ON");
|
||||
SetKeyword("HOLOGRAM_ON");
|
||||
SetKeyword("CHROMABERR_ON");
|
||||
SetKeyword("GLITCH_ON");
|
||||
SetKeyword("FLICKER_ON");
|
||||
SetKeyword("SHADOW_ON");
|
||||
SetKeyword("ALPHACUTOFF_ON");
|
||||
SetKeyword("CHANGECOLOR_ON");
|
||||
SetSceneDirty();
|
||||
}
|
||||
|
||||
private void SetKeyword(string keyword, bool state = false)
|
||||
{
|
||||
if (destroyed) return;
|
||||
if (currMaterial == null)
|
||||
{
|
||||
FindCurrMaterial();
|
||||
if (currMaterial == null)
|
||||
{
|
||||
MissingRenderer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!state) currMaterial.DisableKeyword(keyword);
|
||||
else currMaterial.EnableKeyword(keyword);
|
||||
}
|
||||
|
||||
private void FindCurrMaterial()
|
||||
{
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
currMaterial = GetComponent<Renderer>().sharedMaterial;
|
||||
matAssigned = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
currMaterial = img.material;
|
||||
matAssigned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanMaterial()
|
||||
{
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
GetComponent<Renderer>().sharedMaterial = new Material(Shader.Find("Sprites/Default"));
|
||||
matAssigned = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
img.material = new Material(Shader.Find("Sprites/Default"));
|
||||
matAssigned = false;
|
||||
}
|
||||
}
|
||||
SetSceneDirty();
|
||||
}
|
||||
|
||||
public void SaveMaterial()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string path = "Assets/AllIn1SpriteShader/Materials/";
|
||||
if (PlayerPrefs.HasKey("All1ShaderMaterials")) path = PlayerPrefs.GetString("All1ShaderMaterials") + "/";
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
EditorUtility.DisplayDialog("The desired folder doesn't exist",
|
||||
"Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok");
|
||||
return;
|
||||
}
|
||||
path += gameObject.name;
|
||||
string fullPath = path + ".mat";
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
SaveMaterialWithOtherName(path);
|
||||
}
|
||||
else DoSaving(fullPath);
|
||||
SetSceneDirty();
|
||||
#endif
|
||||
}
|
||||
private void SaveMaterialWithOtherName(string path, int i = 1)
|
||||
{
|
||||
int number = i;
|
||||
string newPath = path + "_" + number.ToString();
|
||||
string fullPath = newPath + ".mat";
|
||||
if (System.IO.File.Exists(fullPath))
|
||||
{
|
||||
number++;
|
||||
SaveMaterialWithOtherName(path, number);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoSaving(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoSaving(string fileName)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
bool rendererExists = false;
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
Material matToSave = null;
|
||||
Material createdMat = null;
|
||||
if (sr != null)
|
||||
{
|
||||
rendererExists = true;
|
||||
matToSave = GetComponent<Renderer>().sharedMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
rendererExists = true;
|
||||
matToSave = img.material;
|
||||
}
|
||||
}
|
||||
if (!rendererExists)
|
||||
{
|
||||
MissingRenderer();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
createdMat = new Material(matToSave);
|
||||
AssetDatabase.CreateAsset(createdMat, fileName);
|
||||
Debug.Log(fileName + " has been saved!");
|
||||
}
|
||||
if (sr != null)
|
||||
{
|
||||
sr.material = createdMat;
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img = GetComponent<Image>();
|
||||
img.material = createdMat;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetSceneDirty()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
#endif
|
||||
}
|
||||
|
||||
private void MissingRenderer()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.DisplayDialog("Missing Renderer", "This GameObject (" +
|
||||
gameObject.name + ") has no Sprite Renderer or UI Image component. This AllIn1Shader component will be removed.", "Ok");
|
||||
destroyed = true;
|
||||
DestroyImmediate(this);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ToggleSetAtlasUvs(bool activate)
|
||||
{
|
||||
SetAtlasUvs atlasUvs = GetComponent<SetAtlasUvs>();
|
||||
if (activate)
|
||||
{
|
||||
if (atlasUvs == null) atlasUvs = gameObject.AddComponent<SetAtlasUvs>();
|
||||
atlasUvs.GetAndSetUVs();
|
||||
SetKeyword("ATLAS_ON", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (atlasUvs != null)
|
||||
{
|
||||
atlasUvs.ResetAtlasUvs();
|
||||
DestroyImmediate(atlasUvs);
|
||||
}
|
||||
SetKeyword("ATLAS_ON", false);
|
||||
}
|
||||
SetSceneDirty();
|
||||
}
|
||||
}
|
||||
11
Assets/AllIn1SpriteShader/Scripts/AllIn1Shader.cs.meta
Normal file
11
Assets/AllIn1SpriteShader/Scripts/AllIn1Shader.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee158225ee1e59f4791627785501d950
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs
Normal file
63
Assets/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
public class AllIn1ShaderWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("Window/AllIn1ShaderWindow")]
|
||||
public static void ShowAllIn1ShaderWindowWindow()
|
||||
{
|
||||
GetWindow<AllIn1ShaderWindow>("All In 1 Shader Window");
|
||||
}
|
||||
|
||||
private DefaultAsset materialTargetFolder = null;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Through this window you'll be able to set the folder where the asset will save it's Materials",
|
||||
EditorStyles.boldLabel);
|
||||
|
||||
GUILayout.Space(20);
|
||||
|
||||
materialTargetFolder = (DefaultAsset)EditorGUILayout.ObjectField(
|
||||
"New Material Folder",
|
||||
materialTargetFolder,
|
||||
typeof(DefaultAsset),
|
||||
false);
|
||||
|
||||
if (materialTargetFolder != null && IsAssetAFolder(materialTargetFolder))
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(materialTargetFolder);
|
||||
PlayerPrefs.SetString("All1ShaderMaterials", path);
|
||||
EditorGUILayout.HelpBox(
|
||||
"Valid folder! Material save path: " + path,
|
||||
MessageType.Info,
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox(
|
||||
"Select the new Material Folder",
|
||||
MessageType.Warning,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAssetAFolder(Object obj)
|
||||
{
|
||||
string path = "";
|
||||
|
||||
if (obj == null) return false;
|
||||
|
||||
path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
|
||||
|
||||
if (path.Length > 0)
|
||||
{
|
||||
if (Directory.Exists(path)) return true;
|
||||
else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs.meta
Normal file
11
Assets/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b642652081667ab4fad9f2579fec0e51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/AllIn1SpriteShader/Scripts/RandomSeed.cs
Normal file
33
Assets/AllIn1SpriteShader/Scripts/RandomSeed.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RandomSeed : MonoBehaviour
|
||||
{
|
||||
//If you want to randomize UI Images, you'll need to create different materials
|
||||
void Start()
|
||||
{
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
Renderer r = GetComponent<Renderer>();
|
||||
if (r != null && r.material != null)
|
||||
{
|
||||
r.material.SetFloat("_RandomSeed", Random.Range(0, 1000f));
|
||||
}
|
||||
else Debug.LogError("Missing Renderer or Material: " + gameObject.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Image i = GetComponent<Image>();
|
||||
if (i != null)
|
||||
{
|
||||
if (i.material != null)
|
||||
{
|
||||
i.material.SetFloat("_RandomSeed", Random.Range(0, 1000f));
|
||||
}
|
||||
else Debug.LogError("Missing Material on UI Image: " + gameObject.name);
|
||||
}
|
||||
else Debug.LogError("Missing Sprite Renderer or UI Image on: " + gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/AllIn1SpriteShader/Scripts/RandomSeed.cs.meta
Normal file
11
Assets/AllIn1SpriteShader/Scripts/RandomSeed.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6078fd4d3c5bd6f4087f8869458662dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
141
Assets/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs
Normal file
141
Assets/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class SetAtlasUvs : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool updateEveryFrame = false;
|
||||
private Renderer render;
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image uiImage;
|
||||
private bool isUI = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (GetRendererReferencesIfNeeded()) GetAndSetUVs();
|
||||
|
||||
if (!updateEveryFrame && Application.isPlaying) this.enabled = false;
|
||||
}
|
||||
|
||||
void OnWillRenderObject()
|
||||
{
|
||||
if (updateEveryFrame)
|
||||
{
|
||||
GetAndSetUVs();
|
||||
}
|
||||
}
|
||||
|
||||
public void GetAndSetUVs()
|
||||
{
|
||||
if (!GetRendererReferencesIfNeeded()) return;
|
||||
|
||||
if (!isUI)
|
||||
{
|
||||
Rect r = spriteRender.sprite.rect;
|
||||
r.x /= spriteRender.sprite.texture.width;
|
||||
r.width /= spriteRender.sprite.texture.width;
|
||||
r.y /= spriteRender.sprite.texture.height;
|
||||
r.height /= spriteRender.sprite.texture.height;
|
||||
|
||||
render.sharedMaterial.SetFloat("_MinXUV", r.xMin);
|
||||
render.sharedMaterial.SetFloat("_MaxXUV", r.xMax);
|
||||
render.sharedMaterial.SetFloat("_MinYUV", r.yMin);
|
||||
render.sharedMaterial.SetFloat("_MaxYUV", r.yMax);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect r = uiImage.sprite.rect;
|
||||
r.x /= uiImage.sprite.texture.width;
|
||||
r.width /= uiImage.sprite.texture.width;
|
||||
r.y /= uiImage.sprite.texture.height;
|
||||
r.height /= uiImage.sprite.texture.height;
|
||||
|
||||
uiImage.material.SetFloat("_MinXUV", r.xMin);
|
||||
uiImage.material.SetFloat("_MaxXUV", r.xMax);
|
||||
uiImage.material.SetFloat("_MinYUV", r.yMin);
|
||||
uiImage.material.SetFloat("_MaxYUV", r.yMax);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetAtlasUvs()
|
||||
{
|
||||
if (!GetRendererReferencesIfNeeded()) return;
|
||||
|
||||
if (!isUI)
|
||||
{
|
||||
render.sharedMaterial.SetFloat("_MinXUV", 0f);
|
||||
render.sharedMaterial.SetFloat("_MaxXUV", 1f);
|
||||
render.sharedMaterial.SetFloat("_MinYUV", 0f);
|
||||
render.sharedMaterial.SetFloat("_MaxYUV", 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiImage.material.SetFloat("_MinXUV", 0f);
|
||||
uiImage.material.SetFloat("_MaxXUV", 1f);
|
||||
uiImage.material.SetFloat("_MinYUV", 0f);
|
||||
uiImage.material.SetFloat("_MaxYUV", 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateEveryFrame(bool everyFrame)
|
||||
{
|
||||
updateEveryFrame = everyFrame;
|
||||
}
|
||||
|
||||
private bool GetRendererReferencesIfNeeded()
|
||||
{
|
||||
if (spriteRender == null) spriteRender = GetComponent<SpriteRenderer>();
|
||||
if (spriteRender != null)
|
||||
{
|
||||
if (spriteRender.sprite == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.DisplayDialog("No sprite found", "The object: " + gameObject.name + ",has Sprite Renderer but no sprite", "Ok");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (render == null) render = GetComponent<Renderer>();
|
||||
isUI = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uiImage == null)
|
||||
{
|
||||
uiImage = GetComponent<Image>();
|
||||
if (uiImage != null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Debug.Log("You added the SetAtlasUv component to: " + gameObject.name + " that has a UI Image\n " +
|
||||
"This SetAtlasUV component will only work properly on UI Images if each Image has a DIFFERENT material instance (See Documentation Sprite Atlases section for more info)");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.DisplayDialog("No Valid Renderer Component Found", "Looks like you have no Sprite Renderer or UI Image on: '"
|
||||
+ gameObject.name + "'\n This SetAtlasUV component will now get destroyed", "Ok");
|
||||
#endif
|
||||
DestroyImmediate(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (render == null) render = GetComponent<Renderer>();
|
||||
isUI = true;
|
||||
}
|
||||
|
||||
if (spriteRender == null && uiImage == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorUtility.DisplayDialog("No Sprite Renderer", "Looks like you are missing a Sprite Renderer on: '"
|
||||
+ gameObject.name + "'\n SetAtlasUvs only works with Sprite Renderers since it needs a 'sharedMaterial' property that UI images lack." +
|
||||
" This SetAtlasUV component will now get destroyed", "Ok");
|
||||
#endif
|
||||
DestroyImmediate(this);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs.meta
Normal file
11
Assets/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1625263d85e5d554284989eb9052e863
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/AllIn1SpriteShader/Scripts/SetGlobalTime.cs
Normal file
22
Assets/AllIn1SpriteShader/Scripts/SetGlobalTime.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AllIn1SpriteShader
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class SetGlobalTime : MonoBehaviour
|
||||
{
|
||||
int globalTime;
|
||||
|
||||
void Start()
|
||||
{
|
||||
globalTime = Shader.PropertyToID("globalUnscaledTime");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Shader.SetGlobalFloat(globalTime, Time.unscaledTime / 20f);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/AllIn1SpriteShader/Scripts/SetGlobalTime.cs.meta
Normal file
11
Assets/AllIn1SpriteShader/Scripts/SetGlobalTime.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee7031a07aea7674fad9a0795b193f56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue