Exemplo n.º 1
0
        /// <summary>
        /// sets all the adaptors that are not connected to be invisble (only the side that's not connected to this part)
        /// also sets adaptor.isUnconnected to the respective value
        ///
        /// TODO: this is a bit of a hack, should come back to this and clean it up
        /// </summary>
        public void ToggleAdaptorVisibility()
        {
            var Hider = new MaterialHider(); //instantiate new hider

            if (AdaptorConnections == null)  //sometimes this isn't initialized for some reason...
            {
                AdaptorConnections = new Dictionary <WeaponPart, Adaptor>();
            }

            if (Adaptors == null) //there are parts that don't have any adaptors (for example a silencer or something like that)
            {
                return;
            }

            foreach (Adaptor a in Adaptors)
            {
                if (!AdaptorConnections.ContainsValue(a)) //adaptor isn't connected
                {
                    a.isUnconnected = true;

                    if (a.ChildPartTransform == null)
                    {
                        continue;
                    }

                    Hider.HideHierarchy(a.ChildPartTransform.gameObject, this.PartID); //hide the unconnected side and set id as this.partid, so we can selectively turn back on
                                                                                       //only the adaptor that belongs to this part instead of the whole hierarchy below our adaptor
                }
                else
                {
                    a.isUnconnected = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// connects a child to an adaptor.
        /// </summary>
        /// <param name="adaptor"></param>
        public void ConnectChildToAdaptor(Adaptor adaptor, WeaponPart child)
        {
            //checks
            if (AdaptorConnections == null) //sometimes this thing isn't initialized properly, don't know why
            {
                AdaptorConnections = new Dictionary <WeaponPart, Adaptor>();
            }

            if (AdaptorConnections.ContainsValue(adaptor))//adaptor already connected
            {
                return;
            }

            if (adaptor.WeaponTypeOfAdaptor != child.PartType) //if trying to connect a wrong part
            {
                return;
            }

            //alignment
            child.transform.parent        = adaptor.ChildPartTransform;
            child.transform.localPosition = Vector3.zero;
            child.transform.localRotation = Quaternion.Euler(0, 0, 0);

            //create connection
            AdaptorConnections.Add(child, adaptor);

            //make connected side visible again
            MaterialHider hider = new MaterialHider();

            hider.DisplayHierarchy(adaptor.ChildPartTransform.gameObject, this.PartID);
            adaptor.isUnconnected = false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// removes a child from this part
        /// </summary>
        /// <param name="child">the child to remove </param>
        public void RemoveChild(WeaponPart child)
        {
            //checks
            if (!Children.Contains(child))//if part is no child
            {
                return;
            }

            //remove child
            Children.Remove(child);
            Adaptor a = AdaptorConnections[child];

            AdaptorConnections.Remove(child);

            if (a != null) //better nullcheck it
            {
                //hide adaptor again
                MaterialHider hider = new MaterialHider();
                hider.HideHierarchy(a.ChildPartTransform.gameObject, this.PartID);
                a.isUnconnected = true;
            }
        }