private static void Traverse(Transform transform, IList <string> results, string path = "") { string thisPath = $"{path}/{transform.name}"; var components = transform.GetComponents <Component>(); for (int i = 0; i < components.Length; ++i) { Component component = components[i]; if (null == component) { AppendComponentResult(results, thisPath, i); } } for (int c = 0; c < transform.childCount; ++c) { Transform t = transform.GetChild(c); PrefabAssetType pt = PrefabUtility.GetPrefabAssetType(t.gameObject); if (pt == PrefabAssetType.MissingAsset) { AppendTransformResult(results, thisPath, t.name); } else { Traverse(t, results, thisPath); } } }
static bool IsSnapsHDPrefab(GameObject targetGo) { PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(targetGo); if (prefabType != PrefabAssetType.Regular && prefabType != PrefabAssetType.Variant) { return(false); } if (IsSnapsPrototypePrefab(targetGo) == false) { Regex reg = new Regex(@"_snaps[0-9][0-9][0-9].prefab$"); string PrefabPath = SwapTool.GetOriginalPrefabPath(targetGo).ToLower(); string SnapsPrototypePath = SwapTool.PrefabPath.Replace(Application.dataPath, string.Empty).ToLower(); if (reg.IsMatch(PrefabPath) && !PrefabPath.Contains(SnapsPrototypePath)) { return(true); } } return(false); }
private static void Traverse(Transform transform, string path = "") { string thisPath = path + "/" + transform.name; Component[] components = transform.GetComponents <Component>(); for (int i = 0; i < components.Length; i++) { if (components[i] == null) { AppendComponentResult(thisPath, i); } } for (int c = 0; c < transform.childCount; c++) { Transform t = transform.GetChild(c); PrefabAssetType pt = PrefabUtility.GetPrefabAssetType(t.gameObject); if (pt == PrefabAssetType.MissingAsset) { AppendTransformResult(path + "/" + transform.name, t.name); } else { Traverse(t, thisPath); } } }
bool FindClone(AmplifyColorBase effect) { #if UNITY_2018_1_OR_NEWER GameObject effectPrefab = PrefabUtility.GetCorrespondingObjectFromSource(effect.gameObject) as GameObject; PrefabAssetType effectPrefabType = PrefabUtility.GetPrefabAssetType(effect.gameObject); PrefabInstanceStatus effectPrefabInstanceStatus = PrefabUtility.GetPrefabInstanceStatus(effect.gameObject); bool effectIsPrefab = (effectPrefabType != PrefabAssetType.NotAPrefab && effectPrefabInstanceStatus == PrefabInstanceStatus.NotAPrefab); #else GameObject effectPrefab = PrefabUtility.GetPrefabParent(effect.gameObject) as GameObject; PrefabType effectPrefabType = PrefabUtility.GetPrefabType(effect.gameObject); bool effectIsPrefab = (effectPrefabType != PrefabType.None && effectPrefabType != PrefabType.PrefabInstance); #endif bool effectHasPrefab = (effectPrefab != null); AmplifyColorBase[] all = Resources.FindObjectsOfTypeAll(typeof(AmplifyColorBase)) as AmplifyColorBase[]; bool foundClone = false; foreach (AmplifyColorBase other in all) { if (other == effect || other.SharedInstanceID != effect.SharedInstanceID) { // skip: same effect or already have different ids continue; } #if UNITY_2018_1_OR_NEWER GameObject otherPrefab = PrefabUtility.GetCorrespondingObjectFromSource(other.gameObject) as GameObject; PrefabAssetType otherPrefabType = PrefabUtility.GetPrefabAssetType(other.gameObject); PrefabInstanceStatus otherPrefabInstanceStatus = PrefabUtility.GetPrefabInstanceStatus(other.gameObject); bool otherIsPrefab = (otherPrefabType != PrefabAssetType.NotAPrefab && otherPrefabInstanceStatus == PrefabInstanceStatus.NotAPrefab); #else GameObject otherPrefab = PrefabUtility.GetPrefabParent(other.gameObject) as GameObject; PrefabType otherPrefabType = PrefabUtility.GetPrefabType(other.gameObject); bool otherIsPrefab = (otherPrefabType != PrefabType.None && otherPrefabType != PrefabType.PrefabInstance); #endif bool otherHasPrefab = (otherPrefab != null); if (otherIsPrefab && effectHasPrefab && effectPrefab == other.gameObject) { // skip: other is a prefab and effect's prefab is other continue; } if (effectIsPrefab && otherHasPrefab && otherPrefab == effect.gameObject) { // skip: effect is a prefab and other's prefab is effect continue; } if (!effectIsPrefab && !otherIsPrefab && effectHasPrefab && otherHasPrefab && effectPrefab == otherPrefab) { // skip: both aren't prefabs and both have the same parent prefab continue; } foundClone = true; } return(foundClone); }
private void drawHandEditor(Rect controlRect) { // Determine whether the target object is a prefab. AttachmentPoints cannot be edited on prefabs. PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(target.gameObject); bool isTargetPrefab = prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Model; // Image container. Rect imageContainerRect = controlRect; EditorGUI.DrawRect(imageContainerRect, new Color(0.2F, 0.2F, 0.2F)); imageContainerRect.x += 1; imageContainerRect.y += 1; imageContainerRect.width -= 2; imageContainerRect.height -= 2; EditorGUI.DrawRect(imageContainerRect, new Color(0.6F, 0.6F, 0.6F)); imageContainerRect.x += 1; imageContainerRect.y += 1; imageContainerRect.width -= 2; imageContainerRect.height -= 2; EditorGUI.DrawRect(imageContainerRect, new Color(0.2F, 0.2F, 0.2F)); // Hand image. _handTexRect = new Rect(0F, 0F, (controlRect.height - 2) * (_handTex.width / (float)_handTex.height), controlRect.height - 2); _handTexRect.center += imageContainerRect.center - _handTexRect.center; EditorGUI.DrawTextureTransparent(_handTexRect, _handTex); // Toggle boxes. EditorGUI.BeginDisabledGroup(isTargetPrefab); makeFingertipToggle(0, new Vector2(-0.390F, 0.110F)); makeFingertipToggle(1, new Vector2(-0.080F, -0.380F)); makeFingertipToggle(2, new Vector2(0.090F, -0.420F)); makeFingertipToggle(3, new Vector2(0.245F, -0.380F)); makeFingertipToggle(4, new Vector2(0.410F, -0.210F)); }
public void GuidInit() { //test if object's nature has changed prefabType = PrefabUtility.GetPrefabAssetType(gameObject); StateCheck(); //if object's nature changed, update and create a new GUID if (thisObjState != initState && serializedGuid != null) { StateUpdate(); initState = thisObjState; //lateInit = true; if (!prefabEdition) { lateInit = true; } } //if GUID has never been generated or is invalid, create a new one else if (serializedGuid == null || serializedGuid.Length != 16) { if (!SceneEventCaller.isSceneOpen) { lateInit = true; } NewGuid(); } //else restore GUID from serialized value else if (guid == Guid.Empty) { guid = new Guid(serializedGuid); guidDisplay = guid.ToString(); } }
public MB_PrefabType GetPrefabType(UnityEngine.Object obj) { #if UNITY_2018_3_OR_NEWER if (PrefabUtility.IsPartOfNonAssetPrefabInstance(obj)) { return(MB_PrefabType.scenePefabInstance); } if (!PrefabUtility.IsPartOfAnyPrefab(obj)) { return(MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab); } PrefabAssetType assetType = PrefabUtility.GetPrefabAssetType(obj); if (assetType == PrefabAssetType.NotAPrefab) { if (PrefabUtility.GetPrefabInstanceStatus(obj) != PrefabInstanceStatus.NotAPrefab) { return(MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab); } else { return(MB_PrefabType.scenePefabInstance); } } else if (assetType == PrefabAssetType.Model) { return(MB_PrefabType.modelPrefabAsset); } else if (assetType == PrefabAssetType.Regular || assetType == PrefabAssetType.Variant || assetType == PrefabAssetType.MissingAsset) { return(MB_PrefabType.prefabAsset); } else { Debug.Assert(false, "Should never get here. Unknown prefab asset type."); return(MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab); } #else PrefabType prefabType = PrefabUtility.GetPrefabType(obj); if (prefabType == PrefabType.ModelPrefab) { return(MB_PrefabType.modelPrefabAsset); } else if (prefabType == PrefabType.Prefab) { return(MB_PrefabType.prefabAsset); } else if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.ModelPrefabInstance) { return(MB_PrefabType.scenePefabInstance); } else { return(MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab); } #endif }
/// <summary> /// Gets the currently selected game objects. /// </summary> void GetSelection() { if (editMode && Selection.activeGameObject != null) { if (prefab == null) // get the prefab 1st { #if UNITY_2018_3_OR_NEWER PrefabAssetType t = PrefabUtility.GetPrefabAssetType(Selection.activeGameObject); if (t == PrefabAssetType.Regular || t == PrefabAssetType.Variant) { prefab = Selection.activeGameObject; } #else PrefabType t = PrefabUtility.GetPrefabType(Selection.activeGameObject); if (t == PrefabType.Prefab) { prefab = Selection.activeGameObject; } #endif } else // get the other objects { ResetPreview(); objectsToReplace.Clear(); foreach (var obj in Selection.gameObjects) { objectsToReplace.Add(obj); } } } }
//Returns a single prefab if and only if it is the only one in the selection private static GameObject GetPrefabOnly(GameObject[] gameObjects) { List <GameObject> prefabs = new List <GameObject>(); foreach (GameObject go in gameObjects) { if (go != null) { PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(go); if (prefabType == PrefabAssetType.Model || prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Variant) { PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(go); if (status == PrefabInstanceStatus.NotAPrefab) { string path = AssetDatabase.GetAssetPath(go); if (!string.IsNullOrEmpty(path)) { prefabs.Add(go); } } } } } // Only return anything if there is one and only one prefab if (prefabs.Count == 1) { return(prefabs[0]); } return(null); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var prefabAttribute = (PrefabAttribute)attribute; if (prefabAttribute != null && property.propertyType == SerializedPropertyType.ObjectReference && (property.objectReferenceValue is GameObject || property.objectReferenceValue == null)) { EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(position, property); if (!EditorGUI.EndChangeCheck()) { return; } if (property.objectReferenceValue == null) { return; } PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType(property.objectReferenceValue); if (prefabAssetType != PrefabAssetType.Regular && prefabAssetType != PrefabAssetType.Variant) { property.objectReferenceValue = null; Debug.LogWarning("Assigned GameObject must be a prefab"); } } else { EditorGUI.LabelField(position, label.text, "Use PrefabAttribute with GameObject fields only."); } }
static bool IsSnapsPrototypePrefab(GameObject targetGo) { PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(targetGo); if (prefabType != PrefabAssetType.Regular && prefabType != PrefabAssetType.Variant) { return(false); } Regex reg = new Regex(@"_snaps[0-9][0-9][0-9].prefab$"); string PrefabPath = SwapTool.GetOriginalPrefabPath(targetGo).ToLower(); if (PrefabPath.Contains(PrefabRoot.ToLower()) || PrefabPath.Contains(GenSnapsPrototypePath.ToLower())) { if (reg.IsMatch(PrefabPath)) { return(true); } } return(false); }
static bool SwapGameObject(GameObject sourceGo, GameObject targetGo) { GameObject genGameObj; PrefabAssetType pref = PrefabUtility.GetPrefabAssetType(targetGo); if (pref == PrefabAssetType.Regular || pref == PrefabAssetType.Model) { genGameObj = (GameObject)PrefabUtility.InstantiatePrefab(targetGo); } else { genGameObj = (GameObject)Editor.Instantiate(targetGo); } Transform gTransform = genGameObj.transform; gTransform.parent = sourceGo.transform.parent; genGameObj.name = targetGo.name; gTransform.localPosition = sourceGo.transform.localPosition; gTransform.localScale = sourceGo.transform.localScale; gTransform.localRotation = sourceGo.transform.localRotation; DestroyImmediate(sourceGo); return(true); }
void CalculatePrefabStatus() { m_PlayModeObjects = false; m_IsAsset = false; m_ImmutableSelf = false; m_ImmutableSourceAsset = false; m_IsDisconnected = false; m_IsMissing = false; m_IsPrefabInstanceAnyRoot = true; m_IsPrefabInstanceOutermostRoot = true; m_AllOfSamePrefabType = true; PrefabAssetType firstType = PrefabUtility.GetPrefabAssetType(targets[0]); PrefabInstanceStatus firstStatus = PrefabUtility.GetPrefabInstanceStatus(targets[0]); foreach (var o in targets) { var go = (GameObject)o; PrefabAssetType type = PrefabUtility.GetPrefabAssetType(go); PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(go); if (type != firstType || status != firstStatus) { m_AllOfSamePrefabType = false; } if (Application.IsPlaying(go)) { m_PlayModeObjects = true; } if (!PrefabUtility.IsAnyPrefabInstanceRoot(go)) { m_IsPrefabInstanceAnyRoot = false; // Conservative is false if any is false } if (!m_IsPrefabInstanceAnyRoot || !PrefabUtility.IsOutermostPrefabInstanceRoot(go)) { m_IsPrefabInstanceOutermostRoot = false; // Conservative is false if any is false } if (PrefabUtility.IsPartOfPrefabAsset(go)) { m_IsAsset = true; // Conservative is true if any is true } if (m_IsAsset && PrefabUtility.IsPartOfImmutablePrefab(go)) { m_ImmutableSelf = true; // Conservative is true if any is true } GameObject originalSourceOrVariant = PrefabUtility.GetOriginalSourceOrVariantRoot(go); if (originalSourceOrVariant != null && PrefabUtility.IsPartOfImmutablePrefab(originalSourceOrVariant)) { m_ImmutableSourceAsset = true; // Conservative is true if any is true } if (PrefabUtility.IsDisconnectedFromPrefabAsset(go)) { m_IsDisconnected = true; } if (PrefabUtility.IsPrefabAssetMissing(go)) { m_IsMissing = true; } } }
static string GetPrefabInfoString(GameObject prefabAssetGameObject) { string name = prefabAssetGameObject.transform.root.gameObject.name; string assetPath = AssetDatabase.GetAssetPath(prefabAssetGameObject); PrefabAssetType type = PrefabUtility.GetPrefabAssetType(prefabAssetGameObject); return(string.Format("<b>{0}</b> (type: {1}) at '{2}'", name, type, assetPath)); }
/// <summary> /// Returns true if the speicified gameObject is a prefab /// </summary> public static bool IsPrefab(GameObject gameObject) { // TODO CHANGED: Unity API has been changed. PrefabAssetType assetType = PrefabUtility.GetPrefabAssetType(gameObject); return(assetType == PrefabAssetType.Regular || assetType == PrefabAssetType.Variant); //return PrefabUtility.GetPrefabType(gameObject) == PrefabType.Prefab; }
bool ReplacePrefabGuid(GameObject asset) { if (!asset) { return(false); } bool changed = false; string assetPath = AssetDatabase.GetAssetPath(asset); //var go = (GameObject)PrefabUtility.InstantiatePrefab(asset); //foreach (var r in go.GetComponentsInChildren<Renderer>(true)) //{ // var mats = r.sharedMaterials; // var matChanged = false; // for (int i = 0; i < mats.Length; i++) // { // if (!mats[i]) // continue; // AssetInfo builtin; // if (builtinExtraRes.TryGetValue(mats[i], out builtin)) // { // if (builtin.replace != null) // { // mats[i] = (Material)builtin.replace.asset; // Debug.Log("mat >" + builtin.replace.assetPath); // matChanged = true; // } // } // } // if (matChanged) // { // r.materials = mats; // changed |= matChanged; // } //} GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)); foreach (var p in FindPrefabs(prefab)) { PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType(p); string prefabAssetPath = AssetDatabase.GetAssetPath(p); if (prefabAssetType == PrefabAssetType.Model) { changed |= ReplaceModelGuid(AssetImporter.GetAtPath(prefabAssetPath) as ModelImporter); } else { //Debug.Log("----- " + prefabAssetPath); changed |= ReplaceFileGuid(prefabAssetPath); } } //PrefabUtility.SaveAsPrefabAsset(go, assetPath); //Object.DestroyImmediate(go); return(changed); }
public bool IsPrefabOrMultipleManagers() { #if UNITY_2019_2_OR_NEWER PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(gameObject); return(!gameObject.activeInHierarchy || prefabType != PrefabAssetType.NotAPrefab || FindObjectsOfType <GrassManager>().Length > 1); #else PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject); return(!gameObject.activeInHierarchy || prefabType == PrefabType.ModelPrefab || prefabType == PrefabType.Prefab || FindObjectsOfType <GrassManager>().Length > 1); #endif }
/// <summary> /// Instantiate a prefab from an asset into the active scene /// </summary> /// <param name="assetName">Asset name</param> /// <param name="undoName">Undo operation name</param> /// <param name="identityPosition">Whether to set position and rotation to 0</param> /// <param name="setup">Callback for any additional setup that will be performed on the instantiated prefab</param> public static void InstantiatePrefab(string assetName, string undoName, bool identityPosition, System.Action <GameObject> setup = null) { string[] results = AssetDatabase.FindAssets(assetName); if (results.Length == 0) { Debug.LogError("Unable to find " + assetName + " in project"); return; } GameObject prefab = null; foreach (string result in results) { string path = AssetDatabase.GUIDToAssetPath(result); prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (prefab != null) { break; } } if (prefab == null) { Debug.LogError("Unable to deserialize prefab"); return; } #if UNITY_2018_3_OR_NEWER PrefabAssetType type = PrefabUtility.GetPrefabAssetType(prefab); if (type == PrefabAssetType.MissingAsset || type == PrefabAssetType.NotAPrefab) #else PrefabType type = PrefabUtility.GetPrefabType(prefab); if (type == PrefabType.None) #endif { Debug.LogError("Unable to load prefab, please reimport all assets"); return; } var obj = PrefabUtility.InstantiatePrefab(prefab) as GameObject; obj.name = obj.name.Replace("(Clone)", string.Empty).Trim(); obj.transform.parent = null; if (identityPosition) { obj.transform.position = Vector3.zero; obj.transform.rotation = Quaternion.identity; } if (setup != null) { setup.Invoke(obj); } Undo.RegisterCreatedObjectUndo(obj, undoName); }
private void Deregister() { if (this != null) { #if UNITY_EDITOR PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(gameObject); if (prefabType == PrefabAssetType.Model || prefabType == PrefabAssetType.Regular) { return; } #endif DynamicDecals.System.Deregister(this); } }
private bool Register() { if (this != null) { #if UNITY_EDITOR PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(gameObject);// PrefabUtility.GetPrefabType(gameObject); if (prefabType == PrefabAssetType.Model || prefabType == PrefabAssetType.Regular) { return(false); } #endif return(DynamicDecals.System.Register(this)); } return(false); }
void OnWizardCreate() { if (replacement == null) { return; } //Undo.RegisterSceneUndo("Replace Selection"); //Undo.RegisterCreatedObjectUndo(global, "Undo Replacement"); Transform[] transforms = Selection.GetTransforms( SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable); foreach (Transform t in transforms) { GameObject g; //PrefabType pref = PrefabUtility.GetPrefabType(replacement); PrefabAssetType pref = PrefabUtility.GetPrefabAssetType(replacement); if (pref != PrefabAssetType.NotAPrefab) { g = (GameObject)PrefabUtility.InstantiatePrefab(replacement); } else { g = (GameObject)Editor.Instantiate(replacement); } Transform gTransform = g.transform; gTransform.parent = t.parent; g.name = replacement.name; gTransform.localPosition = t.localPosition; gTransform.localScale = t.localScale; gTransform.localRotation = t.localRotation; Undo.RegisterCreatedObjectUndo(g, "Undo Replacement"); } if (!keep) { foreach (GameObject g in Selection.gameObjects) { Undo.DestroyObjectImmediate(g); } } }
private static bool IsGameObjectPrefab(GameObject obj) { if (obj == null) { return(false); } //var prefabType = PrefabUtility.GetPrefabType(obj); PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(obj); if (prefabType == PrefabAssetType.NotAPrefab) { return(false); } return(true); // prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.Prefab; }
public override void OnInspectorGUI() { Inventory inventory = target as Inventory; EditorGUILayout.Space(); if (EditorApplication.isPlaying) { using (var h = new EditorGUILayout.HorizontalScope()) { itemToAdd = EditorGUILayout.ObjectField(itemToAdd, typeof(Item), true) as Item; bool isPrefab = false; if (itemToAdd != null) { PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType(itemToAdd); isPrefab = prefabAssetType == PrefabAssetType.Regular || prefabAssetType == PrefabAssetType.Variant; } if (GUILayout.Button("Add")) { if (itemToAdd != null) { if (isPrefab) { Object instance = PrefabUtility.InstantiatePrefab(itemToAdd); GameObject go = PrefabUtility.GetOutermostPrefabInstanceRoot(instance); Inventory.Add(inventory, go.GetComponent <Item>()); } else { Inventory.Add(inventory, itemToAdd); } } } } EditorGUILayout.Space(); } for (int i = 0; i < Inventory.Count(inventory); ++i) { EditorGUILayout.LabelField(new GUIContent(Inventory.Get(inventory, i).name)); } }
//------------------------------------------------- private static bool WillLosePrefab(GameObject root) { if (root == null) { return(false); } if (root.transform != null) { PrefabAssetType type = PrefabUtility.GetPrefabAssetType(root); if (type != PrefabAssetType.NotAPrefab) { return(EditorUtility.DisplayDialog("Losing prefab", "This action will lose the prefab connection. Are you sure you wish to continue?", "Continue", "Cancel")); } } return(true); }
public static void Inspector(HumanoidControl humanoid, Tracker tracker, SerializedProperty enabledProp, string resourceName) { EditorGUILayout.BeginHorizontal(); //EditorGUI.BeginChangeCheck(); bool wasEnabled = enabledProp.boolValue; enabledProp.boolValue = EditorGUILayout.ToggleLeft(tracker.name, enabledProp.boolValue, GUILayout.MinWidth(80)); if (Application.isPlaying && enabledProp.boolValue) { EditorGUILayout.EnumPopup(tracker.status); } EditorGUILayout.EndHorizontal(); #if UNITY_2018_3_OR_NEWER PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(humanoid); if (prefabType != PrefabAssetType.NotAPrefab) { return; } #else PrefabType prefabType = PrefabUtility.GetPrefabType(humanoid); if (prefabType == PrefabType.Prefab) { return; } #endif if (tracker.humanoid == null) { tracker.humanoid = humanoid; } if (enabledProp.boolValue && resourceName != null) { tracker.AddTracker(humanoid, resourceName); } else if (wasEnabled) { RemoveTracker(tracker); } tracker.ShowTracker(humanoid.showRealObjects && enabledProp.boolValue); }
private void OnValidate() { if (EditorApplication.isPlaying) { return; } PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(this); if (prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Model) { netID = null; } else { SetUniqueNetID(); } UpdateAssetGuid(); }
void GetSelection() { if (EditMode && Selection.activeGameObject != null) { PrefabAssetType t = PrefabUtility.GetPrefabAssetType(Selection.activeGameObject); //Debug.Log("Type = "+t.ToString()); if ((t == PrefabAssetType.Regular || t == PrefabAssetType.Variant) && (PrefabUtility.GetPrefabInstanceStatus(Selection.activeGameObject) != PrefabInstanceStatus.Connected)) //2019 syntax { //Debug.Log("Add "+Selection.activeGameObject.name); Prefab = Selection.activeGameObject; } else { //Debug.Log("ResetPreview"); ResetPreview(); ObjectsToReplace = Selection.gameObjects; } } }
private bool CheckIfCanMigrate(Type type, Object selectedObject) { bool canMigrate = false; string objectPath = AssetDatabase.GetAssetPath(selectedObject); if (IsSceneGameObject(selectedObject)) { var objectHierarchy = ((GameObject)selectedObject).GetComponentsInChildren <Transform>(true); for (int i = 0; i < objectHierarchy.Length; i++) { if (migrationHandlerInstance.CanMigrate(objectHierarchy[i].gameObject)) { return(true); } } } else if (IsPrefabAsset(selectedObject)) { PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(selectedObject); if (prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Variant) { var parent = UnityEditor.PrefabUtility.LoadPrefabContents(objectPath); canMigrate = CheckIfCanMigrate(type, parent); PrefabUtility.UnloadPrefabContents(parent); } } else if (IsSceneAsset(selectedObject)) { Scene scene = EditorSceneManager.OpenScene(objectPath); foreach (var parent in scene.GetRootGameObjects()) { if (CheckIfCanMigrate(type, parent)) { return(true); } } } return(canMigrate); }
void Update() { #if UNITY_EDITOR PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(this.gameObject); if (prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Variant || prefabType == PrefabAssetType.Model) { return; } #endif bool requiresReinitialization = false; using (new ProfilerSample("Attachment Hands Update", this.gameObject)) { for (int i = 0; i < _attachmentHands.Length; i++) { var attachmentHand = attachmentHands[i]; if (attachmentHand == null) { requiresReinitialization = true; break; } var leapHand = handAccessors[i](); attachmentHand.isTracked = leapHand != null; using (new ProfilerSample(attachmentHand.gameObject.name + " Update Points")) { foreach (var point in attachmentHand.points) { point.SetTransformUsingHand(leapHand); } } } if (requiresReinitialization) { reinitialize(); } } }
void CalculatePrefabStatus() { m_IsPrefabInstanceAnyRoot = false; m_IsAsset = false; m_AllOfSamePrefabType = true; PrefabAssetType firstType = PrefabUtility.GetPrefabAssetType(targets[0]); PrefabInstanceStatus firstStatus = PrefabUtility.GetPrefabInstanceStatus(targets[0]); foreach (GameObject go in targets) { PrefabAssetType type = PrefabUtility.GetPrefabAssetType(go); PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(go); if (type != firstType || status != firstStatus) { m_AllOfSamePrefabType = false; } if (PrefabUtility.IsAnyPrefabInstanceRoot(go)) { m_IsPrefabInstanceAnyRoot = true; } if (m_IsPrefabInstanceAnyRoot) { m_IsPrefabInstanceOutermostRoot = PrefabUtility.IsOutermostPrefabInstanceRoot(go); } if (PrefabUtility.IsPartOfPrefabAsset(go)) { m_IsAsset = true; } if (m_IsAsset && PrefabUtility.IsPartOfImmutablePrefab(go)) { m_ImmutableSelf = true; } GameObject originalSourceOrVariant = PrefabUtility.GetOriginalSourceOrVariantRoot(go); if (originalSourceOrVariant != null && PrefabUtility.IsPartOfImmutablePrefab(originalSourceOrVariant)) { m_ImmutableSourceAsset = true; } } }