private Object TryGetTargetOfSelectableType([CanBeNull] Object mouseovered, bool checkChildren) { if (mouseovered == null) { return(null); } var mouseoveredType = mouseovered.GetType(); if (type.IsAssignableFrom(mouseoveredType)) { return(mouseovered); } var mouseoveredGameObject = mouseovered.GameObject(); if (mouseoveredGameObject == null) { return(null); } if (type == Types.GameObject) { return(mouseoveredGameObject); } if (Types.Component.IsAssignableFrom(type)) { return(checkChildren ? mouseoveredGameObject.GetComponentInChildren(type) : mouseoveredGameObject.GetComponent(type)); } return(checkChildren ? mouseoveredGameObject.FindAsset(type) : mouseoveredGameObject.FindAssetInChildren(type)); }
public static GameObject AsGameObject(this UnityObject uo) { if (IsComponentHolder(uo)) { return(uo.GameObject()); } else { return(null); } }
private void BuildHierarchy(Object target) { if (target.IsComponentHolder()) { hierarchy = new List <Object>(target.GetComponents <Component>()); var owner = target.GameObject(); if (owner != null) { hierarchy.Insert(0, owner); } hierarchyIndex = hierarchy.IndexOf(target); } else { hierarchy.Clear(); hierarchyIndex = 0; } }
private bool CanDetermineDraggedInput(UnityObject uo) { if (uo.IsSceneBound()) { if (reference.self == uo.GameObject()) { // Because we'll be able to assign it to Self return(true); } if (reference.serializedObject.IsSceneBound()) { // Because we'll be able to use a direct scene reference return(true); } return(false); } else { return(true); } }
/// <summary> If object is a GameObject gets is defining Component, else returns the object itself. </summary> /// <param name="obj"> The object to act on. </param> /// <returns> Defining component or asset itself. </returns> public static Object GetAssetOrMainComponent(this Object obj) { var gameObject = obj.GameObject(); return(gameObject != null?gameObject.GetMainComponent() : obj); }
public static bool IsSceneObject(this Object target) { var go = target.GameObject(); return(go != null && go.scene.IsValid()); }