add
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Very simple example of how to use a TextList with a UIInput for chat.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(UIInput))]
|
||||
[AddComponentMenu("NGUI/Examples/Chat Input")]
|
||||
public class ChatInput : MonoBehaviour
|
||||
{
|
||||
public UITextList textList;
|
||||
public bool fillWithDummyData = false;
|
||||
|
||||
UIInput mInput;
|
||||
|
||||
/// <summary>
|
||||
/// Add some dummy text to the text list.
|
||||
/// </summary>
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mInput = GetComponent<UIInput>();
|
||||
mInput.label.maxLineCount = 1;
|
||||
|
||||
if (fillWithDummyData && textList != null)
|
||||
{
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
textList.Add(((i % 2 == 0) ? "[FFFFFF]" : "[AAAAAA]") +
|
||||
"This is an example paragraph for the text list, testing line " + i + "[-]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Submit notification is sent by UIInput when 'enter' is pressed or iOS/Android keyboard finalizes input.
|
||||
/// </summary>
|
||||
|
||||
public void OnSubmit ()
|
||||
{
|
||||
if (textList != null)
|
||||
{
|
||||
// It's a good idea to strip out all symbols as we don't want user input to alter colors, add new lines, etc
|
||||
string text = NGUIText.StripSymbols(mInput.value);
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
textList.Add(text);
|
||||
mInput.value = "";
|
||||
mInput.isSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c4f0ea813e2aef4588e27970990027a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,40 @@
|
||||
//----------------------------------------------
|
||||
// NGUI: Next-Gen UI kit
|
||||
// Copyright © 2011-2015 Tasharen Entertainment
|
||||
//----------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Simple script that shows how to download a remote texture and assign it to be used by a UITexture.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(UITexture))]
|
||||
public class DownloadTexture : MonoBehaviour
|
||||
{
|
||||
public string url = "http://www.yourwebsite.com/logo.png";
|
||||
public bool pixelPerfect = true;
|
||||
|
||||
Texture2D mTex;
|
||||
|
||||
IEnumerator Start ()
|
||||
{
|
||||
WWW www = new WWW(url);
|
||||
yield return www;
|
||||
mTex = www.texture;
|
||||
|
||||
if (mTex != null)
|
||||
{
|
||||
UITexture ut = GetComponent<UITexture>();
|
||||
ut.mainTexture = mTex;
|
||||
if (pixelPerfect) ut.MakePixelPerfect();
|
||||
}
|
||||
www.Dispose();
|
||||
}
|
||||
|
||||
void OnDestroy ()
|
||||
{
|
||||
if (mTex != null) Destroy(mTex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28e7f0f53a61c6842a620d1114ae614f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,56 @@
|
||||
//----------------------------------------------
|
||||
// NGUI: Next-Gen UI kit
|
||||
// Copyright © 2011-2015 Tasharen Entertainment
|
||||
//----------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Example script that resizes the widget it's attached to in order to envelop the target content.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(UIWidget))]
|
||||
[AddComponentMenu("NGUI/Examples/Envelop Content")]
|
||||
public class EnvelopContent : MonoBehaviour
|
||||
{
|
||||
public Transform targetRoot;
|
||||
public int padLeft = 0;
|
||||
public int padRight = 0;
|
||||
public int padBottom = 0;
|
||||
public int padTop = 0;
|
||||
|
||||
bool mStarted = false;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mStarted = true;
|
||||
Execute();
|
||||
}
|
||||
|
||||
void OnEnable () { if (mStarted) Execute(); }
|
||||
|
||||
[ContextMenu("Execute")]
|
||||
public void Execute ()
|
||||
{
|
||||
if (targetRoot == transform)
|
||||
{
|
||||
Debug.LogError("Target Root object cannot be the same object that has Envelop Content. Make it a sibling instead.", this);
|
||||
}
|
||||
else if (NGUITools.IsChild(targetRoot, transform))
|
||||
{
|
||||
Debug.LogError("Target Root object should not be a parent of Envelop Content. Make it a sibling instead.", this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bounds b = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, targetRoot, false);
|
||||
float x0 = b.min.x + padLeft;
|
||||
float y0 = b.min.y + padBottom;
|
||||
float x1 = b.max.x + padRight;
|
||||
float y1 = b.max.y + padTop;
|
||||
|
||||
UIWidget w = GetComponent<UIWidget>();
|
||||
w.SetRect(x0, y0, x1 - x0, y1 - y0);
|
||||
BroadcastMessage("UpdateAnchors", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc132d2169cbe0478182768b713d882
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,47 @@
|
||||
//----------------------------------------------
|
||||
// NGUI: Next-Gen UI kit
|
||||
// Copyright © 2011-2015 Tasharen Entertainment
|
||||
//----------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Drag and Drop Item (Example)")]
|
||||
public class ExampleDragDropItem : UIDragDropItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Prefab object that will be instantiated on the DragDropSurface if it receives the OnDrop event.
|
||||
/// </summary>
|
||||
|
||||
public GameObject prefab;
|
||||
|
||||
/// <summary>
|
||||
/// Drop a 3D game object onto the surface.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnDragDropRelease (GameObject surface)
|
||||
{
|
||||
if (surface != null)
|
||||
{
|
||||
ExampleDragDropSurface dds = surface.GetComponent<ExampleDragDropSurface>();
|
||||
|
||||
if (dds != null)
|
||||
{
|
||||
GameObject child = NGUITools.AddChild(dds.gameObject, prefab);
|
||||
child.transform.localScale = dds.transform.localScale;
|
||||
|
||||
Transform trans = child.transform;
|
||||
// trans.position = UICamera.lastWorldPosition;
|
||||
|
||||
if (dds.rotatePlacedObject)
|
||||
{
|
||||
trans.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f);
|
||||
}
|
||||
|
||||
// Destroy this icon as it's no longer needed
|
||||
NGUITools.Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
base.OnDragDropRelease(surface);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d331b94ba7bbfa343bb6b9f9282b5c93
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,32 @@
|
||||
//----------------------------------------------
|
||||
// NGUI: Next-Gen UI kit
|
||||
// Copyright © 2011-2015 Tasharen Entertainment
|
||||
//----------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Simple example of an OnDrop event accepting a game object. In this case we check to see if there is a DragDropObject present,
|
||||
/// and if so -- create its prefab on the surface, then destroy the object.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Drag and Drop Surface (Example)")]
|
||||
public class ExampleDragDropSurface : MonoBehaviour
|
||||
{
|
||||
public bool rotatePlacedObject = false;
|
||||
|
||||
//void OnDrop (GameObject go)
|
||||
//{
|
||||
// ExampleDragDropItem ddo = go.GetComponent<ExampleDragDropItem>();
|
||||
|
||||
// if (ddo != null)
|
||||
// {
|
||||
// GameObject child = NGUITools.AddChild(gameObject, ddo.prefab);
|
||||
|
||||
// Transform trans = child.transform;
|
||||
// trans.position = UICamera.lastWorldPosition;
|
||||
// if (rotatePlacedObject) trans.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f);
|
||||
// Destroy(go);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c645c85ed4826348b5000ddccd0f936
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Attach to a game object to make its position always lag behind its parent as the parent moves.
|
||||
/// </summary>
|
||||
|
||||
public class LagPosition : MonoBehaviour
|
||||
{
|
||||
public Vector3 speed = new Vector3(10f, 10f, 10f);
|
||||
public bool ignoreTimeScale = false;
|
||||
|
||||
Transform mTrans;
|
||||
Vector3 mRelative;
|
||||
Vector3 mAbsolute;
|
||||
bool mStarted = false;
|
||||
|
||||
public void OnRepositionEnd ()
|
||||
{
|
||||
Interpolate(1000f);
|
||||
}
|
||||
|
||||
void Interpolate (float delta)
|
||||
{
|
||||
Transform parent = mTrans.parent;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
Vector3 target = parent.position + parent.rotation * mRelative;
|
||||
mAbsolute.x = Mathf.Lerp(mAbsolute.x, target.x, Mathf.Clamp01(delta * speed.x));
|
||||
mAbsolute.y = Mathf.Lerp(mAbsolute.y, target.y, Mathf.Clamp01(delta * speed.y));
|
||||
mAbsolute.z = Mathf.Lerp(mAbsolute.z, target.z, Mathf.Clamp01(delta * speed.z));
|
||||
mTrans.position = mAbsolute;
|
||||
}
|
||||
}
|
||||
|
||||
void Awake () { mTrans = transform; }
|
||||
void OnEnable () { if (mStarted) ResetPosition(); }
|
||||
void Start () { mStarted = true; ResetPosition(); }
|
||||
|
||||
public void ResetPosition ()
|
||||
{
|
||||
mAbsolute = mTrans.position;
|
||||
mRelative = mTrans.localPosition;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
Interpolate(ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e58031db5aeb444da199e06c340c871
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 51
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Attach to a game object to make its rotation always lag behind its parent as the parent rotates.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Lag Rotation")]
|
||||
public class LagRotation : MonoBehaviour
|
||||
{
|
||||
public float speed = 10f;
|
||||
public bool ignoreTimeScale = false;
|
||||
|
||||
Transform mTrans;
|
||||
Quaternion mRelative;
|
||||
Quaternion mAbsolute;
|
||||
|
||||
public void OnRepositionEnd ()
|
||||
{
|
||||
Interpolate(1000f);
|
||||
}
|
||||
|
||||
void Interpolate (float delta)
|
||||
{
|
||||
if (mTrans != null)
|
||||
{
|
||||
Transform parent = mTrans.parent;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
mAbsolute = Quaternion.Slerp(mAbsolute, parent.rotation * mRelative, delta * speed);
|
||||
mTrans.rotation = mAbsolute;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mTrans = transform;
|
||||
mRelative = mTrans.localRotation;
|
||||
mAbsolute = mTrans.rotation;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
Interpolate(ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2f7cad6a754193478a36b8177641278
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 52
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Load Level On Click")]
|
||||
public class LoadLevelOnClick : MonoBehaviour
|
||||
{
|
||||
public string levelName;
|
||||
|
||||
void OnClick ()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(levelName))
|
||||
{
|
||||
Application.LoadLevel(levelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4df31385379812441bfc75a419c76729
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Attaching this script to an object will make that object face the specified target.
|
||||
/// The most ideal use for this script is to attach it to the camera and make the camera look at its target.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Look At Target")]
|
||||
public class LookAtTarget : MonoBehaviour
|
||||
{
|
||||
public int level = 0;
|
||||
public Transform target;
|
||||
public float speed = 8f;
|
||||
|
||||
Transform mTrans;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mTrans = transform;
|
||||
}
|
||||
|
||||
void LateUpdate ()
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
Vector3 dir = target.position - mTrans.position;
|
||||
float mag = dir.magnitude;
|
||||
|
||||
if (mag > 0.001f)
|
||||
{
|
||||
Quaternion lookRot = Quaternion.LookRotation(dir);
|
||||
mTrans.rotation = Quaternion.Slerp(mTrans.rotation, lookRot, Mathf.Clamp01(speed * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2beca3ab63dabae4782a28898bed8b06
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class OpenURLOnClick : MonoBehaviour
|
||||
{
|
||||
void OnClick ()
|
||||
{
|
||||
UILabel lbl = GetComponent<UILabel>();
|
||||
|
||||
if (lbl != null)
|
||||
{
|
||||
string url = lbl.GetUrlAtPosition(UICamera.lastWorldPosition);
|
||||
if (!string.IsNullOrEmpty(url)) Application.OpenURL(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f4e76ca1e5bd9d41938bc027a0aa6b9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Placing this script on the game object will make that game object pan with mouse movement.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Pan With Mouse")]
|
||||
public class PanWithMouse : MonoBehaviour
|
||||
{
|
||||
public Vector2 degrees = new Vector2(5f, 3f);
|
||||
public float range = 1f;
|
||||
|
||||
Transform mTrans;
|
||||
Quaternion mStart;
|
||||
Vector2 mRot = Vector2.zero;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mTrans = transform;
|
||||
mStart = mTrans.localRotation;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
float delta = RealTime.deltaTime;
|
||||
Vector3 pos = Input.mousePosition;
|
||||
|
||||
float halfWidth = Screen.width * 0.5f;
|
||||
float halfHeight = Screen.height * 0.5f;
|
||||
if (range < 0.1f) range = 0.1f;
|
||||
float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth / range, -1f, 1f);
|
||||
float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight / range, -1f, 1f);
|
||||
mRot = Vector2.Lerp(mRot, new Vector2(x, y), delta * 5f);
|
||||
|
||||
mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * degrees.y, mRot.x * degrees.x, 0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cef9873bc3783e249b519e15ee14b35a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,88 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Attach this script to any object that has idle animations.
|
||||
/// It's expected that the main idle loop animation is called "idle", and idle
|
||||
/// break animations all begin with "idle" (ex: idleStretch, idleYawn, etc).
|
||||
/// The script will place the idle loop animation on layer 0, and breaks on layer 1.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Play Idle Animations")]
|
||||
public class PlayIdleAnimations : MonoBehaviour
|
||||
{
|
||||
Animation mAnim;
|
||||
AnimationClip mIdle;
|
||||
List<AnimationClip> mBreaks = new List<AnimationClip>();
|
||||
float mNextBreak = 0f;
|
||||
int mLastIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Find all idle animations.
|
||||
/// </summary>
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mAnim = GetComponentInChildren<Animation>();
|
||||
|
||||
if (mAnim == null)
|
||||
{
|
||||
Debug.LogWarning(NGUITools.GetHierarchy(gameObject) + " has no Animation component");
|
||||
Destroy(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (AnimationState state in mAnim)
|
||||
{
|
||||
if (state.clip.name == "idle")
|
||||
{
|
||||
state.layer = 0;
|
||||
mIdle = state.clip;
|
||||
mAnim.Play(mIdle.name);
|
||||
}
|
||||
else if (state.clip.name.StartsWith("idle"))
|
||||
{
|
||||
state.layer = 1;
|
||||
mBreaks.Add(state.clip);
|
||||
}
|
||||
}
|
||||
|
||||
// No idle breaks found -- this script is unnecessary
|
||||
if (mBreaks.Count == 0) Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If it's time to play a new idle break animation, do so.
|
||||
/// </summary>
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (mNextBreak < Time.time)
|
||||
{
|
||||
if (mBreaks.Count == 1)
|
||||
{
|
||||
// Only one break animation
|
||||
AnimationClip clip = mBreaks[0];
|
||||
mNextBreak = Time.time + clip.length + Random.Range(5f, 15f);
|
||||
mAnim.CrossFade(clip.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = Random.Range(0, mBreaks.Count - 1);
|
||||
|
||||
// Never choose the same animation twice in a row
|
||||
if (mLastIndex == index)
|
||||
{
|
||||
++index;
|
||||
if (index >= mBreaks.Count) index = 0;
|
||||
}
|
||||
|
||||
mLastIndex = index;
|
||||
AnimationClip clip = mBreaks[index];
|
||||
mNextBreak = Time.time + clip.length + Random.Range(2f, 8f);
|
||||
mAnim.CrossFade(clip.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7393c14f99274841887c9890b46216d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Simple script used by Tutorial 11 that sets the color of the sprite based on the string value.
|
||||
/// </summary>
|
||||
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(UIWidget))]
|
||||
[AddComponentMenu("NGUI/Examples/Set Color on Selection")]
|
||||
public class SetColorOnSelection : MonoBehaviour
|
||||
{
|
||||
UIWidget mWidget;
|
||||
|
||||
public void SetSpriteBySelection ()
|
||||
{
|
||||
if (UIPopupList.current == null) return;
|
||||
if (mWidget == null) mWidget = GetComponent<UIWidget>();
|
||||
|
||||
switch (UIPopupList.current.value)
|
||||
{
|
||||
case "White": mWidget.color = Color.white; break;
|
||||
case "Red": mWidget.color = Color.red; break;
|
||||
case "Green": mWidget.color = Color.green; break;
|
||||
case "Blue": mWidget.color = Color.blue; break;
|
||||
case "Yellow": mWidget.color = Color.yellow; break;
|
||||
case "Cyan": mWidget.color = Color.cyan; break;
|
||||
case "Magenta": mWidget.color = Color.magenta; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c0c14d2698771846ad203a553cbc444
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Want something to spin? Attach this script to it. Works equally well with rigidbodies as without.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Spin")]
|
||||
public class Spin : MonoBehaviour
|
||||
{
|
||||
public Vector3 rotationsPerSecond = new Vector3(0f, 0.1f, 0f);
|
||||
public bool ignoreTimeScale = false;
|
||||
|
||||
Rigidbody mRb;
|
||||
Transform mTrans;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mTrans = transform;
|
||||
mRb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (mRb == null)
|
||||
{
|
||||
ApplyDelta(ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (mRb != null)
|
||||
{
|
||||
ApplyDelta(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyDelta (float delta)
|
||||
{
|
||||
delta *= Mathf.Rad2Deg * Mathf.PI * 2f;
|
||||
Quaternion offset = Quaternion.Euler(rotationsPerSecond * delta);
|
||||
|
||||
if (mRb == null)
|
||||
{
|
||||
mTrans.rotation = mTrans.rotation * offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
mRb.MoveRotation(mRb.rotation * offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf6484591c9cb0e409f5c53c6978a95d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Spin With Mouse")]
|
||||
public class SpinWithMouse : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
public float speed = 1f;
|
||||
|
||||
Transform mTrans;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mTrans = transform;
|
||||
}
|
||||
|
||||
void OnDrag (Vector2 delta)
|
||||
{
|
||||
UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
target.localRotation = Quaternion.Euler(0f, -0.5f * delta.x * speed, 0f) * target.localRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTrans.localRotation = Quaternion.Euler(0f, -0.5f * delta.x * speed, 0f) * mTrans.localRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d335b6026587ad24dbe124fe5dd1cc02
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// This simple example script is used in Tutorial 5 to show how custom events work.
|
||||
/// </summary>
|
||||
|
||||
public class Tutorial5 : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// This function is called by the duration slider. Since it's called by a slider,
|
||||
/// UIProgressBar.current will contain the caller. It's identical to other NGUI components.
|
||||
/// A button's callback will set UIButton.current, for example. Input field? UIInput.current, etc.
|
||||
/// </summary>
|
||||
|
||||
public void SetDurationToCurrentProgress (GameObject go=null)
|
||||
{
|
||||
UITweener[] tweens = GetComponentsInChildren<UITweener>();
|
||||
|
||||
foreach (UITweener tw in tweens)
|
||||
{
|
||||
// The slider's value is always limited in 0 to 1 range, however it's trivial to change it.
|
||||
// For example, to make it range from 2.0 to 0.5 instead, you can do this:
|
||||
tw.duration = Mathf.Lerp(2.0f, 0.5f, UIProgressBar.current.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94cd518a0b2919a42af43f5184cd1c05
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,56 @@
|
||||
//----------------------------------------------
|
||||
// NGUI: Next-Gen UI kit
|
||||
// Copyright © 2011-2015 Tasharen Entertainment
|
||||
//----------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// This script automatically changes the color of the specified sprite based on the value of the slider.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Slider Colors")]
|
||||
public class UISliderColors : MonoBehaviour
|
||||
{
|
||||
public UISprite sprite;
|
||||
|
||||
public Color[] colors = new Color[] { Color.red, Color.yellow, Color.green };
|
||||
|
||||
UIProgressBar mBar;
|
||||
UIBasicSprite mSprite;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mBar = GetComponent<UIProgressBar>();
|
||||
mSprite = GetComponent<UIBasicSprite>();
|
||||
Update();
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (sprite == null || colors.Length == 0) return;
|
||||
|
||||
float val = (mBar != null) ? mBar.value : mSprite.fillAmount;
|
||||
val *= (colors.Length - 1);
|
||||
int startIndex = Mathf.FloorToInt(val);
|
||||
|
||||
Color c = colors[0];
|
||||
|
||||
if (startIndex >= 0)
|
||||
{
|
||||
if (startIndex + 1 < colors.Length)
|
||||
{
|
||||
float factor = (val - startIndex);
|
||||
c = Color.Lerp(colors[startIndex], colors[startIndex + 1], factor);
|
||||
}
|
||||
else if (startIndex < colors.Length)
|
||||
{
|
||||
c = colors[startIndex];
|
||||
}
|
||||
else c = colors[colors.Length - 1];
|
||||
}
|
||||
|
||||
c.a = sprite.color.a;
|
||||
sprite.color = c;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d15ff9fd80670345b53fd7be4f2f295
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Attaching this script to an object will make it turn as it gets closer to left/right edges of the screen.
|
||||
/// Look at how it's used in Example 6.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Window Auto-Yaw")]
|
||||
public class WindowAutoYaw : MonoBehaviour
|
||||
{
|
||||
public int updateOrder = 0;
|
||||
public Camera uiCamera;
|
||||
public float yawAmount = 20f;
|
||||
|
||||
Transform mTrans;
|
||||
|
||||
void OnDisable ()
|
||||
{
|
||||
mTrans.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
|
||||
mTrans = transform;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (uiCamera != null)
|
||||
{
|
||||
Vector3 pos = uiCamera.WorldToViewportPoint(mTrans.position);
|
||||
mTrans.localRotation = Quaternion.Euler(0f, (pos.x * 2f - 1f) * yawAmount, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b566c1f22015f644a83ceccc0279fc88
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 100
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Attach this script to a child of a draggable window to make it tilt as it's dragged.
|
||||
/// Look at how it's used in Example 6.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("NGUI/Examples/Window Drag Tilt")]
|
||||
public class WindowDragTilt : MonoBehaviour
|
||||
{
|
||||
public int updateOrder = 0;
|
||||
public float degrees = 30f;
|
||||
|
||||
Vector3 mLastPos;
|
||||
Transform mTrans;
|
||||
float mAngle = 0f;
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
mTrans = transform;
|
||||
mLastPos = mTrans.position;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
Vector3 deltaPos = mTrans.position - mLastPos;
|
||||
mLastPos = mTrans.position;
|
||||
|
||||
mAngle += deltaPos.x * degrees;
|
||||
mAngle = NGUIMath.SpringLerp(mAngle, 0f, 20f, Time.deltaTime);
|
||||
|
||||
mTrans.localRotation = Quaternion.Euler(0f, 0f, -mAngle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df649a5c42709b348bc24a4c552ff369
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 200
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user