bool IsMetalEditorSupportEnabled() { // Versions below 5.6 of Unity don't seem to allow direct access to this asset through // AssetdDatabase.LoadAssetAtPath. AssetDatabase.LoadAllAssetsAtPath, however, does provide // access. To ensure this is setup properly, we use the latter. UnityEngine.Object[] assets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/ProjectSettings.asset"); UnityEngine.Object asset = assets[0]; if (asset == null) { Debug.Log("Error: Can't load Player Settings!"); return(false); } UnityEditor.SerializedObject so = new UnityEditor.SerializedObject(asset); UnityEditor.SerializedProperty metalEditorSupport = so.FindProperty("metalEditorSupport"); if (metalEditorSupport != null) { if (metalEditorSupport.boolValue) { return(metalEditorSupport.boolValue); } } return(false); }
public static StateLayer AddLayer(StateMachine machine, StateLayer layer, UnityEngine.Object parent) { #if UNITY_EDITOR layer.hideFlags = HideFlags.HideInInspector; UnityEditor.SerializedObject parentSerialized = new UnityEditor.SerializedObject(parent); UnityEditor.SerializedObject layerSerialized = new UnityEditor.SerializedObject(layer); UnityEditor.SerializedProperty layersProperty = parentSerialized.FindProperty(parent is StateMachine ? "layers" : "stateReferences"); UnityEditor.SerializedProperty parentProperty = layerSerialized.FindProperty("parentReference"); if (parentProperty.GetValue <UnityEngine.Object>() == null) { parentProperty.SetValue(parent); } layerSerialized.FindProperty("machineReference").SetValue(machine); layerSerialized.ApplyModifiedProperties(); if (!layersProperty.Contains(layer)) { layersProperty.Add(layer); } UpdateLayerStates(machine, layer); #endif return(layer); }
public override void OnGUI(UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) { UnityEditor.EditorGUI.BeginProperty(position, label, property); if (label != null && !string.IsNullOrEmpty(label.text)) { UnityEditor.EditorGUI.LabelField(position, label); position.x += UnityEditor.EditorGUIUtility.labelWidth; position.width -= UnityEditor.EditorGUIUtility.labelWidth; } var indent = UnityEditor.EditorGUI.indentLevel; UnityEditor.EditorGUI.indentLevel = 0; var value = property.FindPropertyRelative("value"); //Since some callback flags are unsupported, some bits are not used. //But when using EditorGUILayout.MaskField, clicking the third flag will set the third bit to one even if the third flag in the AkCallbackType enum is unsupported. //This is a problem because clicking the third supported flag would internally select the third flag in the AkCallbackType enum which is unsupported. //To solve this problem we use a mask for display and another one for the actual callback var displayMask = GetDisplayMask(value.intValue); displayMask = UnityEditor.EditorGUI.MaskField(position, displayMask, SupportedCallbackFlags); value.intValue = GetWwiseCallbackMask(displayMask); UnityEditor.EditorGUI.indentLevel = indent; UnityEditor.EditorGUI.EndProperty(); }
public override bool OnInspectorGUI(UCL_TC_Data tc_data, UnityEditor.SerializedProperty sdata) { { var data = sdata.FindPropertyRelative("m_UCL_Path"); if (data.arraySize == 0) { data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(data.GetArrayElementAtIndex(0), new GUIContent("Path")); } { var data = sdata.FindPropertyRelative("m_Transform"); if (data.arraySize == 0) { data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(data.GetArrayElementAtIndex(0), new GUIContent("Target")); } { var data = sdata.FindPropertyRelative("m_LookAtFront"); if (data.arraySize == 0) { data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(data.GetArrayElementAtIndex(0), new GUIContent("LookAtFront")); } return(true); }
static private float CalculateHeight(UnityEditor.SerializedProperty property) { float height = UnityEditor.EditorGUIUtility.singleLineHeight; property = property.Copy(); UnityEditor.SerializedProperty endProperty = property.GetEndProperty(); bool bHasChildren = property.hasVisibleChildren; if (!bHasChildren) { return(height); } height += 2; bool bEnterChildren = true; while (property.NextVisible(bEnterChildren) && !UnityEditor.SerializedProperty.EqualContents(property, endProperty)) { height += UnityEditor.EditorGUI.GetPropertyHeight(property, true) + 2; bEnterChildren = false; } return(height); }
public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label) { var attr = this.attribute as InspectorDisplayAttribute; var fieldValue = property.FindPropertyRelative(attr.FieldName); UnityEditor.EditorGUI.PropertyField(position, fieldValue, label); }
public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label) { using (new UnityEditor.EditorGUI.DisabledGroupScope(true)) { UnityEditor.EditorGUI.PropertyField(position, property, label); } }
void OnEnable() { m_ShadowAlgorithm = serializedObject.FindProperty("shadowAlgorithm"); m_ShadowVariant = serializedObject.FindProperty("shadowVariant"); m_ShadowData = serializedObject.FindProperty("shadowData"); m_ShadowDatas = serializedObject.FindProperty("shadowDatas"); }
// Gets value from SerializedProperty - even if value is nested public static object GetValue(this UnityEditor.SerializedProperty property) { if (property == null) { return(null); } var path = property.propertyPath.Replace(".Array.data[", "["); object obj = property.serializedObject.targetObject; var elements = path.Split('.'); foreach (var element in elements) { if (element.Contains("[")) { var elementName = element.Substring(0, element.IndexOf("[")); var index = System.Convert.ToInt32(element.Substring(element.IndexOf("[")).Replace("[", "").Replace("]", "")); obj = GetValue_Imp(obj, elementName, index); } else { obj = GetValue_Imp(obj, element); } } return(obj); }
public override void OnGUI(UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) { // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. UnityEditor.EditorGUI.BeginProperty(position, label, property); SetupSerializedProperties(property); // Draw label position = UnityEditor.EditorGUI.PrefixLabel(position, UnityEngine.GUIUtility.GetControlID(UnityEngine.FocusType.Passive), label); /************************************************Update Properties**************************************************/ var componentGuid = new System.Guid[m_guidProperty.Length]; for (var i = 0; i < componentGuid.Length; i++) { var guidBytes = AkUtilities.GetByteArrayProperty(m_guidProperty[i]); componentGuid[i] = guidBytes == null ? System.Guid.Empty : new System.Guid(guidBytes); } var componentName = UpdateIds(componentGuid); /*******************************************************************************************************************/ /********************************************Draw GUI***************************************************************/ var style = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.button); style.alignment = UnityEngine.TextAnchor.MiddleLeft; style.fontStyle = UnityEngine.FontStyle.Normal; if (string.IsNullOrEmpty(componentName)) { SetEmptyComponentName(ref componentName, ref style); } if (UnityEngine.GUI.Button(position, componentName, style)) { m_pressedPosition = position; m_buttonWasPressed = true; // We don't want to set object as dirty only because we clicked the button. // It will be set as dirty if the wwise object has been changed by the tree view. UnityEngine.GUI.changed = false; } var currentEvent = UnityEngine.Event.current; if (currentEvent.type == UnityEngine.EventType.Repaint && m_buttonWasPressed && m_pressedPosition.Equals(position)) { m_serializedObject = property.serializedObject; m_pickerPos = AkUtilities.GetLastRectAbsolute(position); UnityEditor.EditorApplication.delayCall += DelayCreateCall; m_buttonWasPressed = false; } HandleDragAndDrop(currentEvent, position); UnityEditor.EditorGUI.EndProperty(); }
public override float GetPropertyHeight(UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) { var h = 22f + 18f; var list = property.GetSerializedValue <ME.ECS.Collections.DataList <Entity> >(); var world = ME.ECS.Worlds.currentWorld; if (world == null || list.Count == 0) { h += DataListEntityListPropertyEditor.EMPTY_HEIGHT; } else { var i = 0; if (list.IsCreated() == true) { foreach (var item in list.Read()) { var elementLabel = new UnityEngine.GUIContent($"Element {i}"); h += EntityEditor.GetHeight(item, elementLabel); ++i; } } } return(h); }
public void AwakeMe() { if (gameObject.activeInHierarchy) { if (sparseRemove.Length < 10) { System.Array.Resize(ref sparseRemove, 10); } if (sparseRandom.Length < 10) { System.Array.Resize(ref sparseRandom, 10); } for (int i = 0; i < numberOfModifiers; i++) { iteration = i; if (rooftopElements[0] != null) { if (useAdvertising) { bmComponent = gameObject.GetComponent <BuildingModifier>(); roofTopsObject = null; // rooftopHolder = null; if (rooftopHolder[iteration] == null) { rooftopHolder[iteration] = new GameObject(gameObject.transform.name + "_Detail"); #if UNITY_EDITOR if (rooftopHolder[iteration].GetComponent <LODGroup>() == null) { lodComponent = rooftopHolder[iteration].AddComponent <LODGroup>(); UnityEditor.SerializedObject obj = new UnityEditor.SerializedObject(lodComponent); UnityEditor.SerializedProperty valArrProp = obj.FindProperty("m_LODs.Array"); for (int j = 0; valArrProp.arraySize > j; j++) { UnityEditor.SerializedProperty sHeight = obj.FindProperty("m_LODs.Array.data[" + i.ToString() + "].screenRelativeHeight"); if (j == 0) { sHeight.doubleValue = 0.8; } if (j == 1) { sHeight.doubleValue = 0.5; } if (j == 2) { sHeight.doubleValue = 0.1; } } obj.ApplyModifiedProperties(); } #endif } UpdateElements(); } } } } }
private static System.Reflection.FieldInfo GetFieldInfoFromProperty(UnityEditor.SerializedProperty property) { var serializedProperty = property.serializedObject.FindProperty("m_Script"); if (serializedProperty == null) { return(null); } var monoScript = serializedProperty.objectReferenceValue as UnityEditor.MonoScript; if (monoScript == null) { return(null); } var scriptTypeFromProperty = monoScript.GetClass(); if (scriptTypeFromProperty == null) { return(null); } return(GetFieldInfoFromPropertyPath(scriptTypeFromProperty, property.propertyPath)); }
public void OnEnable() { AcousticTexture = serializedObject.FindProperty("AcousticTexture"); EnableDiffraction = serializedObject.FindProperty("EnableDiffraction"); EnableDiffractionOnBoundaryEdges = serializedObject.FindProperty("EnableDiffractionOnBoundaryEdges"); AssociatedRoom = serializedObject.FindProperty("AssociatedRoom"); }
private static bool DisableBuiltInAudio() { UnityEditor.SerializedObject audioSettingsAsset = null; UnityEditor.SerializedProperty disableAudioProperty = null; var assets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/AudioManager.asset"); if (assets.Length > 0) { audioSettingsAsset = new UnityEditor.SerializedObject(assets[0]); } if (audioSettingsAsset != null) { disableAudioProperty = audioSettingsAsset.FindProperty("m_DisableAudio"); } if (disableAudioProperty == null) { return(false); } disableAudioProperty.boolValue = true; audioSettingsAsset.ApplyModifiedProperties(); return(true); }
private void OnEnable() { m_AkGameObject = target as AkGameObj; listeners = serializedObject.FindProperty("m_listeners"); DefaultHandles.Hidden = hideDefaultHandle; }
static public int CreateLayer(string name) { // https://forum.unity.com/threads/adding-layer-by-script.41970/#post-2274824 UnityEditor.SerializedObject tagManager = new UnityEditor.SerializedObject(UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); UnityEditor.SerializedProperty layers = tagManager.FindProperty("layers"); bool ExistLayer = false; for (int i = 8; i < layers.arraySize; i++) { UnityEditor.SerializedProperty layerSP = layers.GetArrayElementAtIndex(i); if (layerSP.stringValue == name) { ExistLayer = true; return(i); } } for (int j = 8; j < layers.arraySize; j++) { UnityEditor.SerializedProperty layerSP = layers.GetArrayElementAtIndex(j); if (layerSP.stringValue == "" && !ExistLayer) { layerSP.stringValue = name; tagManager.ApplyModifiedProperties(); return(j); } } return(0); }
private void OnEnable() { ShowDescription = serializedObject.FindProperty("ShowDescription"); Description = serializedObject.FindProperty("Description"); OnDeactive = serializedObject.FindProperty("OnDeactive"); OnActive = serializedObject.FindProperty("OnActive"); }
static void WriteEntry(UnityEditor.SerializedProperty spAxes, InputManagerEntry entry) { if (InputAlreadyRegistered(entry.name, entry.kind, spAxes)) { return; } spAxes.InsertArrayElementAtIndex(spAxes.arraySize); var spAxis = spAxes.GetArrayElementAtIndex(spAxes.arraySize - 1); spAxis.FindPropertyRelative("m_Name").stringValue = entry.name; spAxis.FindPropertyRelative("descriptiveName").stringValue = entry.desc; spAxis.FindPropertyRelative("negativeButton").stringValue = entry.btnNegative; spAxis.FindPropertyRelative("altNegativeButton").stringValue = entry.altBtnNegative; spAxis.FindPropertyRelative("positiveButton").stringValue = entry.btnPositive; spAxis.FindPropertyRelative("altPositiveButton").stringValue = entry.altBtnPositive; spAxis.FindPropertyRelative("gravity").floatValue = entry.gravity; spAxis.FindPropertyRelative("dead").floatValue = entry.deadZone; spAxis.FindPropertyRelative("sensitivity").floatValue = entry.sensitivity; spAxis.FindPropertyRelative("snap").boolValue = entry.snap; spAxis.FindPropertyRelative("invert").boolValue = entry.invert; spAxis.FindPropertyRelative("type").intValue = (int)entry.kind; spAxis.FindPropertyRelative("axis").intValue = (int)entry.axis; spAxis.FindPropertyRelative("joyNum").intValue = (int)entry.joystick; }
private void OnEnable() { m_AkRadialEmitter = target as AkRadialEmitter; outerRadius = serializedObject.FindProperty("outerRadius"); innerRadius = serializedObject.FindProperty("innerRadius"); }
public override void OnPropertyDrawer(UnityEditor.SerializedProperty prop) { if (editorContent == null || string.IsNullOrEmpty(editorContent.text)) { var name = UnityEditor.ObjectNames.NicifyVariableName(FieldName); editorContent = new GUIContent(name); } Type type; if (FieldType.StartsWith("CS.")) { var typeName = FieldType.Substring(3); type = String2TypeCache.GetType(typeName); } else { type = typeof(LuaBinding); } UnityEditor.EditorGUI.BeginChangeCheck(); UnityEditor.EditorGUILayout.ObjectField(prop, type, editorContent); if (UnityEditor.EditorGUI.EndChangeCheck()) { var path = UnityEditor.AssetDatabase.GetAssetPath(prop.objectReferenceValue); if (string.IsNullOrEmpty(path)) { return; } UnityEditor.EditorUtility.DisplayDialog("ERROR", $"{FieldName} should use AssetReference to a non scene object!", "OK"); prop.objectReferenceValue = null; } }
public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label) { UnityEditor.EditorGUI.BeginProperty(position, label, property); position = UnityEditor.EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); int indent = UnityEditor.EditorGUI.indentLevel; UnityEditor.EditorGUI.indentLevel = 0; Rect valueRect = new Rect(position.x, position.y, 75, position.height); Rect variableRect = new Rect(position.x + 75, position.y, position.width - 75, position.height); GUI.enabled = false; UnityEngine.Object obj = property.FindPropertyRelative("_variable").objectReferenceValue; UnityEditor.SerializedObject variable = obj == null ? null : new UnityEditor.SerializedObject(obj); if (variable != null) { UnityEditor.EditorGUI.PropertyField(valueRect, variable.FindProperty("_value"), GUIContent.none); } else { UnityEditor.EditorGUI.TextField(valueRect, ""); } GUI.enabled = true; UnityEditor.EditorGUI.PropertyField(variableRect, property.FindPropertyRelative("_variable"), GUIContent.none); UnityEditor.EditorGUI.indentLevel = indent; UnityEditor.EditorGUI.EndProperty(); }
public void DestroyHardwarePlayer() { if (_hardwarePlayer == null) { return; } // Get SerializedProperty objects UnityEditor.SerializedObject serializedObject = GetSerializedObject(); serializedObject.Update(); UnityEditor.SerializedProperty hardwarePlayerProperty = serializedObject.FindProperty("_hardwarePlayer"); if (UnityEditor.EditorUtility.DisplayDialog("Heyo, be careful here!", "Is it cool if I destroy the [Camera Rig] instance to make room for a shiny new one?\r\n\r\nAll of your scripts /should/ be on \"Player (Hardware)\", but rules are made to be broken right?\r\n\r\nIf you put some custom stuff on [Camera Rig], that's cool, I won't judge, but hit \"Leave in Place\" to keep it in the scene, otherwise, hit \"Destroy!\" bb.", "Destroy!", "Leave in Place")) { _hardwarePlayer.DestroyDependencies(); DestroyImmediate(_hardwarePlayer); } else { _hardwarePlayer.DisableDependencies(); _hardwarePlayer.enabled = false; } hardwarePlayerProperty.objectReferenceValue = null; // Apply Changes serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnPropertyField(UnityEditor.SerializedProperty property, GUIContent label) { GUILayout.BeginHorizontal(); base.OnPropertyField(property, label); GUILayout.Label(property.boolValue.ToString()); GUILayout.EndHorizontal(); }
public static Matrix4x4 GetMatrix4x4Value(this UnityEditor.SerializedProperty property) { Matrix4x4 matrix = new Matrix4x4(); matrix.m00 = property.FindPropertyRelative("e00").floatValue; matrix.m01 = property.FindPropertyRelative("e01").floatValue; matrix.m02 = property.FindPropertyRelative("e02").floatValue; matrix.m03 = property.FindPropertyRelative("e03").floatValue; matrix.m10 = property.FindPropertyRelative("e10").floatValue; matrix.m11 = property.FindPropertyRelative("e11").floatValue; matrix.m12 = property.FindPropertyRelative("e12").floatValue; matrix.m13 = property.FindPropertyRelative("e13").floatValue; matrix.m20 = property.FindPropertyRelative("e20").floatValue; matrix.m21 = property.FindPropertyRelative("e21").floatValue; matrix.m22 = property.FindPropertyRelative("e22").floatValue; matrix.m23 = property.FindPropertyRelative("e23").floatValue; matrix.m30 = property.FindPropertyRelative("e30").floatValue; matrix.m31 = property.FindPropertyRelative("e31").floatValue; matrix.m32 = property.FindPropertyRelative("e32").floatValue; matrix.m33 = property.FindPropertyRelative("e33").floatValue; return(matrix); }
public override void OnGUI(UnityEngine.Rect position, UnityEditor.SerializedProperty serializedProperty, UnityEngine.GUIContent label) { label.text = serializedProperty.displayName; UnityEditor.EditorGUI.BeginDisabledGroup(true); UnityEditor.EditorGUI.PropertyField(position, serializedProperty, label, false); UnityEditor.EditorGUI.EndDisabledGroup(); // Don't allow Self Assigning when the editor is playing if (UnityEngine.Application.isPlaying == true) { return; } // Don't allow Self Assigning when more than one gameObject is selected if (UnityEditor.Selection.gameObjects.Length != 1) { return; } var _flattenObjectNameRegex = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]"); var _matchComponentNameRegex = new System.Text.RegularExpressions.Regex(@"PPtr<\$(.*?)>"); var _selfReference = (Referenced)attribute; var _selfTransform = ((UnityEngine.MonoBehaviour)serializedProperty.serializedObject.targetObject).transform; var _childTransforms = _selfTransform.GetComponentsInChildren <UnityEngine.Transform> (true); var _targetGameObjectName = _flattenObjectNameRegex.Replace(serializedProperty.name, "").ToLower().Trim(); var _targetTypeName = _matchComponentNameRegex.Match(serializedProperty.type).Groups[1].Value; // Clear the object reference serializedProperty.objectReferenceValue = null; // Loop all the children foreach (var _childTransform in _childTransforms) { var _childGameObjectName = _flattenObjectNameRegex.Replace(_childTransform.gameObject.name, "").ToLower().Trim(); // Match if we're looking at the right object if (_childGameObjectName != _targetGameObjectName) { continue; } // Get the object reference if (_targetTypeName == "GameObject") { serializedProperty.objectReferenceValue = _childTransform.gameObject; } else if (_targetTypeName == "Transform") { serializedProperty.objectReferenceValue = _childTransform; } else // Just try to get the component { serializedProperty.objectReferenceValue = _childTransform.GetComponent(_targetTypeName); } // Our job is done :) return; } }
public void OnEnable(UnityEditor.SerializedProperty m_Rotation, UnityEngine.GUIContent label) { if (__OnEnable_0_2 == null) { __OnEnable_0_2 = (Action <UnityEditor.SerializedProperty, UnityEngine.GUIContent>)Delegate.CreateDelegate(typeof(Action <UnityEditor.SerializedProperty, UnityEngine.GUIContent>), m_instance, UnityTypes.UnityEditor_TransformRotationGUI.GetMethod("OnEnable", R.InstanceMembers, null, new Type[] { typeof(UnityEditor.SerializedProperty), typeof(UnityEngine.GUIContent) }, null)); } __OnEnable_0_2(m_Rotation, label); }
protected void SetEnable() { value = serializedObject.FindProperty("value"); Description = serializedObject.FindProperty("Description"); editDescription = serializedObject.FindProperty("editDescription"); Index = serializedObject.FindProperty("ID"); ShowEvents = serializedObject.FindProperty("ShowEvents"); }
public override void OnGUI(Rect rect, UnityEditor.SerializedProperty prop, GUIContent label) { bool wasEnabled = GUI.enabled; GUI.enabled = false; UnityEditor.EditorGUI.PropertyField(rect, prop); GUI.enabled = wasEnabled; }
void OnEnable() { m_ShadowAlgorithm = serializedObject.FindProperty("shadowAlgorithm"); m_ShadowVariant = serializedObject.FindProperty("shadowVariant"); m_ShadowCascadeCount = serializedObject.FindProperty("shadowCascadeCount"); m_ShadowCascadeRatios = serializedObject.FindProperty("shadowCascadeRatios"); m_ShadowCascadeBorders = serializedObject.FindProperty("shadowCascadeBorders"); }