// =========================================================== // 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(); }
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)); } }
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); }
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; } }
// =========================================================== // 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)); }
public static MadLevelConfiguration GetActive() { var active = FindActive(); MadDebug.Assert(active != null, "There's no active configuration. Please make at least one!"); return(active); }
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); } }
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); } }
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); }
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; } }
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); }
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); }
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 }
// =========================================================== // 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; } }
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); } }
/// <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(); }
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("?"); }
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); } }
// =========================================================== // 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(); }
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); } }
void SwitchPage(int newIndex) { MadDebug.Assert(newIndex >= 0 && newIndex < pages.Count, "There's no page with index " + newIndex); pageCurrentIndex = newIndex; draggable.MoveTo(newIndex); }
static void CheckHasConfiguration() { MadDebug.Assert(hasActiveConfiguration, "This method may only be used when level configuration is set. Please refer to " + MadLevelHelp.ConfigurationWiki); }
public string StringValue() { MadDebug.Assert(type == Type.String, "Property type is " + type); return(strValue); }
public float FloatValue() { MadDebug.Assert(type == Type.Float, "Property type is " + type); return(float.Parse(strValue)); }
internal Group(MadLevelConfiguration parent, int id) { MadDebug.Assert(parent != null, "Parent cannot be null"); this.parent = parent; this.id = id; }
static void CheckLevelExists(string levelName) { var level = activeConfiguration.FindLevelByName(levelName); MadDebug.Assert(level != null, "There's no level with name '" + levelName + "'"); }