Exemple #1
0
        public static bool CanPasteToTarget(ScriptableObjectCollectionItem target)
        {
            if (source == null)
            {
                return(false);
            }

            return(target.GetType() == source.GetType());
        }
Exemple #2
0
        private static void WriteDirectAccessCollectionStatic(ScriptableObjectCollection collection, StreamWriter writer,
                                                              ref int indentation)
        {
            string cachedValuesName = "values";

            AppendLine(writer, indentation, $"private static {collection.GetType().Name} {cachedValuesName};");

            AppendLine(writer, indentation);

            for (int i = 0; i < collection.Items.Count; i++)
            {
                ScriptableObjectCollectionItem collectionItem = collection.Items[i];
                AppendLine(writer, indentation,
                           $"private static {collectionItem.GetType().Name} {collectionItem.name.Sanitize().FirstToLower()};");
            }

            AppendLine(writer, indentation);

            string valuesName = $"Values";

            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++)
            {
                ScriptableObjectCollectionItem 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}.GetItemByGUID(\"{collectionItem.GUID}\");");
                indentation--;
                AppendLine(writer, indentation, $"return {privateStaticName};");
                indentation--;
                AppendLine(writer, indentation, "}");
                indentation--;
                AppendLine(writer, indentation, "}");
                AppendLine(writer, indentation);
            }


            AppendLine(writer, indentation, $"public static IEnumerable<T> GetValues<T>() where T : {collection.GetItemType().Name}");
            AppendLine(writer, indentation, "{");
            indentation++;
            AppendLine(writer, indentation, $"return Values.Where(item => item is T).Cast<T>();");
            indentation--;
            AppendLine(writer, indentation, "}");

            AppendLine(writer, indentation);
        }