コード例 #1
0
ファイル: NPBinding.cs プロジェクト: usfx/frantic-architect
    private T AddComponentBasedOnPlatform <T> () where T : MonoBehaviour
    {
        System.Type _basicType    = typeof(T);
        string      _baseTypeName = _basicType.ToString();

        // Check if we have free version specific class
        string _platformSpecificTypeName = null;

#if UNITY_EDITOR
        _platformSpecificTypeName = _baseTypeName + "Editor";
#elif UNITY_IOS
        _platformSpecificTypeName = _baseTypeName + "IOS";
#elif UNITY_ANDROID
        _platformSpecificTypeName = _baseTypeName + "Android";
#endif

        if (!string.IsNullOrEmpty(_platformSpecificTypeName))
        {
#if !NETFX_CORE
            System.Type _platformSpecificClassType = _basicType.Assembly.GetType(_platformSpecificTypeName, false);
#else
            System.Type _platformSpecificClassType = _basicType;
#endif

            return(CachedGameObject.AddComponent(_platformSpecificClassType) as T);
        }

        return(CachedGameObject.AddComponent <T>());
    }
コード例 #2
0
 public Rigidbody2D ForceGetRigidbody2D()
 {
     if (CachedRigidbody2D == null)
     {
         _cachedRigidbody2D = CachedGameObject.AddComponent <Rigidbody2D>();
     }
     return(_cachedRigidbody2D);
 }
コード例 #3
0
 public Rigidbody ForceGetRigidbody()
 {
     if (CachedRigidbody == null)
     {
         _cachedRigidbody = CachedGameObject.AddComponent <Rigidbody>();
     }
     return(_cachedRigidbody);
 }
コード例 #4
0
    void CreateGround()
    {
        float x = 0f;

        groundCollider = CachedGameObject.AddComponent <BoxCollider2D> ();

        topCollider = tup.gameObject.AddComponent <BoxCollider2D> ();

        leftCollider  = tleft.gameObject.AddComponent <BoxCollider2D> ();
        rightCollider = tright.gameObject.AddComponent <BoxCollider2D> ();

        Vector2 size   = new Vector2(worldWidth, 5f);
        Vector2 offset = new Vector2(0f, -(worldHeight * 0.5f + 2.5f));

        groundCollider.offset = offset;
        groundCollider.size   = size;

        offset = new Vector2(0f, (2.5f));

        topCollider.offset = offset;
        topCollider.size   = size;

        size   = new Vector2(5f, worldHeight);
        offset = new Vector2(-(2.5f), 0f);

        leftCollider.offset = offset;
        leftCollider.size   = size;

        size   = new Vector2(5f, worldHeight);
        offset = new Vector2((2.5f), 0f);

        rightCollider.offset = offset;
        rightCollider.size   = size;

        while (x <= worldWidth)
        {
            TrashGround ground = GetNewGround();

            //ground.CachedTransform.parent = CachedTransform;

            float x_pos = GetXPositionFor(ground, x);

            x = GetNextXPositionFor(ground, x_pos);

            x_pos += tleft.position.x;

            float y = tdown.position.y - ground.GetHeight() * 0.5f;

            Vector2 pos = new Vector2(x_pos, y);

            ground.CachedTransform.position = pos;

            cache_Ground_Size = ground.GetHeight() * 0.99f;
        }
    }
コード例 #5
0
    public T ForceGet <T>() where T : Component
    {
        Component component;

        if (_cachedExtraComponents.TryGetValue(typeof(T), out component))
        {
            return((T)component);
        }
        else
        {
            component = CachedGameObject.GetComponent <T>();
            if (component == null)
            {
                component = CachedGameObject.AddComponent <T>();
            }
            _cachedExtraComponents.Add(typeof(T), component);
            return((T)component);
        }
    }
コード例 #6
0
ファイル: NPBinding.cs プロジェクト: plentypvp/Projects
    private T AddComponentBasedOnPlatformOnlyIfRequired <T> () where T : MonoBehaviour
    {
        T _existingComponent = GetComponent <T>();

        if (_existingComponent != null)
        {
            return(_existingComponent);
        }

        // Until now this component hasn't been added so let's add it now
        System.Type _basicType    = typeof(T);
        string      _baseTypeName = _basicType.ToString();

        string _platformSpecificTypeName = null;

#if UNITY_EDITOR
        _platformSpecificTypeName = _baseTypeName + "Editor";
#elif UNITY_IOS
        _platformSpecificTypeName = _baseTypeName + "IOS";
#elif UNITY_ANDROID
        _platformSpecificTypeName = _baseTypeName + "Android";
#endif

        if (!string.IsNullOrEmpty(_platformSpecificTypeName))
        {
#if !NETFX_CORE
            System.Type _platformSpecificClassType = _basicType.Assembly.GetType(_platformSpecificTypeName, false);
#else
            System.Type _platformSpecificClassType = _basicType;
#endif

            return(CachedGameObject.AddComponent(_platformSpecificClassType) as T);
        }

        return(CachedGameObject.AddComponent <T>());
    }