public void RemoveSelfFromRopesByBalloonsController(bool p_canCreateNewInstanceFromController = true)
    {
        //Clear All Nodes To Recalc
        List <RopesByBallons> v_structsThatContainBallon = RopesByBalloonsController.GetAllStructsWithBallon(this, p_canCreateNewInstanceFromController);

        foreach (RopesByBallons v_struct in v_structsThatContainBallon)
        {
            if (v_struct != null && v_struct.Rope != null)
            {
                List <BalloonProperty> v_newDirectBallonsList   = new List <BalloonProperty>();             // Used to Remove Nulls and Self;
                List <BalloonProperty> v_newIndirectBallonsList = new List <BalloonProperty>();             // Used to Remove Nulls and Self;
                foreach (BalloonProperty v_ballon in v_struct.DirectBallons)
                {
                    if (v_ballon != null && v_ballon != this)
                    {
                        v_newDirectBallonsList.Add(v_ballon);
                        v_ballon.MarkToRecalcForce(false);
                    }
                }
                foreach (BalloonProperty v_ballon in v_struct.IndirectBallons)
                {
                    if (v_ballon != null && v_ballon != this)
                    {
                        v_newIndirectBallonsList.Add(v_ballon);
                        v_ballon.MarkToRecalcForce(false);
                    }
                }
                v_struct.DirectBallons   = v_newDirectBallonsList;
                v_struct.IndirectBallons = v_newIndirectBallonsList;
            }
        }
    }
Esempio n. 2
0
    public static List <RopesByBallons> GetAllStructsWithBallon(BalloonProperty p_ballon, bool p_canCreateNewControllerIfDontExists = true)
    {
        RopesByBalloonsController v_instance   = GetInstance(p_canCreateNewControllerIfDontExists);
        List <RopesByBallons>     v_returnList = new List <RopesByBallons>();

        if (v_instance != null)
        {
            v_returnList = v_instance.GetAllStructsWithBallonInternal(p_ballon);
        }
        return(v_returnList);
    }
Esempio n. 3
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);
    }
    public virtual void RecalcRopesMass()
    {
        float v_indirectSum = 0;
        float v_directSum   = 0;
        List <RopesByBallons> v_structsThatContainBallon = RopesByBalloonsController.GetAllStructsWithBallon(this);

        foreach (RopesByBallons v_struct in v_structsThatContainBallon)
        {
            if (v_struct != null && v_struct.Rope != null)
            {
                if (v_struct.DirectBallons.Contains(this))
                {
                    float v_sumOfDirectIntensitys = 0;
                    foreach (BalloonProperty v_ballon in v_struct.DirectBallons)
                    {
                        if (v_ballon != null)
                        {
                            v_sumOfDirectIntensitys += v_ballon.GetIndependentForceIntensity();
                        }
                    }
                    float v_percent = v_sumOfDirectIntensitys == 0? 1 / v_struct.DirectBallons.Count : GetIndependentForceIntensity() / v_sumOfDirectIntensitys;
                    v_directSum += v_struct.Rope.GetMassAttachedToObject(this.gameObject) * v_percent;                // Mass Of The Rope will be divided to all Direct Ballon
                }
                else if (v_struct.DirectBallons.Count <= 0 && v_struct.IndirectBallons.Contains(this))                // Only if no direct ballons plugged in this rope
                {
                    float v_sumOfIndirectIntensitys = 0;
                    foreach (BalloonProperty v_ballon in v_struct.IndirectBallons)
                    {
                        if (v_ballon != null)
                        {
                            v_sumOfIndirectIntensitys += v_ballon.GetIndependentForceIntensity();
                        }
                    }
                    float v_percent = v_sumOfIndirectIntensitys == 0? 1 / v_struct.IndirectBallons.Count : GetIndependentForceIntensity() / v_sumOfIndirectIntensitys;
                    v_indirectSum += v_struct.Rope.GetRopeMass(true) * v_percent;                  // Mass Of The Rope will be divided to all Indirect Ballon
                }
            }
        }
        _sumOfPluggedRopesMass = v_directSum;
        if (m_includeIndirectRopesInMassCalc)
        {
            _sumOfIndirectRopesMass = v_indirectSum;
        }
        else
        {
            _sumOfIndirectRopesMass = 0;
        }
    }
Esempio n. 5
0
    public static RopesByBalloonsController GetInstance(bool p_canCreateANewOne = false)
    {
        RopesByBalloonsController v_instance = null;

        if (p_canCreateANewOne)
        {
            v_instance = Instance;
        }
        else
        {
            if (m_instance == null)
            {
                m_instance = GameObject.FindObjectOfType(typeof(RopesByBalloonsController)) as RopesByBalloonsController;
            }
            v_instance = m_instance;
        }
        return(v_instance);
    }
    //Used To Calculate amount of Direct/Indirect Ballons plugged in Ropes(Need this to know correct amount of force needed to void ropes mass
    public virtual void UpdateRopesByBalloonsController()
    {
        _waitOneCycle = true;
        RemoveSelfFromRopesByBalloonsController();
        List <RopesByBallons> v_structsThatContainBallon = RopesByBalloonsController.GetAllStructsWithBallon(this);

        foreach (RopesByBallons v_struct in v_structsThatContainBallon)
        {
            if (v_struct != null && v_struct.Rope != null)
            {
                if (!v_struct.DirectBallons.RemoveChecking(this))
                {
                    v_struct.IndirectBallons.RemoveChecking(this);
                }
            }
        }
        if (m_includeIndirectRopesInMassCalc)
        {
            //Get Indirect Ropes and Add in Ballons indirect Plugged in this ropes
            foreach (Rope2D v_indirectRope in RopesAttachedComponent.IndirectRopes)
            {
                if (v_indirectRope != null)
                {
                    RopesByBallons v_struct = RopesByBalloonsController.GetRopeByBallonStructure(v_indirectRope, true);
                    if (v_struct != null)
                    {
                        v_struct.IndirectBallons.AddChecking(this);
                    }
                }
            }
        }
        //Get direct Ropes and Add in Ballons Plugged in this ropes
        foreach (Rope2D v_directRope in RopesAttachedComponent.PluggedRopes)
        {
            if (v_directRope != null)
            {
                RopesByBallons v_struct = RopesByBalloonsController.GetRopeByBallonStructure(v_directRope, true);
                if (v_struct != null)
                {
                    v_struct.DirectBallons.AddChecking(this);
                }
            }
        }
    }
	public static RopesByBalloonsController GetInstance(bool p_canCreateANewOne = false)
	{
		RopesByBalloonsController v_instance = null;
		if(p_canCreateANewOne)
			v_instance = Instance;
		else
		{
			if(m_instance == null )
				m_instance = GameObject.FindObjectOfType(typeof(RopesByBalloonsController)) as RopesByBalloonsController;
			v_instance = m_instance;
		}
		return v_instance;
	}