Exemple #1
0
        /// <summary>
        /// Removes a child mount point from the list
        /// </summary>
        /// <param name="rChild"></param>
        public void RemoveChild(MountPoint rChild)
        {
            if (rChild == null)
            {
                return;
            }

            // Remove the child's parent
            if (rChild.ParentMountPoint == this)
            {
                rChild.ParentMountPoint = null;
            }

            // Remove the child from the list
            for (int i = ChildMountPoints.Count - 1; i >= 0; i--)
            {
                MountPointPtr lChild = ChildMountPoints[i];
                if (lChild.Owner == rChild._Owner && lChild.GUID == rChild.GUID)
                {
                    // Just in case we find it more than once, clear out the parent again
                    MountPoint lChildMountPoint = lChild.MountPoint;
                    if (lChildMountPoint.ParentMountPoint == this)
                    {
                        lChildMountPoint.ParentMountPoint = null;
                    }

                    // Remove it from the list
                    ChildMountPoints.RemoveAt(i);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a child mount point to the list
        /// </summary>
        /// <param name="rChild"></param>
        public void AddChild(MountPoint rChild)
        {
            if (rChild == null)
            {
                return;
            }
            if (!_AllowChildren)
            {
                return;
            }

            // If the child already has a parent, we need to clear it and reset
            if (rChild.ParentMountPoint != null)
            {
                rChild.ParentMountPoint.RemoveChild(rChild);
            }
            rChild.ParentMountPoint = this;

            // First, check if it already exists. We don't want to add it twice
            for (int i = 0; i < ChildMountPoints.Count; i++)
            {
                MountPointPtr lChild = ChildMountPoints[i];
                if (lChild.Owner == rChild._Owner && lChild.GUID == rChild.GUID)
                {
                    return;
                }
            }

            // If we got here, we need to add the child
            MountPointPtr lReference = new MountPointPtr(rChild);

            ChildMountPoints.Add(lReference);
        }
Exemple #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public MountPoint()
            : base()
        {
            // Since Unity won't serialize the same class across objects,
            // we'll use the GUID to help us track unique mount points
            GenerateGUID();

            // Create the parent mount point pointer
            _ParentMountPoint = new MountPointPtr();
        }
Exemple #4
0
        /// <summary>
        /// Determines if the resource is already instanciated and mounted
        /// </summary>
        /// <returns></returns>
        public bool IsChild(string rResourcePath)
        {
            for (int i = 0; i < ChildMountPoints.Count; i++)
            {
                MountPointPtr lChild = ChildMountPoints[i];
                if (lChild.MountPoint != null && lChild.MountPoint.Owner != null)
                {
                    // This is the fastest approach to determninng if the resource is the same
                    if (lChild.MountPoint.OwnerResourcePath.Length > 0)
                    {
                        if (lChild.MountPoint.OwnerResourcePath == rResourcePath)
                        {
                            return(true);
                        }
                    }
                    // This is a slow approach, but we cache the results
                    else if (rResourcePath.Length > 0)
                    {
                        GameObject lObject = Resources.Load(rResourcePath) as GameObject;
                        if (lObject != null)
                        {
                            MeshFilter lMesh = lChild.MountPoint.Owner.GetComponent <MeshFilter>();
                            if (lMesh == null)
                            {
                                lMesh = lChild.MountPoint.Owner.GetComponentInChildren <MeshFilter>();
                            }
                            if (lMesh == null)
                            {
                                continue;
                            }

                            MeshFilter lObjectMesh = lObject.GetComponent <MeshFilter>();
                            if (lObjectMesh == null)
                            {
                                lObjectMesh = lObject.GetComponentInChildren <MeshFilter>();
                            }
                            if (lObjectMesh == null)
                            {
                                continue;
                            }

                            if (lMesh.sharedMesh == lObjectMesh.sharedMesh)
                            {
                                Renderer lRenderer = lChild.MountPoint.Owner.GetComponent <Renderer>();
                                if (lRenderer == null)
                                {
                                    lRenderer = lChild.MountPoint.Owner.GetComponentInChildren <Renderer>();
                                }
                                if (lRenderer == null)
                                {
                                    continue;
                                }

                                Renderer lObjectRenderer = lObject.GetComponent <Renderer>();
                                if (lObjectRenderer == null)
                                {
                                    lObjectRenderer = lObject.GetComponentInChildren <Renderer>();
                                }
                                if (lObjectRenderer == null)
                                {
                                    continue;
                                }

                                if (lRenderer.sharedMaterial == lObjectRenderer.sharedMaterial)
                                {
                                    lChild.MountPoint.OwnerResourcePath = rResourcePath;
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Adds a child mount point to the list
        /// </summary>
        /// <param name="rChild"></param>
        public void AddChild(MountPoint rChild)
        {
            if (rChild == null) { return; }
            if (!_AllowChildren) { return; }

            // If the child already has a parent, we need to clear it and reset
            if (rChild.ParentMountPoint != null) { rChild.ParentMountPoint.RemoveChild(rChild); }
            rChild.ParentMountPoint = this;

            // First, check if it already exists. We don't want to add it twice
            for (int i = 0; i < ChildMountPoints.Count; i++)
            {
                MountPointPtr lChild = ChildMountPoints[i];
                if (lChild.Owner == rChild._Owner && lChild.GUID == rChild.GUID)
                {
                    return;
                }
            }

            // If we got here, we need to add the child
            MountPointPtr lReference = new MountPointPtr(rChild);
            ChildMountPoints.Add(lReference);
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        public MountPoint()
            : base()
        {
            // Since Unity won't serialize the same class across objects,
            // we'll use the GUID to help us track unique mount points
            GenerateGUID();

            // Create the parent mount point pointer
            _ParentMountPoint = new MountPointPtr();
        }