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. [BZOJ4888][TJOI2017]异或和(树状数组)

    题目描述 在加里敦中学的小明最近爱上了数学竞赛,很多数学竞赛的题都是与序列的连续和相关的.所以对于一个序列,求出它们所有的连续和来说,小明觉得十分的简单.但今天小明遇到了一个序列和的难题,这个题目不仅 ...

  2. BZOJ 3231: [Sdoi2008]递归数列 (JZYZOJ 1353) 矩阵快速幂

    http://www.lydsy.com/JudgeOnline/problem.php?id=3231   和斐波那契一个道理在最后加一个求和即可 #include<cstdio> #i ...

  3. HDU 6085 Rikka with Candies(bitset)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6085 [题目大意] 给出一个数组a一个数组b,以及询问数组c, 问对于每个c有多少对a%b=c,答 ...

  4. 【多重背包小小的优化(。・∀・)ノ゙】BZOJ1531-[POI2005]Bank notes

    [题目大意] Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出 ...

  5. 记一次初步Linux提权

    前言. 提权这么久了  还是头一次提下Linux的服务器... 由于之前一直钻研的win服务器  要不是前些日子爆出来Struts2-045漏洞 估计还没时间接触Linux提权.... 正文. st2 ...

  6. Java反射机制涉及的类常见方法使用总结

    import java.lang.reflect.Constructor; import java.lang.reflect.*; /*Class:代表一个字节码文件的对象,每当有类被加载进内存,JV ...

  7. php 对二维数组的某个字段公用排序的方法

    function array_sort($arr ,$keys,$order=0){ if(!is_array($arr)){ return false; } $keysvalue=array(); ...

  8. python开发_fileinput

    python中,fileinput模块对读取文件操作提供了一些有用的方法 下面是我做的demo: 运行效果: ====================================== 代码部分: ...

  9. [转]android中drawable资源的解释及例子

    原文链接:         http://blog.csdn.net/wode_dream/article/details/38584693 文章中的内容参考Dev Guide中的Drawable R ...

  10. PYPY_GC

    Author:Jin Date: 2014-7-8 http://doc.pypy.org/en/latest/windows.html http://www.pypy.org/download.ht ...