예제 #1
0
        public static GameObject DuplicatePrefab(GameObject srcInstance, string name = null)
        {
            string srcname = srcInstance.name;

            if (!nodes.ContainsKey(srcname))
            {
                Debug.LogError("Duplicate Error : nodes does not contain " + srcname);
                return(null);
            }
            Node       srcNode   = nodes[srcname];
            GameObject srcPrefab = srcNode.prefab;

            GameObject prefabClone = SyncData.CreateInstance(srcPrefab, srcPrefab.transform.parent.parent, name);

            Matrix4x4 matrix = root.worldToLocalMatrix * srcInstance.transform.localToWorldMatrix;

            Maths.DecomposeMatrix(matrix, out Vector3 position, out Quaternion quaternion, out Vector3 scale);
            prefabClone.transform.localPosition = position;
            prefabClone.transform.localRotation = quaternion;
            prefabClone.transform.localScale    = scale;

            Node prefabCloneNode = CreateNode(prefabClone.name, null);

            prefabCloneNode.prefab = prefabClone;

            return(prefabClone);
        }
예제 #2
0
 public void RenameObject(GameObject gobject, string newName)
 {
     MixerClient.Instance.SendEvent <RenameInfo>(MessageType.Rename, new RenameInfo {
         srcTransform = gobject.transform, newName = gobject.name
     });
     SyncData.Rename(newName, gobject.name);
 }
예제 #3
0
        public GameObject InstantiateUnityPrefab(GameObject unityPrefab)
        {
            GameObject prefab = SyncData.CreateInstance(unityPrefab, SyncData.prefab, isPrefab: true);
            Node       node   = SyncData.CreateNode(prefab.name);

            node.prefab = prefab;
            return(prefab);
        }
예제 #4
0
 public static void DeleteCollectionInstance(GameObject obj)
 {
     SyncData.RemoveInstanceFromNode(obj);
     for (int i = obj.transform.childCount - 1; i >= 0; i--)
     {
         Transform child = obj.transform.GetChild(i);
         DeleteCollectionInstance(child.gameObject);
     }
 }
예제 #5
0
        public void SetObjectTransform(GameObject gobject, Vector3 position, Quaternion rotation, Vector3 scale)
        {
            string objectName = gobject.name;

            SyncData.SetTransform(objectName, position, rotation, scale);
            foreach (var instance in SyncData.nodes[objectName].instances)
            {
                GlobalState.FireObjectMoving(instance.Item1);
            }
            MixerClient.Instance.SendEvent <Transform>(MessageType.Transform, SyncData.nodes[objectName].prefab.transform);
        }
예제 #6
0
        public void SetObjectMatrix(GameObject gobject, Matrix4x4 matrix)
        {
            string objectName = gobject.name;

            SyncData.SetTransform(gobject.name, matrix);
            foreach (var instance in SyncData.nodes[objectName].instances)
            {
                GlobalState.FireObjectMoving(instance.Item1);
            }
            MixerClient.Instance.SendEvent <Transform>(MessageType.Transform, SyncData.nodes[objectName].prefab.transform);
        }
예제 #7
0
        void Start()
        {
            Connect();

            GameObject prefabGameObject = new GameObject("__Prefab__");

            prefabGameObject.SetActive(false);
            prefab = prefabGameObject.transform;

            SyncData.Init(prefab, root);
            StartCoroutine(ProcessIncomingCommands());
        }
예제 #8
0
        public GameObject DuplicateObject(GameObject gobject)
        {
            GameObject     res            = SyncData.Duplicate(gobject);
            DuplicateInfos duplicateInfos = new DuplicateInfos
            {
                srcObject = gobject,
                dstObject = res
            };

            MixerClient.Instance.SendEvent <DuplicateInfos>(MessageType.Duplicate, duplicateInfos);

            return(res);
        }
예제 #9
0
        public GameObject InstantiateObject(GameObject prefab)
        {
            // if it does not exist in 'Prefab', create it
            if (!SyncData.nodes.TryGetValue(prefab.name, out Node prefabNode))
            {
                return(SyncData.CreateFullHierarchyPrefab(prefab));
            }

            // it already exists in Prefab, duplicate it
            GameObject newPrefab     = SyncData.DuplicatePrefab(prefab);
            Node       newPrefabNode = SyncData.nodes[newPrefab.name];

            foreach (Node childNode in prefabNode.children)
            {
                GameObject newChildPrefab = InstantiateObject(childNode.prefab);
                Node       newChildNode   = SyncData.nodes[newChildPrefab.name];
                newPrefabNode.AddChild(newChildNode);
            }
            return(newPrefab);
        }
예제 #10
0
 public GameObject AddObject(GameObject gobject)
 {
     return(SyncData.InstantiateFullHierarchyPrefab(gobject));
 }
예제 #11
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);
        }
예제 #12
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);
        }