public static void CheckMultipleInstances(OnlineMapsControlBase control) { OnlineMapsControlBase[] controls = control.GetComponents<OnlineMapsControlBase>(); if (controls.Length > 1) { EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.HelpBox("Problem detected:\nMultiple instances of controls.\nYou can use only one control.", MessageType.Error); int controlIndex = -1; for (int i = 0; i < controls.Length; i++) { if (GUILayout.Button("Use " + controls[i].GetType())) controlIndex = i; } if (controlIndex != -1) { OnlineMapsControlBase activeControl = controls[controlIndex]; foreach (OnlineMapsControlBase c in controls) if (c != activeControl) DestroyImmediate(c); } EditorGUILayout.EndVertical(); } }
private void Awake () { foreach (OnlineMaps map in maps) { if(map.target == currentMap) { this.map = map; this.currentControl = map.target == OnlineMapsTarget.tileset? controlMapTileSet : controlMapGUI; } else map.gameObject.SetActive (false); } }
public static OnlineMaps GetOnlineMaps(OnlineMapsControlBase control) { if (control == null) return null; OnlineMaps api = control.GetComponent<OnlineMaps>(); if (api == null) { EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.HelpBox("Problem detected:\nCan not find OnlineMaps component.", MessageType.Error); if (GUILayout.Button("Add OnlineMaps Component")) { api = control.gameObject.AddComponent<OnlineMaps>(); UnityEditorInternal.ComponentUtility.MoveComponentUp(api); if (control is OnlineMapsTileSetControl) api.target = OnlineMapsTarget.tileset; } EditorGUILayout.EndVertical(); } return api; }
private void OnEnable() { _instance = this; dragMarker = null; api = GetComponent<OnlineMaps>(); activeTexture = api.texture; if (api == null) { Debug.LogError("Can not find a script OnlineMaps."); Destroy(this); return; } api.control = this; OnEnableLate(); }
// ReSharper disable once UnusedMember.Global public void Awake() { _instance = this; if (target == OnlineMapsTarget.texture) { width = texture.width; height = texture.height; } else { width = tilesetWidth; height = tilesetHeight; texture = null; } control = GetComponent<OnlineMapsControlBase>(); if (control == null) Debug.LogError("Can not find a Control."); else control.OnAwakeBefore(); if (target == OnlineMapsTarget.texture) { if (texture != null) defaultColors = texture.GetPixels(); if (defaultTileTexture == null) { OnlineMapsTile.defaultColors = new Color[OnlineMapsUtils.sqrTileSize]; for (int i = 0; i < OnlineMapsUtils.sqrTileSize; i++) OnlineMapsTile.defaultColors[i] = emptyColor; } else OnlineMapsTile.defaultColors = defaultTileTexture.GetPixels(); } foreach (OnlineMapsMarker marker in markers) marker.Init(); if (target == OnlineMapsTarget.texture && useSmartTexture && smartTexture == null) { smartTexture = new Texture2D(texture.width / 2, texture.height / 2, TextureFormat.RGB24, false); } }
/// <summary> /// Event that occurs before Awake. /// </summary> public virtual void OnAwakeBefore() { _instance = this; }
private void Start() { map = OnlineMaps.instance; control = OnlineMapsControlBase.instance; control.OnValidateZoom += OnValidateZoom; }
private void CreateTexture() { string texturePath = string.Format("Assets/{0}.png", textureFilename); Texture2D texture = new Texture2D(textureWidth, textureHeight); File.WriteAllBytes(texturePath, texture.EncodeToPNG()); AssetDatabase.Refresh(); TextureImporter textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter; if (textureImporter != null) { textureImporter.mipmapEnabled = false; textureImporter.isReadable = true; #if !UNITY_5_5P textureImporter.textureFormat = TextureImporterFormat.RGB24; #else textureImporter.textureCompression = TextureImporterCompression.Uncompressed; #endif textureImporter.maxTextureSize = Mathf.Max(textureWidth, textureHeight); OnlineMapsControlBase control = api.GetComponent <OnlineMapsControlBase>(); if (control is OnlineMapsUIImageControl || control is OnlineMapsSpriteRendererControl) { textureImporter.spriteImportMode = SpriteImportMode.Single; textureImporter.npotScale = TextureImporterNPOTScale.None; } AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate); Texture2D newTexture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; pTexture.objectReferenceValue = newTexture; if (control is OnlineMapsSpriteRendererControl) { SpriteRenderer spriteRenderer = api.GetComponent <SpriteRenderer>(); spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite; } else if (control is OnlineMapsGUITextureControl) { GUITexture gt = api.GetComponent <GUITexture>(); gt.texture = newTexture; } else if (control is OnlineMapsUIImageControl) { Image img = api.GetComponent <Image>(); img.sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite; } else if (control is OnlineMapsUIRawImageControl) { RawImage img = api.GetComponent <RawImage>(); img.texture = newTexture; } else if (control is OnlineMapsTextureControl) { Renderer renderer = api.GetComponent <Renderer>(); renderer.sharedMaterial.mainTexture = texture; } else if (control is OnlineMapsNGUITextureControl) { #if NGUI UITexture uiTexture = api.GetComponent <UITexture>(); uiTexture.mainTexture = newTexture; #endif } } OnlineMapsUtils.DestroyImmediate(texture); #if !UNITY_5_0P EditorUtility.UnloadUnusedAssets(); #else EditorUtility.UnloadUnusedAssetsImmediate(); #endif }
/// <summary> /// Dispose the current drawer /// </summary> public override void Dispose() { control.OnDrawMarkers -= Draw; control = null; OnSortMarker = null; }
/// <summary> /// Contructor /// </summary> /// <param name="control">Reference to control</param> public OnlineMapsMarkerBufferDrawer(OnlineMapsControlBase control) { this.control = control; control.OnDrawMarkers += Draw; }