private void SetDefaultValue(SerializedProperty serializedInput) { Type nodeInputType = SerializedPropertyUtils.GetSerializedPropertyType(serializedInput); NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; //Default Transform nodes to this GameObject's Transform if (nodeInputType == typeof(NodeGraphComponent.TransformInput)) { DynamicTransformRef transformRef = nodeGraphComponent.transform; SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, transformRef); } //Default Material nodes to this GameObject's Renderer's material else if (nodeInputType == typeof(NodeGraphComponent.MaterialInput)) { Renderer renderer = nodeGraphComponent.GetComponent <Renderer>(); if (renderer != null) { DynamicMaterialRef materialRef = DynamicMaterialRef.InstancedMaterialRef(renderer); SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, materialRef); } } //Default GameObject nodes to this GameObject else if (nodeInputType == typeof(NodeGraphComponent.GameObjectInput)) { DynamicGameObjectRef gameObjectRef = nodeGraphComponent.gameObject; SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, gameObjectRef); } }
private string UpdateNewLocalisedStringRef(SerializedProperty property, string key) { LocalisedString localisedString = key; SerializedPropertyUtils.SetSerializedPropertyValue(property, localisedString); return(key); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty assetProp = property.FindPropertyRelative("_asset"); EditorGUI.BeginChangeCheck(); EditorGUI.ObjectField(position, assetProp, label); if (EditorGUI.EndChangeCheck()) { AnimationTextureRef animationTexture = SerializedPropertyUtils.GetSerializedPropertyValue <AnimationTextureRef>(property); animationTexture.UnloadTexture(); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty localisationkeyProperty = property.FindPropertyRelative("_localisationKey"); string localisationkey = localisationkeyProperty.stringValue; float yPos = position.y; Rect foldoutPosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight); property.isExpanded = !EditorGUI.Foldout(foldoutPosition, !property.isExpanded, property.displayName + " (Localised String)"); yPos += EditorGUIUtility.singleLineHeight; if (!property.isExpanded) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Draw list of possible keys int currentKey = 0; { string[] keys = Localisation.GetStringKeys(); for (int i = 0; i < keys.Length; i++) { if (keys[i] == localisationkey) { currentKey = i; break; } } Rect typePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight); yPos += EditorGUIUtility.singleLineHeight; EditorGUI.BeginChangeCheck(); currentKey = EditorGUI.Popup(typePosition, "Localisation Key", currentKey, keys); if (EditorGUI.EndChangeCheck()) { if (currentKey == 0) { localisationkey = UpdateNewLocalisedStringRef(property, null); } else { localisationkey = UpdateNewLocalisedStringRef(property, keys[currentKey]); } } } //Draw button for adding new key if (currentKey == 0) { string[] folders = Localisation.GetStringFolders(); int currentFolderIndex = 0; string keyWithoutFolder; Localisation.GetFolderIndex(localisationkey, out currentFolderIndex, out keyWithoutFolder); float keyTextWidth = position.width - EditorUtils.GetLabelWidth() - (folderNameWidth + buttonSpace + autoKeybuttonWidth + buttonSpace + addButtonWidth); float buttonWidth = autoKeySlashFakeWidth + keyTextWidth + buttonSpace + autoKeybuttonWidth + buttonSpace + addButtonWidth; //Get list of current folder options Rect folderText = new Rect(position.x, yPos, position.width - buttonWidth, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); int newFolderIndex = EditorGUI.Popup(folderText, "New Key", currentFolderIndex, folders); string currentFolder = newFolderIndex == 0 ? "" : folders[newFolderIndex]; if (EditorGUI.EndChangeCheck()) { if (newFolderIndex != 0) { localisationkey = UpdateNewLocalisedStringRef(property, currentFolder + "/" + keyWithoutFolder); } } Rect addKeySlash = new Rect(position.x + (position.width - buttonWidth) - fudge, yPos, autoKeySlashWidth, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(addKeySlash, new GUIContent("/")); Rect addKeyText = new Rect(position.x + (position.width - buttonWidth) - fudge + autoKeySlashFakeWidth, yPos, keyTextWidth + fudge, EditorGUIUtility.singleLineHeight); if (newFolderIndex != 0) { EditorGUI.BeginChangeCheck(); keyWithoutFolder = EditorGUI.TextField(addKeyText, keyWithoutFolder); if (EditorGUI.EndChangeCheck()) { localisationkey = UpdateNewLocalisedStringRef(property, currentFolder + "/" + keyWithoutFolder); } } else { EditorGUI.BeginChangeCheck(); localisationkey = EditorGUI.TextField(addKeyText, localisationkey); if (EditorGUI.EndChangeCheck()) { UpdateNewLocalisedStringRef(property, localisationkey); } } Rect autoKeyButton = new Rect(position.x + (position.width - buttonWidth) + autoKeySlashFakeWidth + buttonSpace + keyTextWidth, yPos, autoKeybuttonWidth, EditorGUIUtility.singleLineHeight); Rect addKeyButton = new Rect(position.x + (position.width - buttonWidth) + autoKeySlashFakeWidth + buttonSpace + keyTextWidth + buttonSpace + autoKeybuttonWidth, yPos, addButtonWidth, EditorGUIUtility.singleLineHeight); yPos += addKeyButton.height; if (GUI.Button(autoKeyButton, "Auto")) { LocalisedStringRef localisedStringRef = SerializedPropertyUtils.GetSerializedPropertyValue <LocalisedStringRef>(property); Component component = property.serializedObject.targetObject as Component; if (component != null) { string parentName = component.gameObject.name; if (component.gameObject.scene.IsValid()) { parentName = component.gameObject.scene.name + "_" + parentName; } localisedStringRef.SetAutoNameParentName(parentName); } localisationkey = UpdateNewLocalisedStringRef(property, localisedStringRef.GetAutoKey()); } if (GUI.Button(addKeyButton, "Add") && !string.IsNullOrEmpty(localisationkey)) { if (!Localisation.Exists(localisationkey)) { Localisation.Set(localisationkey, Localisation.GetCurrentLanguage(), string.Empty); LocalisationEditorWindow.EditString(localisationkey); } } } //Draw displayed text (can be edited to update localization file) { //Only display if have a valid key if (!string.IsNullOrEmpty(localisationkey) && Localisation.Exists(localisationkey)) { string text = StringUtils.GetFirstLine(Localisation.GetRawString(localisationkey)); float height = EditorGUIUtility.singleLineHeight; float labelWidth = EditorUtils.GetLabelWidth(); Rect textPosition = new Rect(position.x + labelWidth + 2.0f, yPos, position.width - labelWidth - 2.0f - editbuttonWidth - buttonSpace, height); EditorGUI.LabelField(textPosition, text, EditorUtils.ReadonlyTextBoxStyle); Rect editTextPosition = new Rect(textPosition.x + textPosition.width + buttonSpace, yPos, editbuttonWidth, EditorGUIUtility.singleLineHeight); if (GUI.Button(editTextPosition, "Edit")) { LocalisationEditorWindow.EditString(localisationkey); } yPos += height; } } EditorGUI.indentLevel = origIndent; } EditorGUI.EndProperty(); }
public override void OnInspectorGUI() { SerializedProperty nameProperty = serializedObject.FindProperty("m_Name"); SerializedProperty animationsProperty = serializedObject.FindProperty("_animationSource"); SerializedProperty animationIdProperty = serializedObject.FindProperty("_animationId"); SerializedProperty animationDurationProperty = serializedObject.FindProperty("_animationDuration"); SerializedProperty animationSpeedProperty = serializedObject.FindProperty("_animationSpeed"); SerializedProperty orientationsProperty = serializedObject.FindProperty("_validOrientations"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(animationsProperty); if (EditorGUI.EndChangeCheck() || _skeletonData == null) { if (animationsProperty.objectReferenceValue != null) { _skeletonData = ((SkeletonDataAsset)(animationsProperty.objectReferenceValue)).GetSkeletonData(false); } else { animationIdProperty.stringValue = null; } } if (_skeletonData != null) { Animation[] animations = _skeletonData.Animations.Items; string[] animationNames = new string[animations.Length]; for (int i = 0; i < animations.Length; i++) { animationNames[i] = animations[i].Name; } int currentIndex = -1; for (int i = 0; i < animationNames.Length; i++) { if (animationNames[i] == animationIdProperty.stringValue) { currentIndex = i; break; } } int index = EditorGUILayout.Popup("Animation", currentIndex == -1 ? 0 : currentIndex, animationNames); if (currentIndex != index) { nameProperty.stringValue = animationNames[index]; animationIdProperty.stringValue = animationNames[index]; animationDurationProperty.doubleValue = animations[index].Duration; } } else { GUI.enabled = false; EditorGUILayout.PropertyField(animationIdProperty); GUI.enabled = true; } EditorGUILayout.PropertyField(animationSpeedProperty); SerializedPropertyUtils.FlagsField(orientationsProperty); serializedObject.ApplyModifiedProperties(); }