tag:blogger.com,1999:blog-89357803273347751652024-03-07T11:59:03.772+08:00Entity CrisisThe blog of Simon Wittber.Unknownnoreply@blogger.comBlogger545125tag:blogger.com,1999:blog-8935780327334775165.post-3220321068286845972019-10-08T09:26:00.003+08:002019-10-08T09:57:27.264+08:00Notes on Hierarchy Window. GUI interactions are... complex.If nothing is selected, mouse down selects a new item.<br />
<br />
If one item is selected, mouse down on a differet item selects that item.<br />
<br />
If one item is selected, mouse up on that item will rename the item.<br />
<br />
If one or no items are selected, mouse down + ctrl can select multiple items.<br />
<br />
Mouse down and shift will select all items between the first selected item and the mouse down item.<br />
<br />
If more than one item is selected, mouse up on a selected item will isolate and select that item.<br />
<br />
If more than one item is selected, mouse down on a unselected item will select that item.<br />
<br />
If one or more items are selected, mouse down on a selected item will start a drag operation after mouse movement.<br />
<br />
- Unless ctrl is held, which will remove the selected item from the selection.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-5681993783663359322019-05-20T20:14:00.001+08:002019-05-20T20:14:46.093+08:00Building large worlds in Unity.<br />
I made something which lets you render very large worlds with a small farClipPlane.<br />
<br />
https://github.com/simonwittber/scaled-origin<br />
<br />
The demo shows an earth sized planet viewed from about 1000km altitude. It's great for Space Games, <a href="https://simonwittber.itch.io/space-cadet">like this one</a> I've been working on recently. <br />
<br />
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-71922955547665678642019-02-12T19:36:00.000+08:002019-02-12T19:36:03.094+08:00Using ScriptableWizards as Dialogs in CustomEditors<script src="https://gist.github.com/simonwittber/60a50efc7813a6a0576c569a1c5cbd6c.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-91285445537891199292018-09-06T21:57:00.002+08:002018-09-06T22:07:00.152+08:00.Net reflection is expensive in more ways than I thought...<pre>Enter statements below.
csharp> var t = typeof(int);
csharp> Object.ReferenceEquals(t.AssemblyQualifiedName, t.AssemblyQualifiedName);
false
</pre>Every access to the AssemblyQualifiedName property does some lookup work… and returns a NEW copy of the string.<br />
<br />
It’s _almost_ as if one might recommend caching every property, because you never know what it might be doing, and avoid creating auto properties (in place of public fields), so that you know when there is no need to cache the value.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-74428320377269400852018-08-03T19:31:00.000+08:002018-08-03T19:31:21.317+08:00A class for simplifying instanced rendering in Unity.<script src="https://gist.github.com/smnwttbr/c7a9bacfd7c882740781550cbd75ce9d.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-4069188626122738162018-07-18T15:58:00.000+08:002018-07-18T15:58:42.890+08:00Faster Update calls for Unity!These MonoBehaviour classes allow for batch updating of all components in a single call. KinematicMotor example provided. It's a gentle solution to the <a href="https://blogs.unity3d.com/2015/12/23/1k-update-calls/">1k update calls problem</a>.<br />
<br />
<script src="https://gist.github.com/simonwittber/7f1364cd3a82c4281ee3370ef5366a5f.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-91514683429095296172018-07-18T15:55:00.001+08:002018-07-18T15:55:32.031+08:00AssetForge Model Optimizer for UnityA Unity post processor to optimize meshes created with <a href="https://assetforge.io/">AssetForge</a>. Reduces draw calls, combines meshes and allows batching.<br />
<br />
<script src="https://gist.github.com/simonwittber/61fc0f7572116f85a139aaa5359d78f9.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-86828105901747826002018-07-18T15:53:00.000+08:002018-07-18T15:53:26.005+08:00Loose Coupling for your Unity Game Systems<script src="https://gist.github.com/simonwittber/4c29b304665fc5ec28aa1604d3a9028e.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-88044232507013741672018-03-01T07:02:00.000+08:002018-03-01T07:02:05.518+08:00Fizzle: The Unity Modular Synthesizer<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuS0cQqu1_ZKbt0hlVOhxDLPFrecXU6LyK_E7NlVwco1s2RNgldgNcapjmErVEf2VyfBZ_opfKQFCMPAuXbFh7WcnJHo4hoLzqsv9HVm8zg-F8Iv_rSxKeFIaVJB4oGbbn4VOf1X3BYK4/s1600/Screen+Shot+2018-02-28+at+22.59.36.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuS0cQqu1_ZKbt0hlVOhxDLPFrecXU6LyK_E7NlVwco1s2RNgldgNcapjmErVEf2VyfBZ_opfKQFCMPAuXbFh7WcnJHo4hoLzqsv9HVm8zg-F8Iv_rSxKeFIaVJB4oGbbn4VOf1X3BYK4/s200/Screen+Shot+2018-02-28+at+22.59.36.png" width="193" height="200" data-original-width="956" data-original-height="992" /></a></div>Available on GitHub: <a href="https://github.com/simonwittber/fizzle">https://github.com/simonwittber/fizzle</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-80951287601334004982018-02-22T17:19:00.000+08:002018-02-23T17:40:07.724+08:00A unique ID for your Serialized classes in Unity.<script src="https://gist.github.com/simonwittber/ce2461ed412d65803248a9cc2ebbd15f.js"></script><br /><br />
Note, the GetHashCode() method will probably return a unique ID. There is a very remote chance you will get a clashing ID.<br />
<br />
<br />
<b>Update:</b>After further experiments, I believe this does not work well enough to be generally useful. Unity, we need a new serialization system!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-27476036846103724312018-02-21T19:17:00.004+08:002018-02-21T19:17:55.326+08:00Synthesizing Sound Effects in Unity3D.<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ozVkYhkhHkfEu9063w0ejw9zRlSCgtoOY-0F9etEMaCfLE8dG0aGC6bRHZTp25VhlkzDo-f2c1k3m1W2r0ooEIFiR8kdD5761ricWONJCcLkbRAxpS22CAWrnK4eStHqDaMQV1S6ZOM/s1600/Screen+Shot+2018-02-21+at+11.10.44.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ozVkYhkhHkfEu9063w0ejw9zRlSCgtoOY-0F9etEMaCfLE8dG0aGC6bRHZTp25VhlkzDo-f2c1k3m1W2r0ooEIFiR8kdD5761ricWONJCcLkbRAxpS22CAWrnK4eStHqDaMQV1S6ZOM/s400/Screen+Shot+2018-02-21+at+11.10.44.png" width="265" height="400" data-original-width="530" data-original-height="800" /></a></div>I have built a Synthesizer for creating sound effects in Unity. It fills a similar niche to SFXR/BFXR, but aims to have more quality and versatility. It's fully modular, with all parameters able to be modulated via the Unity AnimationCurve.<br />
<br />
I have called it 'Fizzle'.<br />
<br />
Source coming soon.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-66713197784606348452018-02-14T18:58:00.001+08:002018-02-14T18:58:57.850+08:00Supercharged Gizmos for your SceneViewThis code shows how I use the [DrawGizmo] attribute to create special gizmos for my components, which only appear when you're actually near the component.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdfJRQeZ2xJO2PWfFq8-P2FmYQpKBI38B09fQkmybz0r8esqdJAFIKKE4SGH0tIFtz45Ck59QRM80jTYUk5F8lbzd8-KjqVRlsk5BAuhRh41xyv6u93JjgGPV6NXuEFxcVtcZok1Qu8BI/s1600/Screen+Shot+2018-02-14+at+10.51.05.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdfJRQeZ2xJO2PWfFq8-P2FmYQpKBI38B09fQkmybz0r8esqdJAFIKKE4SGH0tIFtz45Ck59QRM80jTYUk5F8lbzd8-KjqVRlsk5BAuhRh41xyv6u93JjgGPV6NXuEFxcVtcZok1Qu8BI/s320/Screen+Shot+2018-02-14+at+10.51.05.png" width="320" height="197" data-original-width="910" data-original-height="559" /></a></div><br />
<script src="https://gist.github.com/simonwittber/60f32ffd122f570e9d643675c3c457a0.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-14749267058892640062018-02-13T21:59:00.000+08:002018-02-13T21:59:07.515+08:00A Unity wizard to generate a palette from a source image.<script src="https://gist.github.com/simonwittber/0fa7efd07e896e4be3a8f4a7f81c516a.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-10010913010430145532018-02-08T00:21:00.001+08:002018-02-08T00:21:16.957+08:00Add an OnContextClick message to your Custom Unity Editors.<script src="https://gist.github.com/simonwittber/3439b68cd341c1ed8f453a23baef038f.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-63250349082491782292018-02-05T05:31:00.002+08:002018-02-05T05:31:45.508+08:00Visual Tools for Gameplay Design in UnityI've put some of my gamedev tools for Unity on Github.<br />
<br />
<li><a href="https://github.com/simonwittber/uniextensions">Uniextensions, some common sense extensions to Unity.</a></li><br />
<li><a href="https://github.com/simonwittber/react">React, a visual logic and behaviour tree designer.</a></li><br />
<li><a href="https://github.com/simonwittber/univent">Univent, a UnityEvent-like set of gadgets for zero-code gameplay construction.</a></li>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-15903743140388949162018-01-03T22:35:00.000+08:002018-01-03T22:35:00.314+08:00Allocations in the Unity Editor when using GetComponent.If you call gameObject.GetComponent<Collider>, and there is no Collider on that gameObject, null is returned, but you will also see a memory allocation in the Unity profiler.<br />
<br />
Why?<br />
<br />
The call is actually returning a "fake null" object, so that when you try and use it a custom error message is displayed. This custom error message causes the allocation.<br />
<br />
This behaviour is disabled in a build, so you will only ever see it in the editor.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-3598739324719192712017-11-10T20:02:00.000+08:002017-11-10T20:02:13.940+08:00The last game object pool you will ever need... maybe.<script src="https://gist.github.com/simonwittber/464bea4a28a7cb516bd96e9a0f685fb4.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-55532117510858393422017-09-15T18:32:00.001+08:002017-09-15T18:32:51.138+08:00Avoid FindObjectsOfType with this Pattern<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">public</span> <span style="color: #008800; font-weight: bold">class</span> <span style="color: #BB0066; font-weight: bold">SomeComponent</span> : MonoBehaviour
{
<span style="color: #008800; font-weight: bold">public</span> <span style="color: #008800; font-weight: bold">static</span> List<SomeComponent> Instances = <span style="color: #008800; font-weight: bold">new</span> List<SomeComponent>();
<span style="color: #008800; font-weight: bold">private</span> <span style="color: #333399; font-weight: bold">int</span> instanceIndex = -<span style="color: #6600EE; font-weight: bold">1</span>;
<span style="color: #008800; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">OnDisable</span>() {
<span style="color: #333399; font-weight: bold">var</span> lastIndex = Instances.Count - <span style="color: #6600EE; font-weight: bold">1</span>;
Instances[instanceIndex] = Instances[lastIndex];
Instances[instanceIndex].instanceIndex = instanceIndex;
Instances.RemoveAt(lastIndex);
}
<span style="color: #008800; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">OnEnable</span>()
{
Instances.Add(<span style="color: #008800; font-weight: bold">this</span>);
instanceIndex = Instances.Count - <span style="color: #6600EE; font-weight: bold">1</span>;
}
}
</pre></div><br />
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-36577184012882544502017-08-22T16:18:00.002+08:002017-08-22T16:18:55.020+08:00Vector3.sqrMagnitude vs Vector3.magntiude<br />
sqrMagnitude is 20% faster than magnitude.<br />
<br />
magnitude: 0.862013<br />
srqMagnitude: 0.689175<br />
<br />
<br />
<pre class="csharpcode"><span class="kwrd">using</span> System.Collections;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> UnityEngine;
<span class="kwrd">using</span> System.Diagnostics;
<span class="kwrd">public</span> <span class="kwrd">class</span> MagVsSqrMag : MonoBehaviour
{
<span class="kwrd">void</span> Start()
{
<span class="kwrd">var</span> C = 10000000f;
<span class="kwrd">var</span> sw = <span class="kwrd">new</span> Stopwatch();
<span class="kwrd">var</span> vec = <span class="kwrd">new</span> Vector3(Random.value, Random.value, Random.value);
<span class="kwrd">var</span> r = 0f;
<span class="kwrd">for</span> (<span class="kwrd">var</span> i = 0; i < C; i++)
{
sw.Start();
r += vec.magnitude;
sw.Stop();
}
UnityEngine.Debug.Log(<span class="str">"magnitude:"</span> + (sw.ElapsedTicks / C));
sw.Reset();
vec = <span class="kwrd">new</span> Vector3(Random.value, Random.value, Random.value);
<span class="kwrd">for</span> (<span class="kwrd">var</span> i = 0; i < C; i++)
{
sw.Start();
r += vec.sqrMagnitude;
sw.Stop();
}
UnityEngine.Debug.Log(<span class="str">"srqMagnitude:"</span> + (sw.ElapsedTicks / C));
UnityEngine.Debug.Log(r);
}
}
</pre>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-71809682188458166492017-02-13T20:29:00.000+08:002017-02-13T20:29:20.274+08:00Take a Unity Screenshot with AlphaThis script takes a screenshot and saves it to the user desktop. It has options to use an alpha background, and also upscale the image. Useful for taking pictures of a scene or model for composition by artists.<br />
<br />
<br />
<pre style="background: #ffffff; color: black;"><span style="color: maroon; font-weight: bold;">using</span> UnityEngine<span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">using</span> System<span style="color: #808030;">.</span>IO<span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">using</span> System<span style="color: purple;">;</span>
<span style="color: #808030;">[</span>RequireComponent <span style="color: #808030;">(</span>typeof<span style="color: #808030;">(</span>Camera<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">]</span>
public class CaptureWithAlpha <span style="color: purple;">:</span> MonoBehaviour
<span style="color: purple;">{</span>
public <span style="color: maroon; font-weight: bold;">int</span> UpScale <span style="color: #808030;">=</span> <span style="color: #008c00;">4</span><span style="color: purple;">;</span>
public bool AlphaBackground <span style="color: #808030;">=</span> true<span style="color: purple;">;</span>
Texture2D Screenshot <span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: purple;">{</span>
var camera <span style="color: #808030;">=</span> GetComponent<span style="color: #808030;"><</span>Camera<span style="color: #808030;">></span> <span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">int</span> w <span style="color: #808030;">=</span> camera<span style="color: #808030;">.</span>pixelWidth <span style="color: #808030;">*</span> UpScale<span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">int</span> h <span style="color: #808030;">=</span> camera<span style="color: #808030;">.</span>pixelHeight <span style="color: #808030;">*</span> UpScale<span style="color: purple;">;</span>
var rt <span style="color: #808030;">=</span> new RenderTexture <span style="color: #808030;">(</span>w<span style="color: #808030;">,</span> h<span style="color: #808030;">,</span> <span style="color: #008c00;">32</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
camera<span style="color: #808030;">.</span>targetTexture <span style="color: #808030;">=</span> rt<span style="color: purple;">;</span>
var screenShot <span style="color: #808030;">=</span> new Texture2D <span style="color: #808030;">(</span>w<span style="color: #808030;">,</span> h<span style="color: #808030;">,</span> TextureFormat<span style="color: #808030;">.</span>ARGB32<span style="color: #808030;">,</span> false<span style="color: #808030;">)</span><span style="color: purple;">;</span>
var clearFlags <span style="color: #808030;">=</span> camera<span style="color: #808030;">.</span>clearFlags<span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">if</span> <span style="color: #808030;">(</span>AlphaBackground<span style="color: #808030;">)</span> <span style="color: purple;">{</span>
camera<span style="color: #808030;">.</span>clearFlags <span style="color: #808030;">=</span> CameraClearFlags<span style="color: #808030;">.</span>SolidColor<span style="color: purple;">;</span>
camera<span style="color: #808030;">.</span>backgroundColor <span style="color: #808030;">=</span> new Color <span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
<span style="color: purple;">}</span>
camera<span style="color: #808030;">.</span>Render <span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
RenderTexture<span style="color: #808030;">.</span>active <span style="color: #808030;">=</span> rt<span style="color: purple;">;</span>
screenShot<span style="color: #808030;">.</span>ReadPixels <span style="color: #808030;">(</span>new Rect <span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> w<span style="color: #808030;">,</span> h<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
screenShot<span style="color: #808030;">.</span>Apply <span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
camera<span style="color: #808030;">.</span>targetTexture <span style="color: #808030;">=</span> null<span style="color: purple;">;</span>
RenderTexture<span style="color: #808030;">.</span>active <span style="color: #808030;">=</span> null<span style="color: purple;">;</span>
DestroyImmediate <span style="color: #808030;">(</span>rt<span style="color: #808030;">)</span><span style="color: purple;">;</span>
camera<span style="color: #808030;">.</span>clearFlags <span style="color: #808030;">=</span> clearFlags<span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">return</span> screenShot<span style="color: purple;">;</span>
<span style="color: purple;">}</span>
<span style="color: #808030;">[</span>ContextMenu <span style="color: #808030;">(</span><span style="color: maroon;">"</span><span style="color: #0000e6;">Capture Screenshot</span><span style="color: maroon;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">]</span>
public <span style="color: maroon; font-weight: bold;">void</span> SaveScreenshot <span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: purple;">{</span>
var path <span style="color: #808030;">=</span> Environment<span style="color: #808030;">.</span>GetFolderPath <span style="color: #808030;">(</span>Environment<span style="color: #808030;">.</span>SpecialFolder<span style="color: #808030;">.</span>Desktop<span style="color: #808030;">)</span><span style="color: purple;">;</span>
var filename <span style="color: #808030;">=</span> <span style="color: maroon;">"</span><span style="color: #0000e6;">SS-</span><span style="color: maroon;">"</span> <span style="color: #808030;">+</span> DateTime<span style="color: #808030;">.</span>Now<span style="color: #808030;">.</span>ToString <span style="color: #808030;">(</span><span style="color: maroon;">"</span><span style="color: #0000e6;">yyyy.MM.dd.HH.mm.ss</span><span style="color: maroon;">"</span><span style="color: #808030;">)</span> <span style="color: #808030;">+</span> <span style="color: maroon;">"</span><span style="color: #0000e6;">.png</span><span style="color: maroon;">"</span><span style="color: purple;">;</span>
File<span style="color: #808030;">.</span>WriteAllBytes <span style="color: #808030;">(</span>Path<span style="color: #808030;">.</span>Combine <span style="color: #808030;">(</span>path<span style="color: #808030;">,</span> filename<span style="color: #808030;">)</span><span style="color: #808030;">,</span> Screenshot <span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">.</span>EncodeToPNG <span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
<span style="color: purple;">}</span>
<span style="color: purple;">}</span>
</pre>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-28856659037464847592017-02-03T23:25:00.003+08:002017-02-03T23:25:53.588+08:00Building fast, quality network server programs with Go.I've been investigating and learning <a href="http://golang.org">Go</a>. There is a lot of high quality tools out there, for example:<br />
<br />
- <a href="https://github.com/knq/xo">xo</a> generates types and functions to match your SQL schema, and<br />
<br />
- <a href="https://goa.design/">goa</a> lets you design a REST api using a DSL, then generate the code to implement that API!<br />
<br />
Compile time for Go is super fast, and so is the built executable. I'm using vim for the IDE, and it has excellent support for Go, including autocompletion which is great when you're learning the language. Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-81130064420697347292017-01-25T06:10:00.000+08:002017-01-25T06:16:50.294+08:00A HTTP server embedded inside Unity3D.Just 514 lines of code. Uses sockets only, no other dependencies.<br />
<br />
<a href="https://github.com/simonwittber/uniwebserver">https://github.com/simonwittber/uniwebserver</a><br />
<br />
Example Component:<br />
<br />
<pre>[RequireComponent(typeof(EmbeddedWebServerComponent))]
public class FileUpload : MonoBehaviour, IWebResource
{
public string path = "/upload";
public TextAsset html;
EmbeddedWebServerComponent server;
void Start ()
{
server = GetComponent<EmbeddedWebServerComponent>();
server.AddResource(path, this);
}
public void HandleRequest (Request request, Response response)
{
response.statusCode = 200;
response.message = "OK.";
response.Write(html.text);
}
}
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-75557642836420675142017-01-24T21:04:00.002+08:002017-01-24T21:05:17.311+08:00A widget to list Github repositories.<pre><span style="font-size: x-small;"><div id="github-activity"></div>
<script type="text/javascript">
window.renderGitHubWidget = function(github) {
console.log(github)
var html = '<div class="widget"><ul>';
for (var i=0; i<github.data.length; i++) {
var item = github.data[i];
var url = item.html_url;
if(item.fork) continue;
var repo = '<a href="' + url + '" target="_blank">' + item.name + '</a>';
html += "<li>" + repo + " <br/>" + item.description+ "</li>"
}
html += '</ul></div>';
var el = document.createElement('div');
el.innerHTML = html;
document.getElementById('github-activity').appendChild(el);
};
{
var URL = 'https://api.github.com/users/simonwittber/repos?callback=renderGitHubWidget';
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', URL);
document.head.appendChild(script);
}
</script></span>
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-30470743955587933862017-01-03T16:23:00.001+08:002017-01-04T19:17:34.640+08:00Notes on the Unity3D UNET HLAPIThe NetworkManager instantiates a Player prefab. This is your Player Object.<br />
<br />
In a two player game, your GameObjects exist conceptually in 3 places, and logically in 2 places. An object exists on each game client, and on the game server. If the game server is also a client, it is called a host, and it shares the GameObject with the client.<br />
<br />
By default:<br />
- only methods on components on the Player Object can have the [Command] attribute.<br />
- you can only call [Command] methods from other methods on the Player Object.<br />
<br />
It is hard to see which code is server code, and which is client code. I recommend using the [Server] and [Client] attributes liberally to add this information to the source code. When this attribute cannot be applied to a method (only NetworkBehaviours support this attribute) then add the attribute inside a comment.<br />
<br />
The NetworkTransform does not provide interpolation when in Transform mode, only when using RigidBody mode. You will need to write this code yourself using [SyncVar].<br />
<br />
For fast iterative development, keep the NetworkManager in your development scene, and add the NetworkManagerHUD component. Set this scene as your startup scene, then Build and Run, choose Host or Client from the GUI, then press Play in the editor, and choose Host or Client.<br />
<br />
NetworkServer.Spawn only create an instance on the client, and sets it's transform component to match the server. You will have to do any other configuration on this object via a secondary [ClientRpc] call.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8935780327334775165.post-18496223275774466122017-01-03T05:19:00.001+08:002017-01-03T05:19:05.963+08:00Less Code is Less Bugs in Less TimeSome favourite quotes from Ron Jeffries, one of the three founders of the Extreme Programming software development methodology...<br />
<br />
<blockquote cite="http://ronjeffries.com/xprog/articles/practices/pracnotneed/">Often you will be building some class and you’ll hear yourself saying “We’re going to need…”.<br />
<br />
Resist that impulse, every time. Always implement things when you <strong>actually</strong> need them, never when you just <strong>foresee</strong> that you need them. <br />
</blockquote><br />
And this too...<br />
<br />
<blockquote cite="http://ronjeffries.com/xprog/articles/practices/pracnotneed/">The best way to implement code quickly is to implement less of it. The best way to have fewer bugs is to implement less code.<br />
</blockquote><br />
<br />
<br />
Unknownnoreply@blogger.com0