void OnGUI() { selectedTag = EditorGUI.TagField(new Rect(3, 3, 300, 20), "New Tag:", selectedTag); selectedLayer = EditorGUI.LayerField(new Rect(3, 30,300, 20), "New Layer:", selectedLayer); selectedFlags = (StaticEditorFlags)EditorGUI.EnumMaskField(new Rect(3, 60 ,300,20), "Select Mask:", selectedFlags); if (Selection.transforms.Length != 0) { if (GUI.Button(new Rect(400, 3, 150, 20), "Change Tags")) SetTag(selectedTag); if (GUI.Button(new Rect(400, 30, 150, 20), "Change Layers")) { SetLayer(selectedLayer); } if (GUI.Button(new Rect(400, 60, 150, 20), "Change Flags")) { SetMask(selectedFlags); } } }
private static bool ShowMixedStaticEditorFlags(StaticEditorFlags mask) { uint num1 = 0; uint num2 = 0; foreach (object obj in Enum.GetValues(typeof (StaticEditorFlags))) { ++num2; if ((mask & (StaticEditorFlags) obj) > (StaticEditorFlags) 0) ++num1; } if (num1 > 0U) return (int) num1 != (int) num2; return false; }
public static extern void SetStaticEditorFlags(GameObject go, StaticEditorFlags flags);
public UTStaticFlagFilter(StaticEditorFlags[] staticFlags) { this.staticFlags = staticFlags; }
private static bool ShowMixedStaticEditorFlags(StaticEditorFlags mask) { uint num = 0; uint num2 = 0; IEnumerator enumerator = Enum.GetValues(typeof(StaticEditorFlags)).GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.Current; num2++; if ((mask & ((StaticEditorFlags) current)) > 0) { num++; } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } return ((num > 0) && (num != num2)); }
private static bool ShowMixedStaticEditorFlags(StaticEditorFlags mask) { uint num = 0u; uint num2 = 0u; foreach (object current in Enum.GetValues(typeof(StaticEditorFlags))) { num2 += 1u; if ((mask & (StaticEditorFlags)((int)current)) > (StaticEditorFlags)0) { num += 1u; } } return num > 0u && num != num2; }
public override void OnInspectorGUI(Terrain terrain, IOnInspectorGUI editContext) { LoadTreeIcons(terrain); // Tree picker GUI.changed = false; ShowUpgradeTreePrototypeScaleUI(terrain); GUILayout.Label(Styles.trees, EditorStyles.boldLabel); selectedTree = TerrainInspector.AspectSelectionGridImageAndText(selectedTree, m_TreeContents, 64, Styles.noTreesDefined, out var doubleClick); if (selectedTree >= m_TreeContents.Length) { selectedTree = PaintTreesTool.kInvalidTree; } if (doubleClick) { TerrainTreeContextMenus.EditTree(new MenuCommand(terrain, selectedTree)); GUIUtility.ExitGUI(); } GUILayout.BeginHorizontal(); using (new EditorGUI.DisabledScope(selectedTree == PaintTreesTool.kInvalidTree)) { if (GUILayout.Button(Styles.massPlaceTrees)) { TerrainMenus.MassPlaceTrees(); } } GUILayout.FlexibleSpace(); TerrainInspector.MenuButton(Styles.editTrees, "CONTEXT/TerrainEngineTrees", terrain, selectedTree); TerrainInspector.ShowRefreshPrototypes(); GUILayout.EndHorizontal(); GUILayout.Label(TerrainInspector.styles.settings, EditorStyles.boldLabel); // Placement distance brushSize = TerrainInspectorUtility.PowerSlider(TerrainInspector.styles.brushSize, brushSize, 1, Mathf.Min(terrain.terrainData.size.x, terrain.terrainData.size.z), 4.0f); float oldDens = (3.3f - spacing) / 3f; float newDens = TerrainInspectorUtility.ScaledSliderWithRounding(Styles.treeDensity, oldDens, 0.1f, 1.0f, 100.0f, 1.0f); // Only set spacing when value actually changes. Otherwise // it will lose precision because we're constantly doing math // back and forth with it. if (newDens != oldDens) { spacing = (1.1f - newDens) * 3f; } GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.Label(Styles.treeHeight, GUILayout.Width(EditorGUIUtility.labelWidth - 6)); GUILayout.Label(Styles.treeHeightRandomLabel, GUILayout.ExpandWidth(false)); allowHeightVar = GUILayout.Toggle(allowHeightVar, Styles.treeHeightRandomToggle, GUILayout.ExpandWidth(false)); if (allowHeightVar) { EditorGUI.BeginChangeCheck(); float min = treeHeight * (1.0f - treeHeightVariation); float max = treeHeight * (1.0f + treeHeightVariation); EditorGUILayout.MinMaxSlider(ref min, ref max, 0.01f, 2.0f); if (EditorGUI.EndChangeCheck()) { treeHeight = (min + max) * 0.5f; treeHeightVariation = (max - min) / (min + max); } } else { treeHeight = EditorGUILayout.Slider(treeHeight, 0.01f, 2.0f); treeHeightVariation = 0.0f; } GUILayout.EndHorizontal(); GUILayout.Space(5); lockWidthToHeight = EditorGUILayout.Toggle(Styles.lockWidthToHeight, lockWidthToHeight); GUILayout.Space(5); using (new EditorGUI.DisabledScope(lockWidthToHeight)) { GUILayout.BeginHorizontal(); GUILayout.Label(Styles.treeWidth, GUILayout.Width(EditorGUIUtility.labelWidth - 6)); GUILayout.Label(Styles.treeWidthRandomLabel, GUILayout.ExpandWidth(false)); allowWidthVar = GUILayout.Toggle(allowWidthVar, Styles.treeWidthRandomToggle, GUILayout.ExpandWidth(false)); if (allowWidthVar) { EditorGUI.BeginChangeCheck(); float min = treeWidth * (1.0f - treeWidthVariation); float max = treeWidth * (1.0f + treeWidthVariation); EditorGUILayout.MinMaxSlider(ref min, ref max, 0.01f, 2.0f); if (EditorGUI.EndChangeCheck()) { treeWidth = (min + max) * 0.5f; treeWidthVariation = (max - min) / (min + max); } } else { treeWidth = EditorGUILayout.Slider(treeWidth, 0.01f, 2.0f); treeWidthVariation = 0.0f; } GUILayout.EndHorizontal(); } if (selectedTree == PaintTreesTool.kInvalidTree) { return; } GUILayout.Space(5); GameObject prefab = terrain.terrainData.treePrototypes[selectedTree].m_Prefab; string treePrototypeWarning; terrain.terrainData.treePrototypes[selectedTree].Validate(out treePrototypeWarning); bool isLodTreePrototype = TerrainEditorUtility.IsLODTreePrototype(prefab); using (new EditorGUI.DisabledScope(!isLodTreePrototype)) { randomRotation = EditorGUILayout.Toggle(Styles.treeRotation, randomRotation); } if (!isLodTreePrototype) { EditorGUILayout.HelpBox(Styles.treeRotationDisabled.text, MessageType.Info); } if (!string.IsNullOrEmpty(treePrototypeWarning)) { EditorGUILayout.HelpBox(treePrototypeWarning, MessageType.Warning); } // TODO: we should check if the shaders assigned to this 'tree' support _TreeInstanceColor or not.. complicated check though treeColorAdjustment = EditorGUILayout.Slider(Styles.treeColorVar, treeColorAdjustment, 0, 1); if (prefab != null) { StaticEditorFlags staticEditorFlags = GameObjectUtility.GetStaticEditorFlags(prefab); bool contributeGI = (staticEditorFlags & StaticEditorFlags.ContributeGI) != 0; using (new EditorGUI.DisabledScope(true)) // Always disabled, because we don't want to edit the prefab. contributeGI = EditorGUILayout.Toggle(Styles.treeContributeGI, contributeGI); } }
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "MeshRenderer"); json.AddField("data", data); MeshFilter meshFilter = renderer.gameObject.GetComponent <MeshFilter>(); if (meshFilter != null && meshFilter.sharedMesh != null) { Mesh mesh = meshFilter.sharedMesh; WXMesh meshConverter = new WXMesh(mesh); string meshPath = meshConverter.Export(context.preset); data.AddField("mesh", meshPath); context.AddResource(meshPath); } else { ErrorUtil.ExportErrorReporter.create() .setGameObject(renderer.gameObject) .setHierarchyContext(context) .error(0, "Mesh资源转换失败,没法拿到对应的MeshFilter或者它上面的mesh"); } JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY); Material[] materials = renderer.sharedMaterials; foreach (Material material in materials) { if (material != null) { WXMaterial materialConverter = new WXMaterial(material, renderer); string materialPath = materialConverter.Export(context.preset); materialArray.Add(materialPath); context.AddResource(materialPath); } } data.AddField("materials", materialArray); int lightmapIndex = renderer.lightmapIndex; JSONObject litmapScaleArr = new JSONObject(JSONObject.Type.ARRAY); data.AddField("lightMapScaleOffset", litmapScaleArr); litmapScaleArr.Add(renderer.lightmapScaleOffset.x); litmapScaleArr.Add(renderer.lightmapScaleOffset.y); litmapScaleArr.Add(renderer.lightmapScaleOffset.z); litmapScaleArr.Add(renderer.lightmapScaleOffset.w); data.AddField("lightMapIndex", lightmapIndex); ShadowCastingMode mode = renderer.shadowCastingMode; StaticEditorFlags shadowFlags = GameObjectUtility.GetStaticEditorFlags(renderer.gameObject); if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0) { data.AddField("castShadow", false); } else { data.AddField("castShadow", true); } bool receiveShadow = renderer.receiveShadows; data.AddField("receiveShadow", receiveShadow); return(json); }
/// <summary> /// 是否包含<see cref="StaticEditorFlags"/> /// </summary> public static bool HasStaticEditorFlag(GameObject gameObject, StaticEditorFlags flag) { return((GameObjectUtility.GetStaticEditorFlags(gameObject) & flag) != 0); }
/// <summary> /// Returns true if GameObject contains flags. /// </summary> /// <param name="go"></param> /// <param name="flags"></param> /// <returns></returns> internal static bool HasStaticFlag(this GameObject go, StaticEditorFlags flags) { return((GameObjectUtility.GetStaticEditorFlags(go) & flags) == flags); }
// DRAW public override void layout(GameObject gameObject, QObjectList objectList, ref Rect rect) { rect.x -= 14; rect.width = 14; staticFlags = GameObjectUtility.GetStaticEditorFlags(gameObject); }
public static extern bool AreStaticEditorFlagsSet(GameObject go, StaticEditorFlags flags);
public static extern void SetStaticEditorFlags(GameObject go, StaticEditorFlags flags);
void SetMask(StaticEditorFlags value) { foreach (var go in Selection.gameObjects) { GameObjectUtility.SetStaticEditorFlags(go, value); } }
// private static void SetEditorFlagsWithBounds(StaticEditorFlags editorFlags, GameObject target) // { // Bounds occluderBounds = target.GetComponent<MeshRenderer>().bounds; // foreach(pb_Object pb in GameObject.FindObjectsOfType(typeof(pb_Object))) // { // if(occluderBounds.Contains(pb.gameObject.transform.position)) // { // GameObjectUtility.SetStaticEditorFlags(pb.gameObject, editorFlags); // } // } // } private static void SetEditorFlags(StaticEditorFlags editorFlags, GameObject target) { GameObjectUtility.SetStaticEditorFlags(target, editorFlags); }
public static extern bool AreStaticEditorFlagsSet(GameObject go, StaticEditorFlags flags);
protected override JSONObject ToJSON(WXHierarchyContext context) { JSONObject json = new JSONObject(JSONObject.Type.OBJECT); JSONObject data = new JSONObject(JSONObject.Type.OBJECT); json.AddField("type", "TrailRenderer"); json.AddField("data", data); data.AddField("active", renderer.enabled); JSONObject materialArray = new JSONObject(JSONObject.Type.ARRAY); Material[] materials = renderer.sharedMaterials; foreach (Material material in materials) { WXMaterial materialConverter = new WXMaterial(material, renderer); string materialPath = materialConverter.Export(context.preset); materialArray.Add(materialPath); context.AddResource(materialPath); } data.AddField("materials", materialArray); ShadowCastingMode mode = renderer.shadowCastingMode; StaticEditorFlags shadowFlags = GameObjectUtility.GetStaticEditorFlags(renderer.gameObject); #if UNITY_2019_2_OR_NEWER if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.ContributeGI) != 0) #else if (mode == ShadowCastingMode.Off || (shadowFlags & StaticEditorFlags.LightmapStatic) != 0) #endif { data.AddField("castShadow", false); } else { data.AddField("castShadow", true); } bool receiveShadow = renderer.receiveShadows; data.AddField("receiveShadow", receiveShadow); int alignmentNum = 0; #if UNITY_2017_1_OR_NEWER LineAlignment alignment = renderer.alignment; switch (alignment) { case LineAlignment.View: alignmentNum = 0; break; #if UNITY_2018_2_OR_NEWER case LineAlignment.TransformZ: alignmentNum = 1; break; #else case LineAlignment.Local: alignmentNum = 1; break; #endif } data.AddField("alignment", alignmentNum); #endif Color startColor = renderer.startColor; data.AddField("startColor", parseColor(startColor)); Color endColor = renderer.endColor; data.AddField("endColor", parseColor(endColor)); float startWidth = renderer.startWidth; data.AddField("startWidth", startWidth); float endWidth = renderer.endWidth; data.AddField("endWidth", endWidth); float time = renderer.time; data.AddField("time", time); LineTextureMode textureMode = renderer.textureMode; int textureModeNum = 0; switch (textureMode) { case LineTextureMode.Stretch: textureModeNum = 0; break; case LineTextureMode.Tile: textureModeNum = 1; break; } data.AddField("textureMode", textureModeNum); data.AddField("numCapVertices", renderer.numCapVertices); data.AddField("numCornerVertices", renderer.numCornerVertices); data.AddField("minVertexDistance", renderer.minVertexDistance); data.AddField("gColor", GetGradientColor(renderer.colorGradient)); data.AddField("widthCurve", GetCurveData(renderer.widthCurve)); data.AddField("widthMultiplier", renderer.widthMultiplier); return(json); }