public static void SetupRelationship(Relationship rel, string name)
        {
            GameObject selObj = rel.gameObject;

            rel.id       = DataUtil.CreateNewId(rel, selObj.name + "-" + name);
            rel.typeName = name;
        }
 public virtual void OnValidate()
 {
     ////Debug.Log(GetType().Name + " Validate " + name);
     if (ownerEntity == null)
     {
         ownerEntity = GetComponent <EntityData>();
     }
     if (string.IsNullOrEmpty(id))
     {
         id = DataUtil.CreateNewId(this, typeName);
     }
     LinkEntities();
 }
Beispiel #3
0
        static void CreateEntityGameObject(MenuCommand menuCommand)
        {
            // Create a custom game object
            GameObject go     = new GameObject("NewEntity");
            var        entity = Undo.AddComponent <EntityData>(go);

            entity.id = DataUtil.CreateNewId(entity);
            // Ensure it gets reparented if this was a context click (otherwise does nothing)
            GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(go, "New Entity " + go.name + " " + entity.id);
            Selection.activeObject = go;
        }
Beispiel #4
0
        /// <summary>
        /// Instantiate a new game object in an asynchronous way.
        /// </summary>
        /// <param name="assetBundleName">Asset bundle name</param>
        /// <param name="assetName">Asset name inside the asset bundle</param>
        /// <param name="reprId">representation identifier to be used for the EntityRepresentation component</param>
        /// <param name="entityId">Entity identifier to be used for the EntityData component</param>
        /// <returns>It must be called iteratively (e.g. with StartCoroutine())</returns>
        protected IEnumerator InstantiateGameObjectAsync(string assetBundleName, string assetName, string reprId, string entityId)
        {
            // This is simply to get the elapsed time for this phase of AssetLoading.
            float startTime = Time.realtimeSinceStartup;

            // TODO: implement instantiation from AddressableAsset
            // Load asset from assetBundle.
            //GameObject prefab = ...;

            // Get the asset.
            UnityEngine.Object prefab = Resources.Load("AddressableAssets/" + assetBundleName + "/" + assetName);

            if (prefab != null)
            {
                if (!entityObjects.ContainsKey(entityId))
                {
                    Debug.LogWarning("Asset " + assetName + " not found.");
                    yield break;
                }
                GameObject go = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
                go.transform.SetParent(entityObjects[entityId].transform, false);
                if (string.IsNullOrEmpty(reprId))
                {
                    reprId = DataUtil.CreateNewId(go, null);
                }
                var entityRepr = go.GetComponent <EntityRepresentation>();
                if (entityRepr == null)
                {
                    entityRepr = go.AddComponent <EntityRepresentation>();
                }
                go.name = reprId;
                entityRepr.assetType       = EntityRepresentation.AssetType.AssetBundle;
                entityRepr.name            = prefab.name;
                entityRepr.assetBundleName = assetBundleName;
                entityRepr.assetName       = assetName;
                entityObjects[entityId].GetComponent <EntityData>().activeRepresentation = entityRepr;
                createdRepresentations++;
            }

            // Calculate and display the elapsed time.
            float elapsedTime = Time.realtimeSinceStartup - startTime;

            if (prefab)
            {
                Debug.Log(assetName + " was loaded successfully in " + elapsedTime + " seconds");
            }
            else
            {
                Debug.LogWarning("Failed to load " + assetName + "  (" + elapsedTime + " seconds)");
            }
        }
        public void OnValidate()
        {
            List <EntityData> entities = new List <EntityData>(FindObjectsOfType <EntityData>());
            EntityData        found    = entities.Find(ent => ent != this && ent.id == id);

            if (found != null)
            {
                string newId = DataUtil.CreateNewId(this, id);
                Debug.LogFormat("{0} with id = {1} already exists, changed to {2}", GetType().Name, id, newId);
                id = newId;
            }
            // clean up relationships references
            if (relationshipsIn != null)
            {
                relationshipsIn.RemoveAll(rel => rel == null || !rel.EntityLinked(this));
            }
            if (relationshipsOut != null)
            {
                relationshipsOut.RemoveAll(rel => rel == null || !rel.EntityLinked(this));
            }
        }