Exemplo n.º 1
0
        public static void AddCollectionToCollection(string parentCollectionName, string collectionName)
        {
            CollectionNode parentNode = null;

            if (collectionNodes.ContainsKey(parentCollectionName))
            {
                parentNode = collectionNodes[parentCollectionName];
            }

            if (!collectionNodes.ContainsKey(collectionName))
            {
                CreateCollectionNode(parentNode, collectionName);
            }
            else
            {
                CollectionNode collectionNode = collectionNodes[collectionName];
                if (null != collectionNode.parent)
                {
                    collectionNode.parent.RemoveChild(collectionNode);
                }

                if (null != parentNode)
                {
                    parentNode.AddChild(collectionNode);
                }
            }
        }
Exemplo n.º 2
0
        public static void RemoveObjectFromCollection(string collectionName, string objectName)
        {
            if (collectionName == "__Trash__")
            {
                return;
            }

            if (!collectionNodes.ContainsKey(collectionName))
            {
                return;
            }

            CollectionNode collectionNode = collectionNodes[collectionName];

            foreach (Node prefabInstanceNode in collectionNode.prefabInstanceNodes)
            {
                foreach (Tuple <GameObject, string> t in prefabInstanceNode.instances)
                {
                    GameObject obj          = t.Item1;
                    Transform  offsetObject = obj.transform.Find(Utils.blenderCollectionInstanceOffset);
                    if (null == offsetObject)
                    {
                        continue;
                    }
                    RemoveObjectFromScene(offsetObject, objectName, obj.name);
                }
            }

            collectionNode.RemoveObject(nodes[objectName]);
        }
Exemplo n.º 3
0
        public static void RemoveCollection(string collectionName)
        {
            if (!collectionNodes.ContainsKey(collectionName))
            {
                return;
            }

            CollectionNode collectionNode = collectionNodes[collectionName];

            foreach (Node node in collectionNode.objects)
            {
                node.RemoveCollection(collectionNode);
                foreach (Tuple <GameObject, string> item in node.instances)
                {
                    ApplyVisibility(item.Item1);
                }
            }

            foreach (CollectionNode child in collectionNode.children)
            {
                child.parent = collectionNode.parent;
            }

            collectionNodes.Remove(collectionName);
        }
Exemplo n.º 4
0
        public static void ApplyVisibility(GameObject obj, bool inheritVisible = true, string instanceName = "")
        {
            Node           node           = nodes[obj.name];
            CollectionNode collectionNode = node.collectionInstance;

            if (null != collectionNode)
            {
                instanceName = instanceName + "/" + obj.name;
                foreach (Node n in collectionNode.objects)
                {
                    foreach (Tuple <GameObject, string> item in n.instances)
                    {
                        if (item.Item2 == instanceName)
                        {
                            ApplyVisibility(item.Item1, collectionNode.visible && collectionNode.tempVisible && node.visible && node.tempVisible && inheritVisible, item.Item2);
                        }
                    }
                }

                ApplyCollectionVisibility(collectionNode, instanceName, collectionNode.visible && collectionNode.tempVisible && node.visible && node.tempVisible && inheritVisible);
                obj = obj.transform.Find(Utils.blenderCollectionInstanceOffset).gameObject;
            }

            EnableComponents(obj, node.containerVisible & node.visible & node.tempVisible & inheritVisible);

            // Enable/Disable light
            VRtistMixer.SetLightEnabled(obj, node.containerVisible & node.visible & node.tempVisible & inheritVisible);
        }
Exemplo n.º 5
0
 public static void RemoveCollectionFromCollection(string parentCollectionName, string collectionName)
 {
     if (collectionNodes.ContainsKey(parentCollectionName))
     {
         CollectionNode parentCollectionNode = collectionNodes[parentCollectionName];
         parentCollectionNode.RemoveChild(collectionNodes[collectionName]);
     }
 }
Exemplo n.º 6
0
        public static void AddCollectionInstance(Transform transform, string collectionName)
        {
            CollectionNode collectionNode = SyncData.collectionNodes.ContainsKey(collectionName) ? SyncData.collectionNodes[collectionName] : SyncData.CreateCollectionNode(null, collectionName);
            Node           instanceNode   = SyncData.nodes.ContainsKey(transform.name) ? SyncData.nodes[transform.name] : SyncData.CreateNode(transform.name);

            instanceNode.prefab             = transform.gameObject;
            instanceNode.collectionInstance = collectionNode;
            collectionNode.AddPrefabInstanceNode(instanceNode);
        }
Exemplo n.º 7
0
 public static void AddCollectionToScene(CollectionNode collectionNode, Transform transform, string collectionInstanceName)
 {
     foreach (Node collectionObject in collectionNode.objects)
     {
         AddObjectToDocument(transform, collectionObject.prefab.name, collectionInstanceName);
     }
     foreach (CollectionNode collectionChild in collectionNode.children)
     {
         AddCollectionToScene(collectionChild, transform, collectionInstanceName);
     }
 }
Exemplo n.º 8
0
        public static void GetRecursiveObjectsOfCollection(CollectionNode collectionNode, ref List <Node> nodes)
        {
            foreach (Node node in collectionNode.objects)
            {
                nodes.Add(node);
            }

            foreach (CollectionNode childCollection in collectionNode.children)
            {
                GetRecursiveObjectsOfCollection(childCollection, ref nodes);
            }
        }
Exemplo n.º 9
0
        public static void AddObjectToCollection(string collectionName, string objectName)
        {
            if (collectionName == "__Trash__")
            {
                RemovePrefab(objectName);
                return;
            }

            if (!collectionNodes.ContainsKey(collectionName))
            {
                return;
            }
            CollectionNode collectionNode = collectionNodes[collectionName];

            if (!nodes.ContainsKey(objectName))
            {
                GetOrCreatePrefabPath(objectName);
            }

            Node objectNode = nodes[objectName];

            collectionNode.AddObject(objectNode);

            foreach (Node prefabInstanceNode in collectionNode.prefabInstanceNodes)
            {
                foreach (Tuple <GameObject, string> t in prefabInstanceNode.instances)
                {
                    GameObject obj          = t.Item1;
                    Transform  offsetObject = obj.transform.Find(Utils.blenderCollectionInstanceOffset);
                    if (null == offsetObject)
                    {
                        continue;
                    }

                    string subCollectionInstanceName = "/" + obj.name;
                    if (t.Item2.Length > 1)
                    {
                        subCollectionInstanceName = t.Item2 + subCollectionInstanceName;
                    }

                    AddObjectToDocument(offsetObject, objectNode.prefab.name, subCollectionInstanceName);
                }
            }

            foreach (Tuple <GameObject, string> item in objectNode.instances)
            {
                ApplyVisibility(item.Item1);
            }
        }
Exemplo n.º 10
0
        public static CollectionNode CreateCollectionNode(CollectionNode parent, string name)
        {
            if (name == "__Trash__")
            {
                return(null);
            }

            CollectionNode newNode = new CollectionNode(name);

            collectionNodes.Add(name, newNode);
            if (parent != null)
            {
                parent.AddChild(newNode);
            }
            return(newNode);
        }
Exemplo n.º 11
0
        public static void ApplyCollectionVisibility(CollectionNode collectionNode, string instanceName = "", bool inheritVisible = true)
        {
            foreach (Node n in collectionNode.objects)
            {
                foreach (Tuple <GameObject, string> item in n.instances)
                {
                    if (item.Item2 == instanceName)
                    {
                        ApplyVisibility(item.Item1, collectionNode.visible && collectionNode.tempVisible && inheritVisible, instanceName);
                    }
                }
            }

            foreach (CollectionNode c in collectionNode.children)
            {
                ApplyCollectionVisibility(c, instanceName, collectionNode.visible && collectionNode.tempVisible && c.visible && inheritVisible);
            }
        }
Exemplo n.º 12
0
        public static void AddCollection(string collectionName, Vector3 offset, bool visible, bool tempVisible)
        {
            if (collectionName == "__Trash__")
            {
                return;
            }

            CollectionNode collectionNode = collectionNodes.ContainsKey(collectionName) ? collectionNodes[collectionName] : CreateCollectionNode(null, collectionName);

            collectionNode.visible     = visible;
            collectionNode.tempVisible = tempVisible;
            collectionNode.offset      = offset;

            List <Node> nodes = new List <Node>();

            GetRecursiveObjectsOfCollection(collectionNode, ref nodes);
            foreach (Node node in nodes)
            {
                node.ComputeContainerVisibility();

                foreach (Tuple <GameObject, string> item in node.instances)
                {
                    ApplyVisibility(item.Item1, node.containerVisible, "");
                }
            }

            // collection instances management
            foreach (Node prefabInstanceNode in collectionNode.prefabInstanceNodes)
            {
                foreach (Tuple <GameObject, string> item in prefabInstanceNode.instances)
                {
                    ApplyVisibility(item.Item1);
                    GameObject offsetObject = item.Item1.transform.Find(Utils.blenderCollectionInstanceOffset).gameObject;
                    offsetObject.transform.localPosition = offset;
                }
            }
        }
Exemplo n.º 13
0
 public void RemoveCollection(CollectionNode collectionNode)
 {
     collections.Remove(collectionNode);
     ComputeContainerVisibility();
 }
Exemplo n.º 14
0
 public void AddCollection(CollectionNode collectionNode)
 {
     collections.Add(collectionNode);
     ComputeContainerVisibility();
 }
Exemplo n.º 15
0
        public static GameObject AddObjectToDocument(Transform transform, string objectName, string collectionInstanceName = "/", bool skipParentCheck = false)
        {
            if (!nodes.ContainsKey(objectName))
            {
                return(null);
            }
            Node objectNode = nodes[objectName];

            ////////////////////////////////////////////////////////////////
            // WARNING : this should not be tolerated !!!!
            // Check if parent of this Object has been instantiated
            // If not, add parent to document (instantiate)
            ////////////////////////////////////////////////////////////////
            if (!skipParentCheck)
            {
                Node parentNode = objectNode.parent;
                if (null != parentNode)
                {
                    bool found = false;
                    foreach (Tuple <GameObject, string> item in parentNode.instances)
                    {
                        if (item.Item2 == collectionInstanceName)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        transform = AddObjectToDocument(transform, parentNode.prefab.name, collectionInstanceName).transform;
                        Debug.LogWarning("Adding object to Document but parent object has not been instantiated : " + objectName);
                    }
                }
            }
            ////////////////////////////////////////////////////////////////

            foreach (Tuple <GameObject, string> item in objectNode.instances)
            {
                if (item.Item2 == collectionInstanceName)
                {
                    return(null); // already instantiated
                }
            }


            GameObject instance = SyncData.CreateInstance(objectNode.prefab, transform, objectName);

            AddInstanceToNode(instance, objectNode, collectionInstanceName);

            // Reparent to parent
            Transform parent = transform;

            if (null != objectNode.parent)
            {
                foreach (Tuple <GameObject, string> t in objectNode.parent.instances)
                {
                    if (t.Item2 == collectionInstanceName)
                    {
                        parent = t.Item1.transform;
                        break;
                    }
                }
            }
            Utils.Reparent(instance.transform.parent, parent);

            // Reparent children
            List <Node>       childrenNodes = objectNode.children;
            List <GameObject> children      = new List <GameObject>();

            foreach (Node childNode in childrenNodes)
            {
                foreach (Tuple <GameObject, string> t in childNode.instances)
                {
                    if (t.Item2 == collectionInstanceName)
                    {
                        children.Add(t.Item1);
                    }
                }
            }
            foreach (GameObject childObject in children)
            {
                Utils.Reparent(childObject.transform.parent, instance.transform);
            }

            if (null != objectNode.collectionInstance)
            {
                CollectionNode collectionNode = objectNode.collectionInstance;

                GameObject offsetObject = new GameObject(Utils.blenderCollectionInstanceOffset);
                offsetObject.transform.parent        = instance.transform;
                offsetObject.transform.localPosition = -collectionNode.offset;
                offsetObject.transform.localRotation = Quaternion.identity;
                offsetObject.transform.localScale    = Vector3.one;
                offsetObject.SetActive(collectionNode.visible & collectionNode.tempVisible & objectNode.visible & objectNode.tempVisible);

                string subCollectionInstanceName = "/" + instance.name;
                if (collectionInstanceName.Length > 1)
                {
                    subCollectionInstanceName = collectionInstanceName + subCollectionInstanceName;
                }

                instanceRoot[subCollectionInstanceName] = offsetObject.transform;
                AddCollectionToScene(collectionNode, offsetObject.transform, subCollectionInstanceName);
            }

            ApplyVisibility(instance);

            return(instance);
        }
Exemplo n.º 16
0
 public void RemoveChild(CollectionNode node)
 {
     node.parent = null;
     children.Remove(node);
 }
Exemplo n.º 17
0
 public void AddChild(CollectionNode node)
 {
     node.parent = this;
     children.Add(node);
 }