// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void LateUpdate() { base.LateUpdate(); if (spriteBorder == null) { spriteBorder = GetComponent <exSpriteBorder>(); if (spriteBorder == null) { Debug.LogError("Can't find exSpriteBorder Component in GameObject " + gameObject.name); return; } } if (lastColor != spriteBorder.color) { lastColor = spriteBorder.color; spriteBorder.updateFlags |= exPlane.UpdateFlags.Color; } if (lastWidth != spriteBorder.width) { lastWidth = spriteBorder.width; spriteBorder.updateFlags |= exPlane.UpdateFlags.Vertex; } if (lastHeight != spriteBorder.height) { lastHeight = spriteBorder.height; spriteBorder.updateFlags |= exPlane.UpdateFlags.Vertex; } }
/////////////////////////////////////////////////////////////////////////////// // Panel /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ static void CreatePanelObject(bool _useSprite) { // create panel object GameObject panelGO = new GameObject("Panel"); exUIPanel panel = panelGO.AddComponent <exUIPanel>(); // create Background if (_useSprite) { GameObject backgroundGO = new GameObject("Background"); exSprite background = backgroundGO.AddComponent <exSprite>(); panel.background = background; backgroundGO.transform.parent = panelGO.transform; } else { GameObject backgroundGO = new GameObject("Background"); exSpriteBorder background = backgroundGO.AddComponent <exSpriteBorder>(); panel.background = background; backgroundGO.transform.parent = panelGO.transform; } panel.width = 100.0f; panel.height = 100.0f; // Selection.activeObject = panelGO; }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void OnEnable() { base.OnEnable(); if (target != editSpriteBorder) { editSpriteBorder = target as exSpriteBorder; } }
/////////////////////////////////////////////////////////////////////////////// // functions /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void Awake () { base.Awake(); spriteBorder = GetComponent<exSpriteBorder>(); lastColor = spriteBorder.color; lastWidth = spriteBorder.width; lastHeight = spriteBorder.height; }
/////////////////////////////////////////////////////////////////////////////// // functions /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void Awake() { base.Awake(); spriteBorder = GetComponent <exSpriteBorder>(); lastColor = spriteBorder.color; lastWidth = spriteBorder.width; lastHeight = spriteBorder.height; }
// ------------------------------------------------------------------ /// \param _spriteBorder the sprite /// \param _texture the raw texture used in the sprite /// build the sprite by texture // ------------------------------------------------------------------ public static void Build(this exSpriteBorder _spriteBorder, Texture2D _texture = null) { #if UNITY_3_4 bool isPrefab = (EditorUtility.GetPrefabType(_spriteBorder) == PrefabType.Prefab); #else bool isPrefab = (PrefabUtility.GetPrefabType(_spriteBorder) == PrefabType.Prefab); #endif EditorUtility.SetDirty(_spriteBorder); // if (_spriteBorder.guiBorder == null && _spriteBorder.atlas == null && _texture == null) { GameObject.DestroyImmediate(_spriteBorder.meshFilter.sharedMesh, true); _spriteBorder.meshFilter.sharedMesh = null; _spriteBorder.GetComponent <Renderer>().sharedMaterial = null; return; } // set a texture to it if (_spriteBorder.atlas != null) { _spriteBorder.GetComponent <Renderer>().sharedMaterial = _spriteBorder.atlas.material; } else if (_texture != null) { _spriteBorder.GetComponent <Renderer>().sharedMaterial = exEditorHelper.GetDefaultMaterial(_texture, _texture.name); } EditorUtility.UnloadUnusedAssets(); // prefab do not need rebuild mesh if (isPrefab == false) { // NOTE: it is possible user duplicate an GameObject, // if we directly change the mesh, the original one will changed either. Mesh newMesh = new Mesh(); newMesh.hideFlags = HideFlags.DontSave; newMesh.Clear(); // build vertices, normals, uvs and colors. _spriteBorder.ForceUpdateMesh(newMesh); // set the new mesh in MeshFilter GameObject.DestroyImmediate(_spriteBorder.meshFilter.sharedMesh, true); // delete old mesh (to avoid leaking) _spriteBorder.meshFilter.sharedMesh = newMesh; } // update collider if (_spriteBorder.collisionHelper) { _spriteBorder.collisionHelper.UpdateCollider(); } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void SetSize(exSpriteBase _sp, float _newWidth, float _newHeight) { exSprite spriteBG = _sp as exSprite; if (spriteBG) { spriteBG.width = _newWidth; spriteBG.height = _newHeight; } else { exSpriteBorder borderBG = _sp as exSpriteBorder; if (borderBG) { borderBG.width = _newWidth; borderBG.height = _newHeight; } } }
/////////////////////////////////////////////////////////////////////////////// // functions /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void UpdateAtlas(exSpriteBorder _spriteBorder, exAtlasDB.ElementInfo _elInfo) { // get atlas and index from textureGUID if (_elInfo != null) { if (_elInfo.guidAtlas != exEditorHelper.AssetToGUID(_spriteBorder.atlas) || _elInfo.indexInAtlas != _spriteBorder.index) { _spriteBorder.SetBorder(_spriteBorder.guiBorder, exEditorHelper.LoadAssetFromGUID <exAtlas>(_elInfo.guidAtlas), _elInfo.indexInAtlas); } } else { exGUIBorder guiBorder = _spriteBorder.guiBorder; _spriteBorder.Clear(); _spriteBorder.SetBorder(guiBorder, null, -1); } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void Update () { base.Update(); if ( spriteBorder == null ) { spriteBorder = GetComponent<exSpriteBorder>(); if ( spriteBorder == null ) { Debug.LogError("Can't find exSpriteBorder Component in GameObject " + gameObject.name); return; } } if ( lastColor != spriteBorder.color ) { lastColor = spriteBorder.color; spriteBorder.updateFlags |= exPlane.UpdateFlags.Color; } if ( lastWidth != spriteBorder.width ) { lastWidth = spriteBorder.width; spriteBorder.updateFlags |= exPlane.UpdateFlags.Vertex; } if ( lastHeight != spriteBorder.height ) { lastHeight = spriteBorder.height; spriteBorder.updateFlags |= exPlane.UpdateFlags.Vertex; } }
/////////////////////////////////////////////////////////////////////////////// // Button /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ static void CreateButtonObject(bool _useSprite) { // create button object GameObject buttonGO = new GameObject("Button"); exUIButton button = buttonGO.AddComponent <exUIButton>(); // create Background if (_useSprite) { GameObject backgroundGO = new GameObject("Background"); exSprite background = backgroundGO.AddComponent <exSprite>(); button.background = background; backgroundGO.transform.parent = buttonGO.transform; } else { GameObject backgroundGO = new GameObject("Background"); exSpriteBorder background = backgroundGO.AddComponent <exSpriteBorder>(); button.background = background; backgroundGO.transform.parent = buttonGO.transform; } // create Font GameObject fontGO = new GameObject("Font"); exSpriteFont font = fontGO.AddComponent <exSpriteFont>(); font.text = ""; button.font = font; fontGO.transform.parent = buttonGO.transform; button.width = 50.0f; button.height = 20.0f; // Selection.activeObject = buttonGO; }
/////////////////////////////////////////////////////////////////////////////// // functions /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void Awake() { if ( renderType == RenderType.Clipping ) { clipPlane = GetComponent<exClipping>(); if (isHorizontal) { total = clipPlane.width; clipPlane.width = total * ratio_; } else { total = clipPlane.height; clipPlane.height = total * ratio_; } } else if ( renderType == RenderType.Sprite ) { sprite = GetComponent<exSprite>(); if (isHorizontal) { total = sprite.width; sprite.width = total * ratio_; } else { total = sprite.height; sprite.height = total * ratio_; } } else { border = GetComponent<exSpriteBorder>(); if (isHorizontal) { total = border.width; border.width = total * ratio_; } else { total = border.height; border.height = total * ratio_; } } }
// ------------------------------------------------------------------ /// \param _atlasInfoGUIDs the list of atlas info guid /// update sprites in current scene and in prefab by atlas info list // ------------------------------------------------------------------ public static void UpdateSprites(List <string> _atlasInfoGUIDs) { if (_atlasInfoGUIDs.Count == 0) { return; } try { EditorUtility.DisplayProgressBar("Update Scene Sprites With Changed Atlas...", "Scanning...", 0.0f); // exSpriteBase[] sprites = GameObject.FindObjectsOfType(typeof(exSpriteBase)) as exSpriteBase[]; exSpriteBase[] sprites = Resources.FindObjectsOfTypeAll(typeof(exSpriteBase)) as exSpriteBase[]; for (int i = 0; i < sprites.Length; ++i) { exSpriteBase spBase = sprites[i]; // ======================================================== // exSprite // ======================================================== if (spBase is exSprite) { exSprite sp = spBase as exSprite; exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(sp.textureGUID); bool needRebuild = false; // NOTE: we test sp.index is -1 or not instead of test atlas is null, because it is possible we delete an atlas and it will always be null if (elInfo != null) { if (sp.index == -1) { needRebuild = true; } else { // find if the sp's atalsInfo need rebuild foreach (string guidAtlasInfo in _atlasInfoGUIDs) { if (elInfo.guidAtlasInfo == guidAtlasInfo) { needRebuild = true; break; } } } } else { if (sp.index != -1) { needRebuild = true; } } // if (needRebuild) { exSpriteEditor.UpdateAtlas(sp, elInfo); #if UNITY_3_4 bool isPrefab = (EditorUtility.GetPrefabType(spBase) == PrefabType.Prefab); #else bool isPrefab = (PrefabUtility.GetPrefabType(spBase) == PrefabType.Prefab); #endif if (isPrefab == false) { Texture2D texture = null; if (sp.index == -1) { texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(sp.textureGUID); } sp.Build(texture); } EditorUtility.SetDirty(sp); } } #if !(EX2D_EVALUATE) // ======================================================== // exSpriteFont // ======================================================== if (spBase is exSpriteFont) { exSpriteFont spFont = spBase as exSpriteFont; // bool needRebuild = false; if (spFont.fontInfo == null) { needRebuild = true; } else { foreach (string guidAtlasInfo in _atlasInfoGUIDs) { exAtlasInfo atlasInfo = exEditorHelper.LoadAssetFromGUID <exAtlasInfo>(guidAtlasInfo); // NOTE: it is possible we process this in delete stage if (atlasInfo == null) { continue; } foreach (exBitmapFont bmfont in atlasInfo.bitmapFonts) { if (spFont.fontInfo == bmfont) { needRebuild = true; break; } } } } // if (needRebuild) { spFont.Build(); } } // ======================================================== // exSpriteBorder // ======================================================== if (spBase is exSpriteBorder) { exSpriteBorder spBorder = spBase as exSpriteBorder; if (spBorder.guiBorder != null) { exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(spBorder.guiBorder.textureGUID); bool needRebuild = false; // NOTE: we test spBorder.index is -1 or not instead of test atlas is null, because it is possible we delete an atlas and it will always be null if (elInfo != null) { if (spBorder.index == -1) { needRebuild = true; } else { // find if the spBorder's atalsInfo need rebuild foreach (string guidAtlasInfo in _atlasInfoGUIDs) { if (elInfo.guidAtlasInfo == guidAtlasInfo) { needRebuild = true; break; } } } } else { if (spBorder.index != -1) { needRebuild = true; } } // if (needRebuild) { exSpriteBorderEditor.UpdateAtlas(spBorder, elInfo); #if UNITY_3_4 bool isPrefab = (EditorUtility.GetPrefabType(spBase) == PrefabType.Prefab); #else bool isPrefab = (PrefabUtility.GetPrefabType(spBase) == PrefabType.Prefab); #endif if (isPrefab == false) { Texture2D texture = null; if (spBorder.index == -1) { texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(spBorder.guiBorder.textureGUID); } spBorder.Build(texture); } EditorUtility.SetDirty(spBorder); } } } #endif // !(EX2D_EVALUATE) // DISABLE: it is too slow { // float progress = (float)i/(float)sprites.Length; // EditorUtility.DisplayProgressBar( "Update Scene Sprites...", // "Update Sprite " + spBase.gameObject.name, progress ); // } DISABLE end } EditorUtility.ClearProgressBar(); } catch (System.Exception) { EditorUtility.ClearProgressBar(); throw; } }
// ------------------------------------------------------------------ /// \param _guiBorderList the list of gui-borders /// update sprite borders in current scene and in prefab by gui-border list // ------------------------------------------------------------------ public static void UpdateSpriteBorders(List <exGUIBorder> _guiBorderList) { if (_guiBorderList.Count == 0) { return; } try { EditorUtility.DisplayProgressBar("Update Scene Sprites With Changed GUIBorders...", "Scanning...", 0.0f); // exSpriteBase[] sprites = GameObject.FindObjectsOfType(typeof(exSpriteBase)) as exSpriteBase[]; exSpriteBase[] sprites = Resources.FindObjectsOfTypeAll(typeof(exSpriteBase)) as exSpriteBase[]; for (int i = 0; i < sprites.Length; ++i) { exSpriteBase spBase = sprites[i]; #if !(EX2D_EVALUATE) // ======================================================== // exSpriteBorder // ======================================================== if (spBase is exSpriteBorder) { exSpriteBorder spBorder = spBase as exSpriteBorder; bool needRebuild = false; // find if the spBorder's atalsInfo need rebuild foreach (exGUIBorder guiBorder in _guiBorderList) { if (spBorder.guiBorder == guiBorder) { needRebuild = true; break; } } // if (needRebuild) { exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(spBorder.guiBorder.textureGUID); exSpriteBorderEditor.UpdateAtlas(spBorder, elInfo); #if UNITY_3_4 bool isPrefab = (EditorUtility.GetPrefabType(spBase) == PrefabType.Prefab); #else bool isPrefab = (PrefabUtility.GetPrefabType(spBase) == PrefabType.Prefab); #endif if (isPrefab == false) { Texture2D texture = null; if (spBorder.useAtlas == false) { texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(spBorder.guiBorder.textureGUID); } spBorder.Build(texture); } EditorUtility.SetDirty(spBorder); } } #endif // !(EX2D_EVALUATE) } EditorUtility.ClearProgressBar(); } catch (System.Exception) { EditorUtility.ClearProgressBar(); throw; } }
static void CreateScrollViewObject() { // create panel object GameObject scrollViewGO = new GameObject("ScrollView"); // GameObject clipRectGO = new GameObject("ClipRect"); clipRectGO.transform.parent = scrollViewGO.transform; exClipping clipRect = clipRectGO.AddComponent <exClipping>(); clipRect.anchor = exPlane.Anchor.TopLeft; // GameObject contentAnchor = new GameObject("ContentAnchor"); contentAnchor.transform.parent = clipRect.transform; // GameObject horizontalBarGO = new GameObject("HorizontalBar"); horizontalBarGO.transform.parent = scrollViewGO.transform; exSpriteBorder horizontalBar = horizontalBarGO.AddComponent <exSpriteBorder>(); // myBorder = AssetDatabase.LoadAssetAtPath("Assets/ex2D_GUI/Resource/GUIBorder/HorizontalScrollBar.asset", // typeof(exGUIBorder)) as exGUIBorder; // elInfo = exAtlasDB.GetElementInfo(myBorder.textureGUID); // if ( elInfo != null ) { // atlas = exEditorHelper.LoadAssetFromGUID<exAtlas>(elInfo.guidAtlas); // index = elInfo.indexInAtlas; // } // horizontalBar.SetBorder( myBorder, atlas, index ); // horizontalBar.Rebuild (); horizontalBar.anchor = exPlane.Anchor.TopLeft; horizontalBar.enabled = false; // GameObject horizontalSliderGO = new GameObject("HorizontalSlider"); horizontalSliderGO.transform.parent = scrollViewGO.transform; exSpriteBorder horizontalSlider = horizontalSliderGO.AddComponent <exSpriteBorder>(); // myBorder = AssetDatabase.LoadAssetAtPath("Assets/ex2D_GUI/Resource/GUIBorder/HorizontalSlider.asset", // typeof(exGUIBorder)) as exGUIBorder; // elInfo = exAtlasDB.GetElementInfo(myBorder.textureGUID); // if ( elInfo != null ) { // atlas = exEditorHelper.LoadAssetFromGUID<exAtlas>(elInfo.guidAtlas); // index = elInfo.indexInAtlas; // } // horizontalSlider.SetBorder( myBorder, atlas, index ); horizontalSlider.anchor = exPlane.Anchor.TopLeft; horizontalSlider.width = 0.0f; horizontalSlider.height = 0.0f; horizontalSlider.enabled = false; // GameObject verticalBarGO = new GameObject("VerticalBar"); verticalBarGO.transform.parent = scrollViewGO.transform; exSpriteBorder verticalBar = verticalBarGO.AddComponent <exSpriteBorder>(); // myBorder = AssetDatabase.LoadAssetAtPath("Assets/ex2D_GUI/Resource/GUIBorder/VerticalScrollBar.asset", // typeof(exGUIBorder)) as exGUIBorder; // elInfo = exAtlasDB.GetElementInfo(myBorder.textureGUID); // if ( elInfo != null ) { // atlas = exEditorHelper.LoadAssetFromGUID<exAtlas>(elInfo.guidAtlas); // index = elInfo.indexInAtlas; // } // verticalBar.SetBorder( myBorder, atlas, index ); // verticalBar.Rebuild (); verticalBar.anchor = exPlane.Anchor.TopLeft; verticalBar.enabled = false; // GameObject verticalSliderGO = new GameObject("VerticalSlider"); verticalSliderGO.transform.parent = scrollViewGO.transform; exSpriteBorder verticalSlider = verticalSliderGO.AddComponent <exSpriteBorder>(); // myBorder = AssetDatabase.LoadAssetAtPath("Assets/ex2D_GUI/Resource/GUIBorder/verticalSlider.asset", // typeof(exGUIBorder)) as exGUIBorder; // elInfo = exAtlasDB.GetElementInfo(myBorder.textureGUID); // if ( elInfo != null ) { // atlas = exEditorHelper.LoadAssetFromGUID<exAtlas>(elInfo.guidAtlas); // index = elInfo.indexInAtlas; // } // verticalSlider.SetBorder( myBorder, atlas, index ); verticalSlider.anchor = exPlane.Anchor.TopLeft; verticalSlider.width = 0.0f; verticalSlider.height = 0.0f; verticalSlider.enabled = false; // exUIScrollView scrollView = scrollViewGO.AddComponent <exUIScrollView>(); scrollView.anchor = exPlane.Anchor.TopCenter; scrollView.horizontalBar = horizontalBar; scrollView.horizontalSlider = horizontalSlider; scrollView.verticalBar = verticalBar; scrollView.verticalSlider = verticalSlider; scrollView.contentAnchor = contentAnchor.transform; scrollView.clipRect = clipRect; scrollView.width = 100.0f; scrollView.height = 100.0f; // Selection.activeObject = scrollViewGO; }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void Rebuild(this exSpriteBorder _spriteBorder) { Texture2D texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(_spriteBorder.guiBorder.textureGUID); _spriteBorder.Build(texture); }
// Use this for initialization void Awake() { _border = GetComponent <exSpriteBorder>(); _tr = transform; }
/////////////////////////////////////////////////////////////////////////////// // functions /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public static void UpdateAtlas( exSpriteBorder _spriteBorder, exAtlasDB.ElementInfo _elInfo ) { // get atlas and index from textureGUID if ( _elInfo != null ) { if ( _elInfo.guidAtlas != exEditorHelper.AssetToGUID(_spriteBorder.atlas) || _elInfo.indexInAtlas != _spriteBorder.index ) { _spriteBorder.SetBorder( _spriteBorder.guiBorder, exEditorHelper.LoadAssetFromGUID<exAtlas>(_elInfo.guidAtlas), _elInfo.indexInAtlas ); } } else { exGUIBorder guiBorder = _spriteBorder.guiBorder; _spriteBorder.Clear(); _spriteBorder.SetBorder( guiBorder, null, -1 ); } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void OnEnable() { base.OnEnable(); if ( target != editSpriteBorder ) { editSpriteBorder = target as exSpriteBorder; } }
public FadeToParams(exSpriteBorder _slider, float _destAlpha, float _duration) { slider = _slider; destAlpha = _destAlpha; duration = _duration; }
// ------------------------------------------------------------------ /// \param _sprites the list of sprites to rebuild /// rebuild the listed sprites // ------------------------------------------------------------------ public static void RebuildSprites(exSpriteBase[] _sprites) { try { EditorUtility.DisplayProgressBar("Rebuild Scene Sprites...", "Rebuild Scene Sprites...", 0.5f); for (int i = 0; i < _sprites.Length; ++i) { exSpriteBase spBase = _sprites[i]; // DISABLE: it is too slow { // float progress = (float)i/(float)_sprites.Length; // EditorUtility.DisplayProgressBar( "Rebuild Scene Sprites...", // "Build Sprite " + spBase.gameObject.name, progress ); // } DISABLE end // if sprite if (spBase is exSprite) { exSprite sp = spBase as exSprite; exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(sp.textureGUID); exSpriteEditor.UpdateAtlas(sp, elInfo); Texture2D texture = null; if (sp.useAtlas == false) { texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(sp.textureGUID); } sp.Build(texture); } #if !(EX2D_EVALUATE) // if sprite font if (spBase is exSpriteFont) { exSpriteFont spFont = spBase as exSpriteFont; spFont.Build(); } // if sprite border if (spBase is exSpriteBorder) { exSpriteBorder spBorder = spBase as exSpriteBorder; Texture2D texture = null; if (spBorder.guiBorder) { exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(spBorder.guiBorder.textureGUID); exSpriteBorderEditor.UpdateAtlas(spBorder, elInfo); if (spBorder.useAtlas == false) { texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(spBorder.guiBorder.textureGUID); } } spBorder.Build(texture); } #endif // EX2D_EVALUATE } EditorUtility.ClearProgressBar(); } catch (System.Exception) { EditorUtility.ClearProgressBar(); throw; } }
public FadeToParams( exSpriteBorder _slider, float _destAlpha, float _duration ) { slider = _slider; destAlpha = _destAlpha; duration = _duration; }