iTweenPath.cs
[pyg language="csharp" s="monokai" ]
//Slight additions for a cleaner interface by Jacob Pennock
//source by Bob Berkebile : Pixelplacement : http://www.pixelplacement.com using UnityEngine;
using System.Collections.Generic; public enum iTweenPathCap {Default, Sphere, Cube, Dot, Circle,Square} public class iTweenPath : MonoBehaviour
{
public string pathName =””;
public Color pathColor = Color.cyan;
public iTweenPathCap capType;
public float capSize;
public List nodes = new List(){Vector3.zero, Vector3.zero};
public int nodeCount;
public static Dictionary paths = new Dictionary();
public bool initialized = false;
public string initialName = “”; void OnEnable(){
paths.Add(pathName.ToLower(), this);
} void OnDrawGizmosSelected(){
if(enabled) { // dkoontz
if(nodes.Count > ){
iTween.DrawPath(nodes.ToArray(), pathColor);
}
} // dkoontz
} public static Vector3[] GetPath(string requestedName){
requestedName = requestedName.ToLower();
if(paths.ContainsKey(requestedName)){
return paths[requestedName].nodes.ToArray();
}else{
Debug.Log(“No path with that name exists! Are you sure you wrote it correctly?”);
return null;
}
}
}
[/pyg] iTweenPathEditor.cs
[pyg language="csharp" s="monokai" ]
//Slight additions for a cleaner interface by Jacob Pennock
//source by Bob Berkebile : Pixelplacement : http://www.pixelplacement.com using UnityEngine;
using UnityEditor;
using System.Collections; [CustomEditor(typeof(iTweenPath))]
public class iTweenPathEditor : Editor
{
iTweenPath _target;
GUIStyle style = new GUIStyle();
public static int count = ; void OnEnable(){
//i like bold handle labels since I’m getting old:
style.fontStyle = FontStyle.Bold;
style.normal.textColor = Color.white;
_target = (iTweenPath)target; //lock in a default path name:
if(!_target.initialized){
_target.initialized = true;
_target.pathName = “New Path ” + ++count;
_target.initialName = _target.pathName;
}
} public override void OnInspectorGUI(){
//path name:
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(“Path Name”);
_target.pathName = EditorGUILayout.TextField(_target.pathName);
EditorGUILayout.EndHorizontal(); if(_target.pathName == “”){
_target.pathName = _target.initialName;
} //path color:
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(“Path Color”);
_target.pathColor = EditorGUILayout.ColorField(_target.pathColor);
EditorGUILayout.EndHorizontal(); //Node Type
_target.capType = (iTweenPathCap)EditorGUILayout.EnumPopup(“Node Type”,_target.capType); //Node size
if(_target.capType != iTweenPathCap.Default)
{
_target.capSize = EditorGUILayout.Slider(“Node Size”,_target.capSize, 0.5f, 5.0f);
} //exploration segment count control:
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(“Node Count”);
_target.nodeCount = Mathf.Clamp(EditorGUILayout.IntSlider(_target.nodeCount, , ), ,);
EditorGUILayout.EndHorizontal(); //add node?
if(_target.nodeCount > _target.nodes.Count){
for (int i = ; i < _target.nodeCount - _target.nodes.Count; i++) {
_target.nodes.Add(Vector3.zero);
}
} //remove node?
if(_target.nodeCount < _target.nodes.Count){
if(EditorUtility.DisplayDialog("Remove path node?","Shortening the node list will permantently destory parts of your path. This operation cannot be undone.", "OK", "Cancel")){
int removeCount = _target.nodes.Count - _target.nodeCount;
_target.nodes.RemoveRange(_target.nodes.Count-removeCount,removeCount);
}else{
_target.nodeCount = _target.nodes.Count;
}
} //node display:
EditorGUI.indentLevel = ;
for (int i = ; i < _target.nodes.Count; i++) {
_target.nodes[i] = EditorGUILayout.Vector3Field("Node " + (i+), _target.nodes[i]);
} //update and redraw:
if(GUI.changed){
EditorUtility.SetDirty(_target);
}
} void OnSceneGUI(){
if(_target.enabled) { // dkoontz
if(_target.nodes.Count > ){
//allow path adjustment undo:
Undo.SetSnapshotTarget(_target,”Adjust iTween Path”); //path begin and end labels:
Handles.Label(_target.nodes[], “‘” + _target.pathName + “‘ Begin”, style);
Handles.Label(_target.nodes[_target.nodes.Count-], “‘” + _target.pathName + “‘ End”, style); //node handle display:
DrawPathCaps();
}
} // dkoontz
} void DrawPathCaps()
{
switch(_target.capType)
{
case iTweenPathCap.Default:
for (int i = ; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.PositionHandle(_target.nodes[i], Quaternion.identity);
}
break;
case iTweenPathCap.Sphere:
Handles.color = _target.pathColor;
for (int i = ; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.FreeMoveHandle(_target.nodes[i],Quaternion.identity,_target.capSize,Vector3.zero,Handles.SphereCap);
}
break;
case iTweenPathCap.Cube:
Handles.color = _target.pathColor;
for (int i = ; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.FreeMoveHandle(_target.nodes[i],Quaternion.identity,_target.capSize,Vector3.zero,Handles.CubeCap);
}
break;
case iTweenPathCap.Dot:
Handles.color = _target.pathColor;
for (int i = ; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.FreeMoveHandle(_target.nodes[i],Quaternion.identity,_target.capSize,Vector3.zero,Handles.DotCap);
}
break;
case iTweenPathCap.Circle:
Handles.color = _target.pathColor;
for (int i = ; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.FreeMoveHandle(_target.nodes[i],Quaternion.identity,_target.capSize,Vector3.zero,Handles.CircleCap);
}
break;
case iTweenPathCap.Square:
Handles.color = _target.pathColor;
for (int i = ; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.FreeMoveHandle(_target.nodes[i],Quaternion.identity,_target.capSize,Vector3.zero,Handles.RectangleCap);
}
break;
}
}
}
[/pyg]

Cleaner ITweenPath Source的更多相关文章

  1. RFIDler - An open source Software Defined RFID Reader/Writer/Emulator

    https://www.kickstarter.com/projects/1708444109/rfidler-a-software-defined-rfid-reader-writer-emul h ...

  2. Using Open Source Static Libraries in Xcode 4

    Using Open Source Static Libraries in Xcode 4 Xcode 4.0.1 allows us to more easily create and use th ...

  3. Cleaner, more elegant, and harder to recognize (msdn blog)

    It appears that some people interpreted the title of one of my rants from many months ago, "Cle ...

  4. AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...

  5. mysql-5.6.34 Installation from Source code

    Took me a while to suffer from the first successful souce code installation of mysql-5.6.34. Just pu ...

  6. source /etc/profile报错-bash: id:command is not found

    由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...

  7. eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过

    问题描述 使用Eclipse调试代码的时候,打了断点,经常出现Source not found,网上找了半天,大部分提示点击Edit Source Lookup Path,添加被调试的工程,然而往往没 ...

  8. Oracle使用java source调用外部程序

    需求 Oracle调用第三方外部程序.Oracle使用sqluldr2快速导出大批量数据,然后用winrar压缩后发送邮件. 本文档主要实现前两步需求,发送邮件程序这里不再说明. 原码 授权 begi ...

  9. Perforce 与Source Insight, Visual Studio集成

    转自:http://shashanzhao.com/archives/837.html 1.Perforce 首先需要为perforce设置系统环境变量,以便perforce命令行可以正常使用. 环境 ...

随机推荐

  1. 【UOJ #107】【APIO 2013】ROBOTS

    http://uoj.ac/problem/107 设\(f(l,r,i,j)\)表示\([l,r]\)中的机器人聚集到\((i,j)\)需要花的最小操作数. \(f(l,r,i,j)=\min\le ...

  2. HDU 6118 度度熊的交易计划(费用流)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6118 [题目大意] 给出一张无向边权图,每个点最多可以生产b[i]商品,每件代价为a[i], 每个 ...

  3. Ural 1519 Formula 1 插头DP

    这是一道经典的插头DP单回路模板题. 用最小表示法来记录连通性,由于二进制的速度,考虑使用8进制. 1.当同时存在左.上插头的时候,需要判断两插头所在连通块是否相同,若相同,只能在最后一个非障碍点相连 ...

  4. 四、python之 if while for

    一.if条件判断 if 条件判断: 逻辑操作…… …… else: 逻辑操作…… 其中"判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来区分表示同一范围. ...

  5. HashSet,TreeSet和LinkedHashSet

    Set接口 Set不允许包含相同的元素,如果试图把两个相同元素加入同一个集合中,add方法返回false. Set判断两个对象相同不是使用==运算符,而是根据equals方法.也就是说,只要两个对象用 ...

  6. react-native-image-zoom-viewer学习

    github原地址 react-native-image-zoom-viewer实现了类似微信朋友圈浏览图片的效果,点击小图片实现浏览原图效果. 安装: npm i react-native-imag ...

  7. object-c的http post请求之 ASIFormDataRequest使用

    ASIHTTPRequest类库中的ASIFormDataRequest是实现HTTP协议中的处理POST表单的很好的类库.使用起来非常简单. 在说明之前先需要了解HTTP请求的Get和Post方法. ...

  8. HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)

    Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  9. TJU 2248. Channel Design 最小树形图

    最小树形图,測模版.... 2248.   Channel Design Time Limit: 1.0 Seconds   Memory Limit: 65536K Total Runs: 2199 ...

  10. C# 怎么获取所有打开的窗体

    FormCollection collection = Application.OpenForms; foreach(Form form in collection){    if(form.Visi ...