public static bool CanPasteToTarget(CollectableScriptableObject target) { if (source == null) { return(false); } return(target.GetType() == source.GetType()); }
private AdvancedDropdownItem GetOrCreateDropdownItemForType(AdvancedDropdownItem root, CollectableScriptableObject collectionItem) { AdvancedDropdownItem item = root.children.FirstOrDefault(dropdownItem => dropdownItem.name.Equals(collectionItem.GetType().Name, StringComparison.Ordinal)); if (item == null) { item = new AdvancedDropdownItem(collectionItem.GetType().Name); root.AddChild(item); } return(item); }
protected override AdvancedDropdownItem BuildRoot() { Type collectableType = collection.GetCollectionType(); AdvancedDropdownItem root = new AdvancedDropdownItem(collectableType.Name); root.AddChild(new AdvancedDropdownItem("None")); for (int i = 0; i < collection.Count; i++) { CollectableScriptableObject collectionItem = collection[i]; if (collectionItem.GetType() == collectableType) { root.AddChild(new CollectableDropdownItem(collectionItem)); } else { AdvancedDropdownItem parent = GetOrCreateDropdownItemForType(root, collectionItem); parent.AddChild(new CollectableDropdownItem(collectionItem)); } } return(root); }
private static void WriteDirectAccessCollectionStatic(ScriptableObjectCollection collection, StreamWriter writer, ref int indentation) { bool isGeneratingCustomStaticFile = ScriptableObjectCollectionSettings.Instance.IsGeneratingCustomStaticFile(collection); string cachedValuesName = "values"; AppendLine(writer, indentation, $"private static {collection.GetType().Name} {cachedValuesName};"); for (int i = 0; i < collection.Items.Count; i++) { CollectableScriptableObject collectionItem = collection.Items[i]; AppendLine(writer, indentation, $"private static {collectionItem.GetType().Name} {collectionItem.name.Sanitize().FirstToLower()};"); } AppendLine(writer, indentation); string valuesName = $"Values"; if (!isGeneratingCustomStaticFile) { AppendLine(writer, indentation, $"public static {collection.GetType().Name} {valuesName}"); } else { AppendLine(writer, indentation, $"public static {collection.GetType().Name} {valuesName}"); } AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, "get"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"if ({cachedValuesName} == null)"); indentation++; AppendLine(writer, indentation, $"{cachedValuesName} = ({collection.GetType()})CollectionsRegistry.Instance.GetCollectionByGUID(\"{collection.GUID}\");"); indentation--; AppendLine(writer, indentation, $"return {cachedValuesName};"); indentation--; AppendLine(writer, indentation, "}"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); AppendLine(writer, indentation); for (int i = 0; i < collection.Items.Count; i++) { CollectableScriptableObject collectionItem = collection.Items[i]; string collectionNameFirstUpper = collectionItem.name.Sanitize().FirstToUpper(); string privateStaticName = collectionItem.name.Sanitize().FirstToLower(); AppendLine(writer, indentation, $"public static {collectionItem.GetType().Name} {collectionNameFirstUpper}"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, "get"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"if ({privateStaticName} == null)"); indentation++; AppendLine(writer, indentation, $"{privateStaticName} = ({collectionItem.GetType().Name}){valuesName}.GetCollectableByGUID(\"{collectionItem.GUID}\");"); indentation--; AppendLine(writer, indentation, $"return {privateStaticName};"); indentation--; AppendLine(writer, indentation, "}"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); } }
private static void WriteTryGetAccessCollectionStatic(ScriptableObjectCollection collection, StreamWriter writer, ref int indentation) { string cachedValuesName = $"values"; string valuesName = $"Values"; string tryGetValuesName = $"TryGet{valuesName}"; AppendLine(writer, indentation, $"private static {collection.GetType().Name} {cachedValuesName};"); for (int i = 0; i < collection.Items.Count; i++) { CollectableScriptableObject collectionItem = collection.Items[i]; AppendLine(writer, indentation, $"private static {collectionItem.GetType().Name} {collectionItem.name.Sanitize().FirstToLower()};"); } AppendLine(writer, indentation); AppendLine(writer, indentation, $"public static bool {tryGetValuesName}(out {collection.GetType().Name} result)"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"if ({cachedValuesName} != null)"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"result = {cachedValuesName};"); AppendLine(writer, indentation, "return true;"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); AppendLine(writer, indentation, $"if (!CollectionsRegistry.Instance.TryGetCollectionByGUID(\"{collection.GUID}\", out ScriptableObjectCollection resultCollection))"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"result = {cachedValuesName};"); AppendLine(writer, indentation, "return false;"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); AppendLine(writer, indentation, $"{cachedValuesName} = ({collection.GetType().Name}) resultCollection;"); AppendLine(writer, indentation, $"result = {cachedValuesName};"); AppendLine(writer, indentation, $"return true;"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); for (int i = 0; i < collection.Items.Count; i++) { CollectableScriptableObject collectionItem = collection.Items[i]; string pascalizedItemName = collectionItem.name.Sanitize().FirstToUpper(); string camelizedItemName = collectionItem.name.Sanitize().FirstToLower(); Type itemType = collectionItem.GetType(); AppendLine(writer, indentation, $"public static bool TryGet{pascalizedItemName}(out {itemType.Name} result)"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"if ({camelizedItemName} != null)"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, $"result = {camelizedItemName};"); AppendLine(writer, indentation, "return true;"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); AppendLine(writer, indentation, $"if (!{tryGetValuesName}(out {collection.GetType().Name} collectionResult))"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, "result = null;"); AppendLine(writer, indentation, "return false;"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); AppendLine(writer, indentation, $"if (!collectionResult.TryGetCollectableByGUID(\"{collectionItem.GUID}\", out CollectableScriptableObject resultCollectable))"); AppendLine(writer, indentation, "{"); indentation++; AppendLine(writer, indentation, "result = null;"); AppendLine(writer, indentation, "return false;"); indentation--; AppendLine(writer, indentation); AppendLine(writer, indentation, "}"); AppendLine(writer, indentation, $"{camelizedItemName} = ({itemType.Name}) resultCollectable;"); AppendLine(writer, indentation, $"result = {camelizedItemName};"); AppendLine(writer, indentation, "return true;"); indentation--; AppendLine(writer, indentation, "}"); AppendLine(writer, indentation); } }