// todo figure out a way to call messages on all objects...
        // so we can get actorstate.GameValue("Health") for instance...
        public static ObjectLoadState AddNewObject(PrefabReference prefabRef, string scene, Vector3 pos, Quaternion rot, bool permanent, out object obj, out string id)
        {
            bool sceneIsLoaded = SceneLoading.currentLoadedScenes.Contains(scene);

            id = GetNewGUID();

            DynamicObjectState objectState = new DynamicObjectState(id, scene, prefabRef, permanent);

            id2ObjectState.Add(id, objectState);

            if (sceneIsLoaded)
            {
                DynamicObject dynamicObject = GetAvailableInstance(prefabRef, pos, rot, id, false, false, false);

                MoveDynamicObjectToTransform(dynamicObject, pos, rot.eulerAngles, false);

                dynamicObject.AdjustState(objectState, scene, pos, rot.eulerAngles, false);

                obj = dynamicObject;
            }
            // add an unloaded representation, instantiate later when the scene is loaded
            else
            {
                if (!prefabRef.isEmpty)
                {
                    DynamicObject basePrefab = PrefabReferenceCollection.GetPrefabReference <DynamicObject>(prefabRef);
                    obj = basePrefab.AdjustState(objectState, scene, pos, rot.eulerAngles, true);
                }
                else
                {
                    obj = objectState;
                }
            }
            return(objectState.isLoaded ? ObjectLoadState.Loaded : ObjectLoadState.Unloaded);
        }
Esempio n. 2
0
 public DynamicObjectState(string id, string scene, PrefabReference prefabRef, bool permanent)
 {
     this.id        = id;
     this.scene     = scene;
     this.prefabRef = prefabRef;
     this.permanent = permanent;
 }
        public static GameObject GetPrefabReference(PrefabReference refInfo)
        {
            PrefabReferenceCollection obj = GameSettings.GetSettings <PrefabReferenceCollection>(refInfo.collection);

            if (obj != null)
            {
                return(obj.GetPrefabReference(refInfo.name));
            }
            return(null);
        }
        public static T GetPrefabReference <T> (PrefabReference refInfo) where T : Component
        {
            PrefabReferenceCollection obj = GameSettings.GetSettings <PrefabReferenceCollection>(refInfo.collection);

            if (obj != null)
            {
                return(obj.GetPrefabReference <T>(refInfo.name));
            }
            return(null);
        }
        public static ObjectLoadState AddNewAliasedObject(string alias, PrefabReference prefabRef, string scene, Vector3 pos, Quaternion rot, bool permanent, out object obj)
        {
            if (alias2ID.ContainsKey(alias))
            {
                Debug.LogError("Object with alias: '" + alias + "' already exists!");
                obj = null;
                return(ObjectLoadState.NotFound);
            }

            string          id;
            ObjectLoadState loadState = AddNewObject(prefabRef, scene, pos, rot, permanent, out obj, out id);

            alias2ID.Add(alias, id);
            id2Alias.Add(id, alias);
            return(loadState);
        }
Esempio n. 6
0
        public static void DrawPrefabReference(PrefabReference reference, GUIContent label, Action <string> onCollectionPicked, Action <string> onPrefabPicked)
        {
            if (!string.IsNullOrEmpty(label.text))
            {
                GUITools.Label(label, GUITools.black, GUITools.boldLabel);
            }

            AssetSelector.DrawName(typeof(PrefabReferenceCollection), reference.collection, new GUIContent("Collection"), null, null, onCollectionPicked);

            if (!string.IsNullOrEmpty(reference.collection))
            {
                EditorGUILayout.BeginHorizontal();
                GUITools.Label(new GUIContent("Prefab"), GUITools.black, GUITools.label, GUILayout.Width(EditorGUIUtility.labelWidth));

                if (GUITools.Button(new GUIContent(reference.name), GUITools.white, GUITools.popup, GUITools.black))
                {
                    PrefabReferenceCollection refObject = GameSettings.GetSettings <PrefabReferenceCollection>(reference.collection);
                    if (refObject != null)
                    {
                        GenericMenu menu = new GenericMenu();
                        for (int i = 0; i < refObject.prefabs.Length; i++)
                        {
                            if (refObject.prefabs[i] != null)
                            {
                                string name = refObject.prefabs[i].name;
                                menu.AddItem(new GUIContent(name), name == reference.name, () => onPrefabPicked(name));
                            }
                        }
                        menu.ShowAsContext();
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            // return reference;
        }
Esempio n. 7
0
 public static T GetAvailableInstance(PrefabReference prefabRef, Vector3 position, Quaternion rotation)
 {
     return(DynamicObjectManager.GetAvailableInstance <T>(prefabRef, position, rotation, null, true, true, false));
 }
 public static T GetAvailableInstance <T> (PrefabReference prefabRef, Vector3 position, Quaternion rotation, string gUID, bool createState, bool createID, bool permanentState) where T : Component
 {
     return(GetAvailableInstance <T>(PrefabReferenceCollection.GetPrefabReference <DynamicObject>(prefabRef), position, rotation, gUID, createState, createID, permanentState));
 }