2017年6月

Texture importer now has "Alpha is Transparency" setting, which does color dilation to fix edge artifacts on semitransparent textures. It is enabled by default for GUI textures.

最初我们使用了DXT5作为贴图压缩格式,希望能减小贴图的内存占用,但很快发现移动平台的显卡是不支持硬件解压DXT5的。因此对于一张1024x1024大小的RGBA32贴图,虽然DXT5可将它从4MB压缩到1MB,但系统将它送进显卡之前,会先用CPU在内存里将它解压成4MB的RGBA32格式(软件解压),然后再将这4MB送进显存。于是在这段时间里,这张贴图就占用了5MB内存和4MB显存;而移动平台往往没有独立显存,需要从内存里抠一块作为显存,于是原以为只占1MB内存的贴图实际却占了9MB

JPEG:https://zh.wikipedia.org/wiki/JPEG

PNG:https://zh.wikipedia.org/wiki/PNG

PNG VS JPEG

JPEG可以对照片(或类似)图像生成更小的文件,这是由于JPEG采用了一种针对照片图像的特定有损编码方法,这种编码适用于低对比,图像颜色过渡平滑,噪声多,且结构不规则的情况下。如果在这种情况下用PNG代替JPEG,文件尺寸增大很多,而图像质量的提高有限。相应的,如果保存文本,线条或类似的边缘清晰,有大块相同颜色区域的图像,PNG格式的压缩效果就要比JPEG好很多,并且不会出现JPEG那样的高对比度区域的图像有损。如果图像既有清晰边缘,又有照片图像的特点,就在在这两种格式之间权衡一下了。JPEG不支持透明度。

由于JPEG是有损压缩,会产生迭代有损,在重复压缩和解码的过程中会不断丢失信息使图像质量下降。由于PNG是无损的,保存将要被编辑的图像来说更加合适。虽然PNG压缩照片图像也有效,但有专门针对照片图像设计的无损压缩格式,比如无损JPEG2000,Adobe DNG等。总的来说这些格式都不能做到适用所有图像。对于将要发布的图像可以保存成JPEG,用JPEG编码一次不会造成明显的图像有损。

Detailed

The Detailed view allows you take a snapshot of the current state. Use the Take Sample button to capture detailed memory usage. Obtaining this data takes some time, so the Detailed view should not be expected to give you real-time details. After taking a sample, the Profiler window is updated with a tree view where you can explore memory usage.

This displays individual Assets and GameObject memory usage. It also displays a reason for a GameObject to be in memory. Common reasons include:

  • Assets: Asset referenced from user or native code
  • Built-in Resources: Unity Editor resources or Unity default resources
  • Not Saved: GameObjects marked as DontSave
  • Scene Memory: GameObject and attached components
  • Other: GameObjects not marked in the above categories

Click on a GameObject in the list to view it in either the Project or the Scene view.

When profiling in the Editor, all numbers displayed by the Memory Profiler indicate the memory usage in the Editor. These are generally larger than when running in a player, because running the Unity Editor adds extra memory. For more precise numbers and memory usage for your app, use the Profiler connection to connect to the running player. This will give the actual usage on the target device.

Memory reported under System.ExecutableAndDlls is read-only memory, so the operating system might discard these pages as needed and later reload them from the file system. This generates lower memory usage, and usually does not directly contribute to the operating system’s decision to kill the application. Some of these pages might also be shared with other applications that are using the same frameworks.

 

Other may be garbage collection or stuff being recycled in memory. 32ms is acceptable, you should only complain if the other peaks above 100ms and/or causes hitching.

 

HideFlags.DontSave
  The object will not be saved to the scene. It will not be destroyed when a new scene is loaded. It is a shortcut for HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor | HideFlags.DontUnloadUnusedAsset.
  It is your responsibility to cleanup the object manually using DestroyImmediate, otherwise it will leak.
HideFlags.DontSaveInBuild
  The object will not be saved when building a player.
HideFlags.DontSaveInEditor
  The object will not be saved to the scene in the editor.
HideFlags.DontUnloadUnusedAsset
  The object will not be unloaded by Resources.UnloadUnusedAssets.
  It is your responsibility to cleanup the object manually using DestroyImmediate, otherwise it will leak.
HideFlags.HideAndDontSave
  A combination of not shown in the hierarchy, not saved to to scenes and not unloaded by The object will not be unloaded by Resources.UnloadUnusedAssets.
  This is most commonly used for objects which are created by scripts and are purely under their control.
HideFlags.HideInHierarchy
  The object will not appear in the hierarchy.
HideFlags.HideInInspector
  It is not possible to view it in the inspector.
HideFlags.None
  A normal, visible object. This is the default.
HideFlags.NotEditable
  The object is not be editable in the inspector.
 
编辑器单个资源占用大小值是真机的两倍.以真机为准.
 
VS 注释 换行 <para>注释</para>
 
Time
Time.captureFramerate          Slows game playback time to allow screenshots to be saved between frames.
Time.deltaTime              The time in seconds it took to complete the last frame (Read Only).
Time.fixedDeltaTime            The interval in seconds at which physics and other fixed frame rate updates (like MonoBehaviour's FixedUpdate) are performed.
Time.fixedTime              The time the latest FixedUpdate has started (Read Only). This is the time in seconds since the start of the game.
Time.fixedUnscaledDeltaTime         The timeScale-independent interval in seconds from the last fixed frame to the current one (Read Only).
Time.fixedUnscaledTime           The timeScale-independent time the latest FixedUpdate has started (Read Only). This is the time in seconds since the start of the game.
Time.frameCount               The total number of frames that have passed (Read Only).
Time.inFixedTimeStep             Returns true if called inside a fixed time step callback (like MonoBehaviour's FixedUpdate), otherwise returns false.
Time.maximumDeltaTime            The maximum time a frame can take. Physics and other fixed frame rate updates (like MonoBehaviour's FixedUpdate).
Time.maximumParticleDeltaTime      The maximum time a frame can spend on particle updates. If the frame takes longer than this, then updates are split into multiple smaller updates.
Time.realtimeSinceStartup         The real time in seconds since the game started (Read Only).
Time.smoothDeltaTime          A smoothed out Time.deltaTime (Read Only).
Time.time                  The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game.
Time.timeScale                  The scale at which the time is passing. This can be used for slow motion effects.
Time.timeSinceLevelLoad         The time this frame has started (Read Only). This is the time in seconds since the last level has been loaded.
Time.unscaleDeltaTime          The timeScale-independent interval in seconds from the last frame to the current one (Read Only).
Time.unscaledTime            The timeScale-independent time for this frame (Read Only). This is the time in seconds since the start of the game.
 
UGUI 四个anchor合在一起(绝对布局),anchor分开(相对布局)
 
Camera
 
You can create multiple Cameras and assign each one to a different Depth. Cameras are drawn from low Depth to high Depth. In other words, a Camera with a Depth of 2 will be drawn on top of a Camera with a depth of 1. You can adjust the values of the Normalized View Port Rectangle property to resize and position the Camera’s view onscreen. This can create multiple mini-views like missile cams, map views, rear-view mirrors, etc.
 
Clear Flags
Each Camera stores color and depth information when it renders its view. The portions of the screen that are not drawn in are empty, and will display the skybox by default. When you are using multiple Cameras, each one stores its own color and depth information in buffers, accumulating more data as each Camera renders. As any particular Camera in your scene renders its view, you can set the Clear Flags to clear different collections of the buffer information. To do this, choose one of the following four options:
 
Skybox
This is the default setting. Any empty portions of the screen will display the current Camera’s skybox. If the current Camera has no skybox set, it will default to the skybox chosen in the Lighting Window (menu: Window > Lighting). It will then fall back to the Background Color. Alternatively a Skybox component can be added to the camera. If you want to create a new Skybox, you can use this guide.
 
Solid color
Any empty portions of the screen will display the current Camera’s Background Color.
 
Depth only
If you want to draw a player’s gun without letting it get clipped inside the environment, set one Camera at Depth 0 to draw the environment, and another Camera at Depth 1 to draw the weapon alone. Set the weapon Camera’s Clear Flags to depth only. This will keep the graphical display of the environment on the screen, but discard all information about where each object exists in 3-D space. When the gun is drawn, the opaque parts will completely cover anything drawn, regardless of how close the gun is to the wall.
 
Don't clear
This mode does not clear either the color or the depth buffer. The result is that each frame is drawn over the next, resulting in a smear-looking effect. This isn’t typically used in games, and would more likely be used with a custom shader.

Note that on some GPUs (mostly mobile GPUs), not clearing the screen might result in the contents of it being undefined in the next frame. On some systems, the screen may contain the previous frame image, a solid black screen, or random colored pixels.

Culling Mask

The Culling Mask is used for selectively rendering groups of objects using Layers.

Normalized Viewport Rectangle

Normalized Viewport Rectangle is specifically for defining a certain portion of the screen that the current camera view will be drawn upon. You can put a map view in the lower-right hand corner of the screen, or a missile-tip view in the upper-left corner. With a bit of design work, you can use Viewport Rectangle to create some unique behaviors.

It’s easy to create a two-player split screen effect using Normalized Viewport Rectangle. After you have created your two cameras, change both camera’s H values to be 0.5 then set player one’s Y value to 0.5, and player two’s Y value to 0. This will make player one’s camera display from halfway up the screen to the top, and player two’s camera start at the bottom and stop halfway up the screen.

A layout element is an Game Object with a Rect Transform and optionally other components as well.

 

RectTransformUtility.ScreenPointToLocalPointInRectangle

 

https://v.qq.com/iframe/player.html?vid=o0512etq2vm&tiny=0&auto=0=

http://k79k06k02k.com/blog/190/unity/unity-ugui-%E5%8E%9F%E7%90%86%E7%AF%87-%E4%B8%80%EF%BC%9Acanvas

 

Mathf.Clamp

 

EventTrigger

class in UnityEngine.EventSystems / Inherits from:MonoBehavior

Implements interfaces:IBeginDragHandler,ICancelHandler,IDeselectHandler,IDragHandler,IDropHandler,IEndDragHandler,IEventSystemHandler,IInitializePotentialDragHandler,IMoveHandler,IPointerClickHandler,IPointerDownHandler,

IPointerEnterHandler,IPointerExitHandler,IPointerUpHandler,IScrollHandler,ISelectHandler,ISubmitHandler,IUpdateSelectedHandler

 

Select,UpdateSelected,Deselect

PointerEnter,PointerDown,PointerUp,PointerClick,PointerExit  

OnPointerEnter-> OnSelect->OnUpdateSelected->[OnPointerDown]-> [OnInitializePotentialDrag]->[OnBeginDrag]->[OnDrag]->[OnPointerUp]->[OnPointerClick]->[OnEndDrag]->OnDeselect

 

The module uses:

  • Vertical / Horizontal axis for keyboard and controller navigation
  • Submit / Cancel button for sending submit and cancel events
  • Has a timeout between events to only allow a maximum number of events a second.

The flow for the module is as follows

  • Send a Move event to the selected object if a valid axis from the input manager is entered
  • Send a submit or cancel event to the selected object if a submit or cancel button is pressed
  • Process Mouse input
    • If it is a new press
      • Send PointerEnter event (sent to every object up the hierarchy that can handle it)
      • Send PointerPress event
      • Cache the drag handler (first element in the hierarchy that can handle it)
      • Send BeginDrag event to the drag handler
      • Set the ‘Pressed’ object as Selected in the event system
    • If this is a continuing press
      • Process movment
      • Send DragEvent to the cached drag handler
      • Handle PointerEnter and PointerExit events if touch moves between objects
    • If this is a release
      • Send PointerUp event to the object that received the PointerPress
      • If the current hover object is the same as the PointerPress object send a PointerClick event
      • Send a Drop event if there was a drag handler cached
      • Send a EndDrag event to teh cached drag handler
    • Process scroll wheel events

 

Supported Events   

The Event System supports a number of events, and they can be customised further in user custom user written Input Modules.

The events that are supported by the Standalone Input Module and Touch Input Module are provided by interface and can be implemented on a MonoBehaviour by implementing the interface. If you have a valid Event System configured the events will be called at the correct time.

  • IPointerEnterHandler - OnPointerEnter - Called when a pointer enters the object
  • IPointerExitHandler - OnPointerExit - Called when a pointer exits the object
  • IPointerDownHandler - OnPointerDown - Called when a pointer is pressed on the object
  • IPointerUpHandler - OnPointerUp - Called when a pointer is released (called on the original the pressed object)
  • IPointerClickHandler - OnPointerClick - Called when a pointer is pressed and released on the same object
  • IInitializePotentialDragHandler - OnInitializePotentialDrag - Called when a drag target is found, can be used to initialise values
  • IBeginDragHandler - OnBeginDrag - Called on the drag object when dragging is about to begin
  • IDragHandler - OnDrag - Called on the drag object when a drag is happening
  • IEndDragHandler - OnEndDrag - Called on the drag object when a drag finishes
  • IDropHandler - OnDrop - Called on the object where a drag finishes
  • IScrollHandler - OnScroll - Called when a mouse wheel scrolls
  • IUpdateSelectedHandler - OnUpdateSelected - Called on the selected object each tick
  • ISelectHandler - OnSelect - Called when the object becomes the selected object
  • IDeselectHandler - OnDeselect - Called on the selected object becomes deselected
  • IMoveHandler - OnMove - Called when a move event occurs (left, right, up, down, ect)
  • ISubmitHandler - OnSubmit - Called when the submit button is pressed
  • ICancelHandler - OnCancel - Called when the cancel button is pressed

 

A ScriptableObject provides a convenient system for developers to define their own data types. These types can be natively serialized and deserialized by Unity, and manipulated in the Unity Editor's Inspector window.

A MonoBehaviour provides a wrapper that links to a MonoScript. A MonoScript is an internal data type that Unity uses to hold a reference to a specific scripting class within a specific assembly and namespace. The MonoScript does not contain any actual executable code.

 

IEventSystemHandler

ExecuteEvent

 

Raycasters

The Event System needs a method for detecting where current input events need to be sent to, and this is provided by the Raycasters. Given a screen space position they will collect all potential targets, figure out if they are under the given position, and then return the object that is closest to the screen. There are a few types of Raycasters that are provided:

  • Graphic Raycaster - Used for UI elements, lives on a Canvas and searches within the canvas
  • Physics 2D Raycaster - Used for 2D physics elements
  • Physics Raycaster - Used for 3D physics elements

When a Raycaster is present and enabled in the scene it will be used by the Event System whenever a query is issued from an Input Module.

If multiple Raycasters are used then they will all have casting happen against them and the results will be sorted based on distance to the elements.

 

Event Trigger

The Event Trigger receives events from the Event System and calls registered functions for each event.

The Event Trigger can be used to specify functions you wish to be called for each Event System event. You can assign multiple functions to a single event and whenever the Event Trigger receives that event it will call those functions.

Note that attaching an Event Trigger component to a GameObject will make that object intercept all events, and no event bubbling will occur from this object!

 

public delegate void UnityAction();

public delegate void UnityAction<T0[,T1][,T2][,T3]>(T0 arg0[,T1][,T2][,T3]);

public class UnityEvent : UnityEventBase {

    [RequiredByNativeCodeAttribute]
    public UnityEvent();

    public void AddListener(UnityAction call);

    public void Invoke();

    public void RemoveListener(UnityAction call);

    protected override MethodInfo FindMethod_Impl(string name, object targetObj);
}

 

DateTime TimeSpan

 

LZMA:https://zh.wikipedia.org/wiki/LZMA

LZ4:https://zh.wikipedia.org/wiki/LZ4

 

public class TriggerEvent : UnityEvent<BaseEventData> {
    public TriggerEvent();
}

public class Entry {
    public EventTriggerType eventID;
    public TriggerEvent callback;

    public Entry();
}

 EventSystem.current.IsPointerOverGameObject

 

IMPORTANT: .meta files must match and stay with their respective asset files. If you move or rename an asset within Unity’s own Project Window, Unity will also automatically move or rename the corresponding .meta file. If you move or rename an asset outside* of Unity (i.e. in Windows Explorer, or Finder on the Mac), you must move or rename the .meta file to match.

 

As well as the unique ID assigned to the asset, the meta files contain values for all the import settings you see in the inspector when you have an asset selected in your project window. For a texture, this includes settings such as the Texture Type, Wrap Mode, Filter Mode and Aniso Level.

If you change the import settings for an asset, those changed settings are stored in the .meta file accompanying the asset. The asset will be re-imported according to your new settings, and the corresponding imported “game-ready” data will be updated in the project’s Library folder.

When backing up a project, or adding a project to a Version Control Repository, you should include the main Unity project folder, containing both the Assets and ProjectSettings folders. All the information in these folders is crucial to the way Unity works. You should omit the Library and Temp folders for backup purposes.

 

A UI Element is normally positioned using its Rect Transform. If the UI Element is a child of a Layout Group it will be automatically positioned and the positioning step can be skipped.

 

fillrate = screen pixels * shader complexity * overdraw

 

Silly issues checklist

  • Textures without proper compression
  • Different solutions for different cases, but be sure to compress textures unless you’re sure you should not.
  • ETC/RGBA16 - default for android but can tweak depending on the GPU vendor. Best approach is to use ETC where possible. Alpha textures can use two ETC files with one channel being for alpha
  • PVRTC - default for iOS, good for most cases
  • Textures having Get/Set pixels enabled - doubles the footprint, uncheck unless Get/Set is needed
  • Textures loaded from JPEG/PNGs on the runtime will be uncompressed
  • Big mp3 files marked as decompress on load
  • Additive scene loading
  • Unused Assets that remain uncleaned in memory.
  • If it randomly crashes, try on a devkit or a device with 2 GB memory (like Ipad 3).

Sometimes there’s nothing in the console, just a random crash

  • Fast script call and stripping may lead to random crashes on iOS. Try without them.

Selectable.interactable

 

posted on 2017-06-02 09:54  void87  阅读(650)  评论(0编辑  收藏  举报

导航