/// <summary> /// Calls the repair routine if needed /// </summary> protected virtual void RepairRoutine() { _targetMMFeedbacks = target as MMFeedbacks; if ((_targetMMFeedbacks.SafeMode == MMFeedbacks.SafeModes.EditorOnly) || (_targetMMFeedbacks.SafeMode == MMFeedbacks.SafeModes.Full)) { _targetMMFeedbacks.AutoRepair(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Fires complete events if needed /// </summary> /// <param name="source"></param> public virtual void TriggerOnComplete(MMFeedbacks source) { if (!OnCompleteIsNull && TriggerUnityEvents) { OnComplete.Invoke(); } if (TriggerMMFeedbacksEvents) { MMFeedbacksEvent.Trigger(source, MMFeedbacksEvent.EventTypes.Complete); } }
/// <summary> /// Fires revert events if needed /// </summary> /// <param name="source"></param> public virtual void TriggerOnRevert(MMFeedbacks source) { if (!OnRevertIsNull && TriggerUnityEvents) { OnRevert.Invoke(); } if (TriggerMMFeedbacksEvents) { MMFeedbacksEvent.Trigger(source, MMFeedbacksEvent.EventTypes.Revert); } }
/// <summary> /// Fires Play events if needed /// </summary> /// <param name="source"></param> public virtual void TriggerOnPlay(MMFeedbacks source) { if (!OnPlayIsNull && TriggerUnityEvents) { OnPlay.Invoke(); } if (TriggerMMFeedbacksEvents) { MMFeedbacksEvent.Trigger(source, MMFeedbacksEvent.EventTypes.Play); } }
/// <summary> /// Fires skip events if needed /// </summary> /// <param name="source"></param> public virtual void TriggerOnSkip(MMFeedbacks source) { if (!OnPauseIsNull && TriggerUnityEvents) { OnPause.Invoke(); } if (TriggerMMFeedbacksEvents) { MMFeedbacksEvent.Trigger(source, MMFeedbacksEvent.EventTypes.Skip); } }
/// <summary> /// Initializes the feedback and its timing related variables /// </summary> /// <param name="owner"></param> public virtual void Initialization(GameObject owner) { _initialized = true; Owner = owner; _playsLeft = Timing.NumberOfRepeats + 1; _hostMMFeedbacks = this.gameObject.GetComponent <MMFeedbacks>(); SetInitialDelay(Timing.InitialDelay); SetDelayBetweenRepeats(Timing.DelayBetweenRepeats); SetSequence(Timing.Sequence); CustomInitialization(owner); }
static public void PasteAll(MMFeedbacksEditor targetEditor) { var sourceFeedbacks = new SerializedObject(CopyAllSourceFeedbacks); SerializedProperty feedbacks = sourceFeedbacks.FindProperty("Feedbacks"); for (int i = 0; i < feedbacks.arraySize; i++) { MMFeedback arrayFeedback = (feedbacks.GetArrayElementAtIndex(i).objectReferenceValue as MMFeedback); FeedbackCopy.Copy(new SerializedObject(arrayFeedback)); MMFeedback newFeedback = targetEditor.AddFeedback(arrayFeedback.GetType()); SerializedObject serialized = new SerializedObject(newFeedback); serialized.Update(); FeedbackCopy.Paste(serialized); serialized.ApplyModifiedProperties(); } CopyAllSourceFeedbacks = null; }
protected virtual void OnEnable() { _hostMMFeedbacks = this.gameObject.GetComponent <MMFeedbacks>(); _isHostMMFeedbacksNotNull = _hostMMFeedbacks != null; }
/// <summary> /// Draw a header similar to the one used for the post-process stack /// </summary> static public Rect DrawHeader(ref bool expanded, ref bool activeField, string title, Color feedbackColor, System.Action <GenericMenu> fillGenericMenu, float startedAt, float duration, float totalDuration, MMFeedbackTiming timing, bool pause, MMFeedbacks host) { var e = Event.current; // Initialize Rects var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); var progressRect = GUILayoutUtility.GetRect(1f, 2f); var offset = 4f; var reorderRect = backgroundRect; reorderRect.xMin -= 8f; reorderRect.y += 5f; reorderRect.width = 9f; reorderRect.height = 9f; var labelRect = backgroundRect; labelRect.xMin += 32f + offset; labelRect.xMax -= 20f; var foldoutRect = backgroundRect; foldoutRect.y += 1f; foldoutRect.xMin += offset; foldoutRect.width = 13f; foldoutRect.height = 13f; var toggleRect = backgroundRect; toggleRect.x += 16f; toggleRect.xMin += offset; toggleRect.y += 2f; toggleRect.width = 13f; toggleRect.height = 13f; var menuIcon = PaneOptionsIcon; var menuRect = new Rect(labelRect.xMax + 4f, labelRect.y + 4f, menuIcon.width, menuIcon.height); _timingStyle.normal.textColor = EditorGUIUtility.isProSkin ? _timingDark : _timingLight; _timingStyle.alignment = TextAnchor.MiddleRight; var colorRect = new Rect(labelRect.xMin, labelRect.yMin, 5f, 17f); colorRect.xMin = 0f; colorRect.xMax = 5f; EditorGUI.DrawRect(colorRect, feedbackColor); // Background rect should be full-width backgroundRect.xMin = 0f; backgroundRect.width += 4f; progressRect.xMin = 0f; progressRect.width += 4f; Color headerBackgroundColor = Color.white; // Background - if color is white we draw the default color if (!pause) { headerBackgroundColor = HeaderBackground; } else { headerBackgroundColor = feedbackColor; } EditorGUI.DrawRect(backgroundRect, headerBackgroundColor); // Foldout expanded = GUI.Toggle(foldoutRect, expanded, GUIContent.none, EditorStyles.foldout); // Title ---------------------------------------------------------------------------------------------------- using (new EditorGUI.DisabledScope(!activeField)) { EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); } // Direction ---------------------------------------------------------------------------------------------- float directionRectWidth = 70f; var directionRect = new Rect(labelRect.xMax - directionRectWidth, labelRect.yMin, directionRectWidth, 17f); directionRect.xMin = labelRect.xMax - directionRectWidth; directionRect.xMax = labelRect.xMax; if (timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenBackwards) { GUIContent directionIcon = EditorGUIUtility.IconContent("vcs_change", "Only play when backwards"); EditorGUI.LabelField(directionRect, directionIcon); } if (timing.MMFeedbacksDirectionCondition == MMFeedbackTiming.MMFeedbacksDirectionConditions.OnlyWhenForwards) { float rotationAngle = 180f; var pivotPoint = new Vector2(directionRect.xMin + 9, directionRect.yMin + 8); var matrixBackup = GUI.matrix; GUIUtility.RotateAroundPivot(rotationAngle, pivotPoint); GUIContent directionIcon = EditorGUIUtility.IconContent("vcs_incoming", "Only play when forwards"); EditorGUI.LabelField(directionRect, directionIcon); GUI.matrix = matrixBackup; } // Time ----------------------------------------------------------------------------------------------------- string timingInfo = ""; bool displayTotal = false; if (host.DisplayFullDurationDetails) { if (timing.InitialDelay != 0) { timingInfo += host.ApplyTimeMultiplier(timing.InitialDelay).ToString() + "s + "; displayTotal = true; } timingInfo += duration.ToString("F2") + "s"; if (timing.NumberOfRepeats != 0) { float delayBetweenRepeats = host.ApplyTimeMultiplier(timing.DelayBetweenRepeats); timingInfo += " + " + timing.NumberOfRepeats.ToString() + " x "; if (timing.DelayBetweenRepeats > 0) { timingInfo += "("; } timingInfo += duration + "s"; if (timing.DelayBetweenRepeats > 0) { timingInfo += " + " + host.ApplyTimeMultiplier(timing.DelayBetweenRepeats) + "s )"; } displayTotal = true; } if (displayTotal) { timingInfo += " = " + totalDuration.ToString("F2") + "s"; } } else { timingInfo = totalDuration.ToString("F2") + "s"; } //"[ 2s + 3 x (4s + 1s) ]" float timingRectWidth = 150f; var timingRect = new Rect(labelRect.xMax - timingRectWidth, labelRect.yMin, timingRectWidth, 17f); timingRect.xMin = labelRect.xMax - timingRectWidth; timingRect.xMax = labelRect.xMax; EditorGUI.LabelField(timingRect, timingInfo, _timingStyle); // Progress bar if (totalDuration == 0f) { totalDuration = 0.1f; } if ((startedAt > 0f) && (Time.time - startedAt < totalDuration + 0.05f)) { float fullWidth = progressRect.width; if (totalDuration == 0f) { totalDuration = 0.1f; } float percent = ((Time.time - startedAt) / totalDuration) * 100f; progressRect.width = percent * fullWidth / 100f; Color barColor = Color.white; if (Time.time - startedAt > totalDuration) { barColor = Color.yellow; } EditorGUI.DrawRect(progressRect, barColor); } else { EditorGUI.DrawRect(progressRect, headerBackgroundColor); } // Active checkbox activeField = GUI.Toggle(toggleRect, activeField, GUIContent.none, SmallTickbox); // Dropdown menu icon GUI.DrawTexture(menuRect, menuIcon); for (int i = 0; i < 3; i++) { Rect r = reorderRect; r.height = 1; r.y = reorderRect.y + reorderRect.height * (i / 3.0f); EditorGUI.DrawRect(r, Reorder); } // Handle events if (e.type == EventType.MouseDown) { if (menuRect.Contains(e.mousePosition)) { var menu = new GenericMenu(); fillGenericMenu(menu); menu.DropDown(new Rect(new Vector2(menuRect.x, menuRect.yMax), Vector2.zero)); e.Use(); } } if (e.type == EventType.MouseDown && labelRect.Contains(e.mousePosition) && e.button == 0) { expanded = !expanded; e.Use(); } return(backgroundRect); }
// Multiple Copy ---------------------------------------------------------- static public void CopyAll(MMFeedbacks sourceFeedbacks) { MMFeedbacksConfiguration.Instance._mmFeedbacks = sourceFeedbacks; }
/// <summary> /// On Enable, grabs properties and initializes the add feedback dropdown's contents /// </summary> void OnEnable() { // Get properties _targetMMFeedbacks = target as MMFeedbacks; _mmfeedbacks = serializedObject.FindProperty("Feedbacks"); _mmfeedbacksInitializationMode = serializedObject.FindProperty("InitializationMode"); _mmfeedbacksSafeMode = serializedObject.FindProperty("SafeMode"); _mmfeedbacksAutoPlayOnStart = serializedObject.FindProperty("AutoPlayOnStart"); _mmfeedbacksAutoPlayOnEnable = serializedObject.FindProperty("AutoPlayOnEnable"); _mmfeedbacksDirection = serializedObject.FindProperty("Direction"); _mmfeedbacksAutoChangeDirectionOnEnd = serializedObject.FindProperty("AutoChangeDirectionOnEnd"); _mmfeedbacksDurationMultiplier = serializedObject.FindProperty("DurationMultiplier"); _mmfeedbacksDisplayFullDurationDetails = serializedObject.FindProperty("DisplayFullDurationDetails"); _mmfeedbacksCooldownDuration = serializedObject.FindProperty("CooldownDuration"); _mmfeedbacksInitialDelay = serializedObject.FindProperty("InitialDelay"); _mmfeedbacksFeedbacksIntensity = serializedObject.FindProperty("FeedbacksIntensity"); _mmfeedbacksEvents = serializedObject.FindProperty("Events"); // store GUI bg color _originalBackgroundColor = GUI.backgroundColor; // Repair routine to catch feedbacks that may have escaped due to Unity's serialization issues RepairRoutine(); // Create editors _editors = new Dictionary <MMFeedback, Editor>(); for (int i = 0; i < _mmfeedbacks.arraySize; i++) { AddEditor(_mmfeedbacks.GetArrayElementAtIndex(i).objectReferenceValue as MMFeedback); } // Retrieve available feedbacks List <System.Type> types = (from domainAssembly in System.AppDomain.CurrentDomain.GetAssemblies() from assemblyType in domainAssembly.GetTypes() where assemblyType.IsSubclassOf(typeof(MMFeedback)) select assemblyType).ToList(); // Create display list from types List <string> typeNames = new List <string>(); for (int i = 0; i < types.Count; i++) { FeedbackTypePair newType = new FeedbackTypePair(); newType.FeedbackType = types[i]; newType.FeedbackName = FeedbackPathAttribute.GetFeedbackDefaultPath(types[i]); if (newType.FeedbackName == "MMFeedbackBase") { continue; } _typesAndNames.Add(newType); } _typesAndNames = _typesAndNames.OrderBy(t => t.FeedbackName).ToList(); typeNames.Add("Add new feedback..."); for (int i = 0; i < _typesAndNames.Count; i++) { typeNames.Add(_typesAndNames[i].FeedbackName); } _typeDisplays = typeNames.ToArray(); _directionButtonStyle = new GUIStyle(); _directionButtonStyle.border.left = 0; _directionButtonStyle.border.right = 0; _directionButtonStyle.border.top = 0; _directionButtonStyle.border.bottom = 0; }
/// <summary> /// On init we initialize our values /// </summary> protected override void Initialization() { base.Initialization(); _mmFeedbacks = this.gameObject.GetComponent <MMFeedbacks>(); }
static public void CopyAll(MMFeedbacks sourceFeedbacks) { CopyAllSourceFeedbacks = sourceFeedbacks; }
static public void Trigger(MMFeedbacks source, EventTypes type) { OnEvent?.Invoke(source, type); }