// 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); }
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); }
void Start() { if (_isPlayer) { return; } if (isInPool) { return; } Debug.Log("Adding to pool: " + name); DynamicObjectManager.pool.AddManualInstance(PrefabReferenceCollection.GetPrefabReference <DynamicObject>(prefabRef), this, onPoolCreateAction); }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { pos.height = GUITools.singleLineHeight; if (!string.IsNullOrEmpty(label.text)) { GUITools.Label(pos, label, GUITools.black, GUITools.boldLabel); pos.y += GUITools.singleLineHeight; } SerializedProperty objProp = prop.FindPropertyRelative("collection"); EditorGUI.PropertyField(pos, objProp, new GUIContent("Collection"), true); pos.y += GUITools.singleLineHeight; if (!string.IsNullOrEmpty(objProp.stringValue)) { SerializedProperty nameProp = prop.FindPropertyRelative("name"); GUITools.Label(new Rect(pos.x, pos.y, EditorGUIUtility.labelWidth, pos.height), new GUIContent("Prefab"), GUITools.black, GUITools.label); if (GUITools.Button(pos.x + EditorGUIUtility.labelWidth, pos.y, pos.width - EditorGUIUtility.labelWidth, pos.height, new GUIContent(nameProp.stringValue), GUITools.white, GUITools.popup, GUITools.black)) { PrefabReferenceCollection refObject = GameSettings.GetSettings <PrefabReferenceCollection>(objProp.stringValue); 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 == nameProp.stringValue, () => { nameProp.stringValue = name; nameProp.serializedObject.ApplyModifiedProperties(); } ); } } menu.ShowAsContext(); } } } }
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; }
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)); }