Visual Studio Tip: Select Word
Press CTRL+W to select the word your cursor is at.
Cookie Run:Kingdom Official!

bliss lane
🪼
art blog(derogatory)
No title available
macklin celebrini has autism
The Bowery Presents
Lint Roller? I Barely Know Her
h

❣ Chile in a Photography ❣

titsay

pixel skylines
Monterey Bay Aquarium
cherry valley forever
No title available
Cosmic Funnies

tannertan36
let's talk about Bridgerton tea, my ask is open

Love Begins
noise dept.

seen from Italy

seen from United States
seen from United States

seen from Israel
seen from Bulgaria

seen from Brazil
seen from Türkiye
seen from Canada
seen from Iraq
seen from Colombia

seen from Indonesia
seen from United States

seen from South Korea
seen from Brazil
seen from Curaçao
seen from Brazil

seen from Brazil
seen from Jordan

seen from Colombia

seen from United States
@jonasjohanssongamedev
Visual Studio Tip: Select Word
Press CTRL+W to select the word your cursor is at.
Creative Freedom
Many of us are creative people with tons of ideas, and we want to set those ideas free. It’s important to have high creative momentum, or else the idea fountain dries up and we end up losing that foolishness that makes us discover and invent new and cool things.
Creative companies often have strict clauses in the employment contract detailing how ideas and other immaterial properties belong to the company. These legal slabs sound scary and threatening, resulting in people holding back ideas — partly because we’re afraid our ideas might get “locked up” in the company and not get acted upon, and partly because we want to save them for the future when we can make them a reality.
I believe this is holding back the success of both companies and individuals. It is, however, hard to find solid solutions that doesn't hurt the company, and to find science to back it up.
I have a desire to discuss ideas at work & outside work, do my best at work & outside work, and release games at work & outside work.
Benefits of side projects: - Talent stays (otherwise the urge to make something gets strong enough to resign) - Brings in practical field experience - Creative outlet when things are stale at work - Some have more than 8 hours a day in them (again, keep talent) - Variety makes people happy, happy people work better - Sparks discussions, creativity, team bonding and knowledge sharing - Open companies attract talent
Help me make it better.
#creativefreedom
C# Protected Member
We had a conversation in the office the other day regarding the protected keyword. More on the specific quirk later on, but let’s start with the basics.
It’s a fairly common keyword but it’s behavior is not always as straight-forward as that of private and public.
Microsoft says
A protected member is accessible within its class and by derived class instances. -- MSDN
Basic Usage
using System.IO; using System; class Program { class Base { protected int x; } class Derived : Base { public void DoSomething() { // OK! Member x is accessible from derived class. int value = this.x; } } static void Main() { Derived derived = new Derived(); // ERROR! Member x is protected from external access. int value = derived.x; } }
Try the code online here.
Access From Another Instance
Now, let's complicate things a little bit. The following is the kind of access pattern that sparked our discussion:
An instance of type Derived is trying to access a protected member in an instance of type Base. Compiler says no! What's the problem? The Derived type inherits from Base, so shouldn't the members of Base be accessible from Derived?
Well, yes, but only from that very same instance. However, protected members are accessible by classes equal to, or deriving from, the type that declared the member, so an instance of Derived can access a protected member in another instance of Derived.
Confused yet? Let's look at an example:
using System.IO; using System; class Base { protected int protectedBaseMember; } class Derived : Base { protected int protectedDerivedMember; public void DoSomethingOnThisInstance() { // OK! Protected member declared in base class can be // accessed from derived class through this instance. int value = this.protectedBaseMember; } public void DoSomethingOnAnotherInstance(Base anotherInstance) { // ERROR! CS1540: Cannot access protected member // `Base.protectedBaseMember' via a qualifier of type `Base'. // The qualifier must be of type `Derived' or derived from it. int value = anotherInstance.protectedBaseMember; } public void DoSomethingOnAnotherInstance(Derived anotherInstance) { // OK! Protected member can be accessed on another instance // if the other instance inherits from this instance's class. int value = anotherInstance.protectedDerivedMember; } } class Program { static void Main() { } }
Try to code online here.
Win32: Center Window On Screen
The following code will center a window on the screen:
void PlaceInCenterOfScreen(HWND window, DWORD style, DWORD exStyle) { int screenWidth = GetSystemMetrics(SM_CXSCREEN); int screenHeight = GetSystemMetrics(SM_CYSCREEN);
RECT clientRect; GetClientRect(window, &clientRect);
AdjustWindowRectEx(&clientRect, style, FALSE, exStyle);
int clientWidth = clientRect.right - clientRect.left; int clientHeight = clientRect.bottom - clientRect.top;
SetWindowPos(window, NULL, screenWidth / 2 - clientWidth / 2, screenHeight / 2 - clientHeight / 2, clientWidth, clientHeight, 0 ); }
End result
Unity Tip: GUILayout
Use GUILayout instead of GUI to lay out prototype UI elements, to avoid having to explicitly design the lay out:
Hard
GUI.Label(new Rect(20.0f, 30.0f, 200.0f, 80.0f), "Some text"); if (GUI.Button(new Rect(20.0f, 30.0f + 100.0f, 200.0f, 80.0f), "Say hi")) { Debug.Log("Hi"); }
Easy
GUILayout.Label("Some text"); if (GUILayout.Button("Say hi")) { Debug.Log("Hi"); }
Unity Tip: Referencing Shader By Name
If you're referencing a shader by name in a script, Unity won't know you depend on it, and thus it won't be included in the build files.
You can specify Always Included Shaders in Graphics Settings.
NGUI UICenterOnChild Tip
UICenterOnChild require things to be laid out in the correct order in the game object hierarchy, so that things left-to-right in the scene are sorted top-to-down in the hierarchy. Fortunately, you can do this manually since Unity 4.5.
Unity Tip: Plugin Lifetime
A Unity plugin has the same lifetime as Unity itself. It's not loaded/unloaded between game sessions (play - stop).
This means that if a plugin fails to manage its own state internally, you might see side-effects even if you hit stop and play again.
Unity Tip: Physical Shape Types In 2D
If you're using 2D physics in Unity you're using the Box2D physics engine behind the scenes.
Box2D has two shape types: convex polygon and circle. A box is still a convex polygon behind the scenes.
Represent your objects as circle colliders if you can, as they perform better.
Unity Tip: Editor Tool Undo
If you're creating an editor tool you need to explicitly inform Unity how to Undo your actions.
http://docs.unity3d.com/Documentation/ScriptReference/Undo.html
Unity Tip: Editor Clipping
When working in the editor, objects can sometimes get clipped by the near plane, especially in orthographic mode when zooming in.
Select the object and hit F - this will focus on the object and set up the view frustum to fit the object inside.
Unity Tip: Accessing transform.position
Accessing transform.position will not simply return a stored Vector3 - it will go from the scripting language into the engine and evaluate the entire game object hierarchy.
This is fantastic as it provides you with the most up-to-date value. However, if you have a deep hierarchy and you call this a lot, you might want to store it in a local variable and work with that one instead.
Unity Tip: Cache Components
In Unity 4, accessing transform, renderer, etc., in a script means you'll actually run GetComponent<Transform>, GetComponent<Renderer>, etc.
It can be quite expensive if you do this a lot. A better way is to cache the component in Awake.
These accessors are gone in Unity 5, and you have to explicitly write GetComponent<Renderer>(). Thanks for pointing that out @CyberBinarin.
Unity Tip: Saving Prefabs
Prefabs are not written to disk when you click Apply, but rather when the Scene is saved.
Unity Tip: Math vs. Mathf
There's both Math and Mathf - which one should I use?
Math comes from System and uses doubles.
Mathf comes from Unity and provides the same functionality but with floats.
Rule of thumb: use Mathf, as most of Unity's APIs take floats.
Unity Tip: Don't Instantiate In OnDestroy
Instantiating a GameObject in an OnDestroy function will cause that new object to remain in the Hierarchy when you exit the game. Unity will report an error, but won't tell you what or why.
The new object will also be saved with the scene, so you'll have to remove it manually.
Unity Tip: Reading From Material
Reading from renderer.material or renderer.materials will actually create a new instance of that material, thus invalidating batching. Yep, just by reading.
It's basically a way to assure that you're modifying a unique instance of the material, and don't mess with a shared material.
To avoid this, use renderer.sharedMaterial or renderer.sharedMaterials instead, if all you want to do is to read information from it.