예제 #1
0
        /// <summary>
        /// Creates a new plugin of the given type and stores it inside the given converterController asset
        /// </summary>
        /// <returns>Returns the created asset</returns>
        private static DynamicDNAPlugin CreatePlugin(System.Type pluginType, DynamicDNAConverterController converter)
        {
            //Checks and warnings
            if (pluginType == null)
            {
                Debug.LogWarning("Could not create plugin because the plugin type was null");
                return(null);
            }
            if (converter == null)
            {
                Debug.LogWarning("Could not create plugin because no converterController was provided to add it to");
                return(null);
            }
            if (!DynamicDNAPlugin.IsValidPluginType(pluginType))
            {
                Debug.LogWarning("Could not create plugin because it did not descend from DynamicDNAPlugin");
                return(null);
            }

            DynamicDNAPlugin asset = ScriptableObject.CreateInstance(pluginType) as DynamicDNAPlugin;

            asset.name = converter.GetUniquePluginName(pluginType.Name.Replace("Plugin", "") + "s");
#if UNITY_EDITOR
            Debug.Log(pluginType + " created successfully! Its asset '" + asset.name + "' has been stored in " + converter.name);
            AssetDatabase.AddObjectToAsset(asset, converter);
#endif
            return(asset);
        }
예제 #2
0
        /// <summary>
        /// At run time this simply clears the plugins list of any empty entries, or null entries, and assigns itself as the converterController for the plugin
        /// At edit time all instantiated plugins inside the given converterController are checked to see if they belong in this list and if they are they get added
        /// This can happen when a plugin script is deleted but then restored again (like when working on different branches in sourceControl)
        /// </summary>
        public void ValidatePlugins()
        {
#if UNITY_EDITOR
            bool changed = false;
#endif
            var cleanList = new List <DynamicDNAPlugin>();
            for (int i = 0; i < _plugins.Count; i++)
            {
                if (_plugins[i] != null)
                {
                    if (DynamicDNAPlugin.IsValidPlugin(_plugins[i]))
                    {
                        cleanList.Add(_plugins[i]);
                        if (_plugins[i].converterController != this)
                        {
                            _plugins[i].converterController = this;
#if UNITY_EDITOR
                            EditorUtility.SetDirty(_plugins[i]);
                            changed = true;
#endif
                        }
                    }
                }
            }
            _plugins = cleanList;
#if UNITY_EDITOR
            //if we are in the editor get all the assets inside the given converterController asset and check if any of those should be in this list
            var thisAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this));
            for (int i = 0; i < thisAssets.Length; i++)
            {
                if (thisAssets[i] == this)
                {
                    continue;
                }
                if (!DynamicDNAPlugin.IsValidPlugin(thisAssets[i]))
                {
                    continue;
                }
                if (!_plugins.Contains(thisAssets[i] as DynamicDNAPlugin))
                {
                    _plugins.Add(thisAssets[i] as DynamicDNAPlugin);
                    changed = true;
                }
            }
            if (changed)
            {
                EditorUtility.SetDirty(this);
                AssetDatabase.SaveAssets();
            }
#endif
            CompileUsedDNANamesList();
        }
예제 #3
0
        /// <summary>
        /// Gets a unique name for a plugin relative to this converterController
        /// </summary>
        /// <param name="desiredName">The name you'd like</param>
        public string GetUniquePluginName(string desiredName, DynamicDNAPlugin existingPlugin = null)
        {
            var intSuffix = 0;

            for (int i = 0; i < _plugins.Count; i++)
            {
                if (_plugins[i].name == desiredName && (existingPlugin == null || (existingPlugin != null && existingPlugin != _plugins[i])))
                {
                    intSuffix++;
                }
            }
            return(desiredName + (intSuffix != 0 ? intSuffix.ToString() : ""));
        }
예제 #4
0
 public void ResetDNA()
 {
     foreach (IDNAConverter converter in dnaConverterList)
     {
         if (converter is DynamicDNAConverterController)
         {
             var c = converter as DynamicDNAConverterController;
             for (int i = 0; i < c.PluginCount; i++)
             {
                 DynamicDNAPlugin ddp = c.GetPlugin(i);
                 ddp.Reset();
             }
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Removes the given plugin from this converterController, and deletes its asset (in the Editor)
        /// </summary>
        /// <param name="pluginToDelete"></param>
        /// <returns></returns>
        public bool DeletePlugin(DynamicDNAPlugin pluginToDelete)
        {
            //check if the given plugin is indeed inside this asset
            //if it is DestroyImmediate
            if (_plugins.Contains(pluginToDelete))
            {
                _prepared = false;
                _plugins.Remove(pluginToDelete);
                Debug.Log(pluginToDelete.name + " successfully deleted from " + this.name);
#if UNITY_EDITOR
                DestroyImmediate(pluginToDelete, true);
                EditorUtility.SetDirty(this);
                AssetDatabase.SaveAssets();
#endif
            }
            //then Validate the list
            ValidatePlugins();
            return(false);
        }
예제 #6
0
        /// <summary>
        /// Creates a plugin of the given type (must descend from DynamicDNAPlugin), adds it to this converterControllers plugins list,  and stores its asset in the given DynamicDNAConverterController asset
        /// </summary>
        /// <param name="pluginType">The type of dna plugin to create (must descend from DynamicDNAPlugin)</param>
        /// <returns>Returns the created plugin</returns>
        //This can happen at runtime but no asset is created or stored, it just exists in memory
        public DynamicDNAPlugin AddPlugin(System.Type pluginType)
        {
            DynamicDNAPlugin plugin = null;

            plugin = CreatePlugin(pluginType, this);
            if (plugin != null)
            {
                _prepared = false;
                _plugins.Add(plugin);
#if UNITY_EDITOR
                EditorUtility.SetDirty(this);
                AssetDatabase.SaveAssets();
#endif
                //ensure the new plugin is added to the _applyPlugins lists
                if (Application.isPlaying)
                {
                    Prepare();
                }
                return(plugin);
            }
            return(null);
        }