예제 #1
0
    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);
        }
    }
예제 #2
0
    public static SmartBeheviour GetSmartBeheviour(this MonoBehaviour obj)
    {
        SmartBeheviour result = null;

        SmartBeheviour.FindByInstanceId.TryGetValue(obj.GetInstanceID(), out result);

        return(result);
    }
예제 #3
0
    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);
    }
예제 #4
0
    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);
    }
예제 #5
0
    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);
    }
예제 #6
0
    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);
    }
예제 #7
0
    //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);
    }
예제 #8
0
    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);
    }