Readd missing import files
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class CameraNavigator : MonoBehaviour
|
||||
{
|
||||
public const int ElementType = 999;
|
||||
public Vector3 Pos = new Vector3(0.8f, 0.8f, 1);
|
||||
|
||||
public enum ENaviType
|
||||
{
|
||||
PX,
|
||||
NX,
|
||||
PY,
|
||||
NY,
|
||||
PZ,
|
||||
NZ,
|
||||
Center,
|
||||
}
|
||||
|
||||
public Camera RendererCamera;
|
||||
public GameObject NaviRoot;
|
||||
private List<GameObject> Navis = new List<GameObject>();
|
||||
|
||||
private List<Vector3> _angles = new List<Vector3>() {
|
||||
Vector3.left, Vector3.right,
|
||||
Vector3.down, Vector3.up,
|
||||
Vector3.back, Vector3.forward,
|
||||
Vector3.zero };
|
||||
private List<Color> _colors = new List<Color>() {
|
||||
Color.red, Color.white,
|
||||
Color.green, Color.white,
|
||||
Color.blue, Color.white,
|
||||
Color.white };
|
||||
private List<MeshRenderer> _naviRenders = new List<MeshRenderer>();
|
||||
private Camera _camera;
|
||||
private bool _enableNaviUpdate = true;
|
||||
private TouchInteraction _interacton;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
|
||||
this.gameObject.SetLayerWithChildren(Settings.NavLayerName);
|
||||
var displayCam = this.gameObject.GetComponentInChildren<Camera>();
|
||||
if(displayCam != null)
|
||||
{
|
||||
displayCam.cullingMask = 1 << this.gameObject.layer;
|
||||
}
|
||||
|
||||
_interacton = this.gameObject.AddComponent<TouchInteraction>();
|
||||
_interacton.Set(RendererCamera, 1 << this.gameObject.layer);
|
||||
_interacton.HoverTargetChangedEvent += _interacton_HoverTargetChangedEvent;
|
||||
_interacton.SelectedEvent += _interacton_SelectedEvent;
|
||||
|
||||
for (int i = 0; i < NaviRoot.transform.childCount; i++)
|
||||
{
|
||||
Transform t = NaviRoot.transform.GetChild(i);
|
||||
Navis.Add(t.gameObject);
|
||||
|
||||
MeshRenderer mr = t.GetComponent<MeshRenderer>();
|
||||
_naviRenders.Add(mr);
|
||||
}
|
||||
}
|
||||
|
||||
private void _interacton_SelectedEvent(ElementTag tag)
|
||||
{
|
||||
if (!_enableNaviUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Navis.Count; i++)
|
||||
{
|
||||
_naviRenders[i].material.color = _colors[i];
|
||||
|
||||
Navis[i].SetActive(true);
|
||||
}
|
||||
|
||||
if (tag != null)
|
||||
{
|
||||
int id = int.Parse(tag.ID);
|
||||
|
||||
if (id == (int)ENaviType.Center)
|
||||
{
|
||||
//CameraCtrl.Instance.Reset(CameraCtrl.Instance.StateType, CameraCtrl.Instance.Locked, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_enableNaviUpdate = false;
|
||||
|
||||
//var currentAngle = _camera.transform.forward;
|
||||
//var targetAngle = _angles[id];
|
||||
var euler = Quaternion.LookRotation(_angles[id], Vector3.up).eulerAngles;
|
||||
Color color = _naviRenders[id].material.color;
|
||||
Tweener tweener = _camera.transform.DORotate(euler, 0.5f);
|
||||
tweener.OnComplete(() =>
|
||||
{
|
||||
_enableNaviUpdate = true;
|
||||
Navis[id].SetActive(false);
|
||||
}).OnUpdate(() =>
|
||||
{
|
||||
color.a = 1 - tweener.timeScale;
|
||||
_naviRenders[id].material.color = color;
|
||||
}).Play();
|
||||
|
||||
//_camera.gameObject.Tween(0.5f)
|
||||
// .SetUpdate((scale) =>
|
||||
// {
|
||||
// color.a = 1 - scale;
|
||||
// _naviRenders[id].material.color = color;
|
||||
// _camera.transform.forward = Vector3.Slerp(currentAngle, targetAngle, scale);
|
||||
// }).
|
||||
// SetComplete(() =>
|
||||
// {
|
||||
// _enableNaviUpdate = true;
|
||||
// Navis[id].SetActive(false);
|
||||
// _camera.transform.forward = targetAngle;
|
||||
// return false;
|
||||
// }).
|
||||
// Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _interacton_HoverTargetChangedEvent(ElementTag tag)
|
||||
{
|
||||
if (_interacton.LastSelectedTag != null)
|
||||
{
|
||||
int id = int.Parse(_interacton.LastSelectedTag.ID);
|
||||
_naviRenders[id].material.color = _colors[id];
|
||||
}
|
||||
if (tag != null)
|
||||
{
|
||||
int id = int.Parse(tag.ID);
|
||||
ENaviType ntype = (ENaviType)id;
|
||||
Color color = _naviRenders[id].material.color * 0.3f;
|
||||
color.a = 1;
|
||||
_naviRenders[id].material.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateNavi()
|
||||
{
|
||||
NaviRoot.transform.eulerAngles = -_camera.transform.eulerAngles;
|
||||
|
||||
Vector3 angles = _camera.transform.eulerAngles;
|
||||
float min = 20;
|
||||
if (Mathf.Abs(angles.x % 90) > min ||
|
||||
Mathf.Abs(angles.y % 90) > min ||
|
||||
Mathf.Abs(angles.z % 90) > min)
|
||||
{
|
||||
for (int i = 0; i < Navis.Count; i++)
|
||||
{
|
||||
_naviRenders[i].material.color = _colors[i];
|
||||
|
||||
Navis[i].SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
UpdateNavi();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7392ee4de9c03984aadb69e2089b9277
|
||||
timeCreated: 1481859635
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public enum EGizmosType
|
||||
{
|
||||
Move,
|
||||
Scale,
|
||||
Rotate,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ada410870bf85449c934880b5b4da2
|
||||
timeCreated: 1481867581
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class GizmosAxis : MonoBehaviour
|
||||
{
|
||||
private GizmosBase _coordinate;
|
||||
private int m_iLayer;
|
||||
private bool mSelected = false;
|
||||
// Use this for initialization
|
||||
void Awake()
|
||||
{
|
||||
_coordinate = transform.parent.parent.GetComponent<GizmosBase>();
|
||||
m_iLayer = LayerMask.NameToLayer(Settings.GizmosLayerName);
|
||||
gameObject.layer = m_iLayer;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (mSelected)
|
||||
{
|
||||
if (!Input.GetMouseButton(0))
|
||||
{
|
||||
mSelected = false;
|
||||
StartCoroutine(delayRelease());
|
||||
}
|
||||
else
|
||||
{
|
||||
_coordinate.OnMouseDrag(gameObject);
|
||||
}
|
||||
}
|
||||
else if(Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 1000, 1 << m_iLayer))
|
||||
{
|
||||
if (hit.collider.gameObject == gameObject)
|
||||
{
|
||||
_coordinate.OnMouseEnter(gameObject);
|
||||
_coordinate.OnMouseDown(gameObject);
|
||||
mSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator delayRelease()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
_coordinate.OnMouseExit(gameObject);
|
||||
_coordinate.OnMouseUp(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56e863f828debb247839287d50197f53
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public enum EGizmosAxisType
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
LockX,
|
||||
LockY,
|
||||
LockZ,
|
||||
CENTER,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81afbe945b2c43e4093a566550df17f5
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,239 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public delegate Vector3 GizmosValueChangedHandler(Vector3 before);
|
||||
|
||||
public class GizmosBase : MonoBehaviour
|
||||
{
|
||||
public event Action<EGizmosAxisType> AxisSelectedEvent;
|
||||
public GameObject _lastSelected;
|
||||
public float scale = 1.0f;
|
||||
private Vector3 _lastMousePt;
|
||||
private bool dirty = false;
|
||||
private float _distanceFactor = 1.0f;
|
||||
protected Dictionary<GameObject, EGizmosAxisType> _axisMap = new Dictionary<GameObject, EGizmosAxisType>();
|
||||
// Use this for initialization
|
||||
void Awake()
|
||||
{
|
||||
transform.localScale = Vector3.zero;
|
||||
OnInit();
|
||||
}
|
||||
|
||||
protected void ConstructAxis(string axisRoot, EGizmosAxisType type)
|
||||
{
|
||||
Transform go = transform.Find(axisRoot);
|
||||
for (int i = 0; i < go.childCount; ++i)
|
||||
{
|
||||
GameObject obj = go.GetChild(i).gameObject;
|
||||
obj.AddComponent<GizmosAxis>();
|
||||
MeshRenderer r = obj.GetComponent<MeshRenderer>();
|
||||
SetColor(r.material, type, false);
|
||||
_axisMap[obj] = type;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetColor(Material mat, EGizmosAxisType type, bool highlight)
|
||||
{
|
||||
if (!highlight)
|
||||
{
|
||||
float lightness = 1.0f;
|
||||
if (type == EGizmosAxisType.X)
|
||||
{
|
||||
mat.color = new Color(lightness, 0.0f, 0.0f, 0.5f);
|
||||
}
|
||||
else if (type == EGizmosAxisType.Y)
|
||||
{
|
||||
mat.color = new Color(0.0f, lightness, 0.0f, 0.5f);
|
||||
}
|
||||
else if (type == EGizmosAxisType.Z)
|
||||
{
|
||||
mat.color = new Color(0.0f, 0.0f, lightness, 0.5f);
|
||||
}
|
||||
else if (type == EGizmosAxisType.LockX)
|
||||
{
|
||||
mat.color = new Color(lightness, 0.0f, 0.0f, 0.5f);
|
||||
}
|
||||
else if (type == EGizmosAxisType.LockY)
|
||||
{
|
||||
mat.color = new Color(0.0f, lightness, 0.0f, 0.5f);
|
||||
}
|
||||
else if (type == EGizmosAxisType.LockZ)
|
||||
{
|
||||
mat.color = new Color(0.0f, 0.0f, lightness, 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.color = new Color(lightness, lightness, lightness, 1.0f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.color = new Color(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 diff = transform.position - Camera.main.transform.position;
|
||||
float d = diff.magnitude * scale * 0.05f;
|
||||
_distanceFactor = ComputeScaleFactor(d);
|
||||
transform.localScale = new Vector3(d, d, d);
|
||||
}
|
||||
|
||||
protected virtual float ComputeScaleFactor(float d)
|
||||
{
|
||||
return d * 1.4f;
|
||||
}
|
||||
|
||||
private void ChangeColor(GameObject go, bool highlight)
|
||||
{
|
||||
Transform root = go.transform.parent;
|
||||
for (int i = 0; i < root.childCount; ++i)
|
||||
{
|
||||
GameObject childGO = root.GetChild(i).gameObject;
|
||||
MeshRenderer r = childGO.GetComponent<MeshRenderer>();
|
||||
EGizmosAxisType type = _axisMap[childGO];
|
||||
SetColor(r.material, type, highlight);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMouseEnter(GameObject go)
|
||||
{
|
||||
if(_lastSelected != null)
|
||||
{
|
||||
ChangeColor(_lastSelected, false);
|
||||
}
|
||||
ChangeColor(go, true);
|
||||
//Debug.Log("OnMouseEnter");
|
||||
_lastSelected = go;
|
||||
OnAxisSelected(_axisMap[go]);
|
||||
}
|
||||
|
||||
public void OnMouseExit(GameObject go)
|
||||
{
|
||||
//ChangeColor(go, false);
|
||||
// Debug.Log("OnMouse Exit");
|
||||
}
|
||||
|
||||
public void OnMouseDown(GameObject go)
|
||||
{
|
||||
_lastMousePt = Input.mousePosition;
|
||||
// Debug.Log("OnMouseDown");
|
||||
OnAxisSelected(_axisMap[go]);
|
||||
}
|
||||
|
||||
public void OnMouseUp(GameObject go)
|
||||
{
|
||||
OnDragEnd(go);
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public void OnMouseDrag(GameObject go)
|
||||
{
|
||||
Vector3 mousePt = Input.mousePosition;
|
||||
Vector3 diff = mousePt - _lastMousePt;
|
||||
if (diff.x + diff.y == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
dirty = true;
|
||||
EGizmosAxisType type = _axisMap[go];
|
||||
float dx = 0;
|
||||
float dy = 0;
|
||||
float dz = 0;
|
||||
float scensitivity = 0.02f;
|
||||
|
||||
Vector3 ogrinPos = transform.position;
|
||||
Vector3 start = Camera.main.WorldToScreenPoint(ogrinPos);
|
||||
start.z = 0;
|
||||
|
||||
if (type != EGizmosAxisType.CENTER)
|
||||
{
|
||||
Vector3 end = Camera.main.WorldToScreenPoint(ogrinPos + transform.right * 2);
|
||||
end.z = 0;
|
||||
Vector3 axisDir = end - start;
|
||||
axisDir.Normalize();
|
||||
dx = (axisDir.x * diff.x + axisDir.y * diff.y) * scensitivity;
|
||||
|
||||
|
||||
end = Camera.main.WorldToScreenPoint(ogrinPos + transform.up * 2);
|
||||
end.z = 0;
|
||||
axisDir = end - start;
|
||||
axisDir.Normalize();
|
||||
dy = (axisDir.x * diff.x + axisDir.y * diff.y) * scensitivity;
|
||||
|
||||
end = Camera.main.WorldToScreenPoint(ogrinPos + transform.forward * 2);
|
||||
end.z = 0;
|
||||
axisDir = end - start;
|
||||
axisDir.Normalize();
|
||||
dz = (axisDir.x * diff.x + axisDir.y * diff.y) * scensitivity;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 end = start + Vector3.one;
|
||||
end.z = 0;
|
||||
Vector3 axisDir = end - start;
|
||||
axisDir.Normalize();
|
||||
dx = dy = dz = (axisDir.x * diff.x + axisDir.y * diff.y) * scensitivity;
|
||||
}
|
||||
|
||||
|
||||
Vector3 axisMask = Vector3.zero;
|
||||
switch (type)
|
||||
{
|
||||
case EGizmosAxisType.X:
|
||||
axisMask.x = 1;
|
||||
break;
|
||||
case EGizmosAxisType.Y:
|
||||
axisMask.y = 1;
|
||||
break;
|
||||
case EGizmosAxisType.Z:
|
||||
axisMask.z = 1;
|
||||
break;
|
||||
case EGizmosAxisType.LockX:
|
||||
axisMask.y = 1;
|
||||
axisMask.z = 1;
|
||||
break;
|
||||
case EGizmosAxisType.LockY:
|
||||
axisMask.x = 1;
|
||||
axisMask.z = 1;
|
||||
break;
|
||||
case EGizmosAxisType.LockZ:
|
||||
axisMask.x = 1;
|
||||
axisMask.y = 1;
|
||||
break;
|
||||
case EGizmosAxisType.CENTER:
|
||||
axisMask.x = 1;
|
||||
axisMask.y = 1;
|
||||
axisMask.z = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
dx = dx * axisMask.x * _distanceFactor;
|
||||
dy = dy * axisMask.y * _distanceFactor;
|
||||
dz = dz * axisMask.z * _distanceFactor;
|
||||
OnDragDelta(go, dx, dy, dz);
|
||||
_lastMousePt = mousePt;
|
||||
}
|
||||
|
||||
protected virtual void OnInit() { }
|
||||
|
||||
protected virtual void OnDragDelta(GameObject go,float dx, float dy, float dz) { }
|
||||
protected virtual void OnDragEnd(GameObject go) { }
|
||||
|
||||
protected virtual void OnAxisSelected(EGizmosAxisType type)
|
||||
{
|
||||
if(AxisSelectedEvent != null)
|
||||
{
|
||||
AxisSelectedEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c23c16d44c0b7241a29cc734b6c70e2
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class GizmosManager : MonoSingleton<GizmosManager>
|
||||
{
|
||||
private GizmosMove _gizmosMove;
|
||||
private GizmosScale _gizmosScale;
|
||||
private GizmosRotate _gizmosRotate;
|
||||
|
||||
void Start()
|
||||
{
|
||||
var glayer = 1 << LayerMask.NameToLayer(Settings.GizmosLayerName);
|
||||
var nlayer = 1 << LayerMask.NameToLayer(Settings.NavLayerName);
|
||||
var mask = Camera.main.cullingMask;
|
||||
Camera.main.cullingMask = ((glayer | mask) & ~nlayer);
|
||||
}
|
||||
|
||||
public static bool IsOnGizmos()
|
||||
{
|
||||
int layer = LayerMask.NameToLayer(Settings.GizmosLayerName);
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 1000, 1 << layer))
|
||||
{
|
||||
return hit.collider.gameObject != null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public GizmosRotate GetSingleRotate()
|
||||
{
|
||||
if(_gizmosRotate == null)
|
||||
{
|
||||
_gizmosRotate = CreateRotate();
|
||||
}
|
||||
return _gizmosRotate;
|
||||
}
|
||||
|
||||
public GizmosRotate CreateRotate()
|
||||
{
|
||||
GameObject go = new GameObject("gizmos-rotate");
|
||||
go.transform.SetParent(this.transform);
|
||||
return go.AddComponent<GizmosRotate>();
|
||||
}
|
||||
|
||||
public GizmosMove GetSingleMove()
|
||||
{
|
||||
if(_gizmosMove == null)
|
||||
{
|
||||
_gizmosMove = CreateMove();
|
||||
}
|
||||
return _gizmosMove;
|
||||
}
|
||||
|
||||
public GizmosMove CreateMove()
|
||||
{
|
||||
GameObject Prefab = Resources.Load("Prefabs/GizmosMove") as GameObject;
|
||||
GameObject obj = Instantiate(Prefab);
|
||||
return obj.GetComponent<GizmosMove>();
|
||||
}
|
||||
|
||||
public GizmosScale GetSingleScale()
|
||||
{
|
||||
if(_gizmosScale == null)
|
||||
{
|
||||
_gizmosScale = CreateScale();
|
||||
}
|
||||
|
||||
return _gizmosScale;
|
||||
}
|
||||
|
||||
public GizmosScale CreateScale()
|
||||
{
|
||||
GameObject Prefab = Resources.Load("Prefabs/GizmosScale") as GameObject;
|
||||
GameObject obj = Instantiate(Prefab);
|
||||
return obj.GetComponent<GizmosScale>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d31ad57e61be2104d8b4a8be87a8681b
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class GizmosMove : GizmosBase
|
||||
{
|
||||
public delegate void MoveEventHandler(float dx, float dy, float dz);
|
||||
|
||||
public event MoveEventHandler OnMove;
|
||||
public event Action OnMoveEnd;
|
||||
// Use this for initialization
|
||||
|
||||
private Vector3 mTotal = Vector3.zero;
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
ConstructAxis("X", EGizmosAxisType.X);
|
||||
ConstructAxis("Y", EGizmosAxisType.Y);
|
||||
ConstructAxis("Z", EGizmosAxisType.Z);
|
||||
ConstructAxis("LockX", EGizmosAxisType.LockX);
|
||||
ConstructAxis("LockY", EGizmosAxisType.LockY);
|
||||
ConstructAxis("LockZ", EGizmosAxisType.LockZ);
|
||||
}
|
||||
|
||||
protected override void OnDragDelta(GameObject go, float dx, float dy, float dz)
|
||||
{
|
||||
//精度捕捉
|
||||
Vector3 delta = new Vector3(dx, dy, dz);
|
||||
Vector3 newPos = Vector3.zero;
|
||||
ISnap snap = SnapFactory.Instance.Get(ESnapType.Move);
|
||||
if (snap.Snap(mTotal + delta, ref newPos))
|
||||
{
|
||||
dx = newPos.x - mTotal.x;
|
||||
dy = newPos.y - mTotal.y;
|
||||
dz = newPos.z - mTotal.z;
|
||||
}
|
||||
mTotal += new Vector3(dx, dy, dz);
|
||||
///////
|
||||
|
||||
base.OnDragDelta(go, dx, dy, dz);
|
||||
transform.Translate(dx, dy, dz);
|
||||
if (OnMove != null)
|
||||
{
|
||||
OnMove(dx, dy, dz);
|
||||
}
|
||||
}
|
||||
|
||||
public void Move(float dx,float dy, float dz)
|
||||
{
|
||||
transform.Translate(dx, dy, dz);
|
||||
if (OnMove != null)
|
||||
{
|
||||
OnMove(dx, dy, dz);
|
||||
}
|
||||
|
||||
if (OnMoveEnd != null)
|
||||
{
|
||||
OnMoveEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDragEnd(GameObject go)
|
||||
{
|
||||
base.OnDragEnd(go);
|
||||
if (OnMoveEnd != null)
|
||||
{
|
||||
OnMoveEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d434a25316520643adde2c711772b5c
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using ToriaCommon.Datas.Types;
|
||||
using UnityEngine;
|
||||
using Color = UnityEngine.Color;
|
||||
using Material = UnityEngine.Material;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
/*
|
||||
* NOTE:
|
||||
* This code comes from an old Gizmos package, it has been modified a long time ago (legacy code).
|
||||
* For improve the system and clean the code I have to modified it again.
|
||||
* Now it's possible to specify around which axis rotate.
|
||||
*
|
||||
* With all these changes, this script has become dependent on ToriaCommon. It is no longer a package script.
|
||||
*/
|
||||
public class GizmosRotate : MonoBehaviour
|
||||
{
|
||||
public delegate void RotateEventHandler(float dx, float dy, float dz);
|
||||
|
||||
public event RotateEventHandler OnRotate;
|
||||
public event Action OnRotateEnd;
|
||||
|
||||
const float interactionAngle = 20; //angle on each side of an arc where it is interactible to track it
|
||||
|
||||
public Camera RenderCamera;
|
||||
public float RotateSpeed = 1;
|
||||
[SerializeField] float radius = .1f; //scale of the sphere
|
||||
public bool EnableFreeRotate = false;
|
||||
|
||||
[Header("Colors")]
|
||||
[SerializeField] Color xColor = new(1, 0, 0, 0.5f);
|
||||
[SerializeField] Color yColor = new(0, 1, 0, 0.5f);
|
||||
[SerializeField] Color zColor = new(0, 0, 1, 0.5f);
|
||||
[SerializeField] Color selectColor = new(1, 0.92f, 0.016f, 0.5f);
|
||||
|
||||
private Vector3 mTotal = Vector3.zero;
|
||||
readonly private List<int> verticesCount = new();
|
||||
|
||||
private float m_fTheta = 0.1f; //arc precision (mesh generation)
|
||||
private GameObject m_pSphere = null;
|
||||
private GameObject m_pMeshGo = null;
|
||||
private Mesh m_pMesh;
|
||||
|
||||
private int m_iLayer = 0;
|
||||
|
||||
private Matrix4x4[] m_arrMats = null;
|
||||
|
||||
private AxisXYZ trackedAxis = AxisXYZ.None;
|
||||
private AxisXYZ allowedAxis = AxisXYZ.All;
|
||||
private bool rotationChanged = false;
|
||||
|
||||
private Vector3 lastMousePosition = Vector3.zero;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (RenderCamera == null)
|
||||
{
|
||||
RenderCamera = Camera.main;
|
||||
}
|
||||
|
||||
m_iLayer = LayerMask.NameToLayer(Settings.GizmosLayerName);
|
||||
|
||||
m_arrMats = new Matrix4x4[]
|
||||
{
|
||||
Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, 90), Vector3.one),
|
||||
Matrix4x4.identity,
|
||||
Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one)
|
||||
};
|
||||
|
||||
CreateSphere();
|
||||
CreateXYZCircles();
|
||||
}
|
||||
|
||||
#region Init
|
||||
public void Initialize(float radius, Quaternion rotation, AxisXYZ allowedAxis, bool enableFreeRotation = false)
|
||||
{
|
||||
//Destroy previous XYZ circles
|
||||
Destroy(m_pSphere.transform.GetChild(0).gameObject);
|
||||
|
||||
m_pSphere.transform.rotation = rotation;
|
||||
EnableFreeRotate = enableFreeRotation;
|
||||
this.radius = radius;
|
||||
this.allowedAxis = allowedAxis;
|
||||
|
||||
CreateXYZCircles();
|
||||
}
|
||||
|
||||
private void CreateSphere()
|
||||
{
|
||||
m_pSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
m_pSphere.transform.SetParent(transform);
|
||||
m_pSphere.transform.localPosition = Vector3.zero;
|
||||
RefreshScale();
|
||||
|
||||
m_pSphere.GetComponent<SphereCollider>().isTrigger = true;
|
||||
m_pSphere.layer = m_iLayer;
|
||||
|
||||
MeshRenderer render = m_pSphere.GetComponent<MeshRenderer>();
|
||||
render.material = new Material(Shader.Find("TransparentShader"));
|
||||
render.material.color = new Color(0.5f, 0.5f, 0.5f, 0.2f);
|
||||
|
||||
//m_pSphere.GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
|
||||
private void CreateXYZCircles()
|
||||
{
|
||||
m_pMesh = new Mesh();
|
||||
m_pMesh.MarkDynamic();
|
||||
int verticesCount;
|
||||
|
||||
//x
|
||||
if (IsAxisAllowed(AxisXYZ.X))
|
||||
{
|
||||
verticesCount = CreateArc(xColor, m_pMesh, m_arrMats[0]);
|
||||
this.verticesCount.Add(verticesCount);
|
||||
}
|
||||
|
||||
//y
|
||||
if (IsAxisAllowed(AxisXYZ.Y))
|
||||
{
|
||||
verticesCount = CreateArc(yColor, m_pMesh, m_arrMats[1]);
|
||||
this.verticesCount.Add(verticesCount);
|
||||
}
|
||||
|
||||
//z
|
||||
if (IsAxisAllowed(AxisXYZ.Z))
|
||||
{
|
||||
verticesCount = CreateArc(zColor, m_pMesh, m_arrMats[2]);
|
||||
this.verticesCount.Add(verticesCount);
|
||||
}
|
||||
|
||||
//Mesh Generation
|
||||
m_pMesh.subMeshCount = 1;
|
||||
m_pMesh.SetIndices(SequentialTriangles(m_pMesh.vertices.Length), MeshTopology.Lines, 0);
|
||||
|
||||
m_pMeshGo = new GameObject("Rotate Axis");
|
||||
m_pMeshGo.transform.SetParent(m_pSphere.transform, false);
|
||||
m_pMeshGo.layer = m_iLayer;
|
||||
m_pMeshGo.AddComponent<MeshFilter>().mesh = m_pMesh;
|
||||
m_pMeshGo.AddComponent<MeshRenderer>().material = new Material(Shader.Find("RotateShader"));
|
||||
|
||||
//reset circles mesh transform
|
||||
m_pMeshGo.transform.localPosition = Vector3.zero;
|
||||
m_pMeshGo.transform.localRotation = Quaternion.identity;
|
||||
m_pMeshGo.transform.localScale = Vector3.one / 2;
|
||||
}
|
||||
|
||||
private int CreateArc(Color color, Mesh mesh, Matrix4x4 mat, float angle = 2 * Mathf.PI, bool close = false)
|
||||
{
|
||||
m_fTheta = Mathf.Max(0.0001f, m_fTheta);
|
||||
|
||||
int count = mesh.vertexCount;
|
||||
List<Vector3> vertices = new List<Vector3>(mesh.vertices);
|
||||
List<Color> colors = new List<Color>(mesh.colors);
|
||||
|
||||
// draw circle
|
||||
Vector3 beginPoint = mat * Vector3.zero;
|
||||
Vector3 firstPoint = mat * Vector3.zero;
|
||||
for (float theta = 0; theta < angle; theta += m_fTheta)
|
||||
{
|
||||
float x = Mathf.Cos(theta);
|
||||
float z = Mathf.Sin(theta);
|
||||
Vector3 endPoint = mat * new Vector3(x, 0, z);
|
||||
if (theta == 0 && !close)
|
||||
{
|
||||
firstPoint = endPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertices.Add(beginPoint);
|
||||
vertices.Add(endPoint);
|
||||
|
||||
colors.Add(color);
|
||||
colors.Add(color);
|
||||
}
|
||||
beginPoint = endPoint;
|
||||
}
|
||||
|
||||
// draw last line
|
||||
vertices.Add(firstPoint);
|
||||
vertices.Add(beginPoint);
|
||||
|
||||
colors.Add(color);
|
||||
colors.Add(color);
|
||||
|
||||
mesh.SetVertices(vertices);
|
||||
mesh.SetColors(colors);
|
||||
|
||||
return vertices.Count - count;
|
||||
}
|
||||
|
||||
private static int[] SequentialTriangles(int len)
|
||||
{
|
||||
int[] array = new int[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
array[i] = i;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Quaternion GetRotation()
|
||||
{
|
||||
return m_pSphere.transform.rotation;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
StartTracking();
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
StopTracking();
|
||||
|
||||
RotateAroundTrackedAxis();
|
||||
RefreshScale();
|
||||
}
|
||||
|
||||
private void StartTracking()
|
||||
{
|
||||
lastMousePosition = Input.mousePosition;
|
||||
Ray ray = RenderCamera.ScreenPointToRay(lastMousePosition);
|
||||
|
||||
//Try select closest axis and start tracking it
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 10000, 1 << m_iLayer, QueryTriggerInteraction.Collide))
|
||||
{
|
||||
AxisXYZ axis = FindClosetAxis(hit.point);
|
||||
|
||||
SelectAxis(axis);
|
||||
rotationChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void StopTracking()
|
||||
{
|
||||
SelectAxis(AxisXYZ.None);
|
||||
|
||||
if (rotationChanged)
|
||||
{
|
||||
StartCoroutine(DelayRelease());
|
||||
rotationChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshScale()
|
||||
{
|
||||
m_pSphere.transform.localScale = (Vector3.Distance(RenderCamera.transform.position, m_pSphere.transform.position) / 4) * radius * Vector3.one;
|
||||
}
|
||||
|
||||
private void RotateAroundTrackedAxis()
|
||||
{
|
||||
if (!IsAxisAllowed(trackedAxis))
|
||||
return;
|
||||
|
||||
Vector3 delta = TrackBall(Input.mousePosition);
|
||||
|
||||
//Snap rotation
|
||||
//NOTE: the snap isn't perfect at the moment, so let it disable.
|
||||
//It snap axis by axis so when you touch all the axis, the final result isn't correctly snapped.
|
||||
//To test the snap, you must activate it beforehand with this line: SnapFactory.Instance.Get(ESnapType.Rotate).Enable = true;
|
||||
Vector3 total = Vector3.zero;
|
||||
ISnap snap = SnapFactory.Instance.Get(ESnapType.Rotate);
|
||||
if (snap.Snap(mTotal + delta, ref total))
|
||||
{
|
||||
delta = total - mTotal;
|
||||
}
|
||||
|
||||
mTotal += delta;
|
||||
mTotal.x %= 360;
|
||||
mTotal.y %= 360;
|
||||
mTotal.z %= 360;
|
||||
//////////////
|
||||
|
||||
if (delta == Vector3.zero)
|
||||
return;
|
||||
|
||||
m_pSphere.transform.Rotate(delta);
|
||||
rotationChanged = true;
|
||||
OnRotate?.Invoke(delta.x, delta.y, delta.z);
|
||||
}
|
||||
|
||||
private IEnumerator DelayRelease()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
// OnRotateEnd(m_eCurrentAxis, GetRotate());
|
||||
OnRotateEnd?.Invoke();
|
||||
}
|
||||
|
||||
private Vector3 ComputeRotateDir(Vector3 offset, AxisXYZ type)
|
||||
{
|
||||
if (offset.x + offset.y == 0)
|
||||
{
|
||||
return Vector3.zero;
|
||||
}
|
||||
Vector3 startPos = m_pSphere.transform.position;
|
||||
Vector3 start = Camera.main.WorldToScreenPoint(startPos);
|
||||
Vector3 axis;
|
||||
Vector3 end;
|
||||
|
||||
if (type == AxisXYZ.X)
|
||||
{
|
||||
end = Camera.main.WorldToScreenPoint(startPos + m_pSphere.transform.right * 2);
|
||||
axis = Vector3.right;
|
||||
}
|
||||
else if (type == AxisXYZ.Y)
|
||||
{
|
||||
end = Camera.main.WorldToScreenPoint(startPos + m_pSphere.transform.up * 2);
|
||||
axis = Vector3.up;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = Camera.main.WorldToScreenPoint(startPos + m_pSphere.transform.forward * 2);
|
||||
axis = Vector3.forward;
|
||||
}
|
||||
|
||||
Vector3 axisDir = end - start;
|
||||
axisDir.Normalize();
|
||||
|
||||
axisDir = Vector3.Cross(Vector3.forward, axisDir);
|
||||
|
||||
float moveLen = axisDir.x * offset.x + axisDir.y * offset.y;
|
||||
|
||||
float mx = moveLen * axis.x;
|
||||
float my = moveLen * axis.y;
|
||||
float mz = moveLen * axis.z;
|
||||
return new Vector3(mx, my, mz);
|
||||
}
|
||||
|
||||
private Vector3 TrackBall(Vector3 screenPosition)
|
||||
{
|
||||
Vector3 offset = (screenPosition - lastMousePosition) * RotateSpeed;
|
||||
lastMousePosition = screenPosition;
|
||||
|
||||
Vector3 angle = Vector3.zero;
|
||||
if (trackedAxis == AxisXYZ.All)
|
||||
{
|
||||
Quaternion q = Quaternion.AngleAxis(offset.y, m_pSphere.transform.InverseTransformVector(RenderCamera.transform.right));
|
||||
q *= Quaternion.AngleAxis(-offset.x, m_pSphere.transform.InverseTransformVector(RenderCamera.transform.up));
|
||||
|
||||
angle += q.eulerAngles;
|
||||
}
|
||||
else
|
||||
{
|
||||
angle += ComputeRotateDir(offset, trackedAxis);
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
private AxisXYZ FindClosetAxis(Vector3 hitPoint)
|
||||
{
|
||||
GetDeltaAngles(hitPoint, out float xAngle, out float yAngle, out float zAngle);
|
||||
(AxisXYZ axis, float angle) closest = (AxisXYZ.None, 0);
|
||||
|
||||
TrySetClosest(AxisXYZ.X, xAngle);
|
||||
TrySetClosest(AxisXYZ.Y, yAngle);
|
||||
TrySetClosest(AxisXYZ.Z, zAngle);
|
||||
|
||||
if (EnableFreeRotate && closest.axis == AxisXYZ.None && IsAxisAllowed(AxisXYZ.All))
|
||||
closest.axis = AxisXYZ.All;
|
||||
|
||||
return closest.axis;
|
||||
|
||||
void TrySetClosest(AxisXYZ axis, float angle)
|
||||
{
|
||||
if (IsAxisAllowed(axis) && angle < interactionAngle && (closest.axis == AxisXYZ.None || angle < closest.angle))
|
||||
closest = (axis, angle);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetDeltaAngles(Vector3 position, out float xAngle, out float yAngle, out float zAngle)
|
||||
{
|
||||
Vector3 dir = m_pSphere.transform.InverseTransformPoint(position).normalized;
|
||||
|
||||
xAngle = Mathf.Acos(dir.x) * Mathf.Rad2Deg;
|
||||
yAngle = Mathf.Asin(dir.y) * Mathf.Rad2Deg;
|
||||
zAngle = Mathf.Acos(dir.z) * Mathf.Rad2Deg;
|
||||
|
||||
xAngle = GetDelta(xAngle, true);
|
||||
yAngle = GetDelta(yAngle, false);
|
||||
zAngle = GetDelta(zAngle, true);
|
||||
}
|
||||
|
||||
private float GetDelta(float angle, bool verticalAxis)
|
||||
{
|
||||
//0° is the angle for a horizontal axis
|
||||
//90° is the angle for a vertical axis
|
||||
//See trigonometry circle
|
||||
return Mathf.Abs(angle - (verticalAxis ? 90 : 0));
|
||||
}
|
||||
|
||||
private void SelectAxis(AxisXYZ toSelect)
|
||||
{
|
||||
if (trackedAxis == toSelect)
|
||||
return;
|
||||
|
||||
trackedAxis = toSelect;
|
||||
List<Color> colors = new();
|
||||
int index = 0;
|
||||
|
||||
SetArcColor(AxisXYZ.X, xColor);
|
||||
SetArcColor(AxisXYZ.Y, yColor);
|
||||
SetArcColor(AxisXYZ.Z, zColor);
|
||||
|
||||
m_pMesh.SetColors(colors);
|
||||
|
||||
void SetArcColor(AxisXYZ axis, Color axisColor)
|
||||
{
|
||||
if (!IsAxisAllowed(axis))
|
||||
return;
|
||||
|
||||
int count = verticesCount[index++];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
colors.Add(trackedAxis == axis || trackedAxis == AxisXYZ.All ? selectColor : axisColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsAxisAllowed(AxisXYZ axis) => axis != AxisXYZ.None && (allowedAxis == AxisXYZ.All || allowedAxis == axis);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f62339974341fc844ae6f591b7ee51db
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class GizmosScale : GizmosBase
|
||||
{
|
||||
public delegate void ScaleEventHandler(float dx, float dy, float dz);
|
||||
|
||||
public event ScaleEventHandler OnScale;
|
||||
public event Action OnScaleEnd;
|
||||
|
||||
private Vector3 mTotal = Vector3.zero;
|
||||
|
||||
private Transform _X;
|
||||
private Transform _Y;
|
||||
private Transform _Z;
|
||||
|
||||
private float originOffset;
|
||||
// Use this for initialization
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
ConstructAxis("X", EGizmosAxisType.X);
|
||||
ConstructAxis("Y", EGizmosAxisType.Y);
|
||||
ConstructAxis("Z", EGizmosAxisType.Z);
|
||||
ConstructAxis("Center", EGizmosAxisType.CENTER);
|
||||
|
||||
_X = transform.Find("X");
|
||||
_Y = transform.Find("Y");
|
||||
_Z = transform.Find("Z");
|
||||
|
||||
originOffset = _X.Find("Cube").transform.localPosition.z;
|
||||
}
|
||||
|
||||
protected override void OnDragDelta(GameObject go, float dx, float dy, float dz)
|
||||
{
|
||||
//精度捕捉
|
||||
Vector3 delta = new Vector3(dx, dy, dz);
|
||||
Vector3 newPos = Vector3.zero;
|
||||
ISnap snap = SnapFactory.Instance.Get(ESnapType.Scale);
|
||||
if (snap.Snap(mTotal + delta, ref newPos))
|
||||
{
|
||||
dx = newPos.x - mTotal.x;
|
||||
dy = newPos.y - mTotal.y;
|
||||
dz = newPos.z - mTotal.z;
|
||||
}
|
||||
mTotal += new Vector3(dx, dy, dz);
|
||||
///////
|
||||
|
||||
base.OnDragDelta(go, dx, dy, dz);
|
||||
SetLengthOfAxis(go, dx, dy, dz, true);
|
||||
//transform.Translate(dx, dy, dz);
|
||||
if (OnScale != null)
|
||||
{
|
||||
OnScale(dx, dy, dz);
|
||||
}
|
||||
}
|
||||
|
||||
public void Scale(float dx,float dy,float dz)
|
||||
{
|
||||
if (OnScale != null)
|
||||
{
|
||||
OnScale(dx, dy, dz);
|
||||
}
|
||||
|
||||
if (OnScaleEnd != null)
|
||||
{
|
||||
OnScaleEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDragEnd(GameObject go)
|
||||
{
|
||||
base.OnDragEnd(go);
|
||||
SetLengthOfAxis(go, originOffset, originOffset, originOffset, false);
|
||||
if (OnScaleEnd != null)
|
||||
{
|
||||
OnScaleEnd();
|
||||
}
|
||||
|
||||
mTotal = Vector3.zero;
|
||||
}
|
||||
|
||||
protected override float ComputeScaleFactor(float d)
|
||||
{
|
||||
float magic = (float)Math.Log10(d + 10) * 1.4f;
|
||||
return magic;
|
||||
}
|
||||
|
||||
private void SetLengthOfAxis(GameObject go, float dx, float dy, float dz, bool delta)
|
||||
{
|
||||
EGizmosAxisType type = _axisMap[go];
|
||||
if (type == EGizmosAxisType.X)
|
||||
{
|
||||
SetLengthOfAxis(go.transform.parent, dx, delta);
|
||||
}
|
||||
else if (type == EGizmosAxisType.Y)
|
||||
{
|
||||
SetLengthOfAxis(go.transform.parent, dy, delta);
|
||||
}
|
||||
else if (type == EGizmosAxisType.Z)
|
||||
{
|
||||
SetLengthOfAxis(go.transform.parent, dz, delta);
|
||||
}
|
||||
else if (type == EGizmosAxisType.CENTER)
|
||||
{
|
||||
SetLengthOfAxis(_X, dx, delta);
|
||||
SetLengthOfAxis(_Y, dx, delta);
|
||||
SetLengthOfAxis(_Z, dx, delta);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLengthOfAxis(Transform axisRoot, float scale,bool delta)
|
||||
{
|
||||
Transform axis = axisRoot.Find("Cylinder");
|
||||
if (axis != null)
|
||||
{
|
||||
Vector3 localScale = axis.localScale;
|
||||
Transform cube = axisRoot.Find("Cube");
|
||||
Vector3 pos = cube.localPosition;
|
||||
if (delta)
|
||||
{
|
||||
pos.z += scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos.z = scale;
|
||||
}
|
||||
|
||||
localScale.z = pos.z / originOffset;
|
||||
axis.localScale = localScale;
|
||||
cube.localPosition = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bd6c43ebfb52b04bb859a4bd74c9d0f
|
||||
timeCreated: 1481857852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
class Settings
|
||||
{
|
||||
public static string GizmosLayerName = "Gizmos";
|
||||
public static string NavLayerName = "Nav";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ed3df845d46d5c4897e88b55b0c4662
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5184a0ba98c0f494790cefafe4d2cec1
|
||||
folderAsset: yes
|
||||
timeCreated: 1481858273
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class AngleSnap : SnapBase
|
||||
{
|
||||
public Vector3 Center = Vector3.zero;
|
||||
|
||||
private float mAngle = 0;
|
||||
public float CurrentAngle
|
||||
{
|
||||
get
|
||||
{
|
||||
return mAngle;
|
||||
}
|
||||
}
|
||||
public AngleSnap()
|
||||
{
|
||||
Precision = 15;
|
||||
}
|
||||
|
||||
protected override void CalcTolerance()
|
||||
{
|
||||
mTolerance = 0.2f * Precision;
|
||||
}
|
||||
|
||||
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
||||
{
|
||||
if (!Enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 dir = inVal.normalized;
|
||||
float angle = GemetryHelper.VectorAngle(Vector3.right, dir);
|
||||
|
||||
mAngle = GemetryHelper.ValueMod(angle, Precision);
|
||||
|
||||
if (force || Mathf.Abs(angle - mAngle) <= Precision)
|
||||
{
|
||||
outVal = Quaternion.Euler(0, mAngle, 0) * Vector3.right;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b0fd1b1ffcafb6498735f6aa8404058
|
||||
timeCreated: 1478770278
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class GridSnap : SnapBase
|
||||
{
|
||||
public Vector3 Center = Vector3.zero;
|
||||
|
||||
public GridSnap()
|
||||
{
|
||||
Precision = 1;
|
||||
}
|
||||
|
||||
protected override void CalcTolerance()
|
||||
{
|
||||
mTolerance = 0.2f * Precision;
|
||||
}
|
||||
|
||||
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
||||
{
|
||||
if (!Enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Vector3 position = inVal;
|
||||
Vector3 offset = position - Center;
|
||||
Vector3 dp = GemetryHelper.Vector3Mod(offset, Precision);
|
||||
|
||||
Vector3 df = position - dp;
|
||||
df.x = Mathf.Abs(df.x);
|
||||
df.y = Mathf.Abs(df.y);
|
||||
df.z = Mathf.Abs(df.z);
|
||||
|
||||
float max = Mathf.Max(df.x, df.y, df.z);
|
||||
|
||||
if (force || max <= mTolerance)
|
||||
{
|
||||
outVal = dp;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3fb8ef001ee43f4e862b612c2ba3ecf
|
||||
timeCreated: 1478770278
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public interface ISnap
|
||||
{
|
||||
bool Enable { get; set; }
|
||||
float Precision { get; set; }
|
||||
bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa4a06a87e47d294a80687a70ef6a733
|
||||
timeCreated: 1478766622
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class MoveSnap : SnapBase
|
||||
{
|
||||
public Vector3 Center = Vector3.zero;
|
||||
|
||||
public MoveSnap()
|
||||
{
|
||||
Precision = 1;
|
||||
}
|
||||
|
||||
protected override void CalcTolerance()
|
||||
{
|
||||
mTolerance = 0.05f * Precision;
|
||||
}
|
||||
|
||||
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
||||
{
|
||||
if (!Enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 position = inVal;
|
||||
Vector3 offset = position - Center;
|
||||
Vector3 dp = GemetryHelper.Vector3Mod(offset, Precision);
|
||||
|
||||
if (force || (position - dp).magnitude <= mTolerance)
|
||||
{
|
||||
outVal = dp;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b21fc2f114b61e418e637a0ab7754f7
|
||||
timeCreated: 1478766622
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class RotateSnap : SnapBase
|
||||
{
|
||||
|
||||
public RotateSnap()
|
||||
{
|
||||
Precision = 5;
|
||||
}
|
||||
|
||||
protected override void CalcTolerance()
|
||||
{
|
||||
mTolerance = 0.2f * Precision;
|
||||
}
|
||||
|
||||
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
||||
{
|
||||
if (!Enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 angle = inVal;
|
||||
outVal = GemetryHelper.Vector3Mod(angle, Precision);
|
||||
|
||||
Vector3 offset = angle - outVal;
|
||||
|
||||
if (force || offset.magnitude <= Precision)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40c4b4487bab18344af53c665aff49d8
|
||||
timeCreated: 1478768767
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class ScaleSnap : SnapBase
|
||||
{
|
||||
public ScaleSnap()
|
||||
{
|
||||
Precision = 0.2f;
|
||||
}
|
||||
|
||||
protected override void CalcTolerance()
|
||||
{
|
||||
mTolerance = 0.5f * Precision;
|
||||
}
|
||||
|
||||
public override bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
||||
{
|
||||
if (!Enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 scale = inVal;
|
||||
Vector3 dp = GemetryHelper.Vector3Mod(scale, Precision);
|
||||
|
||||
if (force || (scale - dp).magnitude <= mTolerance)
|
||||
{
|
||||
outVal = dp;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f0ef511f98bffe44ba2edc3a3d045d1
|
||||
timeCreated: 1478768767
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public class SnapBase : ISnap
|
||||
{
|
||||
protected bool mEnable = false;
|
||||
protected float mPrecision = 0;
|
||||
protected float mTolerance = 0;
|
||||
|
||||
public bool Enable
|
||||
{
|
||||
get
|
||||
{
|
||||
return mEnable;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
mEnable = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Precision
|
||||
{
|
||||
get
|
||||
{
|
||||
return mPrecision;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
mPrecision = value;
|
||||
CalcTolerance();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CalcTolerance()
|
||||
{
|
||||
mTolerance = Precision * 0.2f;
|
||||
}
|
||||
|
||||
public virtual bool Snap(Vector3 inVal, ref Vector3 outVal, bool force = false)
|
||||
{
|
||||
outVal = Vector3.zero;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dbb40102de5ba442a384fd3d31ae70d
|
||||
timeCreated: 1478766622
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wing.Utils;
|
||||
|
||||
namespace Wing.Gizmos
|
||||
{
|
||||
public enum ESnapType
|
||||
{
|
||||
Move,
|
||||
Rotate,
|
||||
Scale,
|
||||
Grid,
|
||||
Angle,
|
||||
}
|
||||
|
||||
public class SnapFactory : NormalSingleton<SnapFactory>
|
||||
{
|
||||
private Dictionary<ESnapType, ISnap> mSnaps = new Dictionary<ESnapType, ISnap>();
|
||||
|
||||
public SnapFactory()
|
||||
{
|
||||
mSnaps.Add(ESnapType.Move, new MoveSnap());
|
||||
mSnaps.Add(ESnapType.Rotate, new RotateSnap());
|
||||
mSnaps.Add(ESnapType.Scale, new ScaleSnap());
|
||||
mSnaps.Add(ESnapType.Grid, new GridSnap());
|
||||
mSnaps.Add(ESnapType.Angle, new AngleSnap());
|
||||
}
|
||||
|
||||
public ISnap Get(ESnapType type)
|
||||
{
|
||||
return mSnaps[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9793fa7f0cf6134cb2c00fdab230811
|
||||
timeCreated: 1478770278
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d20466ffc444e140858d52ccd3c532e
|
||||
folderAsset: yes
|
||||
timeCreated: 1481858057
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,208 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class AnimationComponent : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>true will play more once</returns>
|
||||
public delegate bool TweenCompleteEventHandler();
|
||||
public delegate void TweenUpdateEventHandler(float scale);
|
||||
public event TweenCompleteEventHandler OnComplete;
|
||||
public event TweenUpdateEventHandler OnUpdate;
|
||||
|
||||
public AnimationCurve m_pCurve;
|
||||
|
||||
private bool m_bPlaying = false;
|
||||
|
||||
public float Duration = 0;
|
||||
private float m_fLastTime = 0;
|
||||
|
||||
private bool m_bAutoManager = false;
|
||||
|
||||
private float m_fMinValue = 0;
|
||||
private float m_fMaxValue = 1;
|
||||
|
||||
/// <summary>
|
||||
/// set replay times,default one times,equals zero means loop
|
||||
/// </summary>
|
||||
public uint RepeatTimes = 1;
|
||||
private uint m_iHadRepeatTimes = 0;
|
||||
|
||||
public bool Revert { get; set; }
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (m_pCurve == null)
|
||||
{
|
||||
m_pCurve = AnimationCurve.Linear(0, m_fMinValue, Duration, m_fMaxValue);
|
||||
}
|
||||
|
||||
if (m_bPlaying)
|
||||
{
|
||||
if (m_fLastTime < Duration)
|
||||
{
|
||||
float time = Revert ? Duration - m_fLastTime : m_fLastTime;
|
||||
float scale = m_pCurve.Evaluate(time);
|
||||
if (OnUpdate != null)
|
||||
{
|
||||
OnUpdate(scale);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bPlaying = false;
|
||||
|
||||
if (OnUpdate != null)
|
||||
{
|
||||
OnUpdate(Revert ? m_fMinValue : m_fMaxValue);
|
||||
}
|
||||
|
||||
bool end = true;
|
||||
m_iHadRepeatTimes++;
|
||||
if (RepeatTimes > 0)
|
||||
{
|
||||
if (RepeatTimes > m_iHadRepeatTimes)
|
||||
{
|
||||
end = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Play();
|
||||
return;
|
||||
}
|
||||
|
||||
if (end)
|
||||
{
|
||||
bool moreOnce = false;
|
||||
if (OnComplete != null)
|
||||
{
|
||||
moreOnce = OnComplete();
|
||||
if (moreOnce)
|
||||
{
|
||||
m_iHadRepeatTimes = RepeatTimes - 1;
|
||||
Play();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bAutoManager && !moreOnce)
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_fLastTime += Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCurve(AnimationCurve curve, float duration = -1)
|
||||
{
|
||||
if (duration > 0)
|
||||
{
|
||||
SetDuration(duration);
|
||||
}
|
||||
|
||||
float maxTime = float.MinValue;
|
||||
float minTime = float.MaxValue;
|
||||
float maxValue = float.MinValue;
|
||||
float minValue = float.MaxValue;
|
||||
foreach (Keyframe key in curve.keys)
|
||||
{
|
||||
if (maxTime < key.time)
|
||||
{
|
||||
maxTime = key.time;
|
||||
}
|
||||
if (minTime > key.time)
|
||||
{
|
||||
minTime = key.time;
|
||||
}
|
||||
|
||||
if (maxValue < key.value)
|
||||
{
|
||||
maxValue = key.value;
|
||||
}
|
||||
if (minValue > key.value)
|
||||
{
|
||||
minValue = key.value;
|
||||
}
|
||||
}
|
||||
|
||||
float offsetTime = maxTime - minTime;
|
||||
offsetTime = offsetTime == 0 ? 1 : maxTime - minTime;
|
||||
float offsetValue = maxValue - minValue;
|
||||
offsetValue = offsetValue == 0 ? 1 : offsetValue;
|
||||
|
||||
Keyframe[] keys = new Keyframe[curve.keys.Length];
|
||||
float tv = offsetValue / offsetTime / Duration;
|
||||
for (int i = 0; i < curve.keys.Length; i++)
|
||||
{
|
||||
Keyframe key = curve.keys[i];
|
||||
|
||||
float time = (key.time - minTime) * Duration / offsetTime;
|
||||
float value = (key.value - minValue) / offsetValue;
|
||||
|
||||
keys[i] = new Keyframe(time, value, key.inTangent * tv, key.outTangent * tv);
|
||||
}
|
||||
|
||||
if (keys.Length > 0)
|
||||
{
|
||||
m_pCurve = new AnimationCurve(keys);
|
||||
|
||||
m_pCurve.preWrapMode = curve.preWrapMode;
|
||||
m_pCurve.postWrapMode = curve.postWrapMode;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDuration(float duration)
|
||||
{
|
||||
Duration = duration;
|
||||
}
|
||||
|
||||
public AnimationComponent Play()
|
||||
{
|
||||
m_bPlaying = true;
|
||||
m_fLastTime = 0;
|
||||
m_iHadRepeatTimes = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
m_bPlaying = false;
|
||||
}
|
||||
|
||||
public static AnimationComponent AutoManagerTween(GameObject go, float duration)
|
||||
{
|
||||
AnimationComponent tween = go.AddComponent<AnimationComponent>();
|
||||
tween.Duration = duration;
|
||||
tween.m_bAutoManager = true;
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public AnimationComponent SetUpdate(TweenUpdateEventHandler handler)
|
||||
{
|
||||
OnUpdate += handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnimationComponent SetComplete(TweenCompleteEventHandler handler)
|
||||
{
|
||||
OnComplete += handler;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnimationComponentExt
|
||||
{
|
||||
public static AnimationComponent Tween(this GameObject go, float duration)
|
||||
{
|
||||
return AnimationComponent.AutoManagerTween(go, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e298cadf9846cd84b87633c6759bb064
|
||||
timeCreated: 1481866179
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class Billiboard : MonoBehaviour {
|
||||
|
||||
public Camera RenderCamera;
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
this.transform.forward = RenderCamera.transform.forward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2c65d1d75ecf844a95768ec4c1f6333
|
||||
timeCreated: 1481863066
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class ElementTag : MonoBehaviour
|
||||
{
|
||||
public string ModuleName = "";
|
||||
public string ID = "";
|
||||
public int ElementType = 0;
|
||||
public GameObject Target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fac47bebf754d3844ab3afb3937686f8
|
||||
timeCreated: 1481861944
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class FreeCamera : MonoBehaviour
|
||||
{
|
||||
//for rotate
|
||||
private float m_deltX = 0f;
|
||||
private float m_deltY = 0f;
|
||||
//for zoom
|
||||
private float m_distance = 10f;
|
||||
private float m_mSpeed = 5f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
//GetComponent<Camera>().transform.localPosition = new Vector3(0, m_distance, 0);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//鼠标右键点下控制相机旋转;
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
m_deltX += Input.GetAxis("Mouse X") * m_mSpeed;
|
||||
m_deltY -= Input.GetAxis("Mouse Y") * m_mSpeed;
|
||||
m_deltX = ClampAngle(m_deltX, -360, 360);
|
||||
m_deltY = ClampAngle(m_deltY, -70, 70);
|
||||
GetComponent<Camera>().transform.rotation = Quaternion.Euler(m_deltY, m_deltX, 0);
|
||||
}
|
||||
|
||||
//鼠标中键点下场景缩放;
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
{
|
||||
//自由缩放方式;
|
||||
m_distance = Input.GetAxis("Mouse ScrollWheel") * 10f;
|
||||
GetComponent<Camera>().transform.localPosition = GetComponent<Camera>().transform.position + GetComponent<Camera>().transform.forward * m_distance;
|
||||
}
|
||||
//鼠标点击场景移动;
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
var dx = -Input.GetAxis("Mouse X") * m_mSpeed * 0.1f;
|
||||
var dy = -Input.GetAxis("Mouse Y") * m_mSpeed * 0.1f;
|
||||
GetComponent<Camera>().transform.Translate(new Vector3(dx, dy));
|
||||
}
|
||||
|
||||
//相机复位远点;
|
||||
if (Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
m_distance = 10.0f;
|
||||
GetComponent<Camera>().transform.localPosition = new Vector3(0, m_distance, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//规划角度;
|
||||
float ClampAngle(float angle, float minAngle, float maxAgnle)
|
||||
{
|
||||
if (angle <= -360)
|
||||
angle += 360;
|
||||
if (angle >= 360)
|
||||
angle -= 360;
|
||||
|
||||
return Mathf.Clamp(angle, minAngle, maxAgnle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a68dd72103bf88243af592974a4c92bf
|
||||
timeCreated: 1481708155
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class GemetryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 重新计算中心点
|
||||
/// </summary>
|
||||
/// <param name="raw"></param>
|
||||
/// <param name="bounds"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Vector3> PivotToZero(List<Vector3> raw, out Bounds bounds)
|
||||
{
|
||||
Vector3 min = Vector3.one * float.MaxValue;
|
||||
Vector3 max = Vector3.one * float.MinValue;
|
||||
for (int i = 0; i < raw.Count; i++)
|
||||
{
|
||||
Vector3 pt = raw[i];
|
||||
min = Vector3.Min(pt, min);
|
||||
max = Vector3.Max(pt, max);
|
||||
}
|
||||
|
||||
Vector3 center = (max + min) / 2;
|
||||
List<Vector3> pts = new List<Vector3>();
|
||||
for (int i = 0; i < raw.Count; i++)
|
||||
{
|
||||
pts.Add(raw[i] - center);
|
||||
}
|
||||
|
||||
bounds = new Bounds(center, max - min);
|
||||
|
||||
return pts;
|
||||
}
|
||||
|
||||
public static float ValueMod(float value, float modValue)
|
||||
{
|
||||
float df = value / modValue;
|
||||
int sign = df == 0 ? 1 : (int)(df / Mathf.Abs(df));
|
||||
return ((int)(df + sign * 0.5f)) * modValue;
|
||||
}
|
||||
|
||||
public static Vector3 Vector3Mod(Vector3 value, float modValue)
|
||||
{
|
||||
float dx = ValueMod(value.x, modValue);
|
||||
float dy = ValueMod(value.y, modValue);
|
||||
float dz = ValueMod(value.z, modValue);
|
||||
return new Vector3(dx, dy, dz);
|
||||
}
|
||||
|
||||
public static float VectorAngle(Vector2 from, Vector2 to)
|
||||
{
|
||||
float angle;
|
||||
|
||||
Vector3 cross = Vector3.Cross(from, to);
|
||||
angle = Vector2.Angle(from, to);
|
||||
return cross.y > 0 ? angle : -angle;
|
||||
}
|
||||
|
||||
public static float VectorAngle(Vector3 from, Vector3 to)
|
||||
{
|
||||
float angle;
|
||||
|
||||
Vector3 cross = Vector3.Cross(from, to);
|
||||
angle = Vector3.Angle(from, to);
|
||||
return cross.y > 0 ? angle : -angle;
|
||||
}
|
||||
|
||||
public static Vector3 ClosestPointOnLineExt(Vector3 a, Vector3 b, Vector3 point)
|
||||
{
|
||||
Vector3 v1 = point - a;
|
||||
Vector3 v2 = (b - a).normalized;
|
||||
float t = Vector3.Dot(v2, v1);
|
||||
|
||||
Vector3 v3 = v2 * t;
|
||||
Vector3 closestPoint = a + v3;
|
||||
return closestPoint;
|
||||
}
|
||||
|
||||
public static Vector3 Mirror(Vector3 a, Vector3 b, Vector3 point)
|
||||
{
|
||||
Vector3 closestPoint = ClosestPointOnLineExt(a, b, point);
|
||||
Vector3 v4 = closestPoint - point;
|
||||
return v4 * 2 + point;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2c4e1ac0e8006c448c6a9eb497a5d8e
|
||||
timeCreated: 1481859113
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
protected static bool s_bEnableAutoCreate = true;
|
||||
protected static T s_pInstance;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_pInstance == null)
|
||||
{
|
||||
s_pInstance = GameObject.FindObjectOfType<T>();
|
||||
if (s_pInstance == null && s_bEnableAutoCreate)
|
||||
{
|
||||
GameObject singleGO = GameObject.Find("Singletion");
|
||||
if (singleGO == null)
|
||||
{
|
||||
singleGO = new GameObject("Singletion");
|
||||
}
|
||||
|
||||
GameObject instanceObject = new GameObject(typeof(T).Name);
|
||||
instanceObject.transform.SetParent(singleGO.transform);
|
||||
|
||||
s_pInstance = instanceObject.AddComponent<T>();
|
||||
}
|
||||
else if (s_pInstance == null)
|
||||
{
|
||||
//Debug.LogError("empty refrenced in this scene : " + typeof(T).Name);
|
||||
}
|
||||
}
|
||||
return s_pInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ad23da74c9198f49ae86589dc322328
|
||||
timeCreated: 1481706132
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class NormalSingleton<T> where T : new()
|
||||
{
|
||||
protected static T s_pInstance = new T();
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return s_pInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07fa2347ede9ded42a7662568a48edf4
|
||||
timeCreated: 1481706131
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,232 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public enum EMouseButton
|
||||
{
|
||||
None = -1,
|
||||
Left = 0,
|
||||
Right = 1,
|
||||
Middle = 2,
|
||||
}
|
||||
|
||||
public class TouchInteraction : MonoBehaviour
|
||||
{
|
||||
public delegate void InteractionEventHandler(ElementTag tag);
|
||||
public event InteractionEventHandler SelectedEvent;
|
||||
public event InteractionEventHandler HoverTargetChangedEvent;
|
||||
|
||||
public delegate void InteractionEventHandlerEx(GameObject go);
|
||||
public event InteractionEventHandlerEx SelectedGoEvent;
|
||||
public event InteractionEventHandlerEx HoverGoTargetChangedEvent;
|
||||
|
||||
private Camera m_camera = null;
|
||||
private int m_layerMask = 0;
|
||||
|
||||
private ElementTag m_currentTag = null;
|
||||
private ElementTag m_lastTag = null;
|
||||
|
||||
private GameObject m_currentGameObject = null;
|
||||
|
||||
private bool mMouseDown = false;
|
||||
private Vector3 mMousePos;
|
||||
|
||||
public KeyCode CurrentCode
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public EMouseButton CurrentMouseCode
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool IsShift
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public void Set(Camera camera, int layerMask)
|
||||
{
|
||||
m_camera = camera;
|
||||
m_layerMask = layerMask;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
m_camera = Camera.main;
|
||||
m_layerMask = int.MaxValue;
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (Event.current != null && Input.anyKey)
|
||||
{
|
||||
IsShift = Event.current.shift;
|
||||
if (Event.current.isKey)
|
||||
{
|
||||
CurrentCode = Event.current.keyCode;
|
||||
}
|
||||
|
||||
if(Event.current.isMouse)
|
||||
{
|
||||
CurrentMouseCode = (EMouseButton)Event.current.button;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
IsShift = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkClick()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
mMouseDown = true;
|
||||
mMousePos = Input.mousePosition;
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
var df = Input.mousePosition - mMousePos;
|
||||
var dx = Mathf.Abs(df.x);
|
||||
var dy = Mathf.Abs(df.y);
|
||||
if (mMouseDown && (dx < 2f && dy < 2f))
|
||||
{
|
||||
OnClick();
|
||||
}
|
||||
mMouseDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkClick();
|
||||
|
||||
GameObject go = null;
|
||||
if (Input.touches.Length > 0)
|
||||
{
|
||||
go = DetectiveGameObject(Input.touches[0].position);
|
||||
}
|
||||
else
|
||||
{
|
||||
go = DetectiveGameObject(Input.mousePosition);
|
||||
}
|
||||
if (go != m_currentGameObject)
|
||||
{
|
||||
if(HoverGoTargetChangedEvent != null)
|
||||
{
|
||||
HoverGoTargetChangedEvent(go);
|
||||
}
|
||||
|
||||
ElementTag newTag = m_currentTag;
|
||||
if (go != null)
|
||||
{
|
||||
newTag = go.GetComponent<ElementTag>();
|
||||
}
|
||||
else
|
||||
{
|
||||
newTag = null;
|
||||
}
|
||||
|
||||
if(newTag != m_currentTag)
|
||||
{
|
||||
m_lastTag = m_currentTag;
|
||||
m_currentTag = newTag;
|
||||
|
||||
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
|
||||
|
||||
if (m_lastTag != m_currentTag)
|
||||
{
|
||||
if (HoverTargetChangedEvent != null)
|
||||
{
|
||||
HoverTargetChangedEvent(m_currentTag);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
m_currentGameObject = go;
|
||||
}
|
||||
|
||||
public ElementTag CurrentSelectedTag
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_currentTag;
|
||||
}
|
||||
}
|
||||
|
||||
public ElementTag LastSelectedTag
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_lastTag;
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
GameObject.Destroy(this);
|
||||
}
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
if(SelectedGoEvent != null)
|
||||
{
|
||||
SelectedGoEvent(m_currentGameObject);
|
||||
}
|
||||
|
||||
if (m_currentTag != null && SelectedEvent != null)
|
||||
{
|
||||
SelectedEvent(m_currentTag);
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject DetectiveGameObject(Vector2 screenPoint)
|
||||
{
|
||||
Ray ray = m_camera.ScreenPointToRay(new Vector3(screenPoint.x, screenPoint.y, 0));
|
||||
RaycastHit hitInfo;
|
||||
|
||||
if (Physics.Raycast(ray, out hitInfo, 1000 , m_layerMask))
|
||||
{
|
||||
GameObject go = hitInfo.collider.gameObject;
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ElementTag DetectiveTag(Vector2 screenPoint)
|
||||
{
|
||||
Ray ray = m_camera.ScreenPointToRay(new Vector3(screenPoint.x, screenPoint.y, 0));
|
||||
RaycastHit hitInfo;
|
||||
|
||||
if (Physics.Raycast(ray, out hitInfo, 1000, m_layerMask))
|
||||
{
|
||||
GameObject go = hitInfo.collider.gameObject;
|
||||
ElementTag tag = go.GetComponent<ElementTag>();
|
||||
|
||||
//MaterialSetter setter = new MaterialSetter(tag.Element.ObjInstance);
|
||||
//setter.Set("Custom/Outline");
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 699d5a36f36a84548a12b43db6237424
|
||||
timeCreated: 1481861921
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public static class UnityExt
|
||||
{
|
||||
public static Mesh GetMesh(this GameObject go)
|
||||
{
|
||||
var filter = go.GetComponent<MeshFilter>();
|
||||
if (filter == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return filter.mesh;
|
||||
}
|
||||
|
||||
public static void SetRectTransformSize(this RectTransform trans, Vector2 newSize)
|
||||
{
|
||||
Vector2 oldSize = trans.rect.size;
|
||||
Vector2 deltaSize = newSize - oldSize;
|
||||
trans.offsetMin = trans.offsetMin - new Vector2(deltaSize.x * trans.pivot.x, deltaSize.y * trans.pivot.y);
|
||||
trans.offsetMax = trans.offsetMax + new Vector2(deltaSize.x * (1f - trans.pivot.x), deltaSize.y * (1f - trans.pivot.y));
|
||||
}
|
||||
|
||||
public static void SetLayerWithChildren(this GameObject go, string layer)
|
||||
{
|
||||
var lyr = LayerMask.NameToLayer(layer);
|
||||
go.layer = lyr;
|
||||
var children = go.transform.GetComponentsInChildren<Transform>();
|
||||
foreach(var c in children)
|
||||
{
|
||||
c.gameObject.layer = lyr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20e480b51978648408644331c61e4b1b
|
||||
timeCreated: 1481707497
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public static class UtilsExt
|
||||
{
|
||||
public static int ToInt(this string s)
|
||||
{
|
||||
int ret = 0;
|
||||
int.TryParse(s, out ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static float ToFloat(this string s)
|
||||
{
|
||||
float ret = 0;
|
||||
float.TryParse(s, out ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Color32 Encode2Color32(this int value,bool renderBack = true)
|
||||
{
|
||||
Color32 c = new Color32();
|
||||
c.r = (byte)((value & 0x000000FF) >> 0);
|
||||
c.g = (byte)((value & 0x0000FF00) >> 8);
|
||||
c.b = (byte)((value & 0x00FF0000) >> 16);
|
||||
c.a = (byte)(renderBack ? 0xFF : 0);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static int Encode2Int(this Color32 value)
|
||||
{
|
||||
int r = value.r << 0;
|
||||
int g = value.g << 8;
|
||||
int b = value.b << 16;
|
||||
|
||||
return r | g | b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc7ef0dd44821e74683d228d898c2081
|
||||
timeCreated: 1481706627
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Wing.Utils
|
||||
{
|
||||
public class UtilsHelper
|
||||
{
|
||||
public static string GetDataPath()
|
||||
{
|
||||
string path = "";
|
||||
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
{
|
||||
path = Application.persistentDataPath + "/";
|
||||
}
|
||||
else if (Application.platform == RuntimePlatform.WindowsPlayer)
|
||||
{
|
||||
path = Application.dataPath + "/";
|
||||
}
|
||||
else if (Application.platform == RuntimePlatform.WindowsEditor)
|
||||
{
|
||||
path = Application.dataPath + "/../";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = Application.persistentDataPath + "/";
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string GetResourcePath()
|
||||
{
|
||||
return GetDataPath() + "ResData";
|
||||
}
|
||||
|
||||
public static IEnumerator LoadTexture(string url, Action<Texture2D> cb)
|
||||
{
|
||||
//这里的url可以是web路径也可以是本地路径file://
|
||||
WWW www = new WWW(url);
|
||||
//挂起程序段,等资源下载完成后,继续执行下去
|
||||
yield return www;
|
||||
|
||||
//判断是否有错误产生
|
||||
if (string.IsNullOrEmpty(www.error))
|
||||
{
|
||||
//把下载好的图片回调给调用者
|
||||
cb.Invoke(www.texture);
|
||||
//释放资源
|
||||
www.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator Load(string url, Action<WWW> cb)
|
||||
{
|
||||
//这里的url可以是web路径也可以是本地路径file://
|
||||
WWW www = new WWW(url);
|
||||
//挂起程序段,等资源下载完成后,继续执行下去
|
||||
yield return www;
|
||||
|
||||
//判断是否有错误产生
|
||||
if (string.IsNullOrEmpty(www.error))
|
||||
{
|
||||
//把下载好的图片回调给调用者
|
||||
cb.Invoke(www);
|
||||
//释放资源
|
||||
www.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator Load(string url, Action<WWW,object> cb, object data)
|
||||
{
|
||||
//这里的url可以是web路径也可以是本地路径file://
|
||||
WWW www = new WWW(url);
|
||||
//挂起程序段,等资源下载完成后,继续执行下去
|
||||
yield return www;
|
||||
|
||||
//判断是否有错误产生
|
||||
if (string.IsNullOrEmpty(www.error))
|
||||
{
|
||||
//把下载好的图片回调给调用者
|
||||
cb.Invoke(www, data);
|
||||
//释放资源
|
||||
www.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator LoadAssetBundle(string url, Action<AssetBundle> ab)
|
||||
{
|
||||
WWW www = new WWW(url);
|
||||
yield return www;
|
||||
|
||||
if (string.IsNullOrEmpty(www.error))
|
||||
{
|
||||
ab.Invoke(www.assetBundle);
|
||||
www.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static string StringMD5(string data)
|
||||
{
|
||||
byte[] result = Encoding.Default.GetBytes(data.Trim());
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] output = md5.ComputeHash(result);
|
||||
return BitConverter.ToString(output).Replace("-", "");
|
||||
}
|
||||
|
||||
public static void SaveTextureFile(Texture2D incomingTexture, string filename)
|
||||
{
|
||||
byte[] bytes = incomingTexture.EncodeToPNG();
|
||||
string dir = Path.GetDirectoryName(filename);
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
File.WriteAllBytes(filename, bytes);
|
||||
}
|
||||
|
||||
public static bool SaveRenderTextureToPNG(Texture inputTex, Material mat, string filename)
|
||||
{
|
||||
RenderTexture temp = RenderTexture.GetTemporary(inputTex.width, inputTex.height, 0, RenderTextureFormat.ARGB32);
|
||||
Graphics.Blit(inputTex, temp, mat);
|
||||
bool ret = SaveRenderTextureToPNG(temp, filename);
|
||||
RenderTexture.ReleaseTemporary(temp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static bool SaveRenderTextureToPNG(RenderTexture rt, string filename)
|
||||
{
|
||||
Texture2D png = CreateTexture2DFromRT(rt);
|
||||
|
||||
SaveTextureFile(png, filename);
|
||||
|
||||
Texture2D.DestroyImmediate(png);
|
||||
png = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Texture2D CreateTexture2DFromRT(RenderTexture rt, Rect? rect = null)
|
||||
{
|
||||
RenderTexture prev = RenderTexture.active;
|
||||
RenderTexture.active = rt;
|
||||
if(rect == null)
|
||||
{
|
||||
rect = new Rect(0, 0, rt.width, rt.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
float width = rect.Value.width;
|
||||
if(rect.Value.width + rect.Value.x > rt.width)
|
||||
{
|
||||
width = rt.width - rect.Value.x;
|
||||
}
|
||||
float height = rect.Value.height;
|
||||
if(rect.Value.height + rect.Value.y > rt.height)
|
||||
{
|
||||
height = rt.height - rect.Value.y;
|
||||
}
|
||||
rect = new Rect(rect.Value.x, rect.Value.y, width, height);
|
||||
}
|
||||
Texture2D texture = new Texture2D((int)rect.Value.width, (int)rect.Value.height, TextureFormat.ARGB32, false);
|
||||
texture.ReadPixels(rect.Value, 0 , 0);
|
||||
texture.Apply();
|
||||
|
||||
RenderTexture.active = prev;
|
||||
return texture;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37a9d8249de2a464782f47451e9b5336
|
||||
timeCreated: 1481706748
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user