![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhzOkGapVH3-ZvSeRlFTX-ktm4wqpGrv2xHu4YeRL7b-WTUMR7zW7hZlMOU0H40IJ1CFr7NMAgcWmajGDX1wIdaae5Kjwat7J6QPQlvM7X-rQAVpiANrEwQIpPhiZfqyVLtdV6p_3sgGs/s400/Screen+shot+2011-01-31+at+5.13.59+PM.png)
A screenshot of my spacebox generator, a Toon freighter model and a Crease fullscreen shader, which adds the outline to the silhouette of the ship.
for each member
download avatar image
update avatar texture
for each memberUnityWeb will only redownload a URL if it has changed since you last downloaded it. UnityWeb uses the magic of Etags to make this work. To make this type of caching happen, you simply add:
download avatar image
if image has changed, update avatar texture
request.useCache = true;This results in faster response times, less web traffic, and you could poll much quicker than every 10 minutes, as only changes will be downloaded.
using UnityEngine;
using System.Collections;
public class ErrorReporter : MonoBehaviour
{
string debugText = "";
string postURL = "";
void Awake ()
{
Application.RegisterLogCallback (new Application.LogCallback (CaptureLog));
}
IEnumerator SendDebugToServer ()
{
WWW www = new WWW (postURL, System.Text.ASCIIEncoding.ASCII.GetBytes (debugText));
yield return www;
}
void CaptureLog (string condition, string stacktrace, LogType type)
{
string sep = "------------------------------------------------------------------------------\r\n";
debugText = sep + type.ToString () + " " + Time.realtimeSinceStartup.ToString () + "\r\n" + condition + "\r\n" + stacktrace + debugText;
if (type == LogType.Exception) {
StartCoroutine (SendDebugToServer ());
if (!Application.isEditor) {
SomethingReallyBadHappened ();
}
}
}
void SomethingReallyBadHappened ()
{
//NB: Try and recover or fail gracefully here.
}
}
$data = file_get_contents('php://input');
$file = "reports/report_" . time() . ".txt";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
echo "Saved to $file successfully!";
using UnityEngine;
using System.Collections;
public class ParticleBurst : MonoBehaviour {
public float T = 1;
IEnumerator Start() {
particleEmitter.emit = true;
yield return new WaitForSeconds(T);
particleEmitter.emit = false;
}
}
using UnityEngine;
using UnityEditor;
using System.Collections;
class ModifyTextures : AssetPostprocessor
{
void OnPostprocessTexture (Texture2D texture)
{
if (assetPath.Contains ("_SPECULAR")) {
var diffusePath = assetPath.Replace ("_SPECULAR", "_DIFFUSE");
var bytes = System.IO.File.ReadAllBytes (diffusePath);
var diffuse = new Texture2D (texture.width, texture.height);
diffuse.LoadImage (bytes);
var colors = diffuse.GetPixels ();
var specular = texture.GetPixels ();
if (colors.Length == specular.Length) {
Debug.LogWarning (assetPath + ": Adding specular values to diffuse map alpha.");
for (var i = 0; i < colors.Length; i++) {
colors[i].a = (specular[i].r + specular[i].g + specular[i].b) / 3;
}
diffuse.SetPixels (colors);
diffuse.Apply ();
System.IO.File.WriteAllBytes (diffusePath, diffuse.EncodeToPNG ());
AssetDatabase.ImportAsset (diffusePath);
AssetDatabase.DeleteAsset(assetPath);
} else {
Debug.LogWarning (assetPath + ": specular size must match diffuse size.");
}
return;
}
}
}
yield return www;
try {
var bundle = www.assetBundle;
} catch {
//surely if the bundle load fails, I can catch an exception here?
}
Shader "Planet" {
Properties {
_MainTex ("Diffuse(RGB) Spec(A)", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower ("Rim Power", Range(0,8.0)) = 3.0
_SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Planet
float _Shininess;
sampler2D _MainTex;
sampler2D _BumpMap;
float4 _RimColor;
float _RimPower;
half4 LightingPlanet (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, 48.0);
half rim = ((1 - (dot (normalize(viewDir), (s.Normal)))) + ((dot (normalize(lightDir), (s.Normal)))));
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * s.Alpha * _Shininess * _SpecColor) * (atten * 2);
c.rgb = c.rgb * (pow (rim, _RimPower) * _RimColor.rgb);
return c;
}
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
float3 worldRefl; INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a;
}
ENDCG
}
Fallback "Diffuse"
}
Shader "Planet" {
Properties {
_MainTex ("Diffuse(RGB) Spec(A)", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
_SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf SimpleSpecular
float _Shininess;
half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, 48.0);
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * s.Alpha * _Shininess * _SpecColor) * (atten * 2);
c.a = s.Alpha;
return c;
}
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
};
sampler2D _MainTex;
sampler2D _BumpMap;
float4 _RimColor;
float _RimPower;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow (rim, _RimPower);
o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a;
}
ENDCG
}
Fallback "Diffuse"
}
var myObject = new MyClass();
Prefs.Save<MyClass>("my object", myObject);
var anotherObject = Prefs.Load<MyClass>("my object")
using UnityEngine;
using System.Collections;
using System.Xml.Serialization;
using System.IO;
public class Prefs
{
public static void Save<T> (string name, T instance)
{
XmlSerializer serializer = new XmlSerializer (typeof(T));
using (var ms = new MemoryStream ()) {
serializer.Serialize (ms, instance);
PlayerPrefs.SetString (name, System.Text.ASCIIEncoding.ASCII.GetString (ms.ToArray ()));
}
}
public static T Load<T> (string name)
{
if(!PlayerPrefs.HasKey(name)) return default(T);
XmlSerializer serializer = new XmlSerializer (typeof(T));
T instance;
using (var ms = new MemoryStream (System.Text.ASCIIEncoding.ASCII.GetBytes (PlayerPrefs.GetString (name)))) {
instance = (T)serializer.Deserialize (ms);
}
return instance;
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AsyncComponent : MonoBehaviour
{
public delegate void Anonymous ();
Listcallbacks = new List ();
public virtual void Update ()
{
Anonymous[] c;
lock(this) {
c = callbacks.ToArray();
callbacks.Clear();
}
foreach(var i in c) i();
}
public void ScheduleCallback(Anonymous fn) {
lock(this) {
callbacks.Add(fn);
}
}
}
Error when creating request. GET request with custom headers is not supported.It would have taken longer to write the code to raise this exception than to actually code the functionality, so WHY IS IT MISSING!?!?! And it's been like this for A LONG TIME SO FIX IT ALREADY!