InitInstantiatedPreviewRecursive() static private method

static private InitInstantiatedPreviewRecursive ( GameObject go ) : void
go UnityEngine.GameObject
return void
Ejemplo n.º 1
0
        public void SetCurrentPreviewObject(GameObject go, LookDevEditionContext context)
        {
            DestroyCurrentPreviewObject(context);

            if (go != null)
            {
                int index = (int)context;
                if (m_LookDevView == null ||
                    m_LookDevView.previewUtilityContexts == null ||
                    m_LookDevView.previewUtilityContexts[index] == null)
                {
                    return;
                }

                m_OriginalGameObject[index] = go;

                for (var i = 0; i < m_PreviewObjects[index].Length; ++i)
                {
                    m_PreviewObjects[index][i] = m_LookDevView.previewUtilityContexts[index].m_PreviewUtility[i].InstantiatePrefabInScene(m_OriginalGameObject[index]);
                    m_PreviewObjects[index][i].transform.position = new Vector3(0.0f, 0.0f, 0.0f);
                    m_PreviewObjects[index][i].transform.rotation = Quaternion.identity;
                    EditorUtility.InitInstantiatedPreviewRecursive(m_PreviewObjects[index][i]);
                    DisableRendererProperties(m_PreviewObjects[index][i]); // Avoid light probe influence from the main scene (but still have the default probe lighting)
                    PreviewRenderUtility.SetEnabledRecursive(m_PreviewObjects[index][i], false);
                }

                UpdateCurrentObjectArray();
            }
        }
Ejemplo n.º 2
0
        internal static GameObject InstantiateForAnimatorPreview(UnityEngine.Object original)
        {
            if (original == null)
            {
                throw new ArgumentException("The prefab you want to instantiate is null.");
            }
            GameObject gameObject = EditorUtility.InstantiateRemoveAllNonAnimationComponents(original, Vector3.zero, Quaternion.identity) as GameObject;

            gameObject.name += "AnimatorPreview";
            gameObject.tag   = "Untagged";
            EditorUtility.InitInstantiatedPreviewRecursive(gameObject);
            Animator[] componentsInChildren = gameObject.GetComponentsInChildren <Animator>();
            for (int i = 0; i < componentsInChildren.Length; i++)
            {
                Animator animator = componentsInChildren[i];
                animator.enabled     = false;
                animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
                animator.logWarnings = false;
                animator.fireEvents  = false;
            }
            if (componentsInChildren.Length == 0)
            {
                Animator animator2 = gameObject.AddComponent <Animator>();
                animator2.enabled     = false;
                animator2.cullingMode = AnimatorCullingMode.AlwaysAnimate;
                animator2.logWarnings = false;
                animator2.fireEvents  = false;
            }
            return(gameObject);
        }
Ejemplo n.º 3
0
        void InitInstance(Animator scenePreviewObject, Motion motion)
        {
            m_SourcePreviewMotion        = motion;
            m_SourceScenePreviewAnimator = scenePreviewObject;

            if (m_PreviewInstance == null)
            {
                GameObject go = CalculatePreviewGameObject(scenePreviewObject, motion, animationClipType);
                SetupBounds(go);
            }

            if (timeControl == null)
            {
                timeControl = new TimeControl();
            }

            if (m_ReferenceInstance == null)
            {
                GameObject referenceGO = (GameObject)EditorGUIUtility.Load("Avatar/dial_flat.prefab");
                m_ReferenceInstance = (GameObject)Object.Instantiate(referenceGO, Vector3.zero, Quaternion.identity);
                EditorUtility.InitInstantiatedPreviewRecursive(m_ReferenceInstance);
                previewUtility.AddSingleGO(m_ReferenceInstance);
            }

            if (m_DirectionInstance == null)
            {
                GameObject directionGO = (GameObject)EditorGUIUtility.Load("Avatar/arrow.fbx");
                m_DirectionInstance = (GameObject)Object.Instantiate(directionGO, Vector3.zero, Quaternion.identity);
                EditorUtility.InitInstantiatedPreviewRecursive(m_DirectionInstance);
                previewUtility.AddSingleGO(m_DirectionInstance);
            }

            if (m_PivotInstance == null)
            {
                GameObject pivotGO = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx");
                m_PivotInstance = (GameObject)Object.Instantiate(pivotGO, Vector3.zero, Quaternion.identity);
                EditorUtility.InitInstantiatedPreviewRecursive(m_PivotInstance);
                previewUtility.AddSingleGO(m_PivotInstance);
            }

            if (m_RootInstance == null)
            {
                GameObject rootGO = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx");
                m_RootInstance = (GameObject)Object.Instantiate(rootGO, Vector3.zero, Quaternion.identity);
                EditorUtility.InitInstantiatedPreviewRecursive(m_RootInstance);
                previewUtility.AddSingleGO(m_RootInstance);
            }

            // Load preview settings from prefs
            m_IKOnFeet                = EditorPrefs.GetBool(kIkPref, false);
            m_ShowReference           = EditorPrefs.GetBool(kReferencePref, true);
            is2D                      = EditorPrefs.GetBool(k2DPref, EditorSettings.defaultBehaviorMode == EditorBehaviorMode.Mode2D);
            timeControl.playbackSpeed = EditorPrefs.GetFloat(kSpeedPref, 1f);

            SetPreviewCharacterEnabled(false, false);

            m_PivotPositionOffset = Vector3.zero;
        }
Ejemplo n.º 4
0
        public void ResetPreviewInstance()
        {
            if (m_PreviewUtility == null)
            {
                InitPreviewUtility();
            }

            DestroyPreviewInstance();
            if (palette != null)
            {
                m_PaletteInstance = previewUtility.InstantiatePrefabInScene(palette);

                // Prevent palette from overriding the prefab while it is active, unless user saves the palette
                PrefabUtility.DisconnectPrefabInstance(m_PaletteInstance);

                EditorUtility.InitInstantiatedPreviewRecursive(m_PaletteInstance);
                m_PaletteInstance.transform.position   = new Vector3(0, 0, 0);
                m_PaletteInstance.transform.rotation   = Quaternion.identity;
                m_PaletteInstance.transform.localScale = Vector3.one;

                string      assetPath    = AssetDatabase.GetAssetPath(palette);
                GridPalette paletteAsset = AssetDatabase.LoadAssetAtPath <GridPalette>(assetPath);
                if (paletteAsset != null)
                {
                    if (paletteAsset.cellSizing == GridPalette.CellSizing.Automatic)
                    {
                        Grid grid = m_PaletteInstance.GetComponent <Grid>();
                        if (grid != null)
                        {
                            grid.cellSize = GridPaletteUtility.CalculateAutoCellSize(grid, grid.cellSize);
                        }
                        else
                        {
                            Debug.LogWarning("Grid component not found from: " + assetPath);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("GridPalette subasset not found from: " + assetPath);
                }

                foreach (var renderer in m_PaletteInstance.GetComponentsInChildren <Renderer>())
                {
                    renderer.gameObject.layer          = Camera.PreviewCullingLayer;
                    renderer.allowOcclusionWhenDynamic = false;
                }

                foreach (var transform in m_PaletteInstance.GetComponentsInChildren <Transform>())
                {
                    transform.gameObject.hideFlags = HideFlags.HideAndDontSave;
                }

                PreviewRenderUtility.SetEnabledRecursive(m_PaletteInstance, false);

                clipboardView.ResetPreviewMesh();
            }
        }
Ejemplo n.º 5
0
 internal static void InitInstantiatedPreviewRecursive(GameObject go)
 {
     go.hideFlags = HideFlags.HideAndDontSave;
     go.layer     = Camera.PreviewCullingLayer;
     foreach (Transform transform in go.transform)
     {
         EditorUtility.InitInstantiatedPreviewRecursive(transform.gameObject);
     }
 }
Ejemplo n.º 6
0
 public void ResetPreviewInstance()
 {
     if (this.m_PreviewUtility == null)
     {
         this.InitPreviewUtility();
     }
     this.DestroyPreviewInstance();
     if (this.palette != null)
     {
         this.m_PaletteInstance = this.previewUtility.InstantiatePrefabInScene(this.palette);
         PrefabUtility.DisconnectPrefabInstance(this.m_PaletteInstance);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_PaletteInstance);
         this.m_PaletteInstance.transform.position   = new Vector3(0f, 0f, 0f);
         this.m_PaletteInstance.transform.rotation   = Quaternion.identity;
         this.m_PaletteInstance.transform.localScale = Vector3.one;
         string      assetPath   = AssetDatabase.GetAssetPath(this.palette);
         GridPalette gridPalette = AssetDatabase.LoadAssetAtPath <GridPalette>(assetPath);
         if (gridPalette != null)
         {
             if (gridPalette.cellSizing == GridPalette.CellSizing.Automatic)
             {
                 Grid component = this.m_PaletteInstance.GetComponent <Grid>();
                 if (component != null)
                 {
                     component.cellSize = GridPaletteUtility.CalculateAutoCellSize(component, component.cellSize);
                 }
                 else
                 {
                     Debug.LogWarning("Grid component not found from: " + assetPath);
                 }
             }
         }
         else
         {
             Debug.LogWarning("GridPalette subasset not found from: " + assetPath);
         }
         Renderer[] componentsInChildren = this.m_PaletteInstance.GetComponentsInChildren <Renderer>();
         for (int i = 0; i < componentsInChildren.Length; i++)
         {
             Renderer renderer = componentsInChildren[i];
             renderer.gameObject.layer          = Camera.PreviewCullingLayer;
             renderer.allowOcclusionWhenDynamic = false;
         }
         Transform[] componentsInChildren2 = this.m_PaletteInstance.GetComponentsInChildren <Transform>();
         for (int j = 0; j < componentsInChildren2.Length; j++)
         {
             Transform transform = componentsInChildren2[j];
             transform.gameObject.hideFlags = HideFlags.HideAndDontSave;
         }
         PreviewRenderUtility.SetEnabledRecursive(this.m_PaletteInstance, false);
         this.clipboardView.ResetPreviewMesh();
     }
 }
Ejemplo n.º 7
0
 public void SetCurrentPreviewObject(GameObject go, LookDevEditionContext context)
 {
     this.DestroytCurrentPreviewObject(context);
     if (go != null)
     {
         this.m_OriginalGameObject[(int)context] = go;
         this.m_PreviewObjects[(int)context]     = UnityEngine.Object.Instantiate <GameObject>(this.m_OriginalGameObject[(int)context], Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_PreviewObjects[(int)context]);
         this.SetEnabledRecursive(this.m_PreviewObjects[(int)context], false);
         this.DisableLightProbes(this.m_PreviewObjects[(int)context]);
         this.UpdateCurrentObjectArray();
     }
 }
Ejemplo n.º 8
0
 private void InitInstance(Animator scenePreviewObject, Motion motion)
 {
     this.m_SourcePreviewMotion        = motion;
     this.m_SourceScenePreviewAnimator = scenePreviewObject;
     if (this.m_PreviewInstance == null)
     {
         GameObject go = AvatarPreview.CalculatePreviewGameObject(scenePreviewObject, motion, this.animationClipType);
         this.SetupBounds(go);
     }
     if (this.timeControl == null)
     {
         this.timeControl = new TimeControl();
     }
     if (this.m_ReferenceInstance == null)
     {
         GameObject original = (GameObject)EditorGUIUtility.Load("Avatar/dial_flat.prefab");
         this.m_ReferenceInstance = UnityEngine.Object.Instantiate <GameObject>(original, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_ReferenceInstance);
         this.previewUtility.AddSingleGO(this.m_ReferenceInstance);
     }
     if (this.m_DirectionInstance == null)
     {
         GameObject original2 = (GameObject)EditorGUIUtility.Load("Avatar/arrow.fbx");
         this.m_DirectionInstance = UnityEngine.Object.Instantiate <GameObject>(original2, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_DirectionInstance);
         this.previewUtility.AddSingleGO(this.m_DirectionInstance);
     }
     if (this.m_PivotInstance == null)
     {
         GameObject original3 = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx");
         this.m_PivotInstance = UnityEngine.Object.Instantiate <GameObject>(original3, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_PivotInstance);
         this.previewUtility.AddSingleGO(this.m_PivotInstance);
     }
     if (this.m_RootInstance == null)
     {
         GameObject original4 = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx");
         this.m_RootInstance = UnityEngine.Object.Instantiate <GameObject>(original4, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_RootInstance);
         this.previewUtility.AddSingleGO(this.m_RootInstance);
     }
     this.m_IKOnFeet                = EditorPrefs.GetBool("AvatarpreviewShowIK", false);
     this.m_ShowReference           = EditorPrefs.GetBool("AvatarpreviewShowReference", true);
     this.is2D                      = EditorPrefs.GetBool("Avatarpreview2D", EditorSettings.defaultBehaviorMode == EditorBehaviorMode.Mode2D);
     this.timeControl.playbackSpeed = EditorPrefs.GetFloat("AvatarpreviewSpeed", 1f);
     this.SetPreviewCharacterEnabled(false, false);
     this.m_PivotPositionOffset = Vector3.zero;
 }
Ejemplo n.º 9
0
 private void InitInstance(UnityEngine.Animator scenePreviewObject, Motion motion)
 {
     this.m_SourcePreviewMotion        = motion;
     this.m_SourceScenePreviewAnimator = scenePreviewObject;
     if (this.m_PreviewInstance == null)
     {
         GameObject go = CalculatePreviewGameObject(scenePreviewObject, motion, this.animationClipType);
         this.SetupBounds(go);
     }
     if (this.timeControl == null)
     {
         this.timeControl = new TimeControl();
     }
     if (this.m_ReferenceInstance == null)
     {
         GameObject original = (GameObject)EditorGUIUtility.Load("Avatar/dial_flat.prefab");
         this.m_ReferenceInstance = UnityEngine.Object.Instantiate <GameObject>(original, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_ReferenceInstance);
     }
     if (this.m_DirectionInstance == null)
     {
         GameObject obj4 = (GameObject)EditorGUIUtility.Load("Avatar/arrow.fbx");
         this.m_DirectionInstance = UnityEngine.Object.Instantiate <GameObject>(obj4, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_DirectionInstance);
     }
     if (this.m_PivotInstance == null)
     {
         GameObject obj5 = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx");
         this.m_PivotInstance = UnityEngine.Object.Instantiate <GameObject>(obj5, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_PivotInstance);
     }
     if (this.m_RootInstance == null)
     {
         GameObject obj6 = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx");
         this.m_RootInstance = UnityEngine.Object.Instantiate <GameObject>(obj6, Vector3.zero, Quaternion.identity);
         EditorUtility.InitInstantiatedPreviewRecursive(this.m_RootInstance);
     }
     this.m_IKOnFeet                = EditorPrefs.GetBool("AvatarpreviewShowIK", false);
     this.m_ShowReference           = EditorPrefs.GetBool("AvatarpreviewShowReference", true);
     this.timeControl.playbackSpeed = EditorPrefs.GetFloat("AvatarpreviewSpeed", 1f);
     this.SetPreviewCharacterEnabled(false, false);
 }
Ejemplo n.º 10
0
        internal static GameObject InstantiateForAnimatorPreview(UnityEngine.Object original)
        {
            if (original == null)
            {
                throw new ArgumentException("The prefab you want to instantiate is null.");
            }
            GameObject gameObject = EditorUtility.InstantiateRemoveAllNonAnimationComponents(original, Vector3.zero, Quaternion.identity) as GameObject;

            EditorUtility.InitInstantiatedPreviewRecursive(gameObject);
            Animator component = gameObject.GetComponent <Animator>();

            if (component)
            {
                component.enabled     = false;
                component.cullingMode = AnimatorCullingMode.AlwaysAnimate;
                component.logWarnings = false;
                component.fireEvents  = false;
            }
            return(gameObject);
        }
Ejemplo n.º 11
0
 public void SetCurrentPreviewObject(GameObject go, LookDevEditionContext context)
 {
     this.DestroyCurrentPreviewObject(context);
     if (go != null)
     {
         if (!(this.m_LookDevView == null) && this.m_LookDevView.previewUtilityContexts != null && this.m_LookDevView.previewUtilityContexts[(int)context] != null)
         {
             this.m_OriginalGameObject[(int)context] = go;
             for (int i = 0; i < this.m_PreviewObjects[(int)context].Length; i++)
             {
                 this.m_PreviewObjects[(int)context][i] = this.m_LookDevView.previewUtilityContexts[(int)context].m_PreviewUtility[i].InstantiatePrefabInScene(this.m_OriginalGameObject[(int)context]);
                 this.m_PreviewObjects[(int)context][i].transform.position = new Vector3(0f, 0f, 0f);
                 this.m_PreviewObjects[(int)context][i].transform.rotation = Quaternion.identity;
                 EditorUtility.InitInstantiatedPreviewRecursive(this.m_PreviewObjects[(int)context][i]);
                 LookDevConfig.DisableRendererProperties(this.m_PreviewObjects[(int)context][i]);
                 PreviewRenderUtility.SetEnabledRecursive(this.m_PreviewObjects[(int)context][i], false);
             }
             this.UpdateCurrentObjectArray();
         }
     }
 }
Ejemplo n.º 12
0
        internal static void InitInstantiatedPreviewRecursive(GameObject go)
        {
            go.hideFlags = HideFlags.HideAndDontSave;
            go.layer     = Camera.PreviewCullingLayer;
            IEnumerator enumerator = go.transform.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Transform transform = (Transform)enumerator.Current;
                    EditorUtility.InitInstantiatedPreviewRecursive(transform.gameObject);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }