Example #1
0
        public static GameObject InstantiateEffectOverOwner(Transform p_owner, GameObject p_effect, bool p_forceLocalScale = true, bool p_instantiateInOwnerParent = true, bool p_keepOriginalRotation = false)
        {
            GameObject v_effectObject = null;

            if (p_effect != null)
            {
                if (p_owner != null)
                {
                    v_effectObject = GameObject.Instantiate(p_effect) as GameObject;
                    v_effectObject.transform.position = p_owner.position;
                    v_effectObject.transform.rotation = p_owner.rotation;
                    v_effectObject.transform.parent   = p_instantiateInOwnerParent ? p_owner.parent : p_owner;
                    v_effectObject.transform.Rotate(p_effect.transform.localEulerAngles);
                    //Force Scale to original one
                    if (p_forceLocalScale)
                    {
                        v_effectObject.transform.localScale = p_effect.transform.localScale;
                    }
                    else
                    {
                        RopeInternalUtils.SetLossyScale(v_effectObject.transform, p_effect.transform.localScale);
                    }
                    if (p_keepOriginalRotation)
                    {
                        v_effectObject.transform.eulerAngles = p_effect.transform.localEulerAngles;
                    }
                }
                else
                {
                    v_effectObject = GameObject.Instantiate(p_effect) as GameObject;
                }
            }
            return(v_effectObject);
        }
Example #2
0
 public void AddRandomImpulse(Rigidbody2D p_body)
 {
     if (p_body != null)
     {
         float   v_randomImpulse = Random.Range(m_minImpulseForce, m_maxImpulseForce);
         Vector2 v_finalVector   = RopeInternalUtils.GetVectorDirection(p_body.gameObject.transform.parent.position, p_body.gameObject.transform.position);
         v_finalVector = new Vector2(v_finalVector.x * v_randomImpulse, v_finalVector.y * v_randomImpulse);
         p_body.AddForce(v_finalVector, ForceMode2D.Impulse);
         //p_body.AddForce(new Vector2(0,v_randomImpulse));
     }
 }
Example #3
0
        public virtual bool CheckIfIsInsideMaxLimits()
        {
            Camera v_camera = RopeInternalUtils.GetCameraThatDrawLayer(gameObject.layer);

            if (v_camera != null)
            {
                Vector2 v_viewPortPos = v_camera.WorldToViewportPoint(transform.position);
                if (v_viewPortPos.x >= -MaxDistanceToOutOfBounds && v_viewPortPos.x <= MaxDistanceToOutOfBounds + 1 && v_viewPortPos.y >= -MaxDistanceToOutOfBounds && v_viewPortPos.y <= MaxDistanceToOutOfBounds + 1)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
        protected Vector2 GetWorldMousePosition(GameObject p_selectedObject)
        {
            Vector2 v_worldMousePosition = Vector2.zero;

            if (p_selectedObject != null)
            {
                Camera v_camera = null;
                v_camera = RopeInternalUtils.GetCameraThatDrawLayer(p_selectedObject.layer);
                if (v_camera != null)
                {
                    v_worldMousePosition = v_camera.ScreenToWorldPoint(Input.mousePosition);
                }
            }
            return(v_worldMousePosition);
        }
Example #5
0
        protected void RecreateRopeButtons()
        {
            EditorGUILayout.BeginHorizontal();
            bool v_forceRecreate = InspectorUtils.DrawButton("Force Recreate Rope", Color.cyan);
            bool v_refreshRope   = InspectorUtils.DrawButton("Refresh Rope", Color.cyan);

            if (m_controller != null && m_controller.gameObject != null && !RopeInternalUtils.IsPrefab(m_controller.gameObject))
            {
                if (v_forceRecreate)
                {
                    m_controller.CreateRope(true);
                }
                else if (v_refreshRope)
                {
                    m_controller.CreateRope(false);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
Example #6
0
        protected virtual void StartCollisionEffects(Vector2 p_collisionLocation)
        {
            Vector2 v_directionVector = RopeInternalUtils.GetVectorDirection(p_collisionLocation, this.transform.position);
            float   v_angle           = Vector2.Angle(Vector2.right, v_directionVector) + 180;

            if (CollisionEffectObject != null)
            {
                GameObject v_effectObject = GameObject.Instantiate(CollisionEffectObject) as GameObject;
                v_effectObject.transform.position = p_collisionLocation;
                v_effectObject.transform.rotation = Quaternion.Euler(Vector3.zero);
                v_effectObject.transform.parent   = this.transform.parent;
                //Force Scale to original one
                //v_effectObject.transform.rotation = CollisionEffectObject.transform.rotation;
                //v_effectObject.transform.localScale = DestroyEffectObject.transform.localScale;
                if (DestroyEffectObject != null)
                {
                    RopeInternalUtils.SetLossyScale(v_effectObject.transform, DestroyEffectObject.transform.localScale);
                }
                v_effectObject.transform.Rotate(new Vector3(0, 0, v_angle));
            }
        }
Example #7
0
 public virtual bool CheckIfIsInsideCameraView()
 {
     return(!RopeInternalUtils.IsOutOfScreen(gameObject, false, true));
 }