Example #1
0
        protected virtual void DrawLineRendererProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //LineRenderer Properties
            DrawTitleText("LineRenderer Properties");
            m_controller.UseLineRenderer = EditorGUILayout.Toggle("Use Line Renderer", m_controller.UseLineRenderer);
            if (m_controller.UseLineRenderer)
            {
                m_controller.RopeMaterial = EditorGUILayout.ObjectField("Line Renderer Material", m_controller.RopeMaterial, typeof(Material), false) as Material;
                //m_controller.LineRendererCurveWidth = EditorGUILayout.CurveField("Curve Width", new AnimationCurve(m_controller.LineRendererCurveWidth.keys));

                if (_curveWidthProperty == null)
                {
                    _curveWidthProperty = serializedObject.FindProperty("m_lineRendererCurveWidth");
                }
                if (_curveWidthProperty != null)
                {
                    var v_oldGuiChanged = GUI.changed;
                    serializedObject.Update();
                    EditorGUILayout.PropertyField(_curveWidthProperty, new GUIContent("Curve Width"), false);
                    if (serializedObject.ApplyModifiedProperties() || GUI.changed != v_oldGuiChanged)
                    {
                        m_controller.MarkToRecreateRope();
                    }
                }
                m_controller.LineRendererCornerVertices = EditorGUILayout.IntField("Corner Vertices", m_controller.LineRendererCornerVertices);
                m_controller.LineRendererEndCapVertices = EditorGUILayout.IntField("End Cap Vertices", m_controller.LineRendererEndCapVertices);
            }
            EditorGUILayout.Separator();
        }
Example #2
0
    protected virtual RopesByBallons GetRopeByBallonStructureInternal(Rope2D p_rope, bool p_registerNewIfDontFind = true)
    {
        RopesByBallons v_found = null;

        if (p_rope != null)
        {
            foreach (RopesByBallons v_struct in RopesByBallonsList)
            {
                if (v_struct != null && v_struct.Rope != null)
                {
                    if (v_struct.Rope == p_rope)
                    {
                        v_found = v_struct;
                        break;
                    }
                }
                else
                {
                    _needRemoveNulls = true;
                }
            }
        }
        if (p_registerNewIfDontFind && v_found == null)
        {
            v_found = new RopesByBallons(p_rope);
            RopesByBallonsList.Add(v_found);
        }
        return(v_found);
    }
Example #3
0
        protected virtual void DrawRopeProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Rope Properties
            DrawTitleText("Rope Properties");
            if (m_controller.StableFirstAndLastNodes && m_controller.IsSpringNode)
            {
                EditorGUILayout.HelpBox("We strongly recommend to disable 'Plug First/Last by Center of Mass' when using spring rope. This property can cause physics instabilities with Spring Joints", MessageType.Warning);
            }
            m_controller.StableFirstAndLastNodes = EditorGUILayout.Toggle(new GUIContent("Plug First/Last by Center of Mass", "When this mode is enable, the first and last node will be plugged by the center of mass instead of the borders increasing the rope stability. Disable this property when your PlugguedObject is smaller then one node of this rope or when using Spring Node"),
                                                                          m_controller.StableFirstAndLastNodes);
            m_controller.EditorRopeStyle = (EditorRopeStyleEnum)EditorGUILayout.EnumPopup("Editor Visual Option", m_controller.EditorRopeStyle);
            //Sorting Layer
            string[] v_sortingLayers = GetSortingLayerNames();
            int      v_sortingIndex  = EditorGUILayout.Popup("Rope Sorting Layer", GetObjectIndexInArrayOrStrings(v_sortingLayers, m_controller.RopeSortingLayerName), v_sortingLayers);

            m_controller.RopeSortingLayerName = v_sortingLayers.Length > v_sortingIndex && v_sortingIndex >= 0 ? v_sortingLayers[v_sortingIndex] : "Default";

            m_controller.RopeDepth    = EditorGUILayout.IntField("Rope Depth", m_controller.RopeDepth);
            m_controller.IsSpringNode = EditorGUILayout.Toggle("Spring Rope", m_controller.IsSpringNode);
            if (m_controller.IsSpringNode)
            {
                m_controller.SpringFrequency    = EditorGUILayout.FloatField("Spring Frequency", m_controller.SpringFrequency);
                m_controller.SpringDampingValue = EditorGUILayout.Slider(new GUIContent("Spring Damping Value", "Damping value will stabilize spring rope over time"), m_controller.SpringDampingValue, 0, 1);
            }
            EditorGUILayout.Separator();
        }
Example #4
0
        protected GameObject GetNodeWithSmallestDistanteToPoint(Rope2D p_rope, Vector2 p_point)
        {
            GameObject v_node            = null;
            float      v_currentDistance = -1;

            if (p_rope != null)
            {
                foreach (GameObject p_node in p_rope.Nodes)
                {
                    if (p_node != null)
                    {
                        if (v_currentDistance < 0)
                        {
                            v_node            = p_node;
                            v_currentDistance = Vector2.Distance(p_point, v_node.transform.position);
                        }
                        else
                        {
                            float v_thisNodeDistance = Vector2.Distance(p_point, p_node.transform.position);
                            if (v_thisNodeDistance < v_currentDistance)
                            {
                                v_node            = p_node;
                                v_currentDistance = v_thisNodeDistance;
                                continue;
                            }
                        }
                    }
                }
            }
            return(v_node);
        }
 protected override void Refresh(bool p_force = true)
 {
     if (p_force || m_windowInformation.Ropes != null)
     {
         Rope2D.CleanUselessRopes();
         GameObject v_parentTransform = GameObject.Find("RopesContainer");
         if (v_parentTransform != null)
         {
             m_windowInformation.RopeParent = v_parentTransform.transform;
         }
         List <TackRope> v_tackList = new List <TackRope>(KiltUtils.FindAllResourcesComponentsAtFolder <TackRope>("Prefabs"));
         m_windowInformation.SelectedRopeIndex = 0;
         m_windowInformation.Ropes             = new List <Rope2D>();
         foreach (TackRope v_tackRope in v_tackList)
         {
             if (v_tackRope != null)
             {
                 m_windowInformation.Ropes.Add(v_tackRope);
             }
         }
         if (p_force && m_selectedObjects != null && m_windowInformation.PickSelectedObjects)
         {
             m_selectedObjects.Clear();
         }
         FillSelectedObjects();
     }
 }
Example #6
0
 protected override void Refresh(bool p_force = true)
 {
     if (p_force || m_windowInformation.Ropes != null)
     {
         Rope2D.CleanUselessRopes();
         GameObject v_parentTransform = GameObject.Find("RopesContainer");
         if (v_parentTransform != null)
         {
             m_windowInformation.RopeParent = v_parentTransform.transform;
         }
         List <TackRope> v_tackList = new List <TackRope>(RopeEditorInternalUtils.GetAssetsOfType <TackRope>(".prefab"));
         m_windowInformation.SelectedRopeIndex = 0;
         m_windowInformation.Ropes             = new List <Rope2D>();
         foreach (TackRope v_tackRope in v_tackList)
         {
             if (v_tackRope != null)
             {
                 m_windowInformation.Ropes.Add(v_tackRope);
             }
         }
         if (p_force && m_selectedObjects != null && m_windowInformation.PickSelectedObjects)
         {
             m_selectedObjects.Clear();
         }
         FillSelectedObjects();
     }
 }
    protected override void CreateRopeClicked()
    {
        if (m_windowInformation != null)
        {
            List <Object> v_objectsSelected = new List <Object>();
            if (m_selectedObjects.Count > 2 && m_windowInformation.PlugLastWithFirst)
            {
                m_selectedObjects.Add(m_selectedObjects[0]);
            }
            for (int i = 1; i < m_selectedObjects.Count; i++)
            {
                m_currentCreatedRopes.AddChecking(CreateRope(m_selectedObjects[i - 1].Value, m_selectedObjects[i].Value, m_selectedObjects[i - 1].Key, m_selectedObjects[i].Key));
            }
            Rope2D.CleanUselessRopes();

            //Reset Selection
            foreach (Rope2D v_newRope in m_currentCreatedRopes)
            {
                if (v_newRope != null)
                {
                    v_objectsSelected.Add(v_newRope.gameObject);
                }
            }
            foreach (AOTKeyValuePair <int, GameObject> v_object in m_selectedObjects)
            {
                if (v_object != null && v_object.Value != null)
                {
                    v_objectsSelected.AddChecking(v_object.Value);
                }
            }
            Selection.objects = v_objectsSelected.ToArray();
        }
    }
    protected virtual void DrawRopeProperties()
    {
        if (m_controller == null)
        {
            m_controller = target as Rope2D;
        }

        //Rope Properties
        DrawTitleText("Rope Properties");
        m_controller.StableFirstAndLastNodes = EditorGUILayout.Toggle("Plug First/Last by Center of Mass", m_controller.StableFirstAndLastNodes);
        m_controller.EditorRopeStyle         = (EditorRopeStyleEnum)EditorGUILayout.EnumPopup("Editor Visual Option", m_controller.EditorRopeStyle);
        //Sorting Layer
        string[] v_sortingLayers = GetSortingLayerNames();
        int      v_sortingIndex  = EditorGUILayout.Popup("Rope Sorting Layer", GetObjectIndexInArrayOrStrings(v_sortingLayers, m_controller.RopeSortingLayerName), v_sortingLayers);

        m_controller.RopeSortingLayerName = v_sortingLayers.Length > v_sortingIndex && v_sortingIndex >= 0? v_sortingLayers[v_sortingIndex] : "Default";

        m_controller.RopeDepth    = EditorGUILayout.IntField("Rope Depth", m_controller.RopeDepth);
        m_controller.IsSpringNode = EditorGUILayout.Toggle("Spring Rope", m_controller.IsSpringNode);
        if (m_controller.IsSpringNode)
        {
            m_controller.SpringFrequency = EditorGUILayout.FloatField("Spring Frequency", m_controller.SpringFrequency);
        }
        EditorGUILayout.Separator();
    }
	protected virtual RopesByBallons GetRopeByBallonStructureInternal(Rope2D p_rope , bool p_registerNewIfDontFind = true) 
	{
		RopesByBallons v_found = null;
		if(p_rope != null)
		{
			foreach(RopesByBallons v_struct in RopesByBallonsList)
			{
				if(v_struct != null && v_struct.Rope != null)
				{
					if(v_struct.Rope == p_rope)
					{
						v_found = v_struct;
						break;
					}
				}
				else
					_needRemoveNulls = true;
			}
		}
		if(p_registerNewIfDontFind && v_found == null)
		{
			v_found = new RopesByBallons(p_rope);
			RopesByBallonsList.Add(v_found);
		}
		return v_found;
	}
Example #10
0
        protected virtual void DrawTensionProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Tension Properties
            DrawTitleText("Tension Properties");
            m_controller.MaxDistanceOnlyMode        = EditorGUILayout.Toggle(new GUIContent("Max Distance Only Mode (EXPERIMENTAL)", "(EXPERIMENTAL) Use this method if you want to stabilize the rope when when not tensioned"), m_controller.MaxDistanceOnlyMode);
            m_controller.TensionHelperAddOption     = (TensionHelperAddOptionEnum)EditorGUILayout.EnumPopup("Tension Helper Add Option", m_controller.TensionHelperAddOption);
            m_controller.TensionNormalizedTolerance = EditorGUILayout.Slider(new GUIContent("Tension Normalized Tolerance", "Rope will be considered tensioned if CurrentRopeSize is greater than DefaultRopeSize * (1 + m_tensionNormalizedTolerance)"), m_controller.TensionNormalizedTolerance, 0, 0.99f);
            m_controller.UseTensionColors           = EditorGUILayout.Toggle("Use Tension Color", m_controller.UseTensionColors);
            if (m_controller.UseTensionColors)
            {
                m_controller.NonTensionedColor = EditorGUILayout.ColorField("Non Tensioned Color", m_controller.NonTensionedColor);
                m_controller.TensionedColor    = EditorGUILayout.ColorField("Tensioned Color", m_controller.TensionedColor);
            }
            EditorGUILayout.Separator();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(m_controller);
            }
        }
Example #11
0
        protected virtual Rope2D CreateRope()
        {
            Rope2D v_returnedRope = null;

            if (m_windowInformation.Rope != null)
            {
                GameObject v_ropeInSceneObject = UnityEditor.PrefabUtility.InstantiatePrefab(m_windowInformation.Rope.gameObject) as GameObject;
                v_ropeInSceneObject.transform.parent = m_windowInformation.RopeParent;
                if (m_windowInformation.UsePrefabRopeScale)
                {
                    v_ropeInSceneObject.transform.localScale = m_windowInformation.Rope.transform.localScale;
                }
                v_ropeInSceneObject.name = m_windowInformation.Rope.name + "[(" + m_windowInformation.ObjectA.name.Replace("(Selected)", "") + ") to (" + m_windowInformation.ObjectB.name.Replace("(Selected)", "") + ")]";

                Rope2D v_ropeInScene = v_ropeInSceneObject.GetComponent <Rope2D>();
                v_ropeInScene.ObjectA                    = m_windowInformation.ObjectA;
                v_ropeInScene.ObjectB                    = m_windowInformation.ObjectB;
                v_ropeInScene.RopeDepth                  = m_windowInformation.RopeDepth;
                v_ropeInScene.RopeSortingLayerName       = m_windowInformation.RopeSortingLayerName;
                v_ropeInScene.AutoCalculateAmountOfNodes = m_windowInformation.AutomaticCalculateNodes;
                v_ropeInScene.AmountOfNodes              = m_windowInformation.AmountOfNodes;
                v_ropeInScene.CustomNodePrefab           = m_windowInformation.CustomPrefabNode;

                v_returnedRope = v_ropeInScene;
                EditorUtility.SetDirty(v_ropeInSceneObject);
            }
            return(v_returnedRope);
        }
Example #12
0
 protected void IndirectRopeBroke(Rope2D p_destroyedRope)
 {
     _needRecalcIndirectRopes = true;
     if (OnIndirectRopeBreak != null)
     {
         OnIndirectRopeBreak(p_destroyedRope);
     }
 }
Example #13
0
 protected void IndirectRopeDestroyed(Rope2D p_destroyedRope)
 {
     _needRecalcIndirectRopes = true;
     if (OnIndirectRopeDestroyed != null)
     {
         OnIndirectRopeDestroyed(p_destroyedRope);
     }
 }
Example #14
0
 protected void IndirectRopeCreated(Rope2D p_rope)
 {
     _needRecalcIndirectRopes = true;
     if (OnIndirectRopeCreated != null)
     {
         OnIndirectRopeCreated(p_rope);
     }
 }
Example #15
0
    protected virtual void PlugBallon()
    {
        Rope2D.CleanUselessRopes();
        BalloonProperty v_ballonPrefabComponent = m_windowInformation.Ballons != null && m_windowInformation.SelectedBallonIndex >= 0 && m_windowInformation.Ballons.Count > m_windowInformation.SelectedBallonIndex? m_windowInformation.Ballons[m_windowInformation.SelectedBallonIndex] : null;
        TackRope        v_ropePrefabComponent   = m_windowInformation.Ropes != null && m_windowInformation.SelectedRopeIndex >= 0 && m_windowInformation.Ropes.Count > m_windowInformation.SelectedRopeIndex? m_windowInformation.Ropes[m_windowInformation.SelectedRopeIndex] : null;

        if (v_ballonPrefabComponent != null && v_ropePrefabComponent != null && m_windowInformation.ObjectInSceneToPlug)
        {
            BalloonUtils.PlugBallonToObject(m_windowInformation.ObjectInSceneToPlug, v_ballonPrefabComponent, v_ropePrefabComponent, new Vector2(0.4f, 1f), new Vector2(-0.4f, 0.8f), true, true);
        }
    }
Example #16
0
    public static RopesByBallons GetRopeByBallonStructure(Rope2D p_rope, bool p_registerNewIfDontFind = true, bool p_canCreateNewControllerIfDontExists = true)
    {
        RopesByBalloonsController v_instance = GetInstance(p_canCreateNewControllerIfDontExists);
        RopesByBallons            v_return   = null;

        if (v_instance != null)
        {
            v_return = v_instance.GetRopeByBallonStructureInternal(p_rope, p_registerNewIfDontFind);
        }
        return(v_return);
    }
	protected virtual void DrawAttachedObjects()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Attached Objects Properties
		DrawTitleText("Attached Objects Properties");
		m_controller.ObjectA = EditorGUILayout.ObjectField("Object A", m_controller.ObjectA, typeof(GameObject), true) as GameObject;
		m_controller.ObjectB = EditorGUILayout.ObjectField("Object B", m_controller.ObjectB, typeof(GameObject), true) as GameObject;
		EditorGUILayout.Separator();
	}
Example #18
0
    protected virtual void HandleOnRopeBreak(Rope2D p_rope, int p_brokenIndex)
    {
        if (p_rope != null && p_rope.RopeBreakAction == RopeBreakActionEnum.DestroySelf)
        {
            RemovePluggedRopeFromList(p_rope);
        }

        if (OnRopeBreak != null)
        {
            OnRopeBreak(p_rope, p_brokenIndex);
        }
    }
Example #19
0
        protected virtual void DrawCutProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Cut Properties
            DrawTitleText("Cut Properties");
            m_controller.UserCanCutTheRope = EditorGUILayout.Toggle("User Can Cut The Rope", m_controller.UserCanCutTheRope);
            EditorGUILayout.Separator();
        }
    protected virtual void FillSelectedObjects()
    {
        _needFillSelected = false;
        if (m_currentCreatedRopes == null)
        {
            m_currentCreatedRopes = new List <Rope2D>();
        }
        else
        {
            m_currentCreatedRopes.Clear();
        }

        if (m_selectedObjects == null)
        {
            m_selectedObjects = new AOTDictionaryKV <int, GameObject>();
        }

        if (m_windowInformation.PickSelectedObjects)
        {
            List <Transform> v_transforms = new List <Transform>(Selection.transforms);
            for (int i = 0; i < m_selectedObjects.Count; i++)
            {
                GameObject v_object = m_selectedObjects[i] != null? m_selectedObjects[i].Value : null;
                if (v_object != null && !v_transforms.Contains(v_object.transform))
                {
                    m_selectedObjects[i] = null;
                }
            }
            m_selectedObjects.RemoveNulls();
            m_selectedObjects.RemovePairsWithNullValues();
            foreach (Transform v_transform in v_transforms)
            {
                if (v_transform != null)
                {
                    Rope2D v_rope = v_transform.GetComponent <Rope2D>();
                    if (v_rope == null)
                    {
                        Camera v_camera = v_transform.GetNonMarkedComponentInChildren <Camera>();
                        if (v_camera == null && !m_selectedObjects.ContainsValue(v_transform.gameObject))
                        {
                            m_selectedObjects.Add(0, v_transform.gameObject);
                        }
                    }
                    else
                    {
                        m_currentCreatedRopes.AddChecking(v_rope);
                    }
                }
            }
            RecreateList(true);
        }
    }
Example #21
0
        protected virtual void DrawAttachedObjects()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Attached Objects Properties
            DrawTitleText("Attached Objects Properties");
            m_controller.ObjectA = EditorGUILayout.ObjectField("Object A", m_controller.ObjectA, typeof(GameObject), true) as GameObject;
            m_controller.ObjectB = EditorGUILayout.ObjectField("Object B", m_controller.ObjectB, typeof(GameObject), true) as GameObject;
            EditorGUILayout.Separator();
        }
Example #22
0
 public virtual void AddPluggedRopeInList(Rope2D p_rope)
 {
     if (p_rope != null && !PluggedRopes.Contains(p_rope))
     {
         PluggedRopes.Add(p_rope);
         p_rope.OnRopeDestroyed  += HandleOnRopeDestroy;
         p_rope.OnRopeBreak      += HandleOnRopeBreak;
         _needRecalcIndirectRopes = true;
         if (OnRopePlugged != null)
         {
             OnRopePlugged(p_rope);
         }
     }
 }
	protected virtual void DrawImportantProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Important Properties
		DrawTitleText("Important Properties");
		m_controller.AutoCalculateAmountOfNodes = EditorGUILayout.Toggle("Auto Calculate Amount Of Nodes", m_controller.AutoCalculateAmountOfNodes);
		if(m_controller.AutoCalculateAmountOfNodes)
			GUI.enabled = false;
		m_controller.AmountOfNodes = EditorGUILayout.IntField("Amount Of Nodes", m_controller.AmountOfNodes);
		GUI.enabled = true;
		EditorGUILayout.Separator();
	}
    protected virtual void DrawPhysicsProperties()
    {
        if (m_controller == null)
        {
            m_controller = target as Rope2D;
        }

        //Physics Properties
        DrawTitleText("Physics Properties");
        m_controller.NodeMass         = EditorGUILayout.FloatField("Node Mass", m_controller.NodeMass);
        m_controller.NodeLinearDrag   = EditorGUILayout.FloatField("Node Linear Drag", m_controller.NodeLinearDrag);
        m_controller.NodeAngularDrag  = EditorGUILayout.FloatField("Node Angular Drag", m_controller.NodeAngularDrag);
        m_controller.NodeGravityScale = EditorGUILayout.FloatField("Node Gravity Scale", m_controller.NodeGravityScale);
        m_controller.JointCollider    = (JointColliderEnum)EditorGUILayout.EnumPopup("Joint Collider", m_controller.JointCollider);
        EditorGUILayout.Separator();
    }
Example #25
0
        protected virtual void DrawNodeVisualProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Node Visual Properties
            DrawTitleText("Node Visual Properties");
            m_controller.NodeSprite = EditorGUILayout.ObjectField("Node Sprite", m_controller.NodeSprite, typeof(Sprite), false) as Sprite;
            if (m_controller.NodeSprite != null)
            {
                m_controller.NodeMaterial = EditorGUILayout.ObjectField("Node Material", m_controller.NodeMaterial, typeof(Material), false) as Material;
            }
            EditorGUILayout.Separator();
        }
    protected virtual void DrawLineRendererProperties()
    {
        if (m_controller == null)
        {
            m_controller = target as Rope2D;
        }

        //LineRenderer Properties
        DrawTitleText("LineRenderer Properties");
        m_controller.UseLineRenderer = EditorGUILayout.Toggle("Use Line Renderer", m_controller.UseLineRenderer);
        if (m_controller.UseLineRenderer)
        {
            m_controller.RopeMaterial = EditorGUILayout.ObjectField("Line Renderer Material", m_controller.RopeMaterial, typeof(Material), false) as Material;
        }
        EditorGUILayout.Separator();
    }
Example #27
0
        protected virtual void DrawImportantProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Important Properties
            DrawTitleText("Important Properties");
            m_controller.AutoCalculateAmountOfNodes = EditorGUILayout.Toggle("Auto Calculate Amount Of Nodes", m_controller.AutoCalculateAmountOfNodes);
            if (m_controller.AutoCalculateAmountOfNodes)
            {
                GUI.enabled = false;
            }
            m_controller.AmountOfNodes = EditorGUILayout.IntField("Amount Of Nodes", m_controller.AmountOfNodes);
            GUI.enabled = true;
            EditorGUILayout.Separator();
        }
Example #28
0
        protected virtual void DrawNodeProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Node Properties
            DrawTitleText("Node Properties");
            m_controller.CustomNodePrefab   = EditorGUILayout.ObjectField("Custom Node Prefab", m_controller.CustomNodePrefab, typeof(GameObject), false) as GameObject;
            m_controller.NodeDistanceOffSet = EditorGUILayout.FloatField("Node Distance Offset", m_controller.NodeDistanceOffSet);
            if (m_controller.NodeSprite != null)
            {
                GUI.enabled = false;
            }
            m_controller.NodeSpriteGlobalSize = EditorGUILayout.Vector2Field("Node Global Size", m_controller.NodeSpriteGlobalSize);
            GUI.enabled = true;
            m_controller.NodeLocalScale = EditorGUILayout.Vector2Field("Node Local Scale", m_controller.NodeLocalScale);
            EditorGUILayout.Separator();
        }
    protected virtual void DrawTensionProperties()
    {
        if (m_controller == null)
        {
            m_controller = target as Rope2D;
        }

        //Tension Properties
        DrawTitleText("Tension Properties");
        m_controller.TensionHelperAddOption = (TensionHelperAddOptionEnum)EditorGUILayout.EnumPopup("Tension Helper Add Option", m_controller.TensionHelperAddOption);
        m_controller.UseTensionColors       = EditorGUILayout.Toggle("Use Tension Color", m_controller.UseTensionColors);
        if (m_controller.UseTensionColors)
        {
            m_controller.NonTensionedColor = EditorGUILayout.ColorField("Non Tensioned Color", m_controller.NonTensionedColor);
            m_controller.TensionedColor    = EditorGUILayout.ColorField("Tensioned Color", m_controller.TensionedColor);
        }
        EditorGUILayout.Separator();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(m_controller);
        }
    }
Example #30
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);
    }
Example #31
0
    public virtual void RemovePluggedRopeFromList(Rope2D p_rope)
    {
        //Remove nulls too
        List <Rope2D> v_pluggedRopesAux = new List <Rope2D>();

        foreach (Rope2D v_rope in PluggedRopes)
        {
            if (v_rope != p_rope && v_rope != null)
            {
                v_pluggedRopesAux.Add(v_rope);
            }
        }
        PluggedRopes = v_pluggedRopesAux;
        if (p_rope != null)
        {
            p_rope.OnRopeDestroyed  -= HandleOnRopeDestroy;
            p_rope.OnRopeBreak      -= HandleOnRopeBreak;
            _needRecalcIndirectRopes = true;
            if (OnRopeUnplugged != null)
            {
                OnRopeUnplugged(p_rope);
            }
        }
    }
Example #32
0
        protected virtual void DrawBreakProperties()
        {
            if (m_controller == null)
            {
                m_controller = target as Rope2D;
            }

            //Break Properties
            DrawTitleText("Break Properties");
            m_controller.RopeBreakAction = (RopeBreakActionEnum)EditorGUILayout.EnumPopup("On Rope Break", m_controller.RopeBreakAction);
            if (m_controller.RopeBreakAction == RopeBreakActionEnum.DestroySelf)
            {
                m_controller.DestroyTime = EditorGUILayout.FloatField("Time to Destroy Self", m_controller.DestroyTime);
            }
            m_controller.BreakEffect = EditorGUILayout.ObjectField("Break Effect Prefab", m_controller.BreakEffect, typeof(GameObject), false) as GameObject;
            m_controller.LowMassVariationWhenBroken = EditorGUILayout.Toggle("Enable Low Mass When Broken", m_controller.LowMassVariationWhenBroken);
            m_controller.RopeCanBreak = EditorGUILayout.Toggle("Rope Can Break", m_controller.RopeCanBreak);
            if (m_controller.RopeCanBreak)
            {
                m_controller.BreakAngle            = EditorGUILayout.FloatField("Max Angle Before Break", m_controller.BreakAngle);
                m_controller.RopeMaxSizeMultiplier = EditorGUILayout.FloatField("Max Rope Size (Multiplier)", m_controller.RopeMaxSizeMultiplier);
            }
            EditorGUILayout.Separator();
        }
	public virtual void AddPluggedRopeInList(Rope2D p_rope)
	{
		if(p_rope != null && !PluggedRopes.Contains(p_rope))
		{
			PluggedRopes.Add(p_rope);
			p_rope.OnRopeDestroyed += HandleOnRopeDestroy;
			p_rope.OnRopeBreak += HandleOnRopeBreak;
			_needRecalcIndirectRopes = true;
			if(OnRopePlugged != null)
				OnRopePlugged(p_rope);
		}
	}
	protected virtual void DrawTensionProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Tension Properties
		DrawTitleText("Tension Properties");
		m_controller.TensionHelperAddOption = (TensionHelperAddOptionEnum)EditorGUILayout.EnumPopup("Tension Helper Add Option", m_controller.TensionHelperAddOption);
		m_controller.UseTensionColors = EditorGUILayout.Toggle("Use Tension Color", m_controller.UseTensionColors);
		if(m_controller.UseTensionColors)
		{
			m_controller.NonTensionedColor = EditorGUILayout.ColorField("Non Tensioned Color", m_controller.NonTensionedColor);
			m_controller.TensionedColor = EditorGUILayout.ColorField("Tensioned Color", m_controller.TensionedColor);
		}
		EditorGUILayout.Separator();
		
		if(GUI.changed)
			EditorUtility.SetDirty(m_controller);
	}
	protected virtual void DrawBreakProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Break Properties
		DrawTitleText("Break Properties");
		m_controller.RopeBreakAction = (RopeBreakActionEnum)EditorGUILayout.EnumPopup("On Rope Break", m_controller.RopeBreakAction);
		if(m_controller.RopeBreakAction == RopeBreakActionEnum.DestroySelf)
			m_controller.DestroyTime = EditorGUILayout.FloatField("Time to Destroy Self", m_controller.DestroyTime);
		m_controller.BreakEffect = EditorGUILayout.ObjectField("Break Effect Prefab", m_controller.BreakEffect, typeof(GameObject), false) as GameObject;
		m_controller.LowMassVariationWhenBroken = EditorGUILayout.Toggle("Enable Low Mass When Broken", m_controller.LowMassVariationWhenBroken);
		m_controller.RopeCanBreak = EditorGUILayout.Toggle("Rope Can Break", m_controller.RopeCanBreak);
		if(m_controller.RopeCanBreak)
		{
			m_controller.BreakAngle = EditorGUILayout.FloatField("Max Angle Before Break", m_controller.BreakAngle);
			m_controller.RopeMaxSizeMultiplier = EditorGUILayout.FloatField("Max Rope Size (Multiplier)", m_controller.RopeMaxSizeMultiplier);
			
		}
		EditorGUILayout.Separator();
	}
	protected virtual void DrawCutProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Cut Properties
		DrawTitleText("Cut Properties");
		m_controller.UserCanCutTheRope = EditorGUILayout.Toggle("User Can Cut The Rope", m_controller.UserCanCutTheRope);
		EditorGUILayout.Separator();
	}
	protected void IndirectRopeCreated(Rope2D p_rope)
	{
		_needRecalcIndirectRopes = true;
		if(OnIndirectRopeCreated != null)
			OnIndirectRopeCreated(p_rope);
	}
	public static void PlugBallonToObject(GameObject p_object, BalloonProperty p_ballon, Rope2D p_rope, Vector2 p_minDistance, Vector2 p_maxDistance, bool p_ballonIsAPrefab = true, bool p_ropeIsAPrefab = true, bool p_useBallonPrefabScale = true, bool p_useRopePrefabScale = true, string p_errorSolverDirectory = "Prefabs")
	{
		GameObject v_ropeParentObject = GameObject.Find("RopesContainer");
		GameObject v_blockParentObject = GameObject.Find("BlocksContainer");
		
		GameObject v_ballonInScene = null;
		GameObject v_ropeInScene = null;
		
		//Try Solve Ballon Errors
		if(p_ballon == null)
		{
			BalloonProperty[] v_ballons = KiltUtils.FindAllResourcesComponentsAtFolder<BalloonProperty>(p_errorSolverDirectory);
			if(v_ballons.Length <= 0)
				v_ballons = KiltUtils.FindAllResourcesComponentsOfType<BalloonProperty>();
			if(v_ballons.Length > 0 && v_ballons[0] != null)
			{
				v_ballonInScene = KiltUtils.Instantiate(v_ballons[0].gameObject);
				v_ballonInScene.transform.parent = v_blockParentObject != null? v_blockParentObject.transform : null;
				if(p_useBallonPrefabScale)
					v_ballonInScene.transform.localScale = v_ballons[0].gameObject.transform.localScale;
			}
		}
		else if(p_ballonIsAPrefab)
		{
			v_ballonInScene = KiltUtils.Instantiate(p_ballon.gameObject);
			v_ballonInScene.transform.parent = v_blockParentObject != null? v_blockParentObject.transform : null;
			if(p_useBallonPrefabScale)
				v_ballonInScene.transform.localScale = p_ballon.gameObject.transform.localScale;
		}
		else
			v_ballonInScene = p_ballon.gameObject;
		
		//Try Solve Rope Errors
		if(p_rope == null)
		{
			Rope2D[] v_ropes = KiltUtils.FindAllResourcesComponentsAtFolder<Rope2D>(p_errorSolverDirectory);
			if(v_ropes.Length <= 0)
				v_ropes = KiltUtils.FindAllResourcesComponentsOfType<Rope2D>();
			if(v_ropes.Length > 0 && v_ropes[0] != null)
			{
				v_ropeInScene = KiltUtils.Instantiate(v_ropes[0].gameObject);
				v_ropeInScene.transform.parent = v_ropeParentObject != null? v_ropeParentObject.transform : null;
				if(p_useRopePrefabScale)
					v_ropeInScene.transform.localScale = v_ropes[0].gameObject.transform.localScale;
			}
		}
		else if(p_ropeIsAPrefab)
		{
			v_ropeInScene = KiltUtils.Instantiate(p_rope.gameObject);
			v_ropeInScene.transform.parent = v_ropeParentObject != null? v_ropeParentObject.transform : null;
			if(p_useRopePrefabScale)
				v_ropeInScene.transform.localScale = p_rope.gameObject.transform.localScale;
		}
		else
			v_ropeInScene = p_rope.gameObject;
		
		if(v_ballonInScene != null && p_object != null && v_ropeInScene != null)
		{
			v_ballonInScene.transform.localPosition = new Vector3(v_ballonInScene.transform.localPosition.x, v_ballonInScene.transform.localPosition.y, 20); // Prevent Rope Collider to be in front of this Object
			v_ballonInScene.name = v_ballonInScene.name.Replace("(Clone)","");
			v_ropeInScene.name = v_ropeInScene.name.Replace("(Clone)", "") + "[(" + p_object.name.Replace("(Selected)","") +") to ("+ v_ballonInScene.name + ")]";
			TackRope v_tackRope = v_ropeInScene.GetComponent<TackRope>();
			if(v_tackRope != null)
			{
				v_tackRope.ObjectA = p_object;
				v_tackRope.ObjectB = v_ballonInScene;
				
				Vector2 v_newOffSetPosition = new Vector2(KiltUtils.RandomRange(p_minDistance.x, p_maxDistance.x), KiltUtils.RandomRange(p_minDistance.y, p_maxDistance.y));
				v_ballonInScene.transform.position = new Vector3(p_object.transform.position.x + v_newOffSetPosition.x, p_object.transform.position.y + v_newOffSetPosition.y, p_object.transform.position.z);
				if(Application.isPlaying)
					v_tackRope.CreateRope();
			}
		}
		if(v_ballonInScene != null && v_ballonInScene.GetComponent<BlockSelector>() == null)
			v_ballonInScene.AddComponent<BlockSelector>();
	}
	protected void HandleOnRopePlugged(Rope2D p_rope)
	{
		_needRecalcForce = true;
	}
	public static RopesByBallons GetRopeByBallonStructure(Rope2D p_rope , bool p_registerNewIfDontFind = true, bool p_canCreateNewControllerIfDontExists = true) 
	{
		RopesByBalloonsController v_instance = GetInstance(p_canCreateNewControllerIfDontExists);
		RopesByBallons v_return = null;
		if(v_instance != null)
			v_return = v_instance.GetRopeByBallonStructureInternal(p_rope, p_registerNewIfDontFind);
		return v_return;
	}
	protected void HandleOnRopeBreak(Rope2D p_rope, int p_brokenIndex)
	{
		_needRecalcForce = true;
	}
	public virtual void RemovePluggedRopeFromList(Rope2D p_rope)
	{
		//Remove nulls too
		List<Rope2D> v_pluggedRopesAux = new List<Rope2D>();
		foreach(Rope2D v_rope in PluggedRopes)
		{
			if(v_rope != p_rope && v_rope != null)
			{
				v_pluggedRopesAux.Add(v_rope);
			}
		}
		PluggedRopes = v_pluggedRopesAux;
		if(p_rope != null)
		{
			p_rope.OnRopeDestroyed -= HandleOnRopeDestroy;
			p_rope.OnRopeBreak -= HandleOnRopeBreak;
			_needRecalcIndirectRopes = true;
			if(OnRopeUnplugged != null)
				OnRopeUnplugged(p_rope);
		}
	}
	protected void IndirectRopeBroke(Rope2D p_destroyedRope)
	{
		_needRecalcIndirectRopes = true;
		if(OnIndirectRopeBreak != null)
			OnIndirectRopeBreak(p_destroyedRope);
	}
	protected virtual void DrawPhysicsProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Physics Properties
		DrawTitleText("Physics Properties");
		m_controller.NodeMass = EditorGUILayout.FloatField("Node Mass", m_controller.NodeMass);
		m_controller.NodeLinearDrag = EditorGUILayout.FloatField("Node Linear Drag", m_controller.NodeLinearDrag);
		m_controller.NodeAngularDrag = EditorGUILayout.FloatField("Node Angular Drag", m_controller.NodeAngularDrag);
		m_controller.NodeGravityScale = EditorGUILayout.FloatField("Node Gravity Scale", m_controller.NodeGravityScale);
		m_controller.JointCollider = (JointColliderEnum)EditorGUILayout.EnumPopup("Joint Collider", m_controller.JointCollider);
		EditorGUILayout.Separator();
	}
	protected void HandleOnIndirectRopeDestroyed(Rope2D p_rope)
	{
		_needRecalcForce = true;
	}
	protected virtual void HandleOnRopeDestroy(Rope2D p_rope)
	{
		RemovePluggedRopeFromList(p_rope);
	}
Example #47
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);
	}
	protected virtual void DrawRopeProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Rope Properties
		DrawTitleText("Rope Properties");
		m_controller.StableFirstAndLastNodes = EditorGUILayout.Toggle("Plug First/Last by Center of Mass", m_controller.StableFirstAndLastNodes);
		m_controller.EditorRopeStyle = (EditorRopeStyleEnum)EditorGUILayout.EnumPopup("Editor Visual Option", m_controller.EditorRopeStyle);
		//Sorting Layer
		string[] v_sortingLayers = GetSortingLayerNames();
		int v_sortingIndex = EditorGUILayout.Popup("Rope Sorting Layer", GetObjectIndexInArrayOrStrings(v_sortingLayers, m_controller.RopeSortingLayerName), v_sortingLayers);
		m_controller.RopeSortingLayerName = v_sortingLayers.Length > v_sortingIndex && v_sortingIndex >=0? v_sortingLayers[v_sortingIndex] : "Default";

		m_controller.RopeDepth = EditorGUILayout.IntField("Rope Depth", m_controller.RopeDepth);
		m_controller.IsSpringNode = EditorGUILayout.Toggle("Spring Rope", m_controller.IsSpringNode);
		if(m_controller.IsSpringNode)
			m_controller.SpringFrequency = EditorGUILayout.FloatField("Spring Frequency", m_controller.SpringFrequency);
		EditorGUILayout.Separator();
	}
	protected void HandleOnRopeUnplugged(Rope2D p_rope)
	{
		_needRecalcAndClear = true;
		RecalcOthersMass();
	}
	protected virtual void DrawLineRendererProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//LineRenderer Properties
		DrawTitleText("LineRenderer Properties");
		m_controller.UseLineRenderer = EditorGUILayout.Toggle("Use Line Renderer", m_controller.UseLineRenderer);
		if(m_controller.UseLineRenderer)
			m_controller.RopeMaterial = EditorGUILayout.ObjectField("Line Renderer Material", m_controller.RopeMaterial, typeof(Material), false) as Material;
		EditorGUILayout.Separator();
	}
	protected void HandleOnIndirectRopeBreak(Rope2D p_rope)
	{
		_needRecalcForce = true;
	}
	protected void IndirectRopeDestroyed(Rope2D p_destroyedRope)
	{
		_needRecalcIndirectRopes = true;
		if(OnIndirectRopeDestroyed != null)
			OnIndirectRopeDestroyed(p_destroyedRope);
	}
Example #53
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);
    }
Example #54
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);
	}
	public RopesByBallons(Rope2D p_rope)
	{
		m_rope = p_rope;
	}
	protected virtual void DrawNodeVisualProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Node Visual Properties
		DrawTitleText("Node Visual Properties");
		m_controller.NodeSprite = EditorGUILayout.ObjectField("Node Sprite", m_controller.NodeSprite, typeof(Sprite), false) as Sprite;
		if(m_controller.NodeSprite != null)
			m_controller.NodeMaterial = EditorGUILayout.ObjectField("Node Material", m_controller.NodeMaterial, typeof(Material), false) as Material;
		EditorGUILayout.Separator();
	}
	protected virtual void HandleOnRopeBreak(Rope2D p_rope, int p_brokenIndex)
	{
		if(p_rope != null && p_rope.RopeBreakAction == RopeBreakActionEnum.DestroySelf)
			RemovePluggedRopeFromList(p_rope);

		if(OnRopeBreak != null)
			OnRopeBreak(p_rope, p_brokenIndex);

	}
	protected virtual void DrawNodeProperties()
	{
		if(m_controller == null)
			m_controller = target as Rope2D;
		
		//Node Properties
		DrawTitleText("Node Properties");
		m_controller.CustomNodePrefab = EditorGUILayout.ObjectField("Custom Node Prefab", m_controller.CustomNodePrefab, typeof(GameObject), false) as GameObject;
		m_controller.NodeDistanceOffSet = EditorGUILayout.FloatField("Node Distance Offset", m_controller.NodeDistanceOffSet);
		if(m_controller.NodeSprite != null)
			GUI.enabled = false;
		m_controller.NodeSpriteGlobalSize = EditorGUILayout.Vector2Field("Node Global Size", m_controller.NodeSpriteGlobalSize);
		GUI.enabled = true;
		m_controller.NodeLocalScale = EditorGUILayout.Vector2Field("Node Local Scale", m_controller.NodeLocalScale);
		EditorGUILayout.Separator();
	}
	protected GameObject GetNodeWithSmallestDistanteToPoint(Rope2D p_rope, Vector2 p_point)
	{
		GameObject v_node = null;
		float v_currentDistance = -1;
		if(p_rope != null)
		{
			foreach(GameObject p_node in p_rope.Nodes)
			{
				if(p_node != null)
				{
					if(v_currentDistance < 0)
					{
						v_node = p_node;
						v_currentDistance = Vector2.Distance(p_point, v_node.transform.position);
					}
					else
					{
						float v_thisNodeDistance = Vector2.Distance(p_point, p_node.transform.position);
						if(v_thisNodeDistance < v_currentDistance)
						{
							v_node = p_node;
							v_currentDistance = v_thisNodeDistance;
							continue;
						}
					}
				}
			}
		}
		return v_node;
	}
Example #60
0
	public static void UnregisterRopeFromScene(Rope2D p_rope)
	{
		List<Rope2D> v_ropeList = new List<Rope2D>(_allRopesInScene);
		v_ropeList.RemoveChecking(p_rope);
		_allRopesInScene = v_ropeList.ToArray();
	}