/// <summary>
        /// Gets the proper mass of a connectable object.
        /// </summary>
        /// <param name="con">The connectable to find the mass of.</param>
        /// <returns></returns>
        private float TotalMass(Connectable con)
        {
            // the starting mass of the connectable
            float totalMass = con.startMass;

            // get a list of all children who are connectables
            connectableChildren = new List <Connectable>();
            GetConnectableChildren(con.gameObject.transform, connectableChildren);

            // go through that list
            int numConChildren = connectableChildren.Count;

            for (int c = 0; c < numConChildren; c++)
            {
                // if the child connectables add mass to the parent
                if (connectableChildren[c].addMassToParent)
                {
                    totalMass += connectableChildren[c].startMass;
                }
            }

            // empty list
            connectableChildren.Clear();
            connectableChildren = null;

            return(totalMass);
        }
        /// <summary>
        /// Destorys all ghosts in the list and clears the list.
        /// </summary>
        public void ClearAllGhosts()
        {
            // destroyy all ghots obbjects in the scene
            int numGhosts = ghosts.Count;

            for (int g = 0; g < numGhosts; g++)
            {
                Destroy(ghosts[g]);
            }
            // empty the list
            ghosts.Clear();

            // how many connectables are in the scene
            int numConnectables = connectables.Count;

            // go through the list of connectables
            for (int a = 0; a < numConnectables; a++)
            {
                // how many connectors on the connectable in the list
                int numConnectorsOnListItem = connectables[a].connectors.Count;
                // check all of the connectors of the connectable in the list
                for (int b = 0; b < numConnectorsOnListItem; b++)
                {
                    // indictae there are no ghosts showing for any connectors
                    connectables[a].connectors[b].ghostShowing = false;
                }
            }

            // indicate there are no ghost showing for any object
            ghostShowingForThis = null;
        }
        /// <summary>
        /// Searches for ghosts that can appear to show available places for the connectable to be placed.
        /// </summary>
        /// <param name="connectable">The connectable that is looking for connections.</param>
        public void SearchForGhosts(Connectable cLookingForGhosts)
        {
            // how many connectables are in the scene
            int numConnectables = connectables.Count;
            // how many connectors does this connectable have
            int numConnectors = cLookingForGhosts.connectors.Count;

            // go through the list of connectables
            for (int a = 0; a < numConnectables; a++)
            {
                // skip looking for ghosts on the connectable looking for ghosts
                if (connectables[a] != cLookingForGhosts)
                {
                    // if their family structures are the same
                    if (connectables[a].hierarchalStructure == cLookingForGhosts.hierarchalStructure)
                    {
                        // how many connectors on the connectable in the list
                        int numConnectorsOnListItem = connectables[a].connectors.Count;
                        // check all of the connectors of the connectable in the list
                        for (int b = 0; b < numConnectorsOnListItem; b++)
                        {
                            // check all of the connectors of the connectable looking for ghosts
                            for (int c = 0; c < numConnectors; c++)
                            {
                                // if both are active
                                if (cLookingForGhosts.connectors[c].isUsable && connectables[a].connectors[b].isUsable)
                                {
                                    // if both are not connected
                                    if (!cLookingForGhosts.connectors[c].isConnected && !connectables[a].connectors[b].isConnected)
                                    {
                                        // if coupleIDs match
                                        if (cLookingForGhosts.connectors[c].coupleID == connectables[a].connectors[b].coupleID)
                                        {
                                            // and types are opposite
                                            if (cLookingForGhosts.connectors[c].type != connectables[a].connectors[b].type)
                                            {
                                                // if the connector has a ghost
                                                if (connectables[a].connectors[b].ghost != null)
                                                {
                                                    // create a ghost
                                                    CreateConnectorGhost(connectables[a].connectors[b]);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // indicate which connectable we last search for ghost for
            ghostShowingForThis = cLookingForGhosts;
        }
Exemplo n.º 4
0
 private void Start()
 {
     if (transform.parent.gameObject.GetComponent <Connectable>())
     {
         connectable = transform.parent.gameObject.GetComponent <Connectable>();
     }
     else
     {
         Debug.LogError("Connectors should be children of Connectables!");
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// While a connector is not attached but is touching another connector,
        /// this checks to see if either of the Connectables are currently grabbed.
        /// If neither are grabbed, the connection is made.
        /// </summary>
        public void ConnectionCheck()
        {
            // if the connectors that are touching are not attached
            if (attachedTo == null && touching != null)
            {
                // a check to make sure neither of the two connectables are currently grabbed
                bool noneGrabbed = true;

                bool thisIsGrabbed     = false;
                bool touchingIsGrabbed = false;

                if (connectable.GetComponent <Grabbable>() && connectable.GetComponent <Grabbable>().isGrabbed)
                {
                    noneGrabbed   = false;
                    thisIsGrabbed = true;
                }

                Connectable touchingConnectable = touching.connectable;
                if (touchingConnectable.GetComponent <Grabbable>() && touchingConnectable.GetComponent <Grabbable>().isGrabbed)
                {
                    noneGrabbed       = false;
                    touchingIsGrabbed = true;
                }

                // search the hierarchies for parents that might be grabbed
                // search the hierarchy of this connectable
                List <GameObject> ancestors = PuppetJumpManager.Instance.GetAncestors(connectable.transform.gameObject);
                int numAncestors            = ancestors.Count;
                for (int a = 0; a < numAncestors; a++)
                {
                    if (ancestors[a].GetComponent <Grabbable>() && ancestors[a].GetComponent <Grabbable>().isGrabbed)
                    {
                        noneGrabbed   = false;
                        thisIsGrabbed = true;
                        return;
                    }
                }
                // search the hierarchy of touching connectable
                ancestors    = PuppetJumpManager.Instance.GetAncestors(touchingConnectable.transform.gameObject);
                numAncestors = ancestors.Count;
                for (int a = 0; a < numAncestors; a++)
                {
                    if (ancestors[a].GetComponent <Grabbable>() && ancestors[a].GetComponent <Grabbable>().isGrabbed)
                    {
                        noneGrabbed       = false;
                        touchingIsGrabbed = true;
                        return;
                    }
                }

                //Debug.Log(touchingIsGrabbed +"," + thisIsGrabbed);

                // if neither connectable is grabbed
                if (noneGrabbed)
                {
                    // if the family structure is matriarchal
                    // let the male establish the connection, just so they both aren't at the same time
                    if (connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.matriarchal && type == connectorType.male)
                    {
                        // make a connection
                        Connect();
                    }

                    // if the family structure is patriarchal
                    // let the female establish the connection, just so they both aren't at the same time
                    if (connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.patriarchal && type == connectorType.female)
                    {
                        // make a connection
                        Connect();
                    }
                }

                /*
                 * else if(thisIsGrabbed && !touchingIsGrabbed)
                 * {
                 * touching.Connect();
                 * }
                 * else if(!thisIsGrabbed && touchingIsGrabbed)
                 * {
                 *  Connect();
                 * }
                 */
            }
        }