unity
Zhac
菜菜菜
展开
-
Unity 改变父物体Scale 子物体相对位置如何保存
需求:一个任务配置界面 在鼠标点击地图位置生成目标 地图精度比较大可缩放 此时如何保存生成的目标位置 使其下次加载时还在同样的位置刚开始就觉得是一个普通的LocalPosition 保存相对父节点位置即可,后来实践发现,当保存LocalPosition时 加载出来的目标不在同一个位置。后来又考虑是不是保存RectTransform的位置,结果还是不行。最终发现了 需要保存RectTransform上的anchoredPosition这个位置 加载目标时也给目标的这个参数赋值 就可以实现了。.原创 2021-07-16 17:56:17 · 1364 阅读 · 3 评论 -
git push的时候报错: Out of memory, malloc failed (tried to allocate 82037333 bytes)
原因:上传的文件过大,这里我上传的文件有10G+所以报了上面的错误解决方法:依次运行:git config --global pack.threads 1 git,git config --global pack.deltaCacheSize 128m,git config --global pack.windowMemory 50m。...原创 2021-01-25 13:57:42 · 1237 阅读 · 1 评论 -
Unity引用外部DLL后打包发布需要注意的一些问题
unity的dll中有用到UnityEditor的处理 错误信息:ArgumentException: The Assembly UnityEditor is referenced by Tool ('Assets/Tools/JSBase/DLL/Tool.dll'). But the dll is not allowed to be included or could not be found.原因:封装DLL的时候用到了UnityEditor.dll,但是在项目打包的时候,用到UnityE..原创 2021-01-21 15:49:15 · 2067 阅读 · 0 评论 -
Unity使用DLL封装代码
如博文无法正常显示,请访问原文地址:https://blog.csdn.net/ChinarCSDN/article/details/82809590转载 2020-11-23 10:54:57 · 307 阅读 · 0 评论 -
Unity项目-单例
只实例化一次,减少内存占用普通脚本单例/** *Copyright(C) 2015 by #COMPANY# *All rights reserved. *Author: RenHao *Version: 1.0 *Date: 2020-09-12 15:28:59 *Description: *History:*/using System.Collections;using System.Collections.Generic;原创 2020-09-12 16:03:48 · 265 阅读 · 0 评论 -
Unity项目 Project主要目录
原创 2020-09-12 15:17:27 · 1053 阅读 · 0 评论 -
Unity项目脚本初始化
首先打开unity程序安装位置根目录Unity\Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs输入自己想要初始化的信息/** *Copyright(C) 2015 by #COMPANY# *All rights reserved. *Author: #AUTHOR# *Version: #VERSION# *Date: #CreateTime.原创 2020-09-12 14:51:00 · 1830 阅读 · 0 评论 -
Lua__读取指定路径下的.Lua文件
using System.Collections;using System.Collections.Generic;using System.IO;using UnityEngine;using XLua; public class Hotfix : MonoBehaviour { private LuaEnv luaEnv; void Awake() { luaEnv = new LuaEnv(); luaEnv.AddLoad.转载 2020-06-23 16:22:10 · 2233 阅读 · 0 评论 -
Unity 调用Windows打开、保存窗口并获取文件路径
文件日志using System.Runtime.InteropServices;using System;/// <summary>/// 文件日志类/// </summary>// [特性(布局种类.有序,字符集=字符集.自动)][StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public class ChinarFileDlog{ public int struct转载 2020-06-23 09:36:35 · 1994 阅读 · 2 评论 -
给图片或者其他UI添加鼠标点击抬起事件
UGUI的Image添加点击事件在不用Button按钮的情况下,只使用Image图片,如何有button一样的点击事件呢?在Image下,添加Event Trigger组件 要触发什么事件,就选择相应的事件,比如说当图片被按下,就选PointerDown 最后可以用公开添加事件的方法进行添加监听事件,并且要为Image添加上BoxColider碰撞器,这样就可以了...转载 2020-06-10 19:31:29 · 341 阅读 · 0 评论 -
Unity 拖动鼠标旋转模型(类似时钟拖动指针)
拖动指针在圆中旋转using System;using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using UnityEngine.EventSystems;public class MoveCompass : MonoBehaviour{ private bool isPress;//是否按下 private Vecto...原创 2020-06-10 19:30:41 · 938 阅读 · 0 评论 -
unity3d中Transform组件 Rotate()和rotation变量详解
Transform组件是每个游戏对象必须有的一个组建,因为你创建一个空物体,它也有该组建,因为unity3d是面向组建开发的一款游戏引擎。通过一张图片来看看它的属性你可以在通过代码查看这些属性的区别 Debug.Log("position " + transform.position); //世界坐标的位置 Debug.Log("localPosition " + transform.localPosition); //相对于父位置的坐标 即把父...转载 2020-06-10 19:27:40 · 2315 阅读 · 0 评论 -
Lua读取C#中的List出现的错误LuaException: try to get System.Collections.Generic.List`
情况是我想要把C#的List传入Lua的一个表中,但是一直报错LuaException: try to get System.Collections.Generic.List`for k,v in ipairs(newFighters) do print(k) print(v.xPos) --table.insert(fighters2,{xPos = v.xPos,yPos = v.yPos,groupId =num,groupName = v.groupName,cam原创 2020-05-28 11:25:11 · 1343 阅读 · 0 评论 -
Unity 加载ToggleGroup下激活的Toggle
IEnumerable<Toggle> toggleGroup = this.transParent.Find("ScrollViewMask").Find("Content").GetComponent<ToggleGroup>().ActiveToggles(); foreach (var toggle in toggleGroup) { debug.log(toggle) }...原创 2020-05-27 21:16:19 · 1238 阅读 · 0 评论 -
Unity 判断物体是否含有子物体
if (GetComponentsInChildren<Transform>(true).Length <= 1){ Debug.Log("没有子物体");}这个方法是查询物体下含有多少个transform,需要注意的是因为物体本身也含有transform,所以在计算的时候要<=1原创 2020-05-27 09:53:45 · 5568 阅读 · 0 评论 -
Unity给button添加监听事件
fighterGob.GetComponent<Button>().onClick.AddListener(delegate() { GameObject fighterInfoGob = WindowUIManager.Instance.OpenWindow(WindowUIType.FightInfo); fighterInfoGob.GetComponent<UIFighterInfoCtrl&g...原创 2020-05-26 15:09:55 · 2283 阅读 · 0 评论 -
unity 查找物体的Inputfield文本
一般inputField都属于物体的子物体GameObject.transform.GetComponentInChildren<InputField>().text原创 2020-05-25 13:56:38 · 1394 阅读 · 0 评论 -
VS 解决方案需要迁移(转自知乎)
问题描述:vs打开unity项目显示此项目需要迁移。这个问题是因为关闭了VS与Unity工具解决办法:vs菜单->扩展->找到Visual Studio 2019 Tools for Unity 启用。转载 2020-05-25 12:15:50 · 3829 阅读 · 0 评论 -
Unity寻找子物体的几种方法
经常遇到寻找子物体的问题,寻找子物体有很多种方法,今天就来整理一下:所有的方法都以图下的物体列表进行比较,同时将脚本挂载在父物体上。1.GetComponentsInChildren()这个是获取所有子物体(包括父物体)的方法。Transform[] myTransforms = GetComponentsInChildren<Transform>();foreach (var child in myTransforms){ Debug.Log(child.name)转载 2020-05-25 11:26:39 · 51925 阅读 · 5 评论 -
添加xLua到项目中和遇到的一些坑
目录1、添加xLua 2、注意事项 3、我遇见的一些坑即解决方法1、添加xLua 在GitHub中下载腾讯xLua的最新版本 把Asset文件夹下的四个文件和Tools文件夹添加到项目中 在项目的Player Setting中添加宏 HOTFIX_ENABLE 把Unity安装目录下的3个dll文件加入刚才导入项目的xLua中 导入dll文件F:\Unity\Editor\Data\Managed Unity.Cecil.dll Uni...转载 2020-05-23 12:16:21 · 3863 阅读 · 0 评论 -
Unity C#与Xlua的交互 C#调用Lua CSharpCallLua
CSharpCallLuaCSharpCallLua,顾名思义CS里面去调用访问Lua代码里面的属性方法。对应的官方Demo为“CSharpCallLua”。访问全局基本数据类型假如我在Lua中定义了下面三个变量: a = 1 b = 'hello world' c = true 那么我们只需要通过luaenv.Global.Get<T>(name)就可在C#中访问这几个变量,如下: LuaEnv luaenv = new...转载 2020-05-22 21:17:30 · 633 阅读 · 1 评论 -
Unity回退版本报错
C:/Users/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.collab-proxy@1.2.15/Editor/Collab/Views/CollabHistoryItemFactory.cs(21,28): error CS0122: `UnityEditor.Collaboration.RevisionData' is inaccessible due to its protection levelC:/Use.原创 2020-05-22 20:59:54 · 2526 阅读 · 0 评论 -
Unity3D 快捷键
一、近距离查看游戏对象 在Hierarchy视图中选择游戏对象,然后在Scene视图中按快捷键“F”来近距离查看该游戏对象。二、游戏对象不在主摄像头中? Hierarchy中双击选择需要显示的游戏对象,再单击Main Camera选中,最后Ctrl+Shift+F键盘即可。三、旋转视图 Alt键 + 鼠标左键 可以任意拖动鼠标来旋转视图。如果x,y,z坐标轴恢复不了,可以先单击X轴(Y、Z)再鼠标右键选择“Free” 最后通过这个来调试。四、缩放视图 滚...转载 2020-05-18 16:43:23 · 1462 阅读 · 2 评论