コード例 #1
0
 public void Init(Action <Type> callback, GeneratorTypes type)
 {
     m_Target           = callback.Target as Object;
     m_MethodName.value = callback.Method.Name;
     m_MethodAssemblyQualifiedName.value = callback.Method.DeclaringType.AssemblyQualifiedName;
     m_GeneratorType = type;
     PopulateTypes();
 }
コード例 #2
0
        /// <summary>
        ///     Checks if given asset is added to this package.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        public bool Exist([NotNull] global::UnityEngine.Object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            var guid = GetObjectGUID(obj);

            return(Assets.Any(asset => asset.Guid == guid));
        }
コード例 #3
0
        /// <exception cref="NullReferenceException">Received when AssetDatabase fails to find GUID of target Object.</exception>
        /// <exception cref="ArgumentNullException"/>
        internal static string GetObjectGUID([NotNull] global::UnityEngine.Object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _))
            {
                return(guid);
            }

            throw new NullReferenceException($"We failed to get a GUID of Object of type {obj.GetType()}");
        }
コード例 #4
0
ファイル: JiffyEditor.cs プロジェクト: ByronMayne/JiffyEditor
        /// <summary>
        /// This function takes System.Type and a Generator Type and write a new class. It
        /// first checks to see if the type meets all the conditions then asks the user to
        /// where they would like to save it.
        /// </summary>
        /// <param name="type">The type of class that you want to create an Editor for.</param>
        /// <param name="editorType">The type of Editor you want to create.</param>
        public static void CreateEditor(Type type, GeneratorTypes editorType, string path = "")
        {
            if (editorType == GeneratorTypes.CustomEditor && !IsValidForCustomEditor(type))
            {
                //We can't make an Editor for this class.
                return;
            }
            else if (editorType == GeneratorTypes.PropertyDrawer && !IsValidForPropertyDrawer(type))
            {
                //We can't make an Property Drawer for this type.
                return;
            }

            if (type != null)
            {
                string assetPath = EditorUtility.SaveFilePanelInProject("Save Location", type.Name + "Editor", "cs", "The location you want to save your Editor", path);

                if (string.IsNullOrEmpty(assetPath))
                {
                    //They cancelled selecting a path.
                    return;
                }

                string assetName = Path.GetFileNameWithoutExtension(assetPath);

                Essence essence = ScriptableObject.CreateInstance <Essence>();
                essence.classType        = type;
                essence.outputEditorType = editorType;
                essence.className        = assetName;

                var processor = new JiffyGeneratorPreprocessor(essence);

                string @class = processor.TransformText();


                File.WriteAllText(assetPath, @class);

                AssetDatabase.ImportAsset(assetPath);

                Debug.Log(string.Format("Jiffy | {0}.cs was created for {1}.cs. The script is located {2}", type.Name, assetName, assetPath));

                Object script = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));

                if (script != null)
                {
                    EditorGUIUtility.PingObject(script);
                }

                AssetDatabase.Refresh();
            }
        }
コード例 #5
0
        /// <summary>
        ///     Adds new asset to this package.
        /// </summary>
        public void AddAsset([NotNull] global::UnityEngine.Object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            var objGuid = GetObjectGUID(obj);

            if (Exist(objGuid))
            {
                return;
            }

            var newAsset = new JEMAssetBuilderItem
            {
                Guid    = objGuid,
                Include = true
            };

            Assets.Add(newAsset);
        }
 protected extern void Destroy(global::UnityEngine.Object obj);