本文整理汇总了C#中UISnapshotPoint类的典型用法代码示例。如果您正苦于以下问题:C# UISnapshotPoint类的具体用法?C# UISnapshotPoint怎么用?C# UISnapshotPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UISnapshotPoint类属于命名空间,在下文中一共展示了UISnapshotPoint类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupSnapshotCamera
/// <summary>
/// Set up the camera using the provided snapshot point's values.
/// </summary>
static void SetupSnapshotCamera (GameObject go, Camera cam, UISnapshotPoint point)
{
Vector3 pos = point.transform.localPosition;
Quaternion rot = point.transform.localRotation;
Transform t = go.transform;
if (t.parent != null)
{
pos = t.parent.TransformPoint(pos);
rot = t.parent.rotation * rot;
}
cam.transform.position = pos;
cam.transform.rotation = rot;
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
cam.isOrthoGraphic = point.isOrthographic;
#else
cam.orthographic = point.isOrthographic;
#endif
cam.nearClipPlane = point.nearClip;
cam.farClipPlane = point.farClip;
cam.orthographicSize = point.orthoSize;
cam.fieldOfView = point.fieldOfView;
}
示例2: SetupPreviewFor3D
/// <summary>
/// Set up everything necessary to preview a UI object.
/// </summary>
static bool SetupPreviewFor3D (Camera cam, GameObject root, GameObject child, UISnapshotPoint point)
{
Renderer[] rens = child.GetComponentsInChildren<Renderer>();
if (rens.Length == 0) return false;
Vector3 camDir = new Vector3(-0.25f, -0.35f, -0.5f);
Vector3 lightDir = new Vector3(-0.25f, -0.5f, -0.25f);
camDir.Normalize();
lightDir.Normalize();
// Determine the bounds of the model
Renderer ren = rens[0];
Bounds bounds = ren.bounds;
int mask = (1 << ren.gameObject.layer);
for (int i = 1; i < rens.Length; ++i)
{
ren = rens[i];
mask |= (1 << ren.gameObject.layer);
bounds.Encapsulate(ren.bounds);
}
// Set the camera's properties
cam.cullingMask = mask;
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
cam.isOrthoGraphic = true;
#else
cam.orthographic = true;
#endif
cam.transform.position = bounds.center;
cam.transform.rotation = Quaternion.LookRotation(camDir);
float objSize = bounds.size.magnitude;
if (point != null) SetupSnapshotCamera(child, cam, point);
else SetupSnapshotCamera(child, cam, objSize, objSize * 0.4f, -objSize, objSize);
// Deactivate all scene lights
DeactivateLights();
// Create our own light
GameObject lightGO = NGUITools.AddChild(root);
Light light = lightGO.AddComponent<Light>();
light.type = LightType.Directional;
light.shadows = LightShadows.None;
light.color = Color.white;
light.intensity = 0.65f;
light.transform.rotation = Quaternion.LookRotation(lightDir);
light.cullingMask = mask;
return true;
}
示例3: GeneratePreview
/// <summary>
/// Generate an item preview for the specified item.
/// </summary>
void GeneratePreview (Item item, UISnapshotPoint point)
{
if (item == null || item.prefab == null) return;
if (point == null) point = GetSnapshotPoint(item.prefab.transform);
if (point != null && point.thumbnail != null)
{
Debug.Log(2);
// Explicitly chosen thumbnail
item.tex = point.thumbnail;
item.dynamicTex = false;
return;
}
else if (!UnityEditorInternal.InternalEditorUtility.HasPro())
{
// Render textures only work in Unity Pro
string path = "Assets/NGUI/Editor/Preview/" + item.prefab.name + ".png";
item.tex = File.Exists(path) ? (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) : null;
item.dynamicTex = false;
return;
}
int dim = (cellSize - 4) * 2;
// Asset Preview-based approach is unreliable, and most of the time fails to provide a texture.
// Sometimes it even throws null exceptions.
//item.tex = AssetPreview.GetAssetPreview(item.prefab);
//item.dynamicTex = false;
//if (item.tex != null) return;
// Let's create a basic scene
GameObject root = EditorUtility.CreateGameObjectWithHideFlags(
"Preview Root", HideFlags.HideAndDontSave);
GameObject camGO = EditorUtility.CreateGameObjectWithHideFlags(
"Preview Camera", HideFlags.HideAndDontSave, typeof(Camera));
// Position it far away so that it doesn't interfere with existing objects
root.transform.position = new Vector3(0f, 0f, 10000f);
root.layer = item.prefab.layer;
// Set up the camera
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
Camera cam = camGO.camera;
cam.isOrthoGraphic = true;
#else
Camera cam = camGO.GetComponent<Camera>();
cam.orthographic = true;
#endif
cam.renderingPath = RenderingPath.Forward;
cam.clearFlags = CameraClearFlags.Skybox;
cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
cam.targetTexture = (item.tex as RenderTexture);
cam.enabled = false;
// Finally instantiate the prefab as a child of the root
GameObject child = NGUITools.AddChild(root, item.prefab);
// Try to find the snapshot point script
if (point == null) point = child.GetComponentInChildren<UISnapshotPoint>();
// If there is a UIRect present (widgets or panels) then it's an NGUI object
RenderTexture rt = (SetupPreviewForUI(cam, root, child, point) || SetupPreviewFor3D(cam, root, child, point)) ?
cam.RenderToTexture(dim, dim) : null;
// Did we have a different render texture? Get rid of it.
if (item.tex != rt && item.tex != null && item.dynamicTex)
{
NGUITools.DestroyImmediate(item.tex);
item.tex = null;
item.dynamicTex = false;
}
// Do we have a new render texture? Assign it.
if (rt != null)
{
item.tex = rt;
item.dynamicTex = true;
}
// Clean up everything
DestroyImmediate(camGO);
DestroyImmediate(root);
}
示例4: SetupPreviewForUI
/// <summary>
/// Set up everything necessary to preview a UI object.
/// </summary>
static bool SetupPreviewForUI (Camera cam, GameObject root, GameObject child, UISnapshotPoint point)
{
if (child.GetComponentInChildren<UIRect>() == null) return false;
if (child.GetComponent<UIPanel>() == null)
root.AddComponent<UIPanel>();
Bounds bounds = NGUIMath.CalculateAbsoluteWidgetBounds(child.transform);
Vector3 size = bounds.extents;
float objSize = size.magnitude;
cam.transform.position = bounds.center;
cam.cullingMask = (1 << root.layer);
if (point != null) SetupSnapshotCamera(child, cam, point);
else SetupSnapshotCamera(child, cam, objSize, Mathf.RoundToInt(Mathf.Max(size.x, size.y)), -100f, 100f);
NGUITools.ImmediatelyCreateDrawCalls(root);
return true;
}
示例5: RegenerateTexture
/// <summary>
/// Re-generate the specified prefab's snapshot texture using the provided snapshot point's values.
/// </summary>
public void RegenerateTexture (GameObject prefab, UISnapshotPoint point)
{
for (int i = 0; i < mItems.size; ++i)
{
Item item = mItems[i];
if (item.prefab == prefab)
{
GeneratePreview(item, point);
RectivateLights();
break;
}
}
}