示例#1
0
 protected virtual void OnPerformUndoRedo()
 {
     if (m_controller != null)
     {
         m_controller.CreateRope(false);
     }
 }
    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 && !KiltUtils.IsPrefab(m_controller.gameObject, PrefabSearchMethodEnum.Full))
        {
            if (v_forceRecreate)
            {
                m_controller.CreateRope(true);
            }
            else if (v_refreshRope)
            {
                m_controller.CreateRope(false);
            }
        }
        EditorGUILayout.EndHorizontal();
    }
示例#3
0
    //create rope
    void Create()
    {
        //if rope width is 0, that means that user hadn't set rope width, in that case we make width same as chainObject's renderer size
        if (ropeWidth <= 0.0f)
        {
            ropeWidth = chainObject.GetComponent <Renderer>().bounds.size.x;
        }

        //if connectToA is set to true and pointA doesn't have DistanceJoint2D component yet, add it
        if (connectToA)
        {
            var jointA = pointA.GetComponent <DistanceJoint2D>();
            if (!jointA || (jointA && jointA.connectedBody))
            {
                Undo.AddComponent <DistanceJoint2D>(pointA.gameObject);                 //register undo
            }
        }

        //if connectToB is set to true and pointB doesn't have DistanceJoint2D component yet, add it
        if (connectToB)
        {
            var jointB = pointB.GetComponent <DistanceJoint2D>();
            if (!jointB || (jointB && jointB.connectedBody))
            {
                Undo.AddComponent <DistanceJoint2D>(pointB.gameObject);                 //register undo
            }
        }

        //create "Chains Holder" object, used to make chains children of that object
        chainsHolder = new GameObject("Chains Holder");
        Undo.RegisterCreatedObjectUndo(chainsHolder, "Create Rope");          //register undo

        //create rope
        Rope2D rope = new Rope2D();

        rope.CreateRope(chainsHolder, chainObject, pointA, pointB, lockFirstChain, lockLastChain, connectToA, connectToB, hideEndChains, useLineRenderer, ropeMat, ropeWidth);
    }
示例#4
0
    //create rope
    void Create()
    {
        if (!chainObject.GetComponent <Collider2D>())
        {
            helpText = "Chain Object Doesn't Have Collider2D Attached";
            return;
        }

        if (!chainObject.GetComponent <HingeJoint2D>())
        {
            helpText = "Chain Object Doesn't Have HingeJoint2D Attached";
            return;
        }

        //if rope width is 0, that means that user hadn't set rope width, in that case we make width same as chainObject's renderer size
        if (ropeWidth <= 0.0f)
        {
            ropeWidth = chainObject.GetComponent <Renderer>().bounds.size.x;
        }

        //if pointA has 3D collider attached, remove it
        var colA = pointA.GetComponent <Collider>();

        if (colA)
        {
            Undo.DestroyObjectImmediate(colA);
        }

        //if connectToA is set to true and pointA doesn't have DistanceJoint2D component yet, add it
        if (connectToA)
        {
            var jointA = pointA.GetComponent <DistanceJoint2D>();
            if (!jointA || (jointA && jointA.connectedBody))
            {
                Undo.AddComponent <DistanceJoint2D>(pointA.gameObject);                 //register undo
            }
        }

        //if pointB has 3D collider attached, remove it
        var colB = pointB.GetComponent <Collider>();

        if (colB)
        {
            Undo.DestroyObjectImmediate(colB);
        }

        //if connectToB is set to true and pointB doesn't have DistanceJoint2D component yet, add it
        if (connectToB)
        {
            var jointB = pointB.GetComponent <DistanceJoint2D>();
            if (!jointB || (jointB && jointB.connectedBody))
            {
                Undo.AddComponent <DistanceJoint2D>(pointB.gameObject);                 //register undo
            }
        }

        //calculate how many chains is needed from pointA to pointB
        var chainCount = (int)(Vector3.Distance(pointA.position, pointB.position) / (chainObject.GetComponent <Renderer>().bounds.extents.x * 1.9f));

        if (chainCount < 2)
        {
            helpText = "Distance between PointA & PointB is very small";

            if (pointsHolder)
            {
                Debug.LogWarning("Distance from " + pointA.name + " (PointA) to " + pointB.name + " (PointB) is very small, increase distance");
            }

            return;
        }

        //create "Chains Holder" object, used to make chains children of that object
        chainsHolder = new GameObject("Chains Holder");
        Undo.RegisterCreatedObjectUndo(chainsHolder, "Create Rope");          //register undo

        //create rope
        Rope2D rope = new Rope2D();

        rope.CreateRope(chainsHolder, chainObject, pointA, pointB, lockFirstChain, lockLastChain, connectToA, connectToB, hideEndChains, useLineRenderer, ropeMat, ropeWidth, ropeLength);
    }
示例#5
0
	//create rope
	void Create()
	{
		if(!chainObject.GetComponent<Collider2D>())
		{
			helpText = "Chain Object Doesn't Have Collider2D Attached";
			return;
		}

		if(!chainObject.GetComponent<HingeJoint2D>())
		{
			helpText = "Chain Object Doesn't Have HingeJoint2D Attached";
			return;
		}

		//if rope width is 0, that means that user hadn't set rope width, in that case we make width same as chainObject's renderer size
		if(ropeWidth <= 0.0f)
			ropeWidth = chainObject.GetComponent<Renderer>().bounds.size.x;

		//if pointA has 3D collider attached, remove it
		var colA = pointA.GetComponent<Collider>();
		if(colA)
			Undo.DestroyObjectImmediate(colA);

		//if connectToA is set to true and pointA doesn't have DistanceJoint2D component yet, add it
		if(connectToA)
		{
			var jointA = pointA.GetComponent<DistanceJoint2D>();
			if(!jointA || (jointA && jointA.connectedBody))
				Undo.AddComponent<DistanceJoint2D>(pointA.gameObject);	//register undo
		}

		//if pointB has 3D collider attached, remove it
		var colB = pointB.GetComponent<Collider>();
		if(colB)
			Undo.DestroyObjectImmediate (colB);

		//if connectToB is set to true and pointB doesn't have DistanceJoint2D component yet, add it
		if(connectToB)
		{
			var jointB = pointB.GetComponent<DistanceJoint2D>();
			if(!jointB || (jointB && jointB.connectedBody))
				Undo.AddComponent<DistanceJoint2D>(pointB.gameObject);	//register undo
		}

		//calculate how many chains is needed from pointA to pointB
		var chainCount = (int)(Vector3.Distance(pointA.position, pointB.position) / (chainObject.GetComponent<Renderer>().bounds.extents.x * 1.9f));
		if(chainCount < 2)
		{
			helpText = "Distance between PointA & PointB is very small";

			if(pointsHolder)
				Debug.LogWarning("Distance from "+ pointA.name +" (PointA) to "+ pointB.name +" (PointB) is very small, increase distance");

			return;
		}

		//create "Chains Holder" object, used to make chains children of that object
		chainsHolder = new GameObject("Chains Holder");
		Undo.RegisterCreatedObjectUndo (chainsHolder, "Create Rope"); //register undo

		//create rope
		Rope2D rope = new Rope2D();
		rope.CreateRope (chainsHolder, chainObject, pointA, pointB, lockFirstChain, lockLastChain, connectToA, connectToB, hideEndChains, useLineRenderer, ropeMat, ropeWidth);
	}
示例#6
0
	//create rope
	void Create()
	{
		//if rope width is 0, that means that user hadn't set rope width, in that case we make width same as chainObject's renderer size
		if(ropeWidth <= 0.0f)
			ropeWidth = chainObject.GetComponent<Renderer>().bounds.size.x;

		//if connectToA is set to true and pointA doesn't have DistanceJoint2D component yet, add it
		if(connectToA)
		{
			var jointA = pointA.GetComponent<DistanceJoint2D>();
			if(!jointA || (jointA && jointA.connectedBody))
				Undo.AddComponent<DistanceJoint2D>(pointA.gameObject);	//register undo
		}

		//if connectToB is set to true and pointB doesn't have DistanceJoint2D component yet, add it
		if(connectToB)
		{
			var jointB = pointB.GetComponent<DistanceJoint2D>();
			if(!jointB || (jointB && jointB.connectedBody))
				Undo.AddComponent<DistanceJoint2D>(pointB.gameObject);	//register undo
		}

		//create "Chains Holder" object, used to make chains children of that object
		chainsHolder = new GameObject("Chains Holder");
		Undo.RegisterCreatedObjectUndo (chainsHolder, "Create Rope"); //register undo

		//create rope
		Rope2D rope = new Rope2D();
		rope.CreateRope (chainsHolder, chainObject, pointA, pointB, lockFirstChain, lockLastChain, connectToA, connectToB, hideEndChains, useLineRenderer, ropeMat, ropeWidth);
	}