protected virtual Rope2D CreateRope(GameObject p_objectA, GameObject p_objectB, int p_indexA = 0, int p_indexB = 0)
    {
        TackRope v_returnedRope = null;

        if (m_windowInformation.Rope != null && p_objectA != null && p_objectB != null)
        {
            GameObject v_ropeInSceneObject = KiltUtils.Instantiate(m_windowInformation.Rope.gameObject);
            v_ropeInSceneObject.name             = m_windowInformation.Rope.name + "[(" + p_objectA.name.Replace("(Selected)", "") + ") to (" + p_objectB.name.Replace("(Selected)", "") + ")]";
            v_ropeInSceneObject.transform.parent = m_windowInformation.RopeParent;
            if (m_windowInformation.UsePrefabRopeScale)
            {
                v_ropeInSceneObject.transform.localScale = m_windowInformation.Rope.transform.localScale;
            }

            TackRope v_ropeInScene = v_ropeInSceneObject.GetComponent <TackRope>();
            v_ropeInScene.ObjectA                    = p_objectA;
            v_ropeInScene.ObjectB                    = p_objectB;
            v_ropeInScene.TackAIndex                 = p_indexA;
            v_ropeInScene.TackBIndex                 = p_indexB;
            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);
    }
Exemplo n.º 2
0
        protected override void DrawAttachedObjects()
        {
            if (m_controllerTack == null)
            {
                m_controllerTack = target as TackRope;
            }

            //Attached Objects Properties
            Color v_oldColor = GUI.backgroundColor;

            DrawTitleText("Attached Objects Properties");
            GUILayout.Label("Attached Object A");
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GameObject v_attachedObjectA = EditorGUILayout.ObjectField(m_controllerTack.GetAttachedObjectA(), typeof(GameObject), true) as GameObject;

            if (v_attachedObjectA != m_controllerTack.GetAttachedObjectA())
            {
                m_controllerTack.ObjectA = v_attachedObjectA;
            }
            if (v_attachedObjectA != null)
            {
                TacksInventory v_tackController = v_attachedObjectA.GetNonMarkedComponentInChildren <TacksInventory>();
                if (v_tackController != null)
                {
                    v_tackController.FillWithChildrenTacks(true);
                    GUI.backgroundColor         = m_controllerTack.TackAIndex >= 0 && m_controllerTack.TackAIndex < v_tackController.TacksInObject.Count ? Color.green : Color.red;
                    m_controllerTack.TackAIndex = EditorGUILayout.Popup(m_controllerTack.TackAIndex, v_tackController.TacksInObject.GetStringList().ToArray());
                    GUI.backgroundColor         = v_oldColor;
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Label("Attached Object B");
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GameObject v_attachedObjectB = EditorGUILayout.ObjectField(m_controllerTack.GetAttachedObjectB(), typeof(GameObject), true) as GameObject;

            if (v_attachedObjectB != m_controllerTack.GetAttachedObjectB())
            {
                m_controllerTack.ObjectB = v_attachedObjectB;
            }
            if (v_attachedObjectB != null)
            {
                TacksInventory v_tackController = v_attachedObjectB.GetNonMarkedComponentInChildren <TacksInventory>();
                if (v_tackController != null)
                {
                    v_tackController.FillWithChildrenTacks(true);
                    GUI.backgroundColor         = m_controllerTack.TackBIndex >= 0 && m_controllerTack.TackBIndex < v_tackController.TacksInObject.Count ? Color.green : Color.red;
                    m_controllerTack.TackBIndex = EditorGUILayout.Popup(m_controllerTack.TackBIndex, v_tackController.TacksInObject.GetStringList().ToArray());
                    GUI.backgroundColor         = v_oldColor;
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Separator();
        }
Exemplo n.º 3
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);
        }
    }
	protected override void DrawAttachedObjects()
	{
		if(m_controllerTack == null)
			m_controllerTack = target as TackRope;
		
		//Attached Objects Properties
		Color v_oldColor = GUI.backgroundColor;
		DrawTitleText("Attached Objects Properties");
		GUILayout.Label("Attached Object A");
		GUILayout.BeginHorizontal();
		GUILayout.Space(20);
		GameObject v_attachedObjectA = EditorGUILayout.ObjectField(m_controllerTack.GetAttachedObjectA(), typeof(GameObject), true) as GameObject;
		if(v_attachedObjectA != m_controllerTack.GetAttachedObjectA())
			m_controllerTack.ObjectA = v_attachedObjectA;
		if(v_attachedObjectA != null)
		{
			TacksInventory v_tackController = v_attachedObjectA.GetNonMarkedComponentInChildren<TacksInventory>();
			if(v_tackController != null)
			{
				v_tackController.FillWithChildrenTacks(true);
				GUI.backgroundColor = m_controllerTack.TackAIndex >=0 && m_controllerTack.TackAIndex < v_tackController.TacksInObject.Count? Color.green : Color.red;
				m_controllerTack.TackAIndex = EditorGUILayout.Popup(m_controllerTack.TackAIndex, v_tackController.TacksInObject.GetStringList().ToArray());
				GUI.backgroundColor = v_oldColor;
			}
		}
		GUILayout.EndHorizontal();
		GUILayout.Label("Attached Object B");
		GUILayout.BeginHorizontal();
		GUILayout.Space(20);
		GameObject v_attachedObjectB = EditorGUILayout.ObjectField(m_controllerTack.GetAttachedObjectB(), typeof(GameObject), true) as GameObject;
		if(v_attachedObjectB != m_controllerTack.GetAttachedObjectB())
			m_controllerTack.ObjectB = v_attachedObjectB;
		if(v_attachedObjectB != null)
		{
			TacksInventory v_tackController = v_attachedObjectB.GetNonMarkedComponentInChildren<TacksInventory>();
			if(v_tackController != null)
			{
				v_tackController.FillWithChildrenTacks(true);
				GUI.backgroundColor = m_controllerTack.TackBIndex >=0 && m_controllerTack.TackBIndex < v_tackController.TacksInObject.Count? Color.green : Color.red;
				m_controllerTack.TackBIndex = EditorGUILayout.Popup(m_controllerTack.TackBIndex, v_tackController.TacksInObject.GetStringList().ToArray());
				GUI.backgroundColor = v_oldColor;
			}
		}
		GUILayout.EndHorizontal();
		EditorGUILayout.Separator();
	}
Exemplo n.º 5
0
    protected virtual void OnGUI()
    {
        if (m_windowInformation == null)
        {
            m_windowInformation = new BalloonPluggerWindowInformation();
        }

        EditorGUILayout.BeginHorizontal();

        bool v_refreshClicked = GUILayout.Button("Refresh Informations");

        EditorGUILayout.EndHorizontal();

        if (v_refreshClicked)
        {
            Refresh();
        }

        if (m_windowInformation.Ballons != null)
        {
            EditorGUILayout.BeginHorizontal();

            GUILayout.Label("Ballon");
            m_windowInformation.SelectedBallonIndex = EditorGUILayout.Popup(m_windowInformation.SelectedBallonIndex, m_windowInformation.Ballons.GetStringList().ToArray());

            EditorGUILayout.EndHorizontal();
        }

        if (m_windowInformation.Ropes != null)
        {
            EditorGUILayout.BeginHorizontal();

            GUILayout.Label("Ropes");
            m_windowInformation.SelectedRopeIndex = EditorGUILayout.Popup(m_windowInformation.SelectedRopeIndex, m_windowInformation.Ropes.GetStringList().ToArray());

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();

        GUILayout.Label("Plug In Selected Object In Scene");

        m_windowInformation.PlugInSelectedObject = EditorGUILayout.BeginToggleGroup("", m_windowInformation.PlugInSelectedObject);
        EditorGUILayout.EndToggleGroup();

        EditorGUILayout.EndHorizontal();

        if (!m_windowInformation.PlugInSelectedObject)
        {
            EditorGUILayout.BeginHorizontal();

            m_windowInformation.ObjectInSceneToPlug = (GameObject)EditorGUILayout.ObjectField("Object To Plug", m_windowInformation.ObjectInSceneToPlug, typeof(GameObject), true);

            EditorGUILayout.EndHorizontal();
        }
        else
        {
            Transform v_transform = Selection.activeTransform;
            if (v_transform != null)
            {
                m_windowInformation.ObjectInSceneToPlug = v_transform.gameObject;
            }
        }

        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 (m_windowInformation.ObjectInSceneToPlug != null && v_ballonPrefabComponent != null && v_ropePrefabComponent != null)
        {
            EditorGUILayout.BeginHorizontal();

            bool v_buttonClicked = GUILayout.Button("Plug Ballon");

            EditorGUILayout.EndHorizontal();

            if (v_buttonClicked)
            {
                PlugBallon();
            }
        }
    }
Exemplo n.º 6
0
    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>();
        }
    }