开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (15)
标签 (450)
master
2020.1
2020.2
2019.4
2019.3
2018.4
2017.4
2019.2
2019.1
2018.3
2018.2
2017.2
2018.1
2017.1
2017.3
202010b12
202010b11
202020a13
201940f1
2019年3月15日f1
202010b10
202020a12
202010b9
2019年3月14日f1
202020a11
2018年4月23日f1
2017440f1
2019年3月13日f1
202020a10
202010b8
2019年3月12日f1
202020a9
202010b7
2018年4月22日f1
202010b6
master
分支 (15)
标签 (450)
master
2020.1
2020.2
2019.4
2019.3
2018.4
2017.4
2019.2
2019.1
2018.3
2018.2
2017.2
2018.1
2017.1
2017.3
202010b12
202010b11
202020a13
201940f1
2019年3月15日f1
202010b10
202020a12
202010b9
2019年3月14日f1
202020a11
2018年4月23日f1
2017440f1
2019年3月13日f1
202020a10
202010b8
2019年3月12日f1
202020a9
202010b7
2018年4月22日f1
202010b6
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (15)
标签 (450)
master
2020.1
2020.2
2019.4
2019.3
2018.4
2017.4
2019.2
2019.1
2018.3
2018.2
2017.2
2018.1
2017.1
2017.3
202010b12
202010b11
202020a13
201940f1
2019年3月15日f1
202010b10
202020a12
202010b9
2019年3月14日f1
202020a11
2018年4月23日f1
2017440f1
2019年3月13日f1
202020a10
202010b8
2019年3月12日f1
202020a9
202010b7
2018年4月22日f1
202010b6
SubModuleUI.cs 13.91 KB
一键复制 编辑 原始数据 按行查看 历史
Unity Technologies 提交于 2020年01月30日 19:45 +08:00 . Unity 202010a21 C# reference source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using System.Collections.Generic;
using UnityEditorInternal;
using Object = UnityEngine.Object;
namespace UnityEditor
{
class SubModuleUI : ModuleUI
{
SerializedProperty m_SubEmitters;
private int m_CheckObjectIndex = -1;
// Keep in sync with enum in ParticleSystemCommmon.h
public enum SubEmitterType
{
None = -1,
Birth = 0,
Collision,
Death,
Trigger,
Manual,
TypesMax,
}
class Texts
{
public GUIContent create = EditorGUIUtility.TrTextContent("", "Create and assign a Particle System as sub-emitter.");
public GUIContent inherit = EditorGUIUtility.TrTextContent("Inherit", "Determines what properties to inherit from the parent system.");
public GUIContent emitProbability = EditorGUIUtility.TrTextContent("Emit Probability", "Determines the proportion of sub-emitter spawn events that successfully triggers the associated sub-emitter.");
public GUIContent[] subEmitterTypes = new GUIContent[]
{
EditorGUIUtility.TrTextContent("Birth"),
EditorGUIUtility.TrTextContent("Collision"),
EditorGUIUtility.TrTextContent("Death"),
EditorGUIUtility.TrTextContent("Trigger"),
EditorGUIUtility.TrTextContent("Manual")
};
// Keep in sync with SubModule::InheritedProperties
public string[] propertyTypes =
{
"Color",
"Size",
"Rotation",
"Lifetime",
"Duration"
};
}
private static Texts s_Texts;
ReorderableList m_EmittersList;
static readonly float kSubEmitterPadding = EditorGUIUtility.standardVerticalSpacing * 2;
public SubModuleUI(ParticleSystemUI owner, SerializedObject o, string displayName)
: base(owner, o, "SubModule", displayName)
{
m_ToolTip = L10n.Tr("Sub emission of particles. This allows each particle to emit particles in another system.");
Init(); // Init when created because we need to query if we have any subemitters referenced
}
protected override void Init()
{
// Already initialized?
if (m_SubEmitters != null)
return;
if (s_Texts == null)
s_Texts = new Texts();
m_SubEmitters = GetProperty("subEmitters");
m_EmittersList = new ReorderableList(m_SubEmitters.m_SerializedObject, m_SubEmitters, true, false, true, true);
m_EmittersList.headerHeight = 0;
m_EmittersList.drawElementCallback = DrawSubEmitterElementCallback;
m_EmittersList.elementHeight = kSingleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing * 4 + kSubEmitterPadding * 2;
m_EmittersList.drawElementBackgroundCallback = DrawSubEmitterElementBackgroundCallback;
m_EmittersList.onAddCallback = OnAddSubEmitterElementCallback;
}
void OnAddSubEmitterElementCallback(ReorderableList list)
{
m_SubEmitters.InsertArrayElementAtIndex(m_SubEmitters.arraySize);
SerializedProperty newSubEmitterData = m_SubEmitters.GetArrayElementAtIndex(m_SubEmitters.arraySize - 1);
SerializedProperty newSubEmitter = newSubEmitterData.FindPropertyRelative("emitter");
newSubEmitter.objectReferenceValue = null;
}
static void DrawSubEmitterElementBackgroundCallback(Rect rect, int index, bool isActive, bool isFocused)
{
GUI.Label(rect, GUIContent.none, EditorStyles.helpBox);
ReorderableList.defaultBehaviours.DrawElementBackground(rect, index, isActive, isFocused, true);
}
void DrawSubEmitterElementCallback(Rect rect, int index, bool isActive, bool isFocused)
{
var subEmitterData = m_SubEmitters.GetArrayElementAtIndex(index);
var subEmitter = subEmitterData.FindPropertyRelative("emitter");
var type = subEmitterData.FindPropertyRelative("type");
var properties = subEmitterData.FindPropertyRelative("properties");
var emitProbability = subEmitterData.FindPropertyRelative("emitProbability");
rect.height = kSingleLineHeight;
rect.y += kSubEmitterPadding;
Rect typeRect = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth - EditorGUI.kSpacing, rect.height);
Rect objectRect = new Rect(rect.x + EditorGUIUtility.labelWidth, rect.y, rect.width - EditorGUIUtility.labelWidth - EditorGUI.kSpacing * 3, rect.height);
GUIPopup(typeRect, GUIContent.none, type, s_Texts.subEmitterTypes);
GUIObject(objectRect, GUIContent.none, subEmitter, null);
if (subEmitter.objectReferenceValue == null)
{
Rect buttonRect = new Rect(objectRect.xMax + EditorGUI.kSpacing, rect.y + 4 , ParticleSystemStyles.Get().plus.fixedWidth, rect.height);
if (GUI.Button(buttonRect, s_Texts.create, ParticleSystemStyles.Get().plus))
{
CreateSubEmitter(subEmitter, index, (SubEmitterType)type.intValue);
}
}
rect.y += EditorGUIUtility.standardVerticalSpacing + rect.height;
GUIMask(rect, s_Texts.inherit, properties, s_Texts.propertyTypes);
rect.y += EditorGUIUtility.standardVerticalSpacing + rect.height;
GUIFloat(rect, s_Texts.emitProbability, emitProbability);
}
void CreateSubEmitter(SerializedProperty objectRefProp, int index, SubEmitterType type)
{
GameObject subEmitter = m_ParticleSystemUI.m_ParticleEffectUI.CreateParticleSystem(m_ParticleSystemUI.m_ParticleSystems[0], type);
subEmitter.name = "SubEmitter" + index;
objectRefProp.objectReferenceValue = subEmitter.GetComponent<ParticleSystem>();
}
void Update()
{
if (m_CheckObjectIndex >= 0)
{
// Wait until the ObjectSelector is closed before checking object
if (!ObjectSelector.isVisible)
{
SerializedProperty subEmitterData = m_SubEmitters.GetArrayElementAtIndex(m_CheckObjectIndex);
SerializedProperty subEmitter = subEmitterData.FindPropertyRelative("emitter");
Object obj = subEmitter.objectReferenceValue;
ParticleSystem newSubEmitter = obj as ParticleSystem;
if (newSubEmitter != null)
{
bool validSubemitter = true;
if (ValidateSubemitter(newSubEmitter))
{
string errorMsg = ParticleSystemEffectUtils.CheckCircularReferences(newSubEmitter);
if (errorMsg.Length == 0)
{
// Ok there is no circular references, now check if its a child
if (!CheckIfChild(obj))
validSubemitter = false;
}
else
{
// Circular references detected
string circularRefErrorMsg = string.Format("'{0}' could not be assigned as subemitter on '{1}' due to circular referencing!\nBacktrace: {2} \n\nReference will be removed.", newSubEmitter.gameObject.name, m_ParticleSystemUI.m_ParticleSystems[0].gameObject.name, errorMsg);
EditorUtility.DisplayDialog("Circular References Detected", circularRefErrorMsg, "Ok");
validSubemitter = false;
}
}
else
{
validSubemitter = false;
}
if (!validSubemitter)
{
subEmitter.objectReferenceValue = null; // remove invalid reference
m_ParticleSystemUI.ApplyProperties();
m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint();
}
}
// Cleanup
m_CheckObjectIndex = -1;
EditorApplication.update -= Update;
}
}
}
internal static bool IsChild(ParticleSystem subEmitter, ParticleSystem root)
{
if (subEmitter == null || root == null)
return false;
ParticleSystem subRoot = ParticleSystemEditorUtils.GetRoot(subEmitter);
return subRoot == root;
}
private bool ValidateSubemitter(ParticleSystem subEmitter)
{
if (subEmitter == null)
return false;
ParticleSystem root = ParticleSystemEditorUtils.GetRoot(m_ParticleSystemUI.m_ParticleSystems[0]);
if (root.gameObject.activeInHierarchy && !subEmitter.gameObject.activeInHierarchy)
{
string kReparentText = "The assigned sub emitter is part of a prefab and can therefore not be assigned.";
EditorUtility.DisplayDialog("Invalid Sub Emitter", kReparentText, "Ok");
return false;
}
if (!root.gameObject.activeInHierarchy && subEmitter.gameObject.activeInHierarchy)
{
string kReparentText = "The assigned sub emitter is part of a scene object and can therefore not be assigned to a prefab.";
EditorUtility.DisplayDialog("Invalid Sub Emitter", kReparentText, "Ok");
return false;
}
return true;
}
private bool CheckIfChild(Object subEmitter)
{
ParticleSystem root = ParticleSystemEditorUtils.GetRoot(m_ParticleSystemUI.m_ParticleSystems[0]);
ParticleSystem ps = subEmitter as ParticleSystem;
if (IsChild(ps, root))
{
return true;
}
string kReparentText = string.Format("The assigned sub emitter is not a child of the current root particle system GameObject: '{0}' and is therefore NOT considered a part of the current effect. Do you want to reparent it?", root.gameObject.name);
if (EditorUtility.DisplayDialog(
"Reparent GameObjects",
kReparentText,
"Yes, Reparent",
"No, Remove"))
{
if (EditorUtility.IsPersistent(subEmitter))
{
var newGo = Object.Instantiate(subEmitter) as GameObject;
if (newGo != null)
{
newGo.transform.parent = m_ParticleSystemUI.m_ParticleSystems[0].transform;
newGo.transform.localPosition = Vector3.zero;
newGo.transform.localRotation = Quaternion.identity;
}
}
else
{
if (ps != null)
{
Undo.SetTransformParent(ps.gameObject.transform.transform, m_ParticleSystemUI.m_ParticleSystems[0].transform, "Reparent sub emitter");
}
}
return true;
}
else if (ps != null)
{
// Clear sub-emitters that have been deselected, to avoid having their particles left paused in the Scene View (case 946999)
ps.Clear(true);
}
return false;
}
private List<Object> GetSubEmitterProperties()
{
List<Object> props = new List<Object>();
var enumerator = m_SubEmitters.GetEnumerator();
while (enumerator.MoveNext())
{
SerializedProperty subEmitterData = (SerializedProperty)enumerator.Current;
props.Add(subEmitterData.FindPropertyRelative("emitter").objectReferenceValue);
}
return props;
}
override public void OnInspectorGUI(InitialModuleUI initial)
{
// only allow sub-emitter editing in single edit mode
if (m_ParticleSystemUI.multiEdit)
{
EditorGUILayout.HelpBox("Sub Emitter editing is only available when editing a single Particle System", MessageType.Info, true);
return;
}
// get array of subemitters
List<Object> props = GetSubEmitterProperties();
m_EmittersList.DoLayoutList();
// get new list of subemitters, so we can check for changes
List<Object> props2 = GetSubEmitterProperties();
// validate any new subemitters we assigned
for (int i = 0; i < Mathf.Min(props.Count, props2.Count); i++)
{
if (props[i] != props2[i])
{
if (m_CheckObjectIndex == -1)
EditorApplication.update += Update; // ensure its not added more than once
// We need to let the ObjectSelector finish its SendEvent and therefore delay showing dialog
m_CheckObjectIndex = i;
// Clear sub-emitters that have been deselected, to avoid having their particles left paused in the Scene View (case 946999)
ParticleSystem ps = props[i] as ParticleSystem;
if (ps)
ps.Clear(true);
}
}
}
override public void UpdateCullingSupportedString(ref string text)
{
text += "\nSub Emitters module is enabled.";
}
}
} // namespace UnityEditor
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/billwillman/UnityCsReference.git
git@gitee.com:billwillman/UnityCsReference.git
billwillman
UnityCsReference
UnityCsReference
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /