예제 #1
0
    // ===========================================================
    // Static Methods
    // ===========================================================

    public static void DrawInspector(SerializedObject so)
    {
        so.Update();

        var mode         = so.FindProperty("mode");
        var position     = so.FindProperty("position");
        var anchorObject = so.FindProperty("anchorObject");
        var anchorCamera = so.FindProperty("anchorCamera");
        var moveIn3D     = so.FindProperty("moveIn3D");
        var faceCamera   = so.FindProperty("faceCamera");

        MadGUI.PropertyField(mode, "Mode");
        switch ((MadAnchor.Mode)mode.enumValueIndex)
        {
        case MadAnchor.Mode.ObjectAnchor:
            MadGUI.PropertyField(anchorObject, "Anchor Object");
            MadGUI.PropertyField(anchorCamera, "Anchor Camera");
            MadGUI.PropertyField(moveIn3D, "Move In 3D");
            MadGUI.PropertyField(faceCamera, "Face Camera", "Bar graphics will always face anchor camera.");
            break;

        case MadAnchor.Mode.ScreenAnchor:
            MadGUI.PropertyField(position, "Position");
            break;

        default:
            MadDebug.Assert(false, "Unknown mode: " + (MadAnchor.Mode)mode.enumValueIndex);
            break;
        }

        so.ApplyModifiedProperties();
    }
예제 #2
0
            static Type StringToType(string str)
            {
                string prefix = str.Substring(0, 2);

                if (prefix == "b:")
                {
                    return(Type.Boolean);
                }
                else if (prefix == "i:")
                {
                    return(Type.Integer);
                }
                else if (prefix == "f:")
                {
                    return(Type.Float);
                }
                else if (prefix == "s:")
                {
                    return(Type.String);
                }
                else
                {
                    MadDebug.Assert(false, "Unknown type prefix: " + prefix);
                    return(default(Type));
                }
            }
예제 #3
0
    Vector3 FromPosition(Position position)
    {
        float x = 0, y = 0;

        switch (position)
        {
        case Position.Left:
            x = 0;
            y = 0.5f;
            break;

        case Position.Top:
            y = 1;
            x = 0.5f;
            break;

        case Position.Right:
            x = 1;
            y = 0.5f;
            break;

        case Position.Bottom:
            y = 0;
            x = 0.5f;
            break;

        case Position.TopLeft:
            x = 0;
            y = 1;
            break;

        case Position.TopRight:
            x = 1;
            y = 1;
            break;

        case Position.BottomRight:
            x = 1;
            y = 0;
            break;

        case Position.BottomLeft:
            x = 0;
            y = 0;
            break;

        case Position.Center:
            x = 0.5f;
            y = 0.5f;
            break;

        default:
            MadDebug.Assert(false, "Unknown option: " + position);
            break;
        }

        var pos = root.ScreenGlobal(x, y);

        return(pos);
    }
예제 #4
0
    void SetLevelBoolean(bool val)
    {
        string levelName = icon.level.name;

        switch (specialType)
        {
        case SpecialType.Regular:
            MadLevelProfile.SetLevelBoolean(levelName, name, val);
            break;

        case SpecialType.LevelNumber:
            MadDebug.Assert(false, "Level numbers are not persistent!");
            break;

        case SpecialType.Locked:
            MadLevelProfile.SetLocked(levelName, val);
            break;

        case SpecialType.Completed:
            MadLevelProfile.SetCompleted(levelName, val);
            break;

        default:
            MadDebug.Assert(false, "Unknown special type: " + specialType);
            break;
        }
    }
예제 #5
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));
    }
예제 #6
0
    public static MadLevelConfiguration GetActive()
    {
        var active = FindActive();

        MadDebug.Assert(active != null, "There's no active configuration. Please make at least one!");
        return(active);
    }
예제 #7
0
    public Level FindNextLevel(string currentLevelName, bool sameGroup)
    {
        var currentLevel = FindLevelByName(currentLevelName);

        MadDebug.Assert(currentLevel != null, "Cannot find level " + currentLevelName);

        if (sameGroup)
        {
            var nextLevelQuery =
                from l in levels
                where l.groupId == currentLevel.groupId && l.order > currentLevel.order
                orderby l.order ascending
                select l;

            var nextLevel = nextLevelQuery.FirstOrDefault();
            return(nextLevel);
        }
        else
        {
            var nextLevelQuery =
                from l in levels
                where l.order > currentLevel.order
                orderby l.order ascending
                select l;

            var nextLevel = nextLevelQuery.FirstOrDefault();
            return(nextLevel);
        }
    }
예제 #8
0
    public Level FindPreviousLevel(string currentLevelName, MadLevel.Type type, bool sameGroup)
    {
        var currentLevel = FindLevelByName(currentLevelName);

        MadDebug.Assert(currentLevel != null, "Cannot find level " + currentLevelName);

        if (sameGroup)
        {
            var prevLevelQuery =
                from l in levels
                where l.groupId == currentLevel.groupId && l.order < currentLevel.order && l.type == type
                orderby l.order descending
                select l;

            var prevLevel = prevLevelQuery.FirstOrDefault();
            return(prevLevel);
        }
        else
        {
            var prevLevelQuery =
                from l in levels
                where l.order < currentLevel.order && l.type == type
                orderby l.order descending
                select l;

            var prevLevel = prevLevelQuery.FirstOrDefault();
            return(prevLevel);
        }
    }
예제 #9
0
    public override void OnInspectorGUI()
    {
        GUICreator(script.created);

        switch (script.createStatus)
        {
        case MadFont.CreateStatus.None:
            MadGUI.Warning("This font is not yet created. Please fill above and click on the Create button.");
            break;

        case MadFont.CreateStatus.TooMuchGlypsDefined:
            MadGUI.Error("There more glyphs declared than found in the texture.");
            break;

        case MadFont.CreateStatus.TooMuchGlypsFound:
            MadGUI.Error("There more glyphs found in the texture than declared.");
            break;

        case MadFont.CreateStatus.Ok:
            // nothing wrong
            break;

        default:
            MadDebug.Assert(false, "Unknown create status: " + script.createStatus);
            break;
        }

//        MadGUI.Info("This field is read-only");
//        EditorGUILayout.TextArea(font.dimensions);
    }
예제 #10
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);
    }
    private string GetString(string key)
    {
        string value = GetValue(key);

        MadDebug.Assert(value != null, "Key " + key + " not found");

        MadDebug.Assert(value[0] == '"' && value[value.Length - 1] == '"', "Key " + key + " not a string");
        return(value.Substring(1, value.Length - 2));
    }
    private int GetInt(string key)
    {
        string value = GetValue(key);

        MadDebug.Assert(value != null, "Key " + key + " not found");

        int parsed;

        MadDebug.Assert(int.TryParse(value, out parsed), "Key " + key + "not a int");

        return(parsed);
    }
    void ReadPair(string pair)
    {
        if (!string.IsNullOrEmpty(pair))
        {
            int delimiter = pair.IndexOf("=");
            MadDebug.Assert(delimiter != -1, "Delimiter not found");

            var key   = pair.Substring(0, delimiter);
            var value = pair.Substring(delimiter + 1);

            lineMap[key] = value;
        }
    }
예제 #14
0
    public void RemoveGroup(Group group)
    {
        MadDebug.Assert(groups.Contains(group), "There's no such group");

        var dGroup = defaultGroup;
        var levels = group.GetLevels();

        foreach (var level in levels)
        {
            level.groupId = dGroup.id;
        }

        groups.Remove(group);
        SetDirty();
    }
    private int[] GetIntArray(string key)
    {
        string value = GetValue(key);

        MadDebug.Assert(value != null, "Key " + key + " not found");
        string[] elements = value.Split(',');

        int[] result = new int[elements.Length];
        for (int i = 0; i < elements.Length; ++i)
        {
            result[i] = int.Parse(elements[i]);
        }

        return(result);
    }
예제 #16
0
    public Level FindPreviousLevel(string currentLevelName, MadLevel.Type type)
    {
        var currentLevel = FindLevelByName(currentLevelName);

        MadDebug.Assert(currentLevel != null, "Cannot find level " + currentLevelName);

        var nextLevelQuery =
            from l in levels
            where l.order < currentLevel.order && l.type == type
            orderby l.order descending
            select l;

        var nextLevel = nextLevelQuery.FirstOrDefault();

        return(nextLevel);
    }
예제 #17
0
    protected Vector2 TouchPosition()
    {
        MadDebug.Assert(IsTouchingSingle(), "Not touching anything");
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY
        if (!Application.isEditor)
        {
            return(singleTouch.Value.position);
        }
        else
        {
            return(Input.mousePosition);
        }
#else
        return(Input.mousePosition);
#endif
    }
예제 #18
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    public void Update()
    {
        switch (mode)
        {
        case Mode.ScreenAnchor:
            UpdateScreenAnchor();
            break;

        case Mode.ObjectAnchor:
            UpdateObjectAnchor();
            break;

        default:
            MadDebug.Assert(false, "Unknown mode: " + mode);
            break;
        }
    }
예제 #19
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;
        }

        float z = transform.position.z;

        Camera guiCamera = MadTransform.FindParent <Camera>(transform);

        var pos = camera.WorldToScreenPoint(anchorObject.transform.position);

        pos = guiCamera.ScreenToWorldPoint(pos);

        if (!moveIn3D)
        {
            pos.z = z;
        }

        transform.position = pos;

        if (faceCamera)
        {
            transform.LookAt(anchorCamera.transform);
        }
    }
예제 #20
0
        /// <summary>
        /// Unregisters the given profile name. All profile data will be permanently removed from the device.
        /// If current profile is profile that is given to be unregistered, current profile will be changed to defualt.
        /// </summary>
        /// <param name="profileName">Profile name to unregister.</param>
        public static void UnregisterProfile(string profileName)
        {
            if (profileName == DefaultProfile)
            {
                Debug.LogWarning("Cannot unregister default profile");
                return;
            }

            MadDebug.Assert(profileList.Contains(profileName), "No profile called '" + profileName + "' found.");

            if (profile != profileName)
            {
                var currentProfile = profile;
                profile = profileName;
                EraseProfileData();
                profile = currentProfile;
            }
            else
            {
                // is on current profile - reset and fallback to default
                EraseProfileData();
                profile = DefaultProfile;
            }

            List <string> newProfiles = new List <string>();

            string[] oldProfiles = profileList;

            foreach (string oldProfile in oldProfiles)
            {
                if (oldProfile != profileName)
                {
                    newProfiles.Add(oldProfile);
                }
            }

            profileList = newProfiles.ToArray();
        }
예제 #21
0
            string TypeToString()
            {
                switch (type)
                {
                case Type.Boolean:
                    return("b");

                case Type.Integer:
                    return("i");

                case Type.Float:
                    return("f");

                case Type.String:
                    return("s");

                default:
                    MadDebug.Assert(false, "Unknown type: " + type);
                    break;
                }

                return("?");
            }
예제 #22
0
    bool IsLevelBooleanSet()
    {
        string levelName = icon.level.name;

        switch (specialType)
        {
        case SpecialType.Regular:
            return(MadLevelProfile.IsLevelPropertySet(levelName, name));

        case SpecialType.LevelNumber:
            return(MadLevelProfile.IsLevelPropertySet(levelName, name));

        case SpecialType.Locked:
            return(MadLevelProfile.IsLockedSet(levelName));

        case SpecialType.Completed:
            return(MadLevelProfile.IsCompletedSet(levelName));

        default:
            MadDebug.Assert(false, "Unknown special type: " + specialType);
            return(false);
        }
    }
예제 #23
0
    // ===========================================================
    // Static Methods
    // ===========================================================

    public static void DrawInspector(SerializedObject so)
    {
        so.Update();

        var mode         = so.FindProperty("mode");
        var position     = so.FindProperty("position");
        var anchorObject = so.FindProperty("anchorObject");
        var anchorCamera = so.FindProperty("anchorCamera");

        MadGUI.PropertyField(mode, "Mode");
        switch ((MadAnchor.Mode)mode.enumValueIndex)
        {
        case MadAnchor.Mode.ObjectAnchor:
            MadGUI.PropertyField(anchorObject, "Anchor Object", MadGUI.ObjectIsSet);
            MadGUI.PropertyField(anchorCamera, "Anchor Camera", property => property.objectReferenceValue != null || HasMainCamera());

            if (!HasMainCamera())
            {
                GUIMissingMainCameraWarning();
            }
            else if (anchorCamera.objectReferenceValue == null)
            {
                GUIMainCameraWillBeUsed();
            }
            break;

        case MadAnchor.Mode.ScreenAnchor:
            MadGUI.PropertyField(position, "Position");
            break;

        default:
            MadDebug.Assert(false, "Unknown mode: " + (MadAnchor.Mode)mode.enumValueIndex);
            break;
        }

        so.ApplyModifiedProperties();
    }
예제 #24
0
    bool GetLevelBoolean()
    {
        string levelName = icon.level.name;

        switch (specialType)
        {
        case SpecialType.Regular:
            return(MadLevelProfile.GetLevelBoolean(levelName, name));

        case SpecialType.LevelNumber:
            MadDebug.Assert(false, "Level numbers are not persistent!");
            return(false);

        case SpecialType.Locked:
            return(MadLevelProfile.IsLocked(levelName));

        case SpecialType.Completed:
            return(MadLevelProfile.IsCompleted(levelName));

        default:
            MadDebug.Assert(false, "Unknown special type: " + specialType);
            return(false);
        }
    }
예제 #25
0
 void SwitchPage(int newIndex)
 {
     MadDebug.Assert(newIndex >= 0 && newIndex < pages.Count, "There's no page with index " + newIndex);
     pageCurrentIndex = newIndex;
     draggable.MoveTo(newIndex);
 }
예제 #26
0
 static void CheckHasConfiguration() {
     MadDebug.Assert(hasActiveConfiguration,
         "This method may only be used when level configuration is set. Please refer to "
         + MadLevelHelp.ConfigurationWiki);
 }
예제 #27
0
 public string StringValue()
 {
     MadDebug.Assert(type == Type.String, "Property type is " + type);
     return(strValue);
 }
예제 #28
0
 public float FloatValue()
 {
     MadDebug.Assert(type == Type.Float, "Property type is " + type);
     return(float.Parse(strValue));
 }
예제 #29
0
 internal Group(MadLevelConfiguration parent, int id)
 {
     MadDebug.Assert(parent != null, "Parent cannot be null");
     this.parent = parent;
     this.id     = id;
 }
예제 #30
0
 static void CheckLevelExists(string levelName) {
     var level = activeConfiguration.FindLevelByName(levelName);
     MadDebug.Assert(level != null, "There's no level with name '" + levelName + "'");
 }