unity 工具开发基础
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEditor;
/// <summary>
/// Unity基础工具功能
/// priority菜单项显示排序
/// </summary>
public class TestEditor : MonoBehaviour { [MenuItem("GameObject/获取选中的物体名称", priority = )]
static string GetSelectObject(){
GameObject _selectObject = Selection.gameObjects [];
Debug.Log (_selectObject.name);
return _selectObject.name;
} [MenuItem("GameObject/获取Project视图中的文件和文件夹路径", priority = )]
static string GetSelectFile(){
string[] guidArray = Selection.assetGUIDs;//从meta文件里面取得id
string selectName = AssetDatabase.GUIDToAssetPath (guidArray []);//根据id取得路径
string path = Application.dataPath.Substring (, Application.dataPath.Length - );
Debug.Log (path + selectName);
return path + selectName;
} [MenuItem("GameObject/创建新文件", priority = )]
static void CreateNewFile(){
File.WriteAllText (GetSelectFile () + "/UI_" + GetSelectObject () + ".lua", "xxx文本内容xxx", Encoding.UTF8);
AssetDatabase.Refresh ();
} [MenuItem("GameObject/创建文件夹", priority = )]
static void CreateFolder(){
Directory.CreateDirectory(Application.dataPath + "/文件夹名称");
AssetDatabase.Refresh ();
}
}
放Editor文件下
editor修改prefab https://cnblogs.com/klkucan/p/4934518.html
-10-23新增
[MenuItem("GameObject/获取用户名和当前时间", priority = )]
static void GetUserName(){
string username = System.Environment.UserName;
var time = System.DateTime.Now;
Debug.Log (username);
Debug.Log (time);
} [MenuItem("GameObject/打印选择物体的子物体路径", priority = )]
static void GetChildPath()
{
Transform _selectObject = Selection.gameObjects[].transform;
GetChildObject (_selectObject, _selectObject.name);
} static void GetChildObject(Transform trans, string path){
for(int i = ; i < trans.childCount; i++){
Transform child = trans.GetChild (i);
string comPath = path + "_" + child.name;
GetChildObject (child, comPath);
}
//输出条件:最末端物体 (自由更改)
if(trans.childCount == ){
Debug.Log (path);
}
}
打印 路径 和 名字
static void CreateUI(){
string[] guidArray = Selection.assetGUIDs;
foreach (var item in guidArray)
{
//打印路径
string selecetFloder = AssetDatabase.GUIDToAssetPath(item);
Debug.Log(selecetFloder);
//打印名字
string selectName = Path.GetFileName(selecetFloder);
Debug.Log(selectName);
}
}
遍历文件夹下的包括子文件夹的后缀带有xx文件
以lua为例
[MenuItem("Assets/check",priority = )]
static void CheckChinese()
{
string[] guidArray = Selection.assetGUIDs;
foreach (var item in guidArray)
{
string selectFloder = AssetDatabase.GUIDToAssetPath(item);
DirectoryInfo root = new DirectoryInfo(selectFloder);
GetFloder(root);
}
} static void GetFloder(DirectoryInfo root)
{
GetFile(root);
//查找子文件夹
DirectoryInfo[] array = root.GetDirectories();
//Debug.Log(root);
foreach (DirectoryInfo item in array)
{
GetFloder(item);
}
} static void GetFile(DirectoryInfo root)
{
//DirectoryInfo root = new DirectoryInfo(path);
FileInfo[] fileDic = root.GetFiles();
foreach (var file in fileDic)
{
//sDebug.Log(file);
if (file.FullName.EndsWith("lua"))
{
Debug.Log("-------------" + file.Name);
}
}
}
//获取指定类型资源的路径
string[] spritesPath =
AssetDatabase.FindAssets("t:Sprite", new string[] {Application.dataPath + "/Resources/Sprites/Cloud"}); --------------------------------2019-8-28------------------------------------
代码设置Animator的参数,animator 转 AnimatorController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Spine.Unity;
using UnityEditor.Animations; /// <summary>
/// 制作怪物预制体
/// </summary>
public class CreateMonsterPrefab { [MenuItem("GameObject/添加怪物Animator参数", priority = )]
static void SetACPara()
{
Debug.Log("设置参数");
GameObject _selectObject = Selection.gameObjects[];
AnimatorController controller = _selectObject.GetComponent<Animator>().runtimeAnimatorController as AnimatorController; AddParameter(controller, "Die", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Move", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Hurt", AnimatorControllerParameterType.Bool);
AddParameter(controller, "IsDead", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Speed", AnimatorControllerParameterType.Float);
AddParameter(controller, "Vertigo", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Execute", AnimatorControllerParameterType.Bool);
AddParameter(controller, "IsMoveModeEnable", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Frozen", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Warning", AnimatorControllerParameterType.Bool);
AddParameter(controller, "IsWarning", AnimatorControllerParameterType.Trigger);
AddParameter(controller, "IsAtk", AnimatorControllerParameterType.Bool);
AddParameter(controller, "Attack", AnimatorControllerParameterType.Int);
AddParameter(controller, "AtkType", AnimatorControllerParameterType.Int);
AddParameter(controller, "MoveType", AnimatorControllerParameterType.Int);
AddParameter(controller, "AttackType", AnimatorControllerParameterType.Int); Debug.Log("设置成功");
} //添加
static void AddParameter(AnimatorController controller, string name, AnimatorControllerParameterType _type)
{
if (!CheckParameters(controller, name))
{
controller.AddParameter(name, _type);
}
} //检查
static bool CheckParameters(AnimatorController controller, string parName)
{
foreach (var item in controller.parameters)
{
if (item.name.Equals(parName))
{
return true;
}
}
return false;
}
}
不错的教程:
https://blog.csdn.net/q764424567/article/details/80908614
unity 工具开发基础的更多相关文章
- 【Unity】第6章 Unity脚本开发基础
分类:Unity.C#.VS2015 创建日期:2016-04-16 一.简介 游戏吸引人的地方在于它的可交互性.如果游戏没有交互,场景做得再美观和精致,也难以称其为游戏. 在Unity中,游戏交互通 ...
- Unity脚本开发基础 C#
1. MonoBehaviour 类 常用事件响应函数: 2. 访问游戏对象 (1) 通过名称来查找 (2) 通过标签来查找 上述函数比较费时,应避免在 Update 函数调用. 3. 访问组件 对于 ...
- unity工具开发
1.EditorWindow通过拖拽获取文件夹或者文件路径 #region 拖拽相关 Rect rect4 = EditorGUILayout.GetControlRect(); //将上面的框作为文 ...
- PHP开发工具PHP基础教程
PHP开发 工具PHP基础教程,以下是兄弟连PHP培训小编整理: PHP IDE PHP IDE也不少,主要从几个方面进行筛选: 跨平台(能够同时在windows,mac或者ubuntu上面运 ...
- C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新
本帖是延续的:C# Unity游戏开发--Excel中的数据是如何到游戏中的 (三) 最近项目不算太忙,终于有时间更新博客了.关于数据处理这个主题前面的(一)(二)(三)基本上算是一个完整的静态数据处 ...
- 1.2Linux下C语言开发基础(学习过程)
===============第二节 Linux下C语言开发基础=========== ********************** 重要知识点总结梳理********************* 一 ...
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- 从零3D基础入门XNA 4.0(1)——3D开发基础
[题外话] 最近要做一个3D动画演示的程序,由于比较熟悉C#语言,再加上XNA对模型的支持比较好,故选择了XNA平台.不过从网上找到很多XNA的入门文章,发现大都需要一些3D基础,而我之前并没有接触过 ...
- Android 开发基础及环境配置
2011年买了第一部安卓操作系统的手机,当时势头正盛的HTC不可思议(incredible),当时的想法就是想学习下智能手机开发,但是由于各种原因,客观上是公司的项目太忙了,忙于项目管理.团队建设.客 ...
随机推荐
- Sweetkang 的机器学习实验室 (1)
前言 近年来,Machine Learning 在许多领域上已然取得了可喜的成就,非常火热.就我个人来讲,有意将业余 Sport Programming 的范围扩展一下,譬如 Topcoder Mar ...
- Javascript基础编程の面向对象编程
javascript是解释型的语言,在编译时和运行时之间没有明显区别,因此需要更动态的方法.javascript没有正式的类的概念,我们可以使用在运行时创建新的对象类型来替代,并且可以随时更改已有对象 ...
- memcached整理の实践
对于memcached使用内存来存取数据,一般情况下,速度比直接从数据库或者文件系统存取要快,memcached最常用的场景是利用其“存取快”来保护数据库,防止高频率存取数据库. 缓存数据库查询结果 ...
- C#基础入门 三
C#基础入门 三 类 类使用class关键字进行声明,前面加一个访问修饰符,public class car{} 访问修饰符:修师傅可以用来修饰类和类成员等,控制它们的可见度 修饰符关键字分别为:pu ...
- 折腾了两天的跨站脚本提交问题,与IIS7有关
根据这里提供的方法,本地测试通过没有问题,但是部署到服务器上之后,只有GET请求可以跨站提交,POST请求继续报错,折腾了两天之后觉得,是不是IIS7的问题?果然,找到了这篇文章,照做之后解决.
- 【git】常用命令
// 下载Git项目git clone url // 显示当前git配置git config --list // 设置用户信息git config --global user.name "& ...
- Webbench的使用
Webbench是一个在linux下使用的非常简单的网站压测工具. 它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力 ...
- windows Win7如何设置多用户同时远程登录
windows Win7如何设置多用户同时远程登录 1.创建一个用户 密码永不过期 2.在本地组策略编辑器里面,依次展开计算机配置--->管理模板--->Windows组件---> ...
- Apache启动报错Address already in use: make_sock: could not bind to...
Apache启动时报错:(98)Address already in use: make_sock: could not bind to... # /etc/init.d/httpd start St ...
- OCP 12c最新考试原题及答案(071-4)
4.(4-11) choose two:View the Exhibit and examine the data in the PRODUCT_INFORMATION table.Which two ...