unity

unity中简单的血条制作

ぃ、小莉子 提交于 2019-12-03 15:35:55
unity中制作血条有很多方法,多数用NGUI;这里我就说说一个简单的血条制作方法吧; 这个血条制作不像NGUI一样,它是靠一段代码就可以实现的,但看起来比较效果比较差,还是看代码吧; public Texture2D bg; //血条的背景,需要在外面进行拖拽赋值; public Texture2D blood; //血条 float Life=100; //总的生命值; public Transform m_Transform; //绑定血条的物体Transform组件; void OnGUI() { vector3 headPos=Camera.main.WorldToScreenPoint(m_Transform.position+Vector3.up*2.5f); //将该物体头上的一点转化为屏幕坐标; GUI.DrawTexture(new Rect(headPos.x-15,Screen.Height-headPos.y,100,3),bg); //血条的背景制作完毕,该血条在屏幕上的位置 GUI.DrawTexture(new Rect(headPos.x-15,Screen.Height-headPos.y,100*life/Life,3),blood); //(headPos.x-15,Screen.Height-headPos.y) //该血条长100个单位

Unity中Editor的ProgressBar的使用demo

天涯浪子 提交于 2019-12-03 15:33:04
unity里面的Editor功能,Editor从字面理解为编辑器的意思,然我们可以利用它更方便的使用unity的引擎工具。 官方文档:https://docs.unity3d.com/ScriptReference/Editor.html 1.第一步,新建一个unity项目,然后新建一个脚本命名为MyActor,有两个属性【生命值/攻击力】;代码如下: 2.第二步,在项目中建一个Editor文件夹,这是做成可视化编辑器的关键; 3.第三步,直接写编辑器组件类,特别需要注意的是这个类需要继承Editor类,然后我把它命名为CatEditor.cs,并且放在Editor文件夹下; 代码如下: 4.最后,我们不需要运行项目,直接回到刚才对象的检视面板(Inspector),我们会发现,我们可以直接可视化操作MyActor.cs这个组件类 MyActor.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyActor : MonoBehaviour { public int Health=100; //生命值 public int Attack=10; //攻击力 } MyActorInspector.cs using UnityEditor;

Unity Editor 基础篇(九):EditorUtility编辑器工具

*爱你&永不变心* 提交于 2019-12-03 15:32:48
EditorUtility 编辑器工具 转自:http://blog.csdn.net/liqiangeastsun/article/details/42174339,请查看原文,尊重楼主原创版权。 这是一个编辑器类,如果想使用它你需要把它放到工程目录下的Assets/Editor文件夹下。 编辑器类在UnityEditor命名空间下。所以当使用C#脚本时,你需要在脚本前面加上 "using UnityEditor"引用。 1.ProgressBar 进度条 在Editor文件夹中添加脚本: using UnityEngine; using System.Collections; using UnityEditor; public class TestEditor : EditorWindow { float secs = 10.0f; double startVal = 0; double progress = 0; bool isShow = false; [MenuItem("Examples/Cancelable Progress Bar Usage")] static void Init() { var window = GetWindow(typeof(TestEditor)); window.Show(); } void OnGUI() { secs =

Unity Editor 基础篇(一):Build-In Attribute

自作多情 提交于 2019-12-03 15:32:16
本文参自: http://mp.weixin.qq.com/s/g7nClmQGPwU2o4yyBm6LcQ 本文为本人学习上连接的笔记有改动,请点击以上链接查看原文,尊重楼主知识产权。 关于 Unity 内置属性可以从到官方文档中查询,本篇文章只介绍一些常用的内置属性。 官方文档: https://docs.unity3d.com/ScriptReference/AddComponentMenu.html Attributes属性: 属于U3D的RunTimeClass,所以要加上命名空间: using UnityEngine; using System.Collections; 1.AddComponentMenu AddComponentMenu 属性允许将一个脚本添加到 Component 菜单中,然后你便可以通过 Component ->(你设置的名字)为一个选中的游戏对象创建该脚本,如下所示: [AddComponentMenu("Learning/People")] public class People : MonoBehaviour { } 2.RequireComponent() RequireComponent()属性会自动帮你添加你需要的组件,如果已经存在则不再重复添加,且不能移除,如下所示: [AddComponentMenu("Learning

Unity编辑器 - 自动排版

落爺英雄遲暮 提交于 2019-12-03 15:27:51
Unity编辑器 - 自动排版 使用花括号提高可读性 //一组横向排列的控件 GUILayout .BeginHorizontal () ; { GUILayout .BeginVertical () ; { //横向排列中的第一组竖向控件 } GUILayout .EndVertical () ; GUILayout .BeginVertical () ; { //横向排列中的第二组竖向控件 } GUILayout .EndVertical () ; } GUILayout .EndHorizontal () ; 1 一定要这样写的,不然改的痛不欲生。。 2 把冗长的代码按排版区域拆分成模块 坑爹的GUILayoutUtility.GetRect()和GUILayout.BeginArea() 在组织排版和需要实现交互操作时,需要获取控件的Rect,这时候使用GUILayoutUtility.GetRect()比较方便。 然而这里有两点要特别注意: - 在Event.current.type == EventType.Layout时: GUILayoutUtility.GetRect() = Rect(0, 0, 1, 1); - GUILayoutUtility.GetRect()不能给BeginArea使用,因为GUILayout

Unity Editor 编辑器扩展 五 EditorGUI

让人想犯罪 __ 提交于 2019-12-03 15:27:37
目录 创建一个窗口添加简单控件 制作一个可以渐入渐出的窗口控件 最后做一个比较炫酷的窗口 创建一个窗口,添加简单控件 在Editor创建脚本GUIWindow1如下,添加一些简单的控件,体验一下他们的功能 using UnityEngine; using UnityEditor; public class GUIWindow1 : EditorWindow { // 开启一个窗口 [MenuItem ( "Window/Example1" )] static void Open () { GetWindow<GUIWindow1> (); } bool toogleVale; void OnGUI () { EditorGUI.BeginChangeCheck (); // 绘制一个Lable EditorGUILayout.LabelField ( "Example Label" ); //绘制toogle存储bool值 toogleVale = EditorGUILayout.ToggleLeft ( "Toogle" , toogleVale); //检测窗口改变 if (EditorGUI.EndChangeCheck ()) { if (toogleVale) { Debug.Log ( "toogleVale :" +toogleVale); } } //

(Editor)在Unity上自定义菜单 CustomEditor

让人想犯罪 __ 提交于 2019-12-03 15:27:18
CustormEditor一般与类Editor配合使用!以实现在Inspector面板中的自定义显示! [csharp] view plain copy using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor( typeof (myType))] public class menutest : Editor { public override void OnInspectorGUI() { myType s = target as myType; // ........ } } 使用时有几个注意点: 1、CustomEditor + typeof + 类名 2、自定义类是Editor的派生类 3、绘制自定义UI要重写OnInspectorGUI函数。此函数是虚函数。 ===================================================== Editor类是自定义Editor的基类。它派生自ScriptableObject。 1、变量 serializedObject 序列化对象,代表被Inspector的对象 target 被Inspector的对象。比如某个脚本。 targets 被Inspector的对象数组

unityEditor利用自定义窗口打包AssetBundle

送分小仙女□ 提交于 2019-12-03 15:26:31
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; //初始版本 //参考https://blog.csdn.net/damenhanter/article/details/50221841 public class ExportAssetBundles : EditorWindow { [MenuItem("Build/ExportResource")] static void ExportResource() { //打包方式一 //打开保存文件面板,获取用户选择的路径 //string path = EditorUtility.SaveFilePanel("Save Resource","" ,"New Resource", "assetbundle"); //Debug.Log(path);//保持AB包路径 //if(path.Length!= 0) //{ // //选择要保存的对象 选择模式包含文件夹 // Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); // //打包

Unity可扩展编辑器

Deadly 提交于 2019-12-03 15:26:19
UnityEditor 之 自定义Editor Menu 菜单 菜单栏添加菜单按钮 using UnityEngine; using System.Collections; using UnityEditor; public class Menu : MonoBehaviour { [MenuItem( "ShowDialog/ShowDialog" )] static void showDialog() { EditorUtility.DisplayDialog( "Something Error!" , "This is a new dialog" , "close" ); } } 可扩展编辑器 Texture2D 要可读,改 Texture 属性为 Advance 并在Override 地方的 Format 要设置正确 MyInspector using UnityEngine; using System.Collections; public class MyInspector : MonoBehaviour { public Rect m_rectValue; public Texture2D m_texture; public int m_iCount; public float m_fLength; public string m_strSaveName;

Unity Editor 自定义窗口

淺唱寂寞╮ 提交于 2019-12-03 15:26:09
Unity Editor自定义窗口 简单的介绍一下 自定义窗口,将大部分考虑的布局都写了一下 希望有需要的朋友能够通过这片帖子,学到一些东西 先看效果图 直接上代码,一切尽在不言中 * 脚本必须在Editor 文件夹下* using System . Collections ; using System . Collections . Generic ; using System . IO ; using UnityEditor ; using UnityEditor . SceneManagement ; using UnityEngine ; public class FirstWindow : EditorWindow { string Label = "" ; string description = "" ; GameObject GameObject ; Texture2D Texture2D ; // 利用构造函数来设置窗口名称 FirstWindow () { this.titleContent = new GUIContent ( "第一个窗口" ); } / /添加菜单栏用于打开窗口 [MenuItem("Tool/ 打开窗口 ")] static void showWindow() { EditorWindow.GetWindow(typeof