protected void OnEnable()
		{
#if UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_5_0
			this.title = "SP Reference Replacer";
#else
            this.titleContent = new GUIContent("SP Reference Replacer");
#endif
            if (EditorPrefs.HasKey(SPTools.Settings_SavedInstanceIDKey))
			{
				string instancePath = AssetDatabase.GetAssetPath(EditorPrefs.GetInt(SPTools.Settings_SavedInstanceIDKey, 0));
				
				if (!string.IsNullOrEmpty(instancePath))
				{
					this.m_Instance = AssetDatabase.LoadAssetAtPath(instancePath, typeof(SPInstance)) as SPInstance;
				}
			}
			
			// Default prefs
			if (!EditorPrefs.HasKey(SPReferenceReplacerWindow.PrefsKey_TargetMode))
			{
				EditorPrefs.SetInt(SPReferenceReplacerWindow.PrefsKey_TargetMode, (int)this.m_TargetMode);
			}
			
			// Load target mode setting
			this.m_TargetMode = (TargetMode)EditorPrefs.GetInt(SPReferenceReplacerWindow.PrefsKey_TargetMode);
		}
Exemplo n.º 2
0
		protected void OnEnable()
		{
			this.m_SPInstance = this.target as SPInstance;
			this.m_AtlasBuilder = new SPAtlasBuilder(this.m_SPInstance);
			
			SPTools.PrepareDefaultEditorPrefs();
			
			this.boxStyle = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).box);
			this.paddingStyle = new GUIStyle();
			this.paddingStyle.padding = new RectOffset(3, 3, 3, 3);
		}
Exemplo n.º 3
0
        protected void OnEnable()
        {
            this.title = "SP Drop";

            if (EditorPrefs.HasKey(SPTools.Settings_SavedInstanceIDKey))
            {
                string instancePath = AssetDatabase.GetAssetPath(EditorPrefs.GetInt(SPTools.Settings_SavedInstanceIDKey, 0));

                if (!string.IsNullOrEmpty(instancePath))
                {
                    this.m_Instance = AssetDatabase.LoadAssetAtPath(instancePath, typeof(SPInstance)) as SPInstance;
                }
            }
        }
Exemplo n.º 4
0
        protected void OnEnable()
        {
            #if UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_5_0
            this.title = "SP Drop";
            #else
            this.titleContent = new GUIContent("SP Drop");
            #endif
            if (EditorPrefs.HasKey(SPTools.Settings_SavedInstanceIDKey))
            {
                string instancePath = AssetDatabase.GetAssetPath(EditorPrefs.GetInt(SPTools.Settings_SavedInstanceIDKey, 0));

                if (!string.IsNullOrEmpty(instancePath))
                {
                    this.m_Instance = AssetDatabase.LoadAssetAtPath(instancePath, typeof(SPInstance)) as SPInstance;
                }
            }
        }
 protected void OnDisable()
 {
     this.m_AtlasBuilder = null;
     this.m_SPInstance = null;
 }
Exemplo n.º 6
0
        protected void OnGUI()
        {
            EditorGUIUtility.labelWidth = 100f;

            GUILayout.BeginVertical();
            GUILayout.Space(8f);

            GUI.changed = false;
            this.m_Instance = EditorGUILayout.ObjectField("Sprite Packer", this.m_Instance, typeof(SPInstance), false) as SPInstance;
            if (GUI.changed)
            {
                // Save the instance id
                EditorPrefs.SetInt(SPTools.Settings_SavedInstanceIDKey, (this.m_Instance == null) ? 0 : this.m_Instance.GetInstanceID());
            }

            GUILayout.Space(4f);

            if (this.m_Instance == null)
            {
                EditorGUILayout.HelpBox("Please set the sprite packer instance reference in order to use this feature.", MessageType.Info);
            }
            else
            {
                Event evt = Event.current;
                Rect drop_area = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
                boxStyle.alignment = TextAnchor.MiddleCenter;
                GUI.color = SPDropWindow.green;
                GUI.Box(drop_area, "Add Sprite (Drop Here)", boxStyle);
                GUI.color = Color.white;

                switch (evt.type)
                {
                    case EventType.DragUpdated:
                    case EventType.DragPerform:
                    {
                        if (!drop_area.Contains(evt.mousePosition))
                            return;

                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                        if (evt.type == EventType.DragPerform)
                        {
                            DragAndDrop.AcceptDrag();

                            Object[] filtered = SPTools.FilterResourcesForAtlasImport(DragAndDrop.objectReferences);

                            // Disallow miltiple sprites of the same source, if set so
                            if (!SPTools.GetEditorPrefBool(SPTools.Settings_AllowMuliSpritesOneSource))
                            {
                                // Additional filtering specific to the instance
                                for (int i = 0; i < filtered.Length; i++)
                                {
                                    if (this.m_Instance.sprites.Find(s => s.source == filtered[i]) != null)
                                    {
                                        Debug.LogWarning("A sprite with source \"" + SimpleSpritePackerEditor.SPTools.GetAssetPath(filtered[i]) + "\" already exists in the atlas, consider changing the Sprite Packer settings to allow multiple sprites from the same source.");
                                        System.Array.Clear(filtered, i, 1);
                                    }
                                }
                            }

                            // Types are handled internally
                            this.m_Instance.QueueAction_AddSprites(filtered);

                            Selection.activeObject = this.m_Instance;
                            //EditorPrefs.SetBool(SPTools.Settings_ShowSpritesKeys, false);
                        }
                        break;
                    }
                }
            }

            GUILayout.EndVertical();
        }
        protected void OnGUI()
        {
            EditorGUIUtility.labelWidth = 100f;

            GUILayout.BeginVertical();
            GUILayout.Space((float)SPReferenceReplacerWindow.padding.top);
            GUILayout.BeginHorizontal();
            GUILayout.Space((float)SPReferenceReplacerWindow.padding.left);
            GUILayout.BeginVertical();

            GUI.changed = false;
            this.m_Instance = EditorGUILayout.ObjectField("Sprite Packer", this.m_Instance, typeof(SPInstance), false) as SPInstance;
            if (GUI.changed)
            {
                // Save the instance id
                EditorPrefs.SetInt(SPTools.Settings_SavedInstanceIDKey, (this.m_Instance == null) ? 0 : this.m_Instance.GetInstanceID());
            }

            GUILayout.Space(6f);

            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Space(6f);

            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);

            EditorGUILayout.LabelField("Replace mode", GUILayout.Width(130f));
            this.m_ReplaceMode = (ReplaceMode)EditorGUILayout.EnumPopup(this.m_ReplaceMode);

            GUILayout.Space(6f);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("Replace references in", GUILayout.Width(130f));
            this.m_TargetMode = (TargetMode)EditorGUILayout.EnumPopup(this.m_TargetMode);
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt(SPReferenceReplacerWindow.PrefsKey_TargetMode, (int)this.m_TargetMode);
            }

            GUILayout.Space(6f);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            GUI.changed = false;
            bool spriteRenderersOnly = GUILayout.Toggle(EditorPrefs.GetBool(SPReferenceReplacerWindow.PrefsKey_SpriteRenderersOnly), " Replace references in Sprite Renderers only ?");
            if (GUI.changed)
            {
                EditorPrefs.SetBool(SPReferenceReplacerWindow.PrefsKey_SpriteRenderersOnly, spriteRenderersOnly);
            }
            GUILayout.Space(6f);
            GUILayout.EndHorizontal();

            GUILayout.Space(6f);
            GUILayout.EndVertical();

            GUILayout.Space(6f);

            if (this.m_Instance == null)
            {
                EditorGUILayout.HelpBox("Please set the sprite packer instance reference in order to use this feature.", MessageType.Info);
            }
            else
            {
                if (GUILayout.Button("Replace"))
                {
                    int replacedCount = 0;

                    switch (this.m_TargetMode)
                    {
                    case TargetMode.CurrentScene:
                    {
                        replacedCount += SPTools.ReplaceReferencesInScene(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly);
                        break;
                    }
                    case TargetMode.ProjectOnly:
                    {
                        replacedCount += SPTools.ReplaceReferencesInProject(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly);
                        break;
                    }
                    case TargetMode.CurrentSceneAndProject:
                    {
                        replacedCount += SPTools.ReplaceReferencesInProject(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly);
                        replacedCount += SPTools.ReplaceReferencesInScene(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly);
                        break;
                    }
                    case TargetMode.AllScenes:
                    {
                        replacedCount += SPTools.ReplaceReferencesInAllScenes(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly, false);
                        break;
                    }
                    case TargetMode.AllScenesAndProject:
                    {
                        replacedCount += SPTools.ReplaceReferencesInProject(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly);
                        replacedCount += SPTools.ReplaceReferencesInScene(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly);
                        EditorApplication.SaveScene();
                        replacedCount += SPTools.ReplaceReferencesInAllScenes(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly, true);
                        break;
                    }
                    }

                    EditorUtility.DisplayDialog("Reference Replacer", "Replaced references count: " + replacedCount.ToString(), "Okay");
                }
            }

            GUILayout.EndVertical();
            GUILayout.Space((float)SPReferenceReplacerWindow.padding.right);
            GUILayout.EndHorizontal();
            GUILayout.Space((float)SPReferenceReplacerWindow.padding.bottom);
            GUILayout.EndVertical();
        }
Exemplo n.º 8
0
 // Constructor
 public SPAtlasBuilder(SPInstance instance)
 {
     this.m_Instance = instance;
 }