private IAssetValue GetUnitySerializedPresentation(UnityPresentationType presentationType, object value) { if (presentationType == UnityPresentationType.Bool && value is bool b) { return(b ? new AssetSimpleValue("1") : new AssetSimpleValue("0")); } if (presentationType == UnityPresentationType.ScriptableObject && value == null) { return(new AssetReferenceValue(new LocalReference(0, 0))); } if (presentationType == UnityPresentationType.FileId && value == null) { return(new AssetReferenceValue(new LocalReference(0, 0))); } if ((presentationType == UnityPresentationType.OtherSimple || presentationType == UnityPresentationType.Bool) && value == null) { return(new AssetSimpleValue("0")); } if (value == null) { return(new AssetSimpleValue(string.Empty)); } return(new AssetSimpleValue(value.ToString())); }
private string GetRiderPresentation(UnityPresentationType unityPresentationType, string unityValue, IType enumType, IPsiModule psiModule) { if (unityPresentationType == UnityPresentationType.Bool) { if (unityValue.Equals("0")) { return("\"false\""); } return("\"true\""); } if (unityPresentationType == UnityPresentationType.Enum) { if (!int.TryParse(unityValue, out var result)) { return("..."); } var @enum = enumType.GetTypeElement() as IEnum; var enumMemberType = @enum?.EnumMembers.FirstOrDefault()?.ConstantValue.Type; if (enumMemberType == null) { return("..."); } var enumMembers = CSharpEnumUtil.CalculateEnumMembers(new ConstantValue(result, enumMemberType), @enum); return(string.Join(" | ", enumMembers.Select(t => t.ShortName))); } return($"\"{unityValue ?? "..." }\""); }
private bool IsSameWithInitializer(MonoBehaviourPropertyValue value, UnityPresentationType type, object initValue) { if (value is MonoBehaviourReferenceValue referenceValue) { var fileId = referenceValue.Reference; if (initValue == null && fileId.IsNullReference) { return(true); } return(false); } if (value is MonoBehaviourPrimitiveValue primitiveValue) { if (type == UnityPresentationType.Bool) { if (initValue == null && primitiveValue.PrimitiveValue.Equals("0")) { return(true); } if (initValue == null) { return(false); } if (initValue.Equals(true) && primitiveValue.PrimitiveValue.Equals("1")) { return(true); } if (initValue.Equals(false) && primitiveValue.PrimitiveValue.Equals("0")) { return(true); } return(false); } if (type == UnityPresentationType.String) { if (initValue == null && primitiveValue.PrimitiveValue.Equals(String.Empty)) { return(true); } } return(primitiveValue.PrimitiveValue.Equals(initValue?.ToString())); } return(false); }
private string GetPresentation(MonoBehaviourPropertyValueWithLocation monoBehaviourPropertyValueWithLocation, UnityPresentationType unityPresentationType, IType enumType, ISolution solution, IPsiModule psiModule, bool showOwner) { string baseResult; if (monoBehaviourPropertyValueWithLocation.Value is MonoBehaviourPrimitiveValue) { baseResult = GetRiderPresentation(unityPresentationType, monoBehaviourPropertyValueWithLocation.GetSimplePresentation(solution), enumType, psiModule); } else { baseResult = monoBehaviourPropertyValueWithLocation.GetSimplePresentation(solution); } if (showOwner) { baseResult += " in " + monoBehaviourPropertyValueWithLocation.GetOwnerPresentation(solution); } return(baseResult); }
private object GetUnitySerializedPresentation(UnityPresentationType presentationType, object value) { if (presentationType == UnityPresentationType.Bool && value is bool b) { return(b ? "1" : "0"); } if (presentationType == UnityPresentationType.FileId && value == null) { return(FileID.Null); } if ((presentationType == UnityPresentationType.OtherSimple || presentationType == UnityPresentationType.Bool) && value == null) { return("0"); } if (value == null) { return(string.Empty); } return(value.ToString()); }
private bool ShouldShowUnknownPresentation(UnityPresentationType presentationType) { return(presentationType == UnityPresentationType.Other || presentationType == UnityPresentationType.ValueType); }