Cleaner ITweenPath Source

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 > 0){
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 = 0;

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, 0, 25), 2,100);
EditorGUILayout.EndHorizontal();

//add node?
if(_target.nodeCount > _target.nodes.Count){
for (int i = 0; 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 = 4;
for (int i = 0; i < _target.nodes.Count; i++) {
_target.nodes[i] = EditorGUILayout.Vector3Field("Node " + (i+1), _target.nodes[i]);
}

//update and redraw:
if(GUI.changed){
EditorUtility.SetDirty(_target);
}
}

void OnSceneGUI(){
if(_target.enabled) { // dkoontz
if(_target.nodes.Count > 0){
//allow path adjustment undo:
Undo.SetSnapshotTarget(_target,”Adjust iTween Path”);

//path begin and end labels:
Handles.Label(_target.nodes[0], “‘” + _target.pathName + “‘ Begin”, style);
Handles.Label(_target.nodes[_target.nodes.Count-1], “‘” + _target.pathName + “‘ End”, style);

//node handle display:
DrawPathCaps();
}
} // dkoontz
}

void DrawPathCaps()
{
switch(_target.capType)
{
case iTweenPathCap.Default:
for (int i = 0; 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 = 0; 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 = 0; 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 = 0; 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 = 0; 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 = 0; i < _target.nodes.Count; i++)
{
_target.nodes[i] = Handles.FreeMoveHandle(_target.nodes[i],Quaternion.identity,_target.capSize,Vector3.zero,Handles.RectangleCap);
}
break;
}
}
}
[/pyg]
时间: 2024-10-25 23:40:55

Cleaner ITweenPath Source的相关文章

Codeforces 589J Cleaner Robot(DFS)

Cleaner Robot Time Limit: 2000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Submit Status Description Masha has recently bought a cleaner robot, it can clean a floor without anybody's assistance. Schematically Masha's room is a rectang

Java注解(3)-注解处理器(编译期|RetentionPolicy.SOURCE)

注解的处理除了可以在运行时通过反射机制处理外,还可以在编译期进行处理.在编译期处理注解时,会处理到不再产生新的源文件为止,之后再对所有源文件进行编译. Java5中提供了apt工具来进行编译期的注解处理.apt是命令行工具,与之配套的是一套描述"程序在编译时刻的静态结构"的API:Mirror API(com.sun.mirror.*).通过Mirror API可以获取到被注解的Java类型元素的信息,从而提供自定义的处理逻辑.具体的处理工具交给apt来处理.编写注解处理器的核心是两个

software source

whati is software source? software source is a houselive.it provide any softwares from sources.list. or it can be recognized as a address of server.we can assign this adress of server. so how to alter the address of server? so we have methods ,the on

source insight3.5中文乱码解决方案

source insight3.5中文乱码,网上看别人说改变宽字体.宋体等方法都不起效.根本原因是,source insight 3.5 不支持Unicode编码,所以导致中文的乱码,将文件转为gb2312编码即可正常显示. 转码命令: iconv -c  -f utf-8 -t gb2312  utf8FileName  >>  newGb2321FileName

在eclipse下,package,source folder,folder的区别

在eclipse下,package,source folder,folder都是文件夹. 它们的区别如下:package:当你在建立一个package时,它自动建立到source folder下,也只能建立在这个目录之下. source folder:存放java源代码的文件夹,当然也包括一些package文件夹,还可以包含其他文件.项目构建后,source folder里面的java自动编译成class文件到相应的bin文件夹中,其他文件也会移到到相应的目录下. folder:里面可以放入任何

Source Insight 使用积累

Source Insight 捷键及使用技巧 红色部分为我经常使用的部分 完成语法 :Ctrl+E 复制一行 :Ctrl+K 恰好复制该位置右边的该行的字符: Ctrl+Shift+K 剪切一行 :Ctrl+U 向前搜索 : F4 搜索选择的(比如选择了一个单词,shift+F4将搜索下一个) :Shift+F4 向后搜索 : F3 Shift+F3 : search the word under cusor backward F5: go to Line Ctrl+鼠标点击 :Jump to

CRC32 Source Code

/* The Quest Operating System * Copyright (C) 2005-2010 Richard West, Boston University * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Softwar

linux下shell脚本执行方法及exec和source命令

exec和source都属于bash内部命令(builtins commands),在bash下输入man exec或man source可以查看所有的内部命令信息. bash shell的命令分为两类:外部命令和内部命令.外部命令是通过系统调用或独立的程序实现的,如sed.awk等等.内部命令是由特殊的文件格式(.def)所实现,如cd.history.exec等等. 在说明exe和source的区别之前,先说明一下fork的概念. fork是linux的系统调用,用来创建子进程(child

Ubuntu中使用source报错处理办法

最近一段时间在使用Bash on Ubuntu on Windows做shell脚本调试时发现在脚本中使用source时会报错,上网查了下才了解到原来是在Ubuntu中使用的并不是bash,而是使用优化过的dash,而在dash中是没有source,而在bash中才有source,这就有点麻烦了,平时在写脚本时有时会调用系统的function和一些自定义的function,没有source确实有点不太方便,而在此时可以在使用dpkg-reconfigure来修改配置dash,在平时可以用以下方法