Exemple #1
0
        public void StopPreview()
        {
            DashTween.CleanAll();
            DashTweenCore.Uninitialize();
            DashCore.Instance.CleanPrefabPools();
            DashCore.Instance.CleanSequencers();

            EditorApplication.update -= OnUpdate;

            if (!_isPreviewing)
            {
                return;
            }

            _isPreviewing = false;

            if (_stage == null)
            {
                // Since we can do almost anything in preview we need to reload the scene before it
                EditorSceneManager.OpenScene(EditorSceneManager.GetActiveScene().path);

                DashController[] controllers = GameObject.FindObjectsOfType <DashController>();
                DashController   controller  = controllers.ToList().Find(c => c.previewing);
                DashEditorCore.EditController(controller, DashEditorCore.EditorConfig.editingGraphPath);
                controller.previewing = false;

                EditorUtility.SetDirty(controller);
                EditorSceneManager.SaveOpenScenes();

                Selection.activeGameObject = controller.gameObject;
            }
            else
            {
                _stage.GetType().GetMethod("ReloadStage", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_stage, new object[] {});

                DashController[] controllers = _stage.prefabContentsRoot.GetComponentsInChildren <DashController>();
                DashController   controller  = controllers.ToList().Find(c => c.previewing);
                DashEditorCore.EditController(controller, DashEditorCore.EditorConfig.editingGraphPath);
                controller.previewing = false;
                if (_controllerSelected)
                {
                    Selection.objects = new Object[] { controller.gameObject };
                }

                bool state = (bool)_stage.GetType().GetMethod("SavePrefab", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_stage, new object[] {});
            }
        }
Exemple #2
0
        public override void DrawInspectorControls(Rect p_rect)
        {
            if (!(this is IAnimationNodeBindable) || !DashEditorCore.EditorConfig.enableAnimateNodeInterface)
            {
                return;
            }

            Transform target = ResolveEditorTarget();

            if (target == null)
            {
                return;
            }

            GUIStyle style = new GUIStyle();

            GUI.backgroundColor     = new Color(0, 0, 0, 0.5f);
            style.normal.background = Texture2D.whiteTexture;
            GUI.Box(new Rect(p_rect.x, p_rect.y + p_rect.height + 4, 390, 38), "", style);
            GUI.backgroundColor = Color.white;

            GUILayout.BeginArea(new Rect(p_rect.x + 20, p_rect.y + p_rect.height + 8, p_rect.width - 20, 30));
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            style           = new GUIStyle(GUI.skin.button);
            style.fontStyle = FontStyle.Bold;

            GUI.enabled = ((IAnimationNodeBindable)this).IsFromEnabled();
            if (_bindFrom)
            {
                GUI.backgroundColor = new Color(1, 0, 0);
                if (GUILayout.Button("UNBIND FROM", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    _bindFrom = false;
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                if (GUILayout.Button("BIND FROM", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    ((IAnimationNodeBindable)this).SetTargetFrom(target);
                    _bindTo   = false;
                    _bindFrom = true;
                }
            }

            GUILayout.FlexibleSpace();

            GUI.enabled = ((IAnimationNodeBindable)this).IsToEnabled();
            if (_bindTo)
            {
                GUI.backgroundColor = new Color(1, 0, 0);
                if (GUILayout.Button("UNBIND TO", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    _bindTo = false;
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                if (GUILayout.Button("BIND TO", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    ((IAnimationNodeBindable)this).SetTargetTo(target);
                    _bindFrom = false;
                    _bindTo   = true;
                }
            }

            GUILayout.FlexibleSpace();

            GUI.backgroundColor    = new Color(1, .75f, .5f);
            style.fontSize         = 16;
            style.normal.textColor = GUI.backgroundColor;

            if (GUILayout.Button("PREVIEW", style, GUILayout.Width(100), GUILayout.ExpandHeight(true)))
            {
                TransformStorageData data = new TransformStorageData(target, TransformStorageOption.POSITION);
                AnimateOnTarget(target, NodeFlowDataFactory.Create())?.OnComplete(() =>
                {
                    DashTweenCore.Uninitialize();
                    data.Restore(target);
                }).Start();
            }

            GUI.backgroundColor = Color.white;
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            GUI.enabled = true;

            GUI.color = Color.yellow;
            GUI.DrawTexture(new Rect(p_rect.x + 8, p_rect.y + p_rect.height + 16, 16, 16),
                            IconManager.GetIcon("experimental_icon"));
            GUI.color = Color.white;

            if (_bindFrom)
            {
                ((IAnimationNodeBindable)this).GetTargetFrom(target);
            }
            else if (_bindTo)
            {
                ((IAnimationNodeBindable)this).GetTargetTo(target);
            }
        }