protected static T GetRegisteredComponent <T>(SmartBeheviour obj) where T : Component { Type type = typeof(T); //Get the current list or create a new one if it doesn't exist yet Dictionary <SmartBeheviour, ComponentInfo> existingSet; if (!FindByComponent.TryGetValue(type, out existingSet)) { existingSet = new Dictionary <SmartBeheviour, ComponentInfo>(); FindByComponent[type] = existingSet; } ComponentInfo componentInfo; if (!existingSet.TryGetValue(obj, out componentInfo)) { T component = obj.GetComponent <T>(); existingSet.Add(obj, new ComponentInfo(type, component)); obj._registeredCompnents.Add(type); return(component); } else { return(componentInfo.HasComponent ? (T)componentInfo.Component : null); } }
public static SmartBeheviour GetSmartBeheviour(this MonoBehaviour obj) { SmartBeheviour result = null; SmartBeheviour.FindByInstanceId.TryGetValue(obj.GetInstanceID(), out result); return(result); }
private static void UnregisterLayer(string layerName, SmartBeheviour obj) { //Get the current list or ignore action if it doesn't exist yet HashSet <SmartBeheviour> existingSet; if (!FindByLayer.TryGetValue(layerName, out existingSet)) { return; } existingSet.Remove(obj); }
protected static void UnregisterComponent(SmartBeheviour obj, Type componentType) { //Get the current list or create a new one if it doesn't exist yet Dictionary <SmartBeheviour, ComponentInfo> existingSet; if (!FindByComponent.TryGetValue(componentType, out existingSet)) { return; } existingSet.Remove(obj); }
private static void RegisterLayer(string layerName, SmartBeheviour obj) { //Get the current list or create a new one if it doesn't exist yet HashSet <SmartBeheviour> existingSet; if (!FindByLayer.TryGetValue(layerName, out existingSet)) { existingSet = new HashSet <SmartBeheviour>(); FindByLayer[layerName] = existingSet; } existingSet.Add(obj); }
private static void RegisterTag(string tag, SmartBeheviour obj) { //Get the current list or create a new one if it doesn't exist yet HashSet <SmartBeheviour> existingSet; if (!FindByTag.TryGetValue(tag, out existingSet)) { existingSet = new HashSet <SmartBeheviour>(); FindByTag[tag] = existingSet; } existingSet.Add(obj); }
//Private static methods protected static void RegisterComponent <T>(SmartBeheviour obj, T component) where T : Component { Type type = typeof(T); //Get the current list or create a new one if it doesn't exist yet Dictionary <SmartBeheviour, ComponentInfo> existingSet; if (!FindByComponent.TryGetValue(type, out existingSet)) { existingSet = new Dictionary <SmartBeheviour, ComponentInfo>(); FindByComponent[type] = existingSet; } existingSet.Add(obj, new ComponentInfo(type, component)); obj._registeredCompnents.Add(type); }
public static T TrySelectingWithPointer <T>(string layerName, float distance = 150f) where T : Component { Vector3?pointerScreenPosition = GetPointerScreenPosition(); if (!pointerScreenPosition.HasValue) { return(null); } //raycast from mouse on layermask RaycastHit?hit = RaycastScreenPosition(pointerScreenPosition.Value, layerName, distance); if (!hit.HasValue) { return(null); } //get component, if smartobject get registered component, otherwise it'll use the normal "GetComponent<T>()" T result = SmartBeheviour.ComponentFromInstanceID <T>(hit.Value.transform); return(result); }