예제 #1
0
    private void UpdateTransform() {
        if (transformTranslate) {
            Vector2 translate = translateFunction.Value(ValueF2);

            Vector2 size;
            if (TryGetNativeSize(out size)) {
                imageObject.transform.localPosition = new Vector2(
                translate.x * size.x,
                translate.y * size.y);
            }
        }

        if (transformRotate) {
            Quaternion rotate = rotateFunction.Value(ValueF2);
            var localRotation = Quaternion.identity * Quaternion.Inverse(rotate);

            // ReSharper disable once RedundantCheckBeforeAssignment
            if (imageObject.transform.localRotation != localRotation) {
                imageObject.transform.localRotation = localRotation;
            }
        }

        if (transformScale) {
            Vector3 scale = scaleFunction.Value(ValueF2);
            MadTransform.SetLocalScale(imageObject.transform, scale);
        }
    }
예제 #2
0
        private void UpdateSize()
        {
            var thisRectTransform = rectTransform;

            for (int i = 0; i < createdChildren.Count; ++i)
            {
                var child = createdChildren[i];
                if (child.gameObject == imageObject.gameObject)
                {
                    continue;
                }

                var otherRectTransform = child.GetComponent <RectTransform>();
                if (otherRectTransform != null)
                {
                    SetSize(otherRectTransform, thisRectTransform.rect.size);
                }
            }

            // update container scale
            Vector2 nativeSize;

            if (TryGetNativeSize(out nativeSize))
            {
                var ratio = new Vector3(
                    thisRectTransform.rect.width / nativeSize.x,
                    thisRectTransform.rect.height / nativeSize.y, 1);
                MadTransform.SetLocalScale(imageObjectContainer.transform, ratio);
            }
        }
예제 #3
0
 public static RepeatedRenderer3D Create(MadPanel panel) {
     var bar = MadTransform.CreateChild<RepeatedRenderer3D>(panel.transform, "repeat progress bar");
     TryApplyExampleTextures(bar);
     Selection.activeObject = bar.gameObject;
     
     return bar;
 }
예제 #4
0
        private void UpdateBarScaleAndOffset()
        {
            if (imageBar != null)
            {
                var   pivot = rectTransform.pivot;
                var   rect  = imageBar.rectTransform.rect;
                float ox    = -(pivot.x - 0.5f) * rect.width;
                float oy    = -(pivot.y - 0.5f) * rect.height;
                var   computedLocalPosition = new Vector3(barImageOffset.x + ox, barImageOffset.y + oy, barImageOffset.z);

                MadTransform.SetLocalScale(imageBar.transform, barImageScale);

                MadTransform.SetLocalPosition(imageBar.transform, computedLocalPosition);

                if (effectTilledImageBarMask != null)
                {
                    MadTransform.SetLocalScale(effectTilledImageBarMask.transform, barImageScale);
                    MadTransform.SetLocalPosition(effectTilledImageBarMask.transform, computedLocalPosition);
                }
            }
            if (imageBurn != null)
            {
                var   pivot = rectTransform.pivot;
                var   rect  = imageBurn.rectTransform.rect;
                float ox    = -(pivot.x - 0.5f) * rect.width;
                float oy    = -(pivot.y - 0.5f) * rect.height;
                var   computedLocalPosition = new Vector3(barImageOffset.x + ox, barImageOffset.y + oy, barImageOffset.z);

                MadTransform.SetLocalScale(imageBurn.transform, barImageScale);

                MadTransform.SetLocalPosition(imageBurn.transform, computedLocalPosition);
            }
        }
예제 #5
0
 void SetIconVisible(Image2 image, float scale = 1)
 {
     image.color     = ComputeColor(spriteIcon.color);
     image.fillValue = 1;
     MadTransform.SetLocalScale(image.transform, new Vector3(scale, scale, scale));
     image.enabled = true;
 }
예제 #6
0
 protected T CreateChild<T>(string childName, Transform parent) where T : Component {
     var child = MadTransform.CreateChild<T>(parent, "generated_" + childName);
     createdChildren.Add(child.gameObject);
     SetAsLastGenerated(child.transform);
     ApplyDebugMode(child.gameObject, debugMode);
     return child;
 }
예제 #7
0
    private void UpdateSpriteSize(Vector2 originPosition, Image2 image, Rect spriteRect) {
        float posX = originPosition.x * scaleRatio.x;
        float posY = originPosition.y * scaleRatio.y;

        MadTransform.SetLocalPosition(image.rectTransform, new Vector3(posX, posY));
        SetSize(image.rectTransform, new Vector2(spriteRect.width * scaleRatio.x, spriteRect.height * scaleRatio.y));
    }
예제 #8
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)));
     }
 }
예제 #9
0
    int BuildTextures(Tex[] textures, string prefix, int startDepth, ref List<MadSprite> sprites) {
        
        int counter = 0;
        foreach (var texture in textures) {
            if (texture.texture == null) {
                continue;
            }
        
            string name = string.Format("{0}{1:D2}", prefix, counter + 1);
            var sprite = MadTransform.CreateChild<MadSprite>(transform, name);
#if !MAD_DEBUG
            sprite.gameObject.hideFlags = HideFlags.HideInHierarchy;
#endif
            
            sprite.guiDepth = startDepth + counter;
            sprite.texture = texture.texture;
            sprite.tint = texture.color;
            
            sprites.Add(sprite);
            
            counter++;
        }
        
        return startDepth + counter;
    }
예제 #10
0
    // updates information about this bar position
    // this method is quite heavy, but it will only execute in editor and when application is not playing
    private void UpdatePanelInfo() {
        if (panel != null && Application.isEditor && !Application.isPlaying) {
            var topPanel = MadTransform.FindParent<MadPanel>(transform);
            bool nowUnderThePanel = topPanel == panel;

            underThePanel = nowUnderThePanel;
        }
    }
예제 #11
0
 void UpdateAnchor() {
     // rewriting anchor objects to make them easy accessible
     var anchor = MadTransform.FindParent<MadAnchor>(transform, 1);
     if (anchor != null) {
         anchorObject = anchor.anchorObject;
         anchorCamera = anchor.anchorCamera;
     }
 }
예제 #12
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();
    }
예제 #13
0
    void SetIconVisible(MadSprite sprite) {
        bool wasInvisible = sprite.visible == false;

        sprite.tint = ComputeColor(tintIcon);
        sprite.fillValue = 1;
        MadTransform.SetLocalScale(sprite.transform, 1);
        sprite.visible = true;

        if (wasInvisible && onIconShow != null) {
            onIconShow(sprite);
        }
    }
예제 #14
0
    private void UpdateBarOffset(Image bar) {
        var pivot = rectTransform.pivot;
        var rect = bar.rectTransform.rect;
        float ox = -(pivot.x - 0.5f) * rect.width;
        float oy = -(pivot.y - 0.5f) * rect.height;

        var computedLocalPosition = new Vector3(
            bar.transform.localPosition.x + barImageOffset.x + ox,
            bar.transform.localPosition.y + barImageOffset.y + oy,
            barImageOffset.z);

        MadTransform.SetLocalPosition(bar.transform, computedLocalPosition);
    }
예제 #15
0
    private void UpdateScreenSpace() {
        if (cameraReference == null) {
            Debug.LogError("Render Camera must be set for the follow script to work.", this);
            return;
        }
        var rect = canvas.pixelRect;

        var w2 = rect.width / 2;
        var h2 = rect.height / 2;

        var screenPoint = cameraReference.WorldToScreenPoint(followObject.transform.position);
        var pos = screenPoint + offset - new Vector3(w2, h2);
        pos = new Vector3(pos.x / canvas.scaleFactor, pos.y / canvas.scaleFactor);

        MadTransform.SetLocalPosition(transform, pos);
    }
예제 #16
0
        protected void CreateAnchor()
        {
            MadUndo.LegacyRegisterSceneUndo("Create Anchor");

            if (IsAnchored())
            {
                EditorUtility.DisplayDialog("Anchor already exists", "Your bar object is already under the anchor", "Fine");
                return;
            }

            var anchor = MadTransform.CreateChild <MadAnchor>(energyBarBase.transform.parent, "Anchor");

            energyBarBase.transform.parent = anchor.transform;

            Selection.activeObject = energyBarBase.gameObject;
        }
예제 #17
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();
    }
예제 #18
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);
            }
        }
    }
예제 #19
0
 static Transform ActiveParentOrPanel() {
     Transform parentTransform = null;
     
     var transforms = Selection.transforms;
     if (transforms.Length > 0) {
         var firstTransform = transforms[0];
         if (MadTransform.FindParent<MadPanel>(firstTransform) != null) {
             parentTransform = firstTransform;
         }
     }
     
     if (parentTransform == null) {
         var panel = MadPanel.UniqueOrNull();
         if (panel != null) {
             parentTransform = panel.transform;
         }
     }
     
     return parentTransform;
 }
예제 #20
0
 protected int RebuildLabel(int depth) {
     if (labelSprite != null) {
         MadGameObject.SafeDestroy(labelSprite.gameObject);
     }
     
     if (labelEnabled && labelFont != null) {
         labelSprite = MadTransform.CreateChild<MadText>(transform, "label");
         labelSprite.font = labelFont;
         labelSprite.guiDepth = depth++;
         
         #if !MAD_DEBUG
         labelSprite.gameObject.hideFlags = HideFlags.HideInHierarchy;
         #endif
     }
     
     // after build we must update label at least once to make it visible
     UpdateLabel();
     
     return depth;
 }
 // ===========================================================
 // Static Methods
 // ===========================================================
 
 public static FilledRenderer3D Create() {
     var panel = MadPanel.UniqueOrNull();
     
     if (panel == null) {
         if (EditorUtility.DisplayDialog(
             "Init Scene?",
             "Scene not initialized for 3D bars. You cannot place new bar without proper initialization. Do it now?",
             "Yes", "No")) {
             MadInitTool.ShowWindow();
             return null;
         }
         
         panel = MadPanel.UniqueOrNull();
     }
 
     var bar = MadTransform.CreateChild<FilledRenderer3D>(panel.transform, "fill progress bar");
     TryApplyExampleTextures(bar);
     Selection.activeObject = bar.gameObject;
     
     return bar;
 }
예제 #22
0
    protected T CreateHidden<T>(string name, Transform parent = null) where T : Component {
        if (container == null) {
            // create container
            container = new GameObject("_container").transform;

#if !MAD_DEBUG
            container.gameObject.hideFlags = HideFlags.HideAndDontSave;
#else
            container.gameObject.hideFlags = HideFlags.DontSave;
#endif
        }

        if (parent == null) {
            parent = container;
        }

        var obj = MadTransform.CreateChild<T>(parent, name, true);

        // if created object is mad sprite, then assign the panel
        if (obj is MadSprite) {
            var sprite = obj as MadSprite;
            sprite.panel = panel;

            if (obj.GetType() == typeof(MadSprite)) {
                sprite.hasPremultipliedAlpha = premultipliedAlpha;
            }
        }

        MadGameObject.SetActive(obj.gameObject, true);

        #if !MAD_DEBUG
        obj.gameObject.hideFlags = HideFlags.HideAndDontSave;
        #else
        obj.gameObject.hideFlags = HideFlags.DontSave;
        #endif

        hiddenObjects.Insert(0, obj.gameObject);

        return obj;
    }
예제 #23
0
        private void UpdateFollowEffect()
        {
            if (!effectFollow)
            {
                return;
            }

            UpdateEffectFollowDefaults();

            Color color    = effectFollowColor.Evaluate(ValueF2);
            float scaleX   = effectFollowScaleX.Evaluate(ValueF2);
            float scaleY   = effectFollowScaleY.Evaluate(ValueF2);
            float scaleZ   = effectFollowScaleZ.Evaluate(ValueF2);
            float rotation = effectFollowRotation.Evaluate(ValueF2) * 360;

            if (effectFollowObject != null)
            {
                var        worldPos = imageBar.transform.TransformPoint(EdgePosition());
                GameObject obj      = effectFollowObject;
                MadTransform.SetPosition(obj.transform, worldPos);
                MadTransform.SetLocalScale(obj.transform, new Vector3(scaleX, scaleY, scaleZ));
                if (obj.GetComponent <Renderer>() != null)
                {
                    obj.GetComponent <Renderer>().sharedMaterial.color = color;
                }
                var newEulerAngles = new Vector3(0, 0, rotation);
                if (obj.transform.localEulerAngles != newEulerAngles)
                {
                    obj.transform.localEulerAngles = newEulerAngles;
                }

                // if object contains Graphic, then manipulate the color
                var graphics = obj.GetComponent <Graphic>();
                if (graphics)
                {
                    graphics.color = color;
                }
            }
        }
예제 #24
0
 int BuildTextures(int depth) {
     for (int i = 0; i < repeatCount; ++i) {
     
         // creating slot
         if (textureSlot != null) {
             string name = string.Format("slot_{0:D2}", i + 1);
             var sprite = MadTransform.CreateChild<MadSprite>(transform, name);
             sprite.texture = textureSlot;
             sprite.transform.localPosition = repeatPositionDelta * i;
             sprite.transform.localPosition += (Vector3) LocalIconOffset(sprite.size);
             
             sprite.guiDepth = depth++;
             
             #if !MAD_DEBUG
             sprite.gameObject.hideFlags = HideFlags.HideInHierarchy;
             #endif
             
             slotSprites.Add(sprite);
         }
         
         // creating icon
         if (textureIcon != null) {
             string name = string.Format("icon_{0:D2}", i + 1);
             var sprite = MadTransform.CreateChild<MadSprite>(transform, name);
             sprite.texture = textureIcon;
             sprite.transform.localPosition = repeatPositionDelta * i;
             sprite.transform.localPosition += (Vector3) LocalIconOffset(sprite.size);
             sprite.guiDepth = depth++;
             
             #if !MAD_DEBUG
             sprite.gameObject.hideFlags = HideFlags.HideInHierarchy;
             #endif
             
             iconSprites.Add(sprite);
         }
     }
     
     return depth;
 }
예제 #25
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();
    }
예제 #26
0
    private void ReconnectPanelIfNeeded(bool firstTime) {
        if (panel == null) {
            panel = MadPanel.FirstOrNull(transform);
            if (panel == null && firstTime) {
                Debug.LogError("You have to initialize scene first! Please execute Tools -> Energy Bar Toolkit -> Initialize");
            } else {
                // check if now I am under the panel
                var topPanel = MadTransform.FindParent<MadPanel>(transform);
                bool nowUnderThePanel = topPanel == panel;

                // new scale should be applied if location of bar relative to panel has changed
                if (nowUnderThePanel && !underThePanel) {
                    // now is under the panel, but wasn't before
                    transform.localScale /= panel.transform.lossyScale.x;
                } else if (!nowUnderThePanel && underThePanel) {
                    // was under the panel before, now it isn't
                    transform.localScale *= panel.transform.lossyScale.x;
                }

                underThePanel = nowUnderThePanel;
            }
        }
    }
예제 #27
0
 void UpdateFollowEffect() {
     if (!effectFollow) {
         return;
     }
     
     Color color = effectFollowColor.Evaluate(ValueF2);
     float scaleX = effectFollowScaleX.Evaluate(ValueF2);
     float scaleY = effectFollowScaleY.Evaluate(ValueF2);
     float scaleZ = effectFollowScaleZ.Evaluate(ValueF2);
     float rotation = effectFollowRotation.Evaluate(ValueF2) * 360;
     
     if (effectFollowSprite != null) {
         MadTransform.SetLocalPosition(effectFollowSprite.transform, EdgePosition());
         MadTransform.SetLocalScale(effectFollowSprite.transform, new Vector3(scaleX, scaleY, scaleZ));
         effectFollowSprite.tint = color;
         var newEulerAngles = new Vector3(0, 0, rotation);
         if (effectFollowSprite.transform.localEulerAngles != newEulerAngles) {
             effectFollowSprite.transform.localEulerAngles = newEulerAngles;
         }
     } else if (effectFollowObject != null && effectFollowObject is GameObject) {
         var worldPos = spriteBar.transform.TransformPoint(EdgePosition());
         GameObject obj = effectFollowObject as GameObject;
         MadTransform.SetPosition(obj.transform, worldPos);
         MadTransform.SetLocalScale(obj.transform, new Vector3(scaleX, scaleY, scaleZ));
         if (obj.GetComponent<Renderer>() != null) {
             obj.GetComponent<Renderer>().sharedMaterial.color = color;
         }
         var newEulerAngles = new Vector3(0, 0, rotation);
         if (obj.transform.localEulerAngles != newEulerAngles) {
             obj.transform.localEulerAngles = newEulerAngles;
         }
         
     }
     
     
 }
예제 #28
0
 protected MadAnchor GetAnchor()
 {
     return(MadTransform.FindParent <MadAnchor>(energyBarBase.transform, 0));
 }
예제 #29
0
 void SetSpriteVisible(MadSprite sprite) {
     sprite.tint = tintIcon;
     sprite.fillValue = 1;
     MadTransform.SetLocalScale(sprite.transform, 1);
     sprite.visible = true;
 }
예제 #30
0
 private void UpdateFollowObjectWorldSpace() {
     MadTransform.SetPosition(transform, followObject.transform.position + offset);
 }