コード例 #1
0
ファイル: LaunchRenderArc.cs プロジェクト: AshIrvin/Cubey
 private void Awake()
 {
     lr        = GetComponent <LineRenderer>();
     g         = Mathf.Abs(Physics2D.gravity.y);
     cubey     = transform.parent.gameObject;
     leanForce = transform.GetComponentInParent <LeanForceRigidbody>();
 }
コード例 #2
0
ファイル: BlockModel.cs プロジェクト: contrejo27/Jose
        } //END CheckIfWeShouldAddMeshColliderToModel

        //---------------------------------------//
        private void CheckIfWeShouldAddRigidbodyToModel()
        //---------------------------------------//
        {

            //Check if we should add a Rigidbody to the model
            if( model != null && addMeshCollider && addRigidbody && _meshCollider != null )
            {
                //Only add a Rigidbody if there isn't one already
                if( model.GetComponentInChildren<Rigidbody>() == null )
                {
                    _rigidbody = _meshCollider.gameObject.AddComponent<Rigidbody>();
                }
                else
                {
                    _rigidbody = model.GetComponentInChildren<Rigidbody>();
                }

                //Disable gravity until the floor plane has been created, otherwise it will fall through the floor!
                _rigidbody.isKinematic = false;
                _rigidbody.useGravity = false;
                _rigidbody.mass = 1f;
                _rigidbody.drag = dragEndEaseSpeed;
                _rigidbody.angularDrag = dragEndEaseSpeed;
                _rigidbody.freezeRotation = true;

                //Setup the other features we'll need to apply physics
#if LEANTOUCH
                //Add a LeanTouchRigidbody component to the model
                if( leanForceRigidbody == null )
                {
                    leanForceRigidbody = _meshCollider.gameObject.AddComponent<LeanForceRigidbody>();
                    leanForceRigidbody.cachedBody = _rigidbody;
                }
                else
                {
                    Debug.Log( "model = " + model + ", leanForceRigidbody != null... " + leanForceRigidbody );
                }

                //Add a LeanFingerSwipe component to the model
                if( leanFingerSwipe == null )
                {
                    leanFingerSwipe = _meshCollider.gameObject.AddComponent<LeanFingerSwipe>();
                    leanFingerSwipe.Clamp = LeanFingerSwipe.ClampType.ScaledDelta;
                }

                //Connect the finger swipe event to the Rigidbody
                if( leanFingerSwipe != null && leanForceRigidbody != null )
                {
                    if( leanFingerSwipe.OnSwipeDelta == null ) { leanFingerSwipe.OnSwipeDelta = new LeanFingerSwipe.Vector2Event(); }
                    leanFingerSwipe.OnSwipeDelta.AddListener( leanForceRigidbody.Apply );
                }
#endif
            }

        } //END CheckIfWeShouldAddRigidbodyToModel
コード例 #3
0
ファイル: BlockModel.cs プロジェクト: contrejo27/Jose
        } //END CheckIfWeShouldChangeModelOnStart

        //--------------------------------//
        /// <summary>
        /// Replaces the existing instantiated 3D model with the one passed in. Expects a prefab/gameObject reference to clone
        /// </summary>
        /// <param name="newModelToClone">The GameObject prefab we want to clone</param>
        public void ChangeModel( GameObject newModelToClone )
        //--------------------------------//
        {
#if LEANTOUCH
            leanForceRigidbody = null;
            leanFingerSwipe = null;
#endif

            //Destroy any existing model(s)
            if( faceCameraTransform.childCount > 0 )
            {
#if UNITY_EDITOR
                //Wait a moment before calling DestroyImmediate to make sure no logic is running
                UnityEditor.EditorApplication.delayCall += () =>
                {
                    DestroyImmediate( faceCameraTransform.GetChild(0).gameObject );
                };
#else
                Destroy( faceCameraTransform.GetChild(0).gameObject );
#endif
            }

            //Instantiate the new model to show
            if( newModelToClone != null )
            {
                model = Instantiate( newModelToClone, faceCameraTransform );
                
                //Remove (Clone) from the models name
                if( model.name.Contains( "(Clone)" ))
                {
                    string[] words = model.name.Split( '(' );
                    model.name = words[ 0 ];
                }
                
                model.SetActive( true );

                transformToMove = this.transform;
                transformToPinch = this.transform;
                transformToTwist = this.transform;
                /*
                transformToMove = model.transform;
                transformToPinch = model.transform;
                transformToTwist = model.transform;
                */

            }

            //Add a ColorTweenManager to the new model, and link all of the renderers to it
            if ( model.GetComponent<UIColorTweenManager>() == null )
            {
                uiColorTweenManager = model.AddComponent<UIColorTweenManager>();
            }
            else
            {
                uiColorTweenManager = model.GetComponent<UIColorTweenManager>();
            }

            //Find all of the Renderers on the object, attach a UIColorTweener to those gameObjects and link them to the uiColorTweenManager
            if( model.GetComponentInChildren<Renderer>() != null )
            {
                uiColorTweenManager.tweeners = new List<UIColorTweener>();

                foreach( Renderer rend in model.GetComponentsInChildren<Renderer>().ToList() )
                {
                    if ( rend != null && rend.gameObject.GetComponent<UIColorTweener>() == null )
                    {
                        uiColorTweenManager.tweeners.Add( rend.gameObject.AddComponent<UIColorTweener>() );
                    }
                    else if( rend != null && rend.gameObject.GetComponent<UIColorTweener>() != null )
                    {
                        uiColorTweenManager.tweeners.Add( rend.gameObject.GetComponent<UIColorTweener>() );
                    }
                }
            }

            CheckIfWeShouldAddMeshColliderToModel();

            CheckIfWeShouldAddRigidbodyToModel();

        } //END ChangeModel