public void CloseSameLevelPanels(WooPanel panel, bool immediate = false, bool notify = true) { if (panel.PanelType == PanelType.Independent) { return; } var parent = GetParent(panel); if (parent != null) { var children = GetChildren(parent.Panel); for (int i = 0; i < children.Count; i++) { if (panel != children[i].Panel && children[i].Panel.PanelType != PanelType.Independent) { Close(children[i].Panel, immediate, notify); } } } else { var rootNodes = GetRootNodes(panel); for (int i = 0; i < rootNodes.Count; i++) { if (rootNodes[i].Panel != panel && rootNodes[i].Panel.PanelType != PanelType.Independent) { Close(rootNodes[i].Panel, immediate, notify); } } } }
private void DrawPanelPropertiesTextures(WooPanel panel) { if (panel == null || panel.PanelProperties == null) { return; } var shouldOpenWithChild = panel.PanelProperties.WithChild && WooPanelsEngine.Instance.GetChildren(panel) != null && WooPanelsEngine.Instance.GetChildren(panel).Count > 0; var shouldOpenWithParent = panel.PanelProperties.WithParent && WooPanelsEngine.Instance.GetParent(panel) != null; if (shouldOpenWithChild || shouldOpenWithParent || panel.PanelProperties.OnAwake) { var iconRect = panelNodes[panel].rect; iconRect.position += Vector2.right * (iconRect.width + 5.0f); iconRect.width = openWithChildTexture.width * iconRect.height / openWithChildTexture.height; GUILayout.Space(30.0f); if (shouldOpenWithChild) { GUI.DrawTexture(iconRect, openWithChildTexture); } if (shouldOpenWithParent) { GUI.DrawTexture(iconRect, openWithParentTexture); } if (panel.PanelProperties.OnAwake) { GUI.DrawTexture(iconRect, openOnAwakeTexture); } } }
public void PlayOpenAnimationImmdiately(WooPanel panel, bool notify = true) { panel.gameObject.SetActive(true); panelNodes[panel].StopCoroutines(); panel.PanelState = PanelState.IsOpening; if (notify) { panel.NotifyOpeningBegin(); } panel.PanelState = PanelState.Opened; if (notify) { panel.NotifyOpeningEnd(); } ProcessAlwaysOnTop(panel); panel.PanelState = PanelState.IsOpening; RewindToEndPanelAnimation(panel); SamplePanelAnimator(panel); panel.PanelState = PanelState.Opened; }
public void PlayCloseAnimationImmdiately(WooPanel panel, bool notify = true) { panel.gameObject.SetActive(true); panelNodes[panel].StopCoroutines(); panel.PanelState = PanelState.IsClosing; if (notify) { panel.NotifyClosingBegin(); } panel.PanelState = PanelState.Closed; if (notify) { panel.NotifyClosingEnd(); } panel.PanelState = PanelState.IsClosing; RewindToEndPanelAnimation(panel); SamplePanelAnimator(panel); panel.PanelState = PanelState.Closed; panel.gameObject.SetActive(panel.PanelProperties.ActiveWhenClosed); }
public void OpenNotAnimated(WooPanel panel, bool notify = true, WooPanel target = null) { if (IsOpen(panel) || !CanBeOpened(panel)) { return; } if (panel == null) { return; } RebuildIfPanelGameObjectIsNull(panel); panel.gameObject.SetActive(true); ProcessAlwaysOnTop(panel); TryOpeningParents(panel, true, notify, target); CloseSameLevelPanels(panel, true, notify); panelNodes[panel].IsOpening = true; RewindToEndPanelAnimation(panel); SamplePanelAnimator(panel); panelNodes[panel].IsOpen = true; if (notify) { panel.NotifyOpeningBegin(); } TryOpeningChildren(panel, true, target); if (notify) { panel.NotifyOpeningEnd(); } }
private void DrawLinesRecursive(WooPanel panel, int level) { var children = WooPanelsEngine.Instance.GetChildren(panel); if (WooPanelsEngine.Instance.panelNodes[panel].Children.Count > 1) { var firstPanel = children.Find((p) => p.Panel.PanelType == PanelType.Dependent); var lastPanel = children.FindLast((p) => p.Panel.PanelType == PanelType.Dependent); if (firstPanel != lastPanel) { WooPanelsEngine.Instance.panelNodes[panel].Children.ForEach((p) => { if (p.Panel.PanelType == PanelType.Dependent) { DrawDependentHandles((p as WooPanelNode).rect, LinesColor); } } ); } DrawConnectionBetweenPanels(firstPanel as WooPanelNode, lastPanel as WooPanelNode, LinesColor); } for (int i = 0; i < children.Count; i++) { DrawLinesRecursive(children[i].Panel, level + 1); } }
private void DrawAnimatorProperty(WooPanel panel) { GUILayout.BeginVertical(); GUILayout.Space(10.0f); panel.GetComponent <Animator>().runtimeAnimatorController = EditorGUILayout.ObjectField(panel.GetComponent <Animator>().runtimeAnimatorController, typeof(UnityEditor.Animations.AnimatorController), false) as UnityEditor.Animations.AnimatorController; GUILayout.EndVertical(); }
private void DrawCreateButtons(WooPanel panel, int level) { if (selectedPanel != null && panelNodes.ContainsKey(selectedPanel) && panelNodes[selectedPanel] != null) { if (panelNodes[selectedPanel].Children.Count > 0 && panelNodes[panel].Parent != null) { if (panelNodes[selectedPanel].Children.Last() == panelNodes[panel]) { DrawCreatePanelButton("Create Child Panel", level, panelNodes[selectedPanel].Panel.transform); } } else if (panelNodes[selectedPanel].Children.Count == 0 && selectedPanel == panel) { DrawCreatePanelButton("Create Child Panel", level + 1, panel.transform); } if (panelNodes[selectedPanel].ParentTransform == panelNodes[panel].ParentTransform) { if (panelNodes[selectedPanel].Parent == null) { if (allRootNodes[panelNodes[panel].ParentTransform].Last().Panel == panel) { DrawCreatePanelButton("Create Sibling Panel", level, panel.transform.parent); } } else { if (panelNodes[selectedPanel].Parent.Children.Count > 0 && panelNodes[selectedPanel].Parent.Children.Last().Panel == panel) { DrawCreatePanelButton("Create Sibling Panel", level, panel.transform.parent); } } } } }
private void DrawSelectedIndicator(WooPanel panel) { if (selectedPanel == panel) { DrawSelectedIndicator(panelNodes[panel].rect, WooPanelsEngine.Instance.IsOpen(panel)); } }
public void ProcessAlwaysOnTop(WooPanel panel) { if (panel.PanelProperties.AlwaysOnTop) { panel.transform.SetAsLastSibling(); } }
public void TryOpeningChildren(WooPanel panel, bool immediate = false, bool notify = false, WooPanel target = null) { var children = GetChildren(panel); bool foundDependent = false; for (int i = 0; i < children.Count; i++) { if (HasInTree(children[i].Panel, target)) { Open(children[i].Panel, immediate, notify, target); if (children[i].Panel.PanelType == PanelType.Dependent) { foundDependent = true; } } } for (int i = 0; i < children.Count; i++) { if (foundDependent && children[i].Panel.PanelType == PanelType.Dependent) { continue; } if (children[i].Panel.PanelProperties.WithParent) { Open(children[i].Panel, immediate, notify, target); } } }
public void CloseNotAnimated(WooPanel panel, bool notify = true) { if (panel.IsClosed()) { return; } RebuildIfPanelGameObjectIsNull(panel); panel.gameObject.SetActive(true); panel.PanelState = PanelState.IsClosing; var children = GetChildren(panel); for (int i = 0; i < children.Count; i++) { Close(children[i].Panel, true, notify); } if (notify) { panel.NotifyClosingBegin(); } CloseImmediately(panel, notify); panel.gameObject.SetActive(panel.PanelProperties.ActiveWhenClosed); }
private void DrawAnimationProgress(WooPanel panel) { var prevColor = GUI.backgroundColor; var color = new Color(0.8f, 0.8f, 0.8f, 1.0f); var sliderColor = LinesColor; var rect = panelNodes[panel].rect; rect.position = rect.position + Vector2.right * 1.0f - Vector2.down * rect.height + Vector2.down * 5.0f; rect.height = 5.0f; rect.width -= 2.0f; var sliderValue = 0.0f; if (panelNodes[panel].IsClosing || panelNodes[panel].IsClosed) { sliderValue = 1.0f - panelNodes[panel].simulatedTime; } else { sliderValue = panelNodes[panel].simulatedTime; } if (panelNodes[panel].IsWaiting) { sliderValue = (panelNodes[panel].waitingTime - panelNodes[panel].remainingWaitingTime) / panelNodes[panel].waitingTime; sliderColor = new Color(0.5f, 0.7f, 1.0f, 1.0f); } if (panelNodes[panel].IsClosing || panelNodes[panel].IsOpening || panelNodes[panel].IsWaiting) { GUI.backgroundColor = color; if (panelNodes[panel].IsWaitingToOpen) { rect.width *= sliderValue; } else if (panelNodes[panel].IsWaitingToClose) { rect.position += rect.width * Vector2.right * (1.0f - sliderValue); rect.width *= sliderValue; } GUI.Box(rect, ""); if (!panelNodes[panel].IsWaiting) { rect.width *= sliderValue; if (sliderValue > Mathf.Epsilon) { GUI.backgroundColor = sliderColor; GUI.Box(rect, ""); } } } GUI.backgroundColor = prevColor; }
public float TimeToStartOpening(WooPanel panel) { if (panel == null) { return(0.0f); } return(TimeToOpenParents(panel) * panel.PanelProperties.ParentToOpen + TimeForSameLevelToClose(panel) * panel.PanelProperties.SiblingsToClose); }
public bool RegisterPanel(WooPanel panel) { if (!panelNodes.ContainsKey(panel)) { Rebuild(); } return(false); }
private void DrawNode(WooPanel panel, int level) { if (panel == null) { return; } GUILayout.BeginHorizontal(); DrawPanelButton(panel, level); DrawSelectedIndicator(panel); DrawAlwaysOnTopIndicator(panel); if (showIcons) { DrawPanelPropertiesTextures(panel); } if (showControllers) { DrawAnimatorProperty(panel); } DrawAnimationProgress(panel); if (editAnimators) { DrawAnimatorSliders(panel); } if (showType) { DrawScriptProperty(panel); } if (showTexts) { DrawPanelPropertiesText(panel); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); var children = WooPanelsEngine.Instance.GetChildren(panel); if (!panelNodes[panel].Collapsed) { for (int i = 0; i < children.Count; i++) { DrawNode(children[i].Panel, level + 1); } } if (!Application.isPlaying) { DrawCreateButtons(panel, level); } }
public float TimeToClose(WooPanel panel) { float timeToClose = 0.0f; timeToClose += TimeForChildrenToClose(panel) * panel.PanelProperties.ChildrenToClose; timeToClose += panelNodes[panel].TimeToClose(); return(timeToClose); }
private void ProcessEffects() { WooPanel myScript = (WooPanel)target; foldout = EditorGUILayout.Foldout(foldout, "Effects", true); if (foldout) { blurSelected = GUILayout.Button("Add Blur"); whiteSelected = GUILayout.Button("Add White Background"); darkSelected = GUILayout.Button("Add Dark Background"); } var effects = myScript.transform.Find("Effects"); if (blurSelected || whiteSelected || darkSelected) { if (myScript.transform.Find("Effects") == null) { effects = CreateGameObject("Effects", myScript.transform).transform; effects.SetAsFirstSibling(); } if (blurSelected) { var blur = effects.Find("Blur"); if (blur == null) { var go = CreateGameObjectWithRawImage("Blur", effects); var blurMaterial = Resources.Load <Material>("WooPanels/Materials/Blurred");; go.GetComponent <RawImage>().material = blurMaterial; } } if (whiteSelected) { var blur = effects.Find("Whiten"); if (blur == null) { var go = CreateGameObjectWithRawImage("Whiten", effects); go.GetComponent <RawImage>().color = new Color(1.0f, 1.0f, 1.0f, 0.3f); } } if (darkSelected) { var blur = effects.Find("Darken"); if (blur == null) { var go = CreateGameObjectWithRawImage("Darken", effects); go.GetComponent <RawImage>().color = new Color(0.0f, 0.0f, 0.0f, 0.3f); } } } }
public void Toggle(WooPanel panel, bool immediate = false, bool notify = true) { if (panel.IsOpenedOrOpening()) { Close(panel, immediate, notify); } else { Open(panel, immediate, notify); } }
public void RewindPanelAnimation(WooPanel panel) { // if (panelNodes[panel].NotDefined) // { // panelNodes[panel].simulatedTime = panel.PanelProperties.SkipFirstAnimation ? 1.0f : 0.0f; // } // else // { panelNodes[panel].simulatedTime = 1.0f - Mathf.Min(panelNodes[panel].simulatedTime, 1.0f); // } }
public void Close(WooPanel panel, bool immediate = false, bool notify = true) { if (!immediate) { CloseAnimated(panel, notify); } else { CloseNotAnimated(panel, notify); } }
private void Close(WooPanel panel, bool immmediate = false) { if (editAnimators && !immmediate) { WooPanelsEngine.Instance.Close(panel); } else { WooPanelsEngine.Instance.Close(panel, true); } }
private void MakeTreeActive(WooPanel panel) { var parent = GetParent(panel); panel.gameObject.SetActive(true); if (parent != null) { MakeTreeActive(parent.Panel); } }
private void Open(WooPanel panel) { if (editAnimators) { WooPanelsEngine.Instance.Open(panel); } else { WooPanelsEngine.Instance.Open(panel, true); } }
private void CloseChildrenAndSelfImmediately(WooPanel panel, bool notify = true) { var children = GetChildren(panel); panel.gameObject.SetActive(true); foreach (var child in children) { CloseChildrenAndSelfImmediately(child.Panel, notify); } PlayCloseAnimationImmdiately(panel, notify); }
private void RebuildIfPanelGameObjectIsNull(WooPanel panel) { if (panel.gameObject == null) { Rebuild(); } if (panel.gameObject == null) { return; } }
private void SamplePanelAnimator(WooPanel panel) { if (panel == null || panel.GetComponent <Animator>() == null) { return; } AnimationClip animation = null; var animatorController = panel.GetComponent <Animator>().runtimeAnimatorController; animation = panelNodes[panel].GetActiveAnimation(); var time = panelNodes[panel].simulatedTime; time = Mathf.Clamp(time, 0.0f, 1.0f); if (panelNodes[panel].IsClosed || panelNodes[panel].IsClosing || panelNodes[panel].IsWaitingToClose) { if (panelNodes[panel].IsMirrored()) { time = 1.0f - time; } } if (animation != null) { #if UNITY_EDITOR if (AnimationMode.InAnimationMode()) { if (!Application.isPlaying) { AnimationMode.SampleAnimationClip(panel.gameObject, animation, animation.length * time); } } else { if (!Application.isPlaying && panel.GetLayerIndex() != -1) { panel.GetAnimator().Play(animation.name, panel.GetLayerIndex(), time); panel.GetAnimator().Update(Time.deltaTime); panel.GetAnimator().StopPlayback(); } } #endif if (Application.isPlaying && panel.GetLayerIndex() != -1) { panel.GetAnimator().Play(animation.name, panel.GetLayerIndex(), time); panel.GetAnimator().Update(Time.deltaTime); panel.GetAnimator().StopPlayback(); } } }
public Transform GetRoot(WooPanel panel) { var underRootPanel = GetParent(panel); var underRootTransform = panel.transform; if (underRootPanel != null && underRootPanel.Panel != null) { underRootTransform = underRootPanel.Panel.transform; } return(underRootTransform.parent); }
public void TryOpeningParents(WooPanel panel, bool immediate = false, bool notify = true, WooPanel target = null) { var parent = GetParent(panel); if (parent != null) { if (parent.Panel.PanelProperties.WithChild) { Open(parent.Panel, immediate, notify, target); } } }
public float TimeToOpenParents(WooPanel panel) { float timeForParentsToOpen = 0.0f; var parent = GetParent(panel); if (parent != null) { timeForParentsToOpen += TimeToOpen(parent.Panel); } return(timeForParentsToOpen); }