Exemplo n.º 1
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    public override MadLevelIcon GetIcon(string levelName)
    {
        MadDebug.Assert(!string.IsNullOrEmpty(levelName), "null or empty level name");
        return(MadTransform.FindChild <MadLevelIcon>(draggable.transform, (icon) => {
            return MadGameObject.IsActive(icon.gameObject) && icon.level.name == levelName;
        }, 0));
    }
Exemplo n.º 2
0
    void UpdateObjectAnchor()
    {
        if (anchorObject == null)
        {
            return;
        }

        Camera camera = anchorCamera;

        if (camera == null)
        {
            if (Application.isPlaying)
            {
                MadDebug.LogOnce("Anchor camera not set. Using main camera.", this);
            }
            camera = Camera.main;
            if (camera == null)
            {
                Debug.LogWarning("There's no camera tagged as MainCamera on this scene. Please make sure that there is one or assign a custom camera to this anchor object.", this);
                return;
            }
        }

        var pos = panel.WorldToPanel(camera, anchorObject.transform.position);

        MadTransform.SetPosition(transform, pos);
    }
Exemplo n.º 3
0
    private void StartScaleMode()
    {
        if (scaleMode != ScaleMode.FitToAreaWidth && scaleMode != ScaleMode.FitToAreaHeight)
        {
            return;
        }

        var root = MadTransform.FindParent <MadRootNode>(transform);

        Vector3 scale;

        switch (scaleMode)
        {
        case ScaleMode.FitToAreaWidth:
            float width       = dragBounds.size.x;
            float screenWidth = root.screenWidth;
            scale = Vector3.one * screenWidth / width;
            break;

        case ScaleMode.FitToAreaHeight:
            float height       = dragBounds.size.y;
            float screenHeight = root.screenHeight;
            scale = Vector3.one * screenHeight / height;
            break;

        default:
            Debug.Log("Unknown scale mode: " + scaleMode);
            scale = Vector3.one;
            break;
        }

        transform.localScale = scale;
    }
    void RebuildConstruct()
    {
        int count = draggable.dragStopCount;

        bulletSprites = new MadSprite[count];

        Vector3 startPosition = -(bulletDistance * (count - 1)) / 2;

        for (int i = 0; i < count; ++i)
        {
            var sprite = MadTransform.CreateChild <MadSprite>(transform, "generated_bullet_" + (i + 1));
            sprite.transform.localPosition = startPosition + ((Vector3)bulletDistance * i);

            sprite.texture  = BulletTexture(i);
            sprite.guiDepth = guiDepth;

            bulletSprites[i] = sprite;

            if (hideManagedObjects)
            {
                sprite.gameObject.hideFlags = HideFlags.HideInHierarchy;
            }
            else
            {
                //sprite.gameObject.hideFlags = HideFlags.DontSave;
            }
        }
    }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
    MadSprite BuildSlide(MadSprite template, string anchorName, bool left)
    {
        MadAnchor slideAnchor = MadTransform.FindChildWithName <MadAnchor>(transform, anchorName);

        if (slideAnchor != null)
        {
            DestroyImmediate(slideAnchor.gameObject);
        }

        slideAnchor = CreateChild <MadAnchor>(anchorName);
        if (hideManagedObjects)
        {
            slideAnchor.gameObject.hideFlags = HideFlags.HideInHierarchy;
        }

        slideAnchor.position = left ? MadAnchor.Position.Left : MadAnchor.Position.Right;
        slideAnchor.Update(); // explict update call because position has changed

        var offset = MadTransform.CreateChild(slideAnchor.transform, "Offset");

        offset.transform.localPosition =
            new Vector3(left ? template.texture.width / 2 : -template.texture.width / 2, 0, 0);

        var slide = MadTransform.CreateChild <MadSprite>(offset.transform, "slide", template);

        slide.transform.localScale    = Vector3.one;
        slide.transform.localPosition = Vector3.zero;
        slide.guiDepth = 1000;

        return(slide);
    }
Exemplo n.º 7
0
    void CleanUp(bool forceDelete)
    {
        int levelCount = configuration.LevelCount(MadLevel.Type.Level);
        var children   = MadTransform.FindChildren <MadLevelIcon>(transform, (icon) => icon.hasLevelConfiguration);

        if (forceDelete)
        {
            foreach (var child in children)
            {
                MadGameObject.SafeDestroy(child.gameObject);
            }
        }
        else
        {
            var sorted = from c in children orderby c.levelIndex ascending select c;

            foreach (MadLevelIcon levelIcon in sorted)
            {
                if (levelIcon.levelIndex >= levelCount)
                {
                    // disable leftovers
                    MadGameObject.SetActive(levelIcon.gameObject, false);
                }
            }
        }
    }
 protected MadLevelProfileBufferedBackend() {
     // create a object to keep the coroutine working
     if (Application.isPlaying) {
         profileWatcher = MadTransform.GetOrCreateChild<MadLevelProfileWatcher>(null, "_MLM_ProfileWatcher");
         profileWatcher.Watch(this);
     }
 }
Exemplo n.º 9
0
        static Transform ActiveParentOrPanel()
        {
            Transform parentTransform = null;

            var transforms = Selection.transforms;

            if (transforms.Length > 0)
            {
                var firstTransform = transforms[0];
                if (firstTransform.GetComponent <MadPanel>() != null || MadTransform.FindParent <MadPanel>(firstTransform) != null)
                {
                    parentTransform = firstTransform;
                }
            }

            if (parentTransform == null)
            {
                var       selected          = Selection.activeGameObject;
                Transform selectedTransform = null;

                if (selected != null)
                {
                    selectedTransform = selected.transform;
                }

                var panel = MadPanel.FirstOrNull(selectedTransform);
                if (panel != null)
                {
                    parentTransform = panel.transform;
                }
            }

            return(parentTransform);
        }
Exemplo n.º 10
0
    MadRootNode Init(string rootObjectName, int layer)
    {
        var go = new GameObject();

        go.name = rootObjectName;
        var root = go.AddComponent <MadRootNode>();

        bool hasOtherCamera = GameObject.FindObjectOfType(typeof(Camera)) != null;

        var camera = MadTransform.CreateChild <MadNode>(go.transform, "Camera 2D");
        var cam    = camera.gameObject.AddComponent <Camera>();

        cam.backgroundColor      = Color.gray;
        cam.orthographic         = true;
        cam.orthographicSize     = 1;
        cam.nearClipPlane        = -2;
        cam.farClipPlane         = 2;
        cam.transform.localScale = new Vector3(1, 1, 0.01f);

        if (hasOtherCamera)
        {
            cam.clearFlags = CameraClearFlags.Depth;
        }

        var panel = camera.CreateChild <MadPanel>("Panel");

        // setup layers
        cam.cullingMask        = 1 << layer;
        panel.gameObject.layer = layer;

        AfterCreate(root);

        return(root);
    }
Exemplo n.º 11
0
 private void UpdateRenderMode()
 {
     if (panel.renderMode == MadPanel.RenderMode.DepthBased)
     {
         var loc = transform.localPosition;
         MadTransform.SetLocalPosition(transform, new Vector3(loc.x, loc.y, -guiDepth * 10));
     }
 }
Exemplo n.º 12
0
    void CreateFree(MadRootNode root, MadLevelIcon icon)
    {
        var panel      = MadTransform.FindChild <MadPanel>(root.transform);
        var freeLayout = MadLevelFreeTool.CreateUnderPanel(panel);

        freeLayout.iconTemplate = icon;
        freeLayout.dirty        = true;
    }
Exemplo n.º 13
0
    /// <summary>
    /// Gets all active icons available in the layout.
    /// </summary>
    /// <returns></returns>
    public MadLevelIcon[] GetAllIcons()
    {
        // find under the page
        var icons = MadTransform.FindChildren <MadLevelIcon>(
            transform, (ic) => MadGameObject.IsActive(ic.gameObject), 3);

        return(icons.ToArray());
    }
Exemplo n.º 14
0
    public static MadRootNode Init(string rootObjectName, int layer, bool hideInvisibleSprites = false, bool depthBasedRenderMode = false)
    {
        CheckEmptyScene();

        var go = new GameObject();

        go.name = rootObjectName;
        var root = go.AddComponent <MadRootNode>();

        Camera[] otherCameras   = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[];
        bool     hasOtherCamera = otherCameras.Length > 0;

        float maxDepth = 0;

        for (int i = 0; i < otherCameras.Length; ++i)
        {
            if (otherCameras[i].depth > maxDepth)
            {
                maxDepth = otherCameras[i].depth;
            }
        }

        var camera = MadTransform.CreateChild <MadNode>(go.transform, "Camera 2D");
        var cam    = camera.gameObject.AddComponent <Camera>();

        cam.backgroundColor  = Color.gray;
        cam.orthographic     = true;
        cam.orthographicSize = 1;
        cam.nearClipPlane    = CameraNearClip;
        cam.farClipPlane     = CameraFarClip;
        //cam.transform.localScale = new Vector3(1, 1, 0.01f);
        cam.depth = maxDepth + 1;

        if (hasOtherCamera)
        {
            cam.clearFlags = CameraClearFlags.Depth;
        }
        else
        {
            cam.tag        = "MainCamera";
            cam.clearFlags = CameraClearFlags.SolidColor;
            cam.gameObject.AddComponent <AudioListener>();
        }

        var panel = MadTransform.CreateChild <MadPanel>(go.transform, "Panel");

        panel.hideInvisibleSprites = hideInvisibleSprites;
        if (depthBasedRenderMode)
        {
            panel.renderMode = MadPanel.RenderMode.DepthBased;
        }

        // setup layers
        cam.cullingMask        = 1 << layer;
        panel.gameObject.layer = layer;

        return(root);
    }
Exemplo n.º 15
0
    void Update()
    {
        MadTransform.SetLocalScale(drawCall.transform, transform.lossyScale);

        drawCall.transform.position = transform.position;
        drawCall.transform.rotation = transform.rotation;

        drawCall.gameObject.layer = gameObject.layer;
    }
Exemplo n.º 16
0
    public static MadLevelFreeLayout CreateUnderPanel(MadPanel panel)
    {
        MadUndo.LegacyRegisterSceneUndo("Creating Free Layout");
        var child = MadTransform.CreateChild <MadLevelFreeLayout>(panel.transform, "Free Layout");

        Selection.activeObject = child;

        return(child);
    }
    void RebuildClean()
    {
        var generated = MadTransform.FindChildren <MadSprite>(transform, (sprite) => sprite.name.StartsWith("generated_"));

        foreach (var obj in generated)
        {
            MadGameObject.SafeDestroy(obj.gameObject);
        }
    }
Exemplo n.º 18
0
    private void ClearSlide(string anchorName)
    {
        MadAnchor slideAnchor = MadTransform.FindChildWithName <MadAnchor>(transform, anchorName);

        if (slideAnchor != null)
        {
            DestroyImmediate(slideAnchor.gameObject);
        }
    }
Exemplo n.º 19
0
    private void CreateEmpty()
    {
        var empty = MadTransform.CreateChild <Transform>(sprite.transform, "new_empty");

        empty.transform.localPosition = Vector3.zero;
        empty.transform.localScale    = Vector3.one;

        Selection.activeGameObject = empty.gameObject;
    }
    public static MadLevelGridLayout CreateUnderPanel(MadPanel panel)
    {
        MadUndo.LegacyRegisterSceneUndo("Creating Grid Layout");
        var child = MadTransform.CreateChild <MadLevelGridLayout>(panel.transform, "Grid Layout");

        child.setupMethod      = MadLevelGridLayout.SetupMethod.Generate;
        Selection.activeObject = child;

        return(child);
    }
Exemplo n.º 21
0
    // ===========================================================
    // Methods
    // ===========================================================

    void CreateGrid(MadRootNode root, MadLevelIcon icon, MadSprite slideLeft, MadSprite slideRight)
    {
        var panel      = MadTransform.FindChild <MadPanel>(root.transform);
        var gridLayout = MadLevelGridTool.CreateUnderPanel(panel);

        gridLayout.iconTemplate     = icon;
        gridLayout.leftSlideSprite  = slideLeft;
        gridLayout.rightSlideSprite = slideRight;
        gridLayout.dirty            = true;
    }
Exemplo n.º 22
0
    void Create()
    {
        var background = MadTransform.CreateChild <MadLevelBackground>(panel.transform, objectName);

        Selection.activeGameObject = background.gameObject;

        if (draggable != null)
        {
            background.draggable = draggable;
        }
    }
Exemplo n.º 23
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    public override MadLevelIcon GetIcon(string levelName)
    {
        var icon = MadTransform.FindChild <MadLevelIcon>(transform, (i) => i.level.name == levelName);

        if (icon != null)
        {
            return(icon);
        }

        return(null);
    }
Exemplo n.º 24
0
    void Create()
    {
        var background = MadTransform.CreateChild <MadLevelBackground>(panel.transform, objectName);

        background.transform.localPosition = new Vector3(0, 0, 1000);
        Selection.activeGameObject         = background.gameObject;

        if (draggable != null)
        {
            background.draggable = draggable;
        }
    }
Exemplo n.º 25
0
    // deactivates all other icons under the draggable than given
    private void DeactivateAllOther(HashSet <MadLevelIcon> activeIcons)
    {
        var allIcons = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);

        foreach (var icon in allIcons)
        {
            if (!activeIcons.Contains(icon))
            {
                MadGameObject.SetActive(icon.gameObject, false);
            }
        }
    }
Exemplo n.º 26
0
    private void CreateSprite()
    {
        var s = MadTransform.CreateChild <MadSprite>(sprite.transform, "new_sprite");

        s.transform.localPosition = Vector3.zero;
        s.transform.localScale    = Vector3.one;

        s.ResizeToTexture();
        s.guiDepth = NextDepth();

        Selection.activeGameObject = s.gameObject;
    }
Exemplo n.º 27
0
    private void ResizeDragAreaToBackground()
    {
        var background = MadTransform.FindChildWithName <MadSprite>(script.transform, "background");

        MadUndo.RecordObject2(script, "Resize Drag Area");

        Rect spriteBounds = background.GetTransformedBounds();

        script.dragBounds = new Bounds(spriteBounds.center, new Vector2(spriteBounds.xMax - spriteBounds.xMin, spriteBounds.yMax - spriteBounds.yMin));

        EditorUtility.SetDirty(script);
    }
    void ActivateAction(
        SerializedProperty playAudio,
        SerializedProperty playAudioClip,
        SerializedProperty playAudioVolume,
        SerializedProperty message,
        SerializedProperty messageReceiver,
        SerializedProperty messageMethodName,
        SerializedProperty messageIncludeChildren
        )
    {
        MadGUI.PropertyField(playAudio, "Play Audio");
        MadGUI.ConditionallyEnabled(playAudio.boolValue, () => {
            MadGUI.Indent(() => {
                if (playAudio.boolValue && !FoundAudioListener())
                {
                    if (MadGUI.ErrorFix("There's no AudioListener on the scene. Do you want me to add an "
                                        + "AudioListener to Camera 2D?", "Add"))
                    {
                        var camera = MadTransform.FindParent <Camera>((target as Component).transform);
                        if (camera == null)
                        {
                            camera = FindObjectOfType(typeof(Camera)) as Camera;
                        }
                        if (camera != null)
                        {
                            camera.gameObject.AddComponent <AudioListener>();
                        }
                        else
                        {
                            Debug.LogError("There's no camera on this scene!");
                        }
                    }
                }

                MadGUI.PropertyField(playAudioClip, "Audio Clip", MadGUI.ObjectIsSet);
                MadGUI.PropertyFieldSlider(playAudioVolume, 0, 1, "Volume");
            });
        });

        MadGUI.PropertyField(message, "Send Message");
        MadGUI.ConditionallyEnabled(message.boolValue, () => {
            MadGUI.Indent(() => {
                MadGUI.PropertyField(messageReceiver, "Receiver", MadGUI.ObjectIsSet);
                MadGUI.PropertyField(messageMethodName, "Method Name", MadGUI.StringNotEmpty);
                MadGUI.PropertyField(messageIncludeChildren, "Include Children");

                if (message.boolValue)
                {
                    MadGUI.Info("This should look like this:\nvoid " + messageMethodName.stringValue + "(MadLevelIcon icon)");
                }
            });
        });
    }
Exemplo n.º 29
0
    void ClampPosition()
    {
        var position = cameraPos;
        var rootNode = MadTransform.FindParent <MadRootNode>(transform);

        var areaBottomLeft = new Vector2(dragArea.xMin, dragArea.yMin);
        var areaTopRight   = new Vector2(dragArea.xMax, dragArea.yMax);

        var screenBottomLeft = transform.InverseTransformPoint(rootNode.ScreenGlobal(0, 0));
        var screenTopRight   = transform.InverseTransformPoint(rootNode.ScreenGlobal(1, 1));

        float deltaLeft   = screenBottomLeft.x - areaBottomLeft.x;
        float deltaRight  = screenTopRight.x - areaTopRight.x;
        float deltaTop    = screenTopRight.y - areaTopRight.y;
        float deltaBottom = screenBottomLeft.y - areaBottomLeft.y;

        // apply scale because transform matrix does not contain it
        float scale = transform.localScale.x;

        deltaLeft   *= scale;
        deltaRight  *= scale;
        deltaTop    *= scale;
        deltaBottom *= scale;

        if (dragArea.width < (screenTopRight.x - screenBottomLeft.x))   // drag area smaller
        {
            position.x = (areaTopRight.x + areaBottomLeft.x) / 2;
        }
        else if (deltaLeft < 0)
        {
            position.x -= deltaLeft;
        }
        else if (deltaRight > 0)
        {
            position.x -= deltaRight;
        }

        if (dragArea.height < (screenTopRight.y - screenBottomLeft.y))
        {
            position.y = (areaBottomLeft.y + areaTopRight.y) / 2;
        }
        else if (deltaBottom < 0)
        {
            position.y -= deltaBottom;
        }
        else if (deltaTop > 0)
        {
            position.y -= deltaTop;
        }

        cameraPos = position;
    }
Exemplo n.º 30
0
        static bool ValidateHasGridLayout()
        {
            var panel = MadPanel.UniqueOrNull();

            if (panel == null)
            {
                return(false);
            }

            var gridLayout = MadTransform.FindChild <MadLevelGridLayout>(panel.transform);

            return(gridLayout != null);
        }