Skip to content

Instantly share code, notes, and snippets.

View wuyouchao's full-sized avatar

youchao.woo wuyouchao

  • Tencent
  • Shenzhen.China
View GitHub Profile
@wuyouchao
wuyouchao / optimizations.md
Created January 21, 2016 02:59 — forked from mandarinx/optimizations.md
Unity3D optimization tips

#Unity3D optimization tips

Some code allocates memory when running in the editor and not on the device. This is due to Unity doing some extra error handling so possible error messages can be output in the console. Much of this code is stripped during build. It's therefore important to profile on device, and do it regularly.

Optimizations often makes code more rigid and harder to reason. Don't do it until you really need to.

When profiling, wrap methods or portions of a method in Profiler.BeginSample(string name) and Profiler.EndSample() to make them easier to find in the profiler.

public class SomeClass {
using UnityEngine;
using UnityEditor;
using System.IO;
[InitializeOnLoad]
public class BundleVersionChecker
{
/// <summary>
/// Class name to use when referencing from code.
/// </summary>
using UnityEngine;
public class UIScaleOnCenter : MonoBehaviour {
/// <summary>
/// Scale applies to all involved childs, dependent on distance from center object,
/// the higher distance the lower scale modifier is applied.
/// </summary>
public Vector3 scaleIncreaseBy = Vector3.zero;
@wuyouchao
wuyouchao / C#
Created September 6, 2013 05:44
C#获取某个操作时间消耗
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
for (int i = 0; i < 1000; i++)
{
gcMultiRow1.Sort();
}
watch.Stop();
var useTime = (double)watch.ElapsedMilliseconds / 1000;