static void CreateDynamicAvatarMenuItem() { var res = new GameObject("New Dynamic Avatar"); var da = res.AddComponent <UMADynamicAvatar>(); da.context = UMAContextBase.FindInstance(); da.umaGenerator = Component.FindObjectOfType <UMAGeneratorBase>(); UnityEditor.Selection.activeGameObject = res; }
public static GameObject CreateEditorContext() { GameObject EditorUMAContextBase = null; if (UnityEditor.BuildPipeline.isBuildingPlayer) { return(null); } if (Application.isPlaying) { if (Debug.isDebugBuild) { Debug.LogWarning("There was no UMAContext in this scene. Please add the UMA context prefab to this scene before you try to generate an UMA."); } return(null); } if (Debug.isDebugBuild) { Debug.Log("UMA Recipe Editor created an UMAEditorContext to enable editing. This will auto delete once you have finished editing your recipe or you add a UMA prefab with a context to this scene."); } //if there is already an EditorUMAContextBase use it if (UMAContextBase.FindInstance() != null) { if (UMAContextBase.FindInstance().gameObject.name == "UMAEditorContext") { EditorUMAContextBase = UMAContextBase.FindInstance().gameObject; //if the UMAContextBase itself is on this game object, it means this was created and not deleted by the previous version of 'CreateEditorContext' //(The new version creates the UMAContextBase on a child game object called 'UMAContextBase' so that UMAContextBase.FindInstance can find it properly) //so in this case delete all the components that would have been added from the found gameObject from the previous code if (EditorUMAContextBase.GetComponent <UMAContextBase>()) { UMAUtils.DestroySceneObject(EditorUMAContextBase.GetComponent <UMAContextBase>()); //should also make the instance null again } } else if (UMAContextBase.FindInstance().gameObject.transform.parent.gameObject.name == "UMAEditorContext") { EditorUMAContextBase = UMAContextBase.FindInstance().gameObject.transform.parent.gameObject; } } else if (GameObject.Find("UMAEditorContext")) { EditorUMAContextBase = GameObject.Find("UMAEditorContext"); } else { EditorUMAContextBase = new GameObject(); EditorUMAContextBase.name = "UMAEditorContext"; } //Make this GameObject not show up in the scene or save EditorUMAContextBase.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; //if this gameobject does not contain an UMAContextBase add it - we have to call it UMAContextBase because UMAContextBase.FindInstance searches for that game object var context = UMAContextBase.Instance = EditorUMAContextBase.GetComponentInChildren <UMAContextBase>(); if (UMAContextBase.Instance == null) { var GO = new GameObject(); GO.name = "UMAContext"; GO.transform.parent = EditorUMAContextBase.transform; context = GO.AddComponent <UMAGlobalContext>(); GO.AddComponent <UMADefaultMeshCombiner>(); var gen = GO.AddComponent <UMAGenerator>(); gen.fitAtlas = true; gen.SharperFitTextures = true; gen.AtlasOverflowFitMethod = UMAGeneratorBase.FitMethod.BestFitSquare; gen.convertRenderTexture = false; gen.editorAtlasResolution = 1024; gen.InitialScaleFactor = 2; gen.collectGarbage = false; gen.IterationCount = 1; gen.fastGeneration = true; gen.processAllPending = false; gen.NoCoroutines = true; UMAContextBase.Instance = context; } return(EditorUMAContextBase); }
public static GameObject CreateEditorContext() { GameObject EditorUMAContextBase = null; if (UnityEditor.BuildPipeline.isBuildingPlayer) { return(null); } if (Application.isPlaying) { if (Debug.isDebugBuild) { Debug.LogWarning("There was no UMAContext in this scene. Please add the UMA_DCS prefab to this scene before you try to generate an UMA."); } return(null); } if (Debug.isDebugBuild) { Debug.Log("UMA Recipe Editor created an UMAEditorContext to enable editing. This will auto delete once you have finished editing your recipe or you add the UMA_DCS prefab to this scene."); } //if there is already an EditorUMAContextBase use it if (UMAContextBase.FindInstance() != null) { if (UMAContextBase.FindInstance().gameObject.name == "UMAEditorContext") { EditorUMAContextBase = UMAContextBase.FindInstance().gameObject; //if the UMAContextBase itself is on this game object, it means this was created and not deleted by the previous version of 'CreateEditorContext' //(The new version creates the UMAContextBase on a child game object called 'UMAContextBase' so that UMAContextBase.FindInstance can find it properly) //so in this case delete all the components that would have been added from the found gameObject from the previous code if (EditorUMAContextBase.GetComponent <UMAContextBase>()) { UMAUtils.DestroySceneObject(EditorUMAContextBase.GetComponent <UMAContextBase>()); //should also make the instance null again } } else if (UMAContextBase.FindInstance().gameObject.transform.parent.gameObject.name == "UMAEditorContext") { EditorUMAContextBase = UMAContextBase.FindInstance().gameObject.transform.parent.gameObject; } } else if (GameObject.Find("UMAEditorContext")) { EditorUMAContextBase = GameObject.Find("UMAEditorContext"); } else { EditorUMAContextBase = new GameObject(); EditorUMAContextBase.name = "UMAEditorContext"; } //Make this GameObject not show up in the scene or save EditorUMAContextBase.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; //if this gameobject does not contain an UMAContextBase add it - we have to call it UMAContextBase because UMAContextBase.FindInstance searches for that game object var thisUMAContextBase = UMAContextBase.Instance = EditorUMAContextBase.GetComponentInChildren <UMAContextBase>(); if (UMAContextBase.Instance == null) { var thisUMAContextBaseGO = new GameObject(); thisUMAContextBaseGO.name = "UMAContext"; thisUMAContextBaseGO.transform.parent = EditorUMAContextBase.transform; thisUMAContextBase = thisUMAContextBaseGO.AddComponent <UMAGlobalContext>(); UMAContextBase.Instance = thisUMAContextBase; } return(EditorUMAContextBase); }