Exemplo n.º 1
0
 // ===========================================================
 // Methods for/from SuperClass/Interfaces
 // ===========================================================
 
 // ===========================================================
 // Methods
 // ===========================================================
 
 #if UNITY_EDITOR
 void OnDrawGizmos() {
     
     // Draw the gizmo
     Gizmos.matrix = transform.localToWorldMatrix;
     
     Gizmos.color = (UnityEditor.Selection.activeGameObject == gameObject)
         ? Color.green : new Color(1, 1, 1, 0.2f);
     
     var childSprites = MadTransform.FindChildren<MadSprite>(transform);
     Bounds totalBounds = new Bounds(Vector3.zero, Vector3.zero);
     bool totalBoundsSet = false;
     
     foreach (var sprite in childSprites) {
         Rect boundsRect = sprite.GetBounds();
         boundsRect = MadMath.Translate(boundsRect, sprite.transform.localPosition);
         Bounds bounds = new Bounds(boundsRect.center, new Vector2(boundsRect.width, boundsRect.height));
         
         if (!totalBoundsSet) {
             totalBounds = bounds;
             totalBoundsSet = true;
         } else {
             totalBounds.Encapsulate(bounds);
         }
     }
     
     
     Gizmos.DrawWireCube(totalBounds.center, totalBounds.size);
     
     if (editorSelectable) {
         // Make the widget selectable
         Gizmos.color = Color.clear;
         Gizmos.DrawCube(totalBounds.center,
                         new Vector3(totalBounds.size.x, totalBounds.size.y, 0.01f * (guiDepth + 1)));
     }
 }
Exemplo n.º 2
0
    protected override void Rebuild() {
        base.Rebuild();

        // remove all hidden child sprites
        var hidden = MadTransform.FindChildren<MadSprite>(
            transform, (s) => s.gameObject.hideFlags == HideFlags.HideInHierarchy);
        for (int i = 0; i < hidden.Count; ++i) {
            MadGameObject.SafeDestroy(hidden[i].gameObject);
        }
    
        int nextDepth = guiDepth * DepthSpace;
        
        // build background
        nextDepth = BuildBackgroundTextures(nextDepth);

        // build the bar        
        if (textureBar != null) {
            if (effectBurn) {
                spriteBurnBar = CreateHidden<MadSprite>("bar_effect_burn");
                spriteBurnBar.guiDepth = nextDepth++;

                if (TextureValid(effectBurnTextureBar, atlasEffectBurnTextureBarGUID)) {
                    SetTexture(spriteBurnBar, effectBurnTextureBar, atlasEffectBurnTextureBarGUID);
                } else {
                    SetTexture(spriteBurnBar, textureBar, atlasTextureBarGUID);
                }
                
                spriteBurnBar.fillType = ToFillType(growDirection);
                spriteBurnBar.radialFillOffset = radialOffset;
                spriteBurnBar.radialFillLength = radialLength;
            }
        
            spriteBar = CreateHidden<MadSprite>("bar");
            spriteBar.guiDepth = nextDepth++;

            SetTexture(spriteBar, textureBar, atlasTextureBarGUID);
            
            spriteBar.fillType = ToFillType(growDirection);
            spriteBar.radialFillOffset = radialOffset;
            spriteBar.radialFillLength = radialLength;
        }
        
        // build foreground textures
        nextDepth = BuildForegroundTextures(nextDepth);
        
        // follow effect
        if (effectFollow) {
            if (effectFollowObject != null && effectFollowObject is Texture2D) {
                effectFollowSprite = CreateHidden<MadSprite>("bar_effect_follow");
                effectFollowSprite.texture = effectFollowObject as Texture2D;
                effectFollowSprite.guiDepth = nextDepth++;
            }
        }
        
        nextDepth = RebuildLabel(nextDepth);

        UpdateContainer();
    }
Exemplo n.º 3
0
    protected void RemoveCreatedChildren() {
        for (int i = 0; i < createdChildren.Count; ++i) {
            MadGameObject.SafeDestroy(createdChildren[i]);
        }

        // scan for generated children that were not removed
        // this is needed when user performs an undo operation
        var existingChildren = MadTransform.FindChildren<Transform>(transform, c => c.name.StartsWith("generated_"), 0);
        for (int i = 0; i < existingChildren.Count; i++) {
            var child = existingChildren[i];
            MadGameObject.SafeDestroy(child.gameObject);
        }

        createdChildren.Clear();
        backgroundBinds.Clear();
        foregroundBinds.Clear();
    }
Exemplo n.º 4
0
    protected virtual void Rebuild() {
#if MAD_DEBUG
        Debug.Log("rebuilding " + this, this);
#endif

        spriteObjectsBg.Clear();
        spriteObjectsFg.Clear();

        DestroyAllHidden();

        // as a precaution I will search for hidden sprites at level 0
        var hidden = MadTransform.FindChildren<MadSprite>(transform, (s) => (s.hideFlags | HideFlags.HideInHierarchy) != 0, 0);
        if (hidden.Count > 0) {
            Debug.Log("There were " + hidden.Count + " hidden unmanaged sprites under this bar. I will remove them.");
            for (int i = 0; i < hidden.Count; ++i) {
				MadGameObjectDestroy.SafeDestroy(hidden[i].gameObject);
            }
        }
    }
Exemplo n.º 5
0
    protected virtual void Rebuild() {
#if MAD_DEBUG
        Debug.Log("rebuilding " + this, this);
#endif

        if (spriteObjectsBg.Count == 0 && spriteObjectsFg.Count == 0) {
            // in previous version sprites were created without reference in spriteObjects
            // is spriteObjects is empty it's better to assume, that references are not created yet
            // and background objects may exist
            var children = MadTransform.FindChildren<MadSprite>(transform,
                    (s) => s.name.StartsWith("bg_") || s.name.StartsWith("fg_") || s.name == "label",
                    0);
            foreach (var child in children) {
                MadGameObject.SafeDestroy(child.gameObject);
            }
        } else {
            spriteObjectsBg.Clear();
            spriteObjectsFg.Clear();
        }

        DestroyAllHidden();
    }
Exemplo n.º 6
0
    void Rebuild() {
#if MAD_DEBUG
        Debug.Log("rebuilding " + this, this);
#endif
    
        if (spriteObjectsBg.Count == 0 && spriteObjectsFg.Count == 0) {
            // in previous version sprites were created without reference in spriteObjects
            // is spriteObjects is empty it's better to assume, that references are not created yet
            // and background objects may exist
            var children = MadTransform.FindChildren<MadSprite>(transform,
                (s) => s.name.StartsWith("bg_") || s.name.StartsWith("fg_") || s.name == "label",
                0);
            foreach (var child in children) {
                MadGameObject.SafeDestroy(child.gameObject);
            }
        } else {
            foreach (var sprite in spriteObjectsBg) {
                if (sprite != null) {
                    MadGameObject.SafeDestroy(sprite.gameObject);
                }
            }
            
            foreach (var sprite in spriteObjectsFg) {
                if (sprite != null) {
                    MadGameObject.SafeDestroy(sprite.gameObject);
                }
            }
            
            spriteObjectsBg.Clear();
            spriteObjectsFg.Clear();
        }
        
        if (spriteBar != null) {
            MadGameObject.SafeDestroy(spriteBar.gameObject);
        }
        
        if (spriteBurnBar != null) {
            MadGameObject.SafeDestroy(spriteBurnBar.gameObject);
        }
        
        if (effectFollowSprite != null) {
            MadGameObject.SafeDestroy(effectFollowSprite.gameObject);
        }
        
        int nextDepth = BuildTextures(texturesBackground, "bg_", guiDepth * DepthSpace, ref spriteObjectsBg);
        
        if (textureBar != null) {
        
            if (effectBurn) {
                spriteBurnBar = MadTransform.CreateChild<MadSprite>(transform, "bar_effect_burn");
#if !MAD_DEBUG
                spriteBurnBar.gameObject.hideFlags = HideFlags.HideInHierarchy;
#endif
                spriteBurnBar.guiDepth = nextDepth++;
                spriteBurnBar.texture = textureBar;
                
                spriteBurnBar.fillType = ToFillType(growDirection);
            }
        
            spriteBar = MadTransform.CreateChild<MadSprite>(transform, "bar");
#if !MAD_DEBUG
            spriteBar.gameObject.hideFlags = HideFlags.HideInHierarchy;
#endif
            spriteBar.guiDepth = nextDepth++;
            spriteBar.texture = textureBar;
            
            spriteBar.fillType = ToFillType(growDirection);
        }
        
        nextDepth = BuildTextures(texturesForeground, "fg_", nextDepth, ref spriteObjectsFg);
        
        if (effectFollow) {
            if (effectFollowObject != null && effectFollowObject is Texture2D) {
                effectFollowSprite = MadTransform.CreateChild<MadSprite>(transform, "bar_effect_follow");
                effectFollowSprite.texture = effectFollowObject as Texture2D;
                effectFollowSprite.guiDepth = nextDepth++;
                #if !MAD_DEBUG
                effectFollowSprite.gameObject.hideFlags = HideFlags.HideInHierarchy;
                #endif
            }
        }
        
        nextDepth = RebuildLabel(nextDepth);
    }