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);
    }
Ejemplo n.º 2
0
    public GameObject InstantiateObjectByPrefab(GameObject p_prefab, bool p_keepLifePercert = false, bool p_destroyOldObject = true, bool p_keepEffectProperties = true)
    {
        if (p_prefab != null)
        {
            CachedPrefab = p_prefab;
            GameObject v_newObject = KiltUtils.Instantiate(p_prefab);
            v_newObject.name               = p_prefab.name + "(Selected)";
            v_newObject.transform.parent   = this.transform.parent;
            v_newObject.transform.position = this.transform.position;
            v_newObject.transform.rotation = this.transform.rotation;

            float v_signX = Mathf.Sign(this.transform.localScale.x);
            float v_signY = Mathf.Sign(this.transform.localScale.y);

            Vector3 v_localScale = new Vector3(p_prefab.transform.localScale.x * v_signX, p_prefab.transform.localScale.y * v_signY, p_prefab.transform.localScale.z);
            v_newObject.transform.localScale = v_localScale;
            if (p_keepLifePercert)
            {
                CopyDamagePercentToNewObject(v_newObject);
            }
            //MergeGameObjectWithThisObject(p_prefab);
            BlockSelector v_newComponent = CopyThisComponent(v_newObject);
            //Move New Component to first in new prefab
            MoveComponentToFirst(v_newComponent);
            //Plug Ropes To New Component
            AttachAllRopesToNewObject(v_newObject);
            //Select New Object in Editor Selection (if old object is previous selected and will be destroyed)
            if (p_destroyOldObject)
            {
                CheckIfNeedSelect(v_newObject);
            }
            //Apply Modifications in Cloned Component
            ApplyModificationsInEditMode(v_newComponent);
            ApplyShowHideComponent();

            if (p_destroyOldObject)
            {
                if (Application.isPlaying)
                {
                    GameObject.Destroy(this.gameObject);
                }
                else
                {
                    KiltUtils.Destroy(this.gameObject);
                }
            }

            return(v_newObject);
        }
        return(this.gameObject);
    }
Ejemplo n.º 3
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>();
        }
    }