public static string GetTextureName(PrefabType prefabType) { switch (prefabType) { case PrefabType.Ball: return "ball"; case PrefabType.GoldBox: return "box1"; case PrefabType.GrayBox: return "box2"; case PrefabType.Pig: return "pig"; case PrefabType.Smoke: return "smoke"; case PrefabType.TriangleLeft: return "triangleL"; case PrefabType.TriangleRight: return "triangleR"; case PrefabType.Floor: return "floor"; //Wood case PrefabType.Wood100x20: return "Textures/Wood/100x20"; case PrefabType.Wood175x20: return "Textures/Wood/175x20"; case PrefabType.Wood200x20: return "Textures/Wood/200x20"; case PrefabType.Wood25x20: return "Textures/Wood/25x20"; case PrefabType.Wood50x20: return "Textures/Wood/50x20"; //ICE case PrefabType.Ice100x20: return "Textures/Ice/100x20"; case PrefabType.Ice175x20: return "Textures/Ice/175x20"; case PrefabType.Ice200x20: return "Textures/Ice/200x20"; case PrefabType.Ice25x20: return "Textures/Ice/25x20"; case PrefabType.Ice50x20: return "Textures/Ice/50x20"; } return ""; }
public static void RevertSelectedPrefabs(MenuCommand command) { Predicate <GameObject> predicate = go => { PrefabType goPrefabType = PrefabUtility.GetPrefabType(go); return(goPrefabType == PrefabType.DisconnectedPrefabInstance || goPrefabType == PrefabType.DisconnectedModelPrefabInstance || goPrefabType == PrefabType.ModelPrefabInstance || goPrefabType == PrefabType.PrefabInstance); }; Action <GameObject> action = go => { PrefabUtility.ReconnectToLastPrefab(go); PrefabUtility.RevertPrefabInstance(go); }; FindPrefabsAndDoSomething(command, predicate, action); }
private static void ApplyByRoot(GameObject root) { PrefabType type = PrefabUtility.GetPrefabType(root); if (type == PrefabType.PrefabInstance || type == PrefabType.DisconnectedPrefabInstance) { string path = AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(root)); //CreateNew(root,path); PrefabUtility.ReplacePrefab(root, PrefabUtility.GetCorrespondingObjectFromSource(root), ReplacePrefabOptions.ConnectToPrefab); } else { for (int i = 0; i < root.transform.childCount; i++) { ApplyByRoot(root.transform.GetChild(i).gameObject); } } }
public GameObject NewObj(PrefabType type, GameObject prefab) { if (!this.m_prefabs.TryGetValue(type, out Queue <GameObject> gameObjects)) { this.m_prefabs.Add(type, new Queue <GameObject>()); } if (this.m_prefabs[type].Count == 0) { return(UnityEngine.Object.Instantiate(prefab)); } GameObject old = this.m_prefabs[type].Dequeue(); old.SetActive(true); return(old); }
internal static long GetLocalIdentifierInFileForObject(Object unityObject) { long id = -1; if (unityObject == null) { return(id); } SerializedObject serializedObject = new SerializedObject(unityObject); CSReflectionTools.GetInspectorModePropertyInfo().SetValue(serializedObject, InspectorMode.Debug, null); SerializedProperty serializedProperty = serializedObject.FindProperty("m_LocalIdentfierInFile"); #if UNITY_5_PLUS id = serializedProperty.longValue; #else id = serializedProperty.intValue; #endif if (id <= 0) { PrefabType prefabType = PrefabUtility.GetPrefabType(unityObject); if (prefabType != PrefabType.None) { id = GetLocalIdentifierInFileForObject(PrefabUtility.GetPrefabParent(unityObject)); } else { // this will work for the new objects in scene which weren't saved yet id = unityObject.GetInstanceID(); } } if (id <= 0) { GameObject go = unityObject as GameObject; if (go != null) { id = go.transform.GetSiblingIndex(); } } return(id); }
private void OnGUI() { prefab = (GameObject)EditorGUILayout.ObjectField("Prefab", prefab, typeof(GameObject), false); if (GUILayout.Button("Replace")) { var selection = Selection.gameObjects; for (var i = selection.Length - 1; i >= 0; --i) { var selected = selection[i]; PrefabType prefabType = PrefabUtility.GetPrefabType(prefab); GameObject newObject; if (prefabType == PrefabType.Prefab) { newObject = (GameObject)PrefabUtility.InstantiatePrefab(prefab); } else { newObject = Instantiate(prefab); newObject.name = prefab.name; } if (newObject == null) { Debug.LogError("Error instantiating prefab"); break; } Undo.RegisterCreatedObjectUndo(newObject, "Replace With Prefabs"); newObject.transform.parent = selected.transform.parent; newObject.transform.localPosition = selected.transform.localPosition; newObject.transform.localRotation = selected.transform.localRotation; newObject.transform.localScale = selected.transform.localScale; newObject.name += " (" + i + ")"; newObject.transform.SetSiblingIndex(selected.transform.GetSiblingIndex()); Undo.DestroyObjectImmediate(selected); } } GUI.enabled = false; EditorGUILayout.LabelField("Selection count: " + Selection.objects.Length); }
public static void Inspector(HumanoidControl humanoid, Tracker tracker, SerializedProperty enabledProp, string resourceName) { EditorGUILayout.BeginHorizontal(); //EditorGUI.BeginChangeCheck(); bool wasEnabled = enabledProp.boolValue; enabledProp.boolValue = EditorGUILayout.ToggleLeft(tracker.name, enabledProp.boolValue, GUILayout.MinWidth(80)); if (Application.isPlaying && enabledProp.boolValue) { EditorGUILayout.EnumPopup(tracker.status); } EditorGUILayout.EndHorizontal(); #if UNITY_2018_3_OR_NEWER PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(humanoid); if (prefabType != PrefabAssetType.NotAPrefab) { return; } #else PrefabType prefabType = PrefabUtility.GetPrefabType(humanoid); if (prefabType == PrefabType.Prefab) { return; } #endif if (tracker.humanoid == null) { tracker.humanoid = humanoid; } if (enabledProp.boolValue && resourceName != null) { tracker.AddTracker(humanoid, resourceName); } else if (wasEnabled) { RemoveTracker(tracker); } tracker.ShowTracker(humanoid.showRealObjects && enabledProp.boolValue); }
void OnWizardCreate() { if (replacement == null) { Debug.LogError("You must choose an object to replace your selection with!"); return; } Undo.RegisterSceneUndo("Replace Selection"); Transform[] transforms = Selection.GetTransforms( SelectionMode.TopLevel | SelectionMode.Editable); foreach (Transform t in transforms) { GameObject g; PrefabType pref = PrefabUtility.GetPrefabType(replacement); if (pref == PrefabType.Prefab || pref == PrefabType.ModelPrefab) { g = (GameObject)PrefabUtility.InstantiatePrefab(replacement); } else { g = (GameObject)Instantiate(replacement); } Transform gTransform = g.transform; gTransform.parent = t.parent; g.name = replacement.name; gTransform.localPosition = t.localPosition; gTransform.localScale = t.localScale; gTransform.localRotation = t.localRotation; } if (!keep) { foreach (GameObject g in Selection.gameObjects) { DestroyImmediate(g); } } }
public static void LoadLevel() { DeGenerate(); PrefabType prefabType = PrefabType.None; var path = EditorUtility.OpenFilePanel("Select File", "", "lvl"); if (path.Length != 0) { StreamReader theReader = new StreamReader(path, Encoding.Default); string line; using (theReader) { // While there's lines left in the text file, do this: do { line = theReader.ReadLine(); if (line != null) { if (line == "Blue") { prefabType = PrefabType.BlueCube; } else if (line == "Gold") { prefabType = PrefabType.GoldenCube; } else if (line == "Life") { prefabType = PrefabType.ExtraLife; } else if (line != "") { PlaceObject(line, prefabType); } } }while (line != null); // Done reading, close the reader and return true to broadcast success theReader.Close(); } } }
static void InjectVariable() { Debug.Log("Inject"); GameObject[] objs = FindObjectsOfType <GameObject>(); for (int i = 0; i < objs.Length; i++) { UIBase uibase = objs[i].GetComponent <UIBase>(); if (uibase != null) { uibase.Inject(); PrefabType t_type = PrefabUtility.GetPrefabType(objs[i]); if (t_type == PrefabType.PrefabInstance) { PrefabUtility.ReplacePrefab(objs[i], PrefabUtility.GetPrefabParent(objs[i])); } } } EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); }
private void OnWizardCreate() { if (m_replacement == null) { return; } Transform[] targets = Selection.GetTransforms(SelectionMode.OnlyUserModifiable); for (int i = 0; i < targets.Length; i++) { GameObject newObj; PrefabType type = PrefabUtility.GetPrefabType(m_replacement); if (type == PrefabType.Prefab || type == PrefabType.ModelPrefab) { newObj = PrefabUtility.InstantiatePrefab(m_replacement) as GameObject; } else { newObj = Editor.Instantiate(m_replacement) as GameObject; } Transform newTrs = newObj.transform; newTrs.parent = targets[i].parent; newTrs.name = m_replacement.name; newTrs.localPosition = targets[i].localPosition; newTrs.localScale = targets[i].localScale; newTrs.localRotation = targets[i].localRotation; Undo.RegisterCreatedObjectUndo(newObj, "Undo Replacement"); } if (!m_keepOriginals) { foreach (GameObject go in Selection.gameObjects) { if (go != null) { Undo.DestroyObjectImmediate(go); } } } }
public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect) { PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject); if (prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance || prefabType == PrefabType.DisconnectedModelPrefabInstance) { QColorUtils.setColor(inactiveColor); GUI.DrawTexture(rect, prefabTexture); QColorUtils.clearColor(); } else if (!showPrefabConnectedIcon && prefabType != PrefabType.None) { QColorUtils.setColor(activeColor); GUI.DrawTexture(rect, prefabTexture); QColorUtils.clearColor(); } }
public override void OnInspectorGUI() { DrawCustomHeader(); PrefabType prType = PrefabUtility.GetPrefabType(lava); if (AssetDatabase.Contains(lava)) { DrawProjectInspector(); } else if (prType != PrefabType.DisconnectedPrefabInstance) { DrawPrefabInspector(); } else { DrawCustomWaterInspector(); } }
private void CalculatePrefabStatus() { this.m_HasInstance = false; this.m_AllOfSamePrefabType = true; PrefabType prefabType = PrefabUtility.GetPrefabType(base.targets[0] as GameObject); foreach (GameObject obj2 in base.targets) { PrefabType type2 = PrefabUtility.GetPrefabType(obj2); if (type2 != prefabType) { this.m_AllOfSamePrefabType = false; } if (((type2 != PrefabType.None) && (type2 != PrefabType.Prefab)) && (type2 != PrefabType.ModelPrefab)) { this.m_HasInstance = true; } } }
public override Object getCellPrefabFor(GameObject cell) { PrefabType type = PrefabUtility.GetPrefabType(cell); if (type == PrefabType.PrefabInstance) { return(PrefabUtility.GetPrefabObject(cell)); } Cell c = cell.GetComponent <Cell>(); string path = "Assets/CellPrefabs/" + Mathf.CeilToInt(c.Properties.height) + "/"; Object prefab = null; if (AssetDatabase.IsValidFolder(path)) { string[] prefabs = AssetDatabase.FindAssets(c.Properties.ToString(), new string[] { path }); if (prefabs != null && prefabs.Length > 0) { prefab = AssetDatabase.LoadAssetAtPath(prefabs[0], typeof(Object)); } } else { AssetDatabase.CreateFolder("Assets/CellPrefabs", Mathf.CeilToInt(c.Properties.height) + ""); } if (prefab == null) { prefab = PrefabUtility.CreateEmptyPrefab(path); CellProperties properties = c.Properties; /*Material myMat = new Material(Shader.Find("Transparent/Cutout/Diffuse")); * texture.filterMode = FilterMode.Point; * myMat.SetTexture("_MainTex", texture); * this.GetComponent<Renderer>().sharedMaterial = myMat;*/ } return(prefab); }
public static Result ExtractSceneBlueprintId(string id_opt) { if (id_opt != null) { var match = worldIdRex.Match(id_opt); if (match.Success) { var r = new Result(null, true, ""); r.blueprintId = match.Value; return(r); } else { var r = new Result(null, false, "It's not a world ID string (wrong format)"); return(r); } } #if UNITY_2018_4_OR_NEWER var vrcPipelineManager = Resources.FindObjectsOfTypeAll(typeof(VRC.Core.PipelineManager)) as VRC.Core.PipelineManager[]; #else var vrcPipelineManager = Resources.FindObjectsOfTypeAll(typeof(VRC.Core.VRCPipelineManager)) as VRC.Core.VRCPipelineManager[]; #endif foreach (var pm in vrcPipelineManager) { // PrefabUtility.GetPrefabType returns None on Unity 2017.4.15f1, PrefabInstance on Unity 2017.4.28f1 // And GetPrefabType is obsolete in Unity 2018.3.x. Use PrefabUtility.IsPartOfPrefabAsset instead in future. PrefabType ptype = PrefabUtility.GetPrefabType(pm); if ((ptype == PrefabType.PrefabInstance) || (ptype == PrefabType.None)) { var blueprintId = pm.blueprintId; if (blueprintId == null || blueprintId == "") { return(new Result(null, false, "Not publishd yet? (blueprintId is empty)")); } var r = new Result(null, true, ""); r.blueprintId = blueprintId; return(r); } } return(new Result(null, false, "VRC_SceneDescriptor is missing? (vrcPipelineManager.Length=" + vrcPipelineManager.Length + ")")); }
public static T InstantiatePrefab <T>(PrefabType type, Transform parent) where T : Component { if (!instance.typedPrefabsFastAccess.ContainsKey(type)) { return(null); } //need this object to have component(T) specified if (!instance.typedPrefabsFastAccess[type].prefab.GetComponent <T>()) { return(null); } GameObject result = Instantiate(instance.typedPrefabsFastAccess[type].prefab, parent); result.transform.localScale = Vector3.one; return(result.GetComponent <T>()); }
private static void RecursivelyExtract(GameObject extract, List <GameObject> foliageInstances) { // If it is a prefab instance and we have PrefabType type = PrefabUtility.GetPrefabType(extract); if (type == PrefabType.ModelPrefabInstance || type == PrefabType.PrefabInstance) { foliageInstances.Add(extract); } // else { // Extract it's owned entities. Only extract if the object is NOT a prefab, we don't want to extract owned entities from prefabs for (int i = 0; i < extract.transform.childCount; i++) { RecursivelyExtract(extract.transform.GetChild(i).gameObject, foliageInstances); } } }
/// <summary> /// All widgets have depth, color and make pixel-perfect options /// </summary> protected void DrawCommonProperties() { PrefabType type = PrefabUtility.GetPrefabType(mWidget.gameObject); if (NGUIEditorTools.DrawHeader("Widget")) { NGUIEditorTools.BeginContents(); if (mWidget.GetType() != typeof(UIWidget)) { // Color tint GUILayout.BeginHorizontal(); SerializedProperty sp = NGUIEditorTools.DrawProperty("Color Tint", serializedObject, "mColor"); if (GUILayout.Button("Copy", GUILayout.Width(50f))) { NGUISettings.color = sp.colorValue; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUISettings.color = EditorGUILayout.ColorField("Clipboard", NGUISettings.color); if (GUILayout.Button("Paste", GUILayout.Width(50f))) { sp.colorValue = NGUISettings.color; } GUILayout.EndHorizontal(); GUILayout.Space(6f); } DrawPivot(); DrawDepth(type == PrefabType.Prefab); DrawDimensions(type == PrefabType.Prefab); if (serializedObject.isEditingMultipleObjects || mWidget.hasBoxCollider) { GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty("Box Collider", serializedObject, "autoResizeBoxCollider", GUILayout.Width(100f)); GUILayout.Label("auto-adjust to match"); GUILayout.EndHorizontal(); } NGUIEditorTools.EndContents(); } }
void CalculatePrefabStatus() { m_HasInstance = false; m_AllOfSamePrefabType = true; PrefabType firstType = PrefabUtility.GetPrefabType(targets[0] as GameObject); foreach (GameObject go in targets) { PrefabType type = PrefabUtility.GetPrefabType(go); if (type != firstType) { m_AllOfSamePrefabType = false; } if (type != PrefabType.None && type != PrefabType.Prefab && type != PrefabType.ModelPrefab) { m_HasInstance = true; } } }
void OnWizardCreate() { if (replacement == null) { return; } //Undo.RegisterSceneUndo("Replace Selection"); //Undo.reg() Transform[] transforms = Selection.GetTransforms( SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable); foreach (Transform t in transforms) { GameObject g; PrefabType pref = PrefabUtility.GetPrefabType(replacement); if (pref == PrefabType.Prefab || pref == PrefabType.ModelPrefab) { g = (GameObject)PrefabUtility.InstantiatePrefab(replacement); } else { g = (GameObject)Editor.Instantiate(replacement); } Transform gTransform = g.transform; gTransform.parent = t.parent; g.name = replacement.name; gTransform.localPosition = t.localPosition; gTransform.localScale = t.localScale; gTransform.localRotation = t.localRotation; } if (!keep) { foreach (GameObject g in Selection.gameObjects) { GameObject.DestroyImmediate(g); } } }
private void CalculatePrefabStatus() { this.m_HasInstance = false; this.m_AllOfSamePrefabType = true; PrefabType prefabType1 = PrefabUtility.GetPrefabType((UnityEngine.Object)(this.targets[0] as GameObject)); foreach (UnityEngine.Object target in this.targets) { PrefabType prefabType2 = PrefabUtility.GetPrefabType(target); if (prefabType2 != prefabType1) { this.m_AllOfSamePrefabType = false; } if (prefabType2 != PrefabType.None && prefabType2 != PrefabType.Prefab && prefabType2 != PrefabType.ModelPrefab) { this.m_HasInstance = true; } } }
void Update() { #if UNITY_EDITOR PrefabType prefabType = PrefabUtility.GetPrefabType(this.gameObject); if (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab) { return; } #endif bool requiresReinitialization = false; using (new ProfilerSample("Attachment Hands Update", this.gameObject)) { for (int i = 0; i < _attachmentHands.Length; i++) { var attachmentHand = attachmentHands[i]; if (attachmentHand == null) { requiresReinitialization = true; break; } var leapHand = handAccessors[i](); attachmentHand.isTracked = leapHand != null; using (new ProfilerSample(attachmentHand.gameObject.name + " Update Points")) { foreach (var point in attachmentHand.points) { point.SetTransformUsingHand(leapHand); } } } if (requiresReinitialization) { reinitialize(); } } }
private void BakeAGameObject(GameObject go) { ShadowVolumeObject svo = go.GetComponent <ShadowVolumeObject>(); if (svo != null) { go = svo.source; } PrefabType type = PrefabUtility.GetPrefabType(go); if (type == PrefabType.Prefab) { Debug.LogError("Skip a Shadow Volume Baking, because of it is a Prefab. " + go.name, go); return; } MeshFilter mf = go.GetComponent <MeshFilter>(); if (mf == null) { Debug.LogError("Skip a Shadow Volume Baking, becase of there is no MeshFilter. " + go.name, go); return; } if (mf.sharedMesh == null) { Debug.LogError("Skip a Shadow Volume Baking, becase of there is no Mesh. " + go.name, go); return; } if (!mf.sharedMesh.isReadable) { Debug.LogError("Skip a Shadow Volume Baking, becase of Mesh is not readable. " + go.name, go); return; } Transform transform = go.transform; ABakingTask task = new ABakingTask(); task.Init(transform, transform.localToWorldMatrix, transform.worldToLocalMatrix, dirLight.transform.forward, mf.sharedMesh, capsOffset, groundLayer, twoSubMeshes); bakingTaskManager.AddTask(task); }
public static void Export() { SceneConfigInfo info = new SceneConfigInfo(); string curSceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; info.sceneName = curSceneName; GameObject[] sceneObjs = GameObject.FindObjectsOfType <GameObject> (); for (int i = 0; i < sceneObjs.Length; ++i) { GameObject obj = sceneObjs [i]; if (obj.transform.parent != null) { continue; } PrefabType pbjPrefabType = PrefabUtility.GetPrefabType(obj); if (pbjPrefabType == PrefabType.None) { continue; } Object prefab = PrefabUtility.GetPrefabParent(obj); if (null != prefab) { ScenePrefabInfo prefabInfo = new ScenePrefabInfo(); prefabInfo.prefabName = prefab.name; prefabInfo.position = obj.transform.localPosition; prefabInfo.eularAngles = obj.transform.localEulerAngles; prefabInfo.scale = obj.transform.localScale; info.prefabList.Add(prefabInfo); } else { Debug.LogError("未找到场景中的对象对应的预制体,对象名字:" + obj.name); } } string configStr = Newtonsoft.Json.JsonConvert.SerializeObject(info); string filePath = Path.Combine(SceneConfigPath, curSceneName + FileExtension); File.WriteAllText(filePath, configStr); AssetDatabase.Refresh(); }
private int CheckScene(string filename, System.Collections.Generic.Dictionary <int, string> indexed) { if (EditorApplication.currentScene != filename) { EditorApplication.OpenScene(filename); } if (_uniqueMode == (int)UniqueMode.OnlyWithinEachSelectedScene) { indexed.Clear(); } var all = Resources.FindObjectsOfTypeAll(typeof(uLink.NetworkView)) as uLink.NetworkView[]; int maxID = 0; foreach (var nv in all) { PrefabType prefabType = EditorUtility.GetPrefabType(nv); if (prefabType == PrefabType.Prefab) { continue; } if (maxID < nv._manualViewID) { maxID = nv._manualViewID; } string other; if (indexed.TryGetValue(nv._manualViewID, out other)) { Debug.LogWarning("In scene " + filename + ": manual ViewID " + nv._manualViewID + " in " + nv + " is already assigned to " + other, nv); } else { string name = nv.ToHierarchyString() + "(Scene: " + filename + ")"; indexed.Add(nv._manualViewID, name); } } return(maxID); }
/// <summary> /// Finds the first instance of a preface in the Hierarchy. /// </summary> /// <param name="prefab"></param> /// <returns>First instance of the prefab or null if one is not found.</returns> public static GameObject FindFirstPrefabInstance(GameObject prefab) { GameObject result = null; GameObject[] allObjects = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject)); foreach (GameObject obj in allObjects) { PrefabType type = PrefabUtility.GetPrefabType(obj); if (type == PrefabType.PrefabInstance) { UnityEngine.Object GO_prefab = PrefabUtility.GetPrefabParent(obj); if (prefab == GO_prefab) { result = obj; break; } } } return(result); }
/// <summary> /// Helper function that checks to see if a prefab is currently selected. /// </summary> static bool PrefabCheck() { if (Selection.activeTransform != null) { // Check if the selected object is a prefab instance and display a warning #if UNITY_3_4 PrefabType type = EditorUtility.GetPrefabType(Selection.activeGameObject); #else PrefabType type = PrefabUtility.GetPrefabType(Selection.activeGameObject); #endif if (type == PrefabType.PrefabInstance) { return(EditorUtility.DisplayDialog("Losing prefab", "This action will lose the prefab connection. Are you sure you wish to continue?", "Continue", "Cancel")); } } return(true); }
bool ThisIsASceneObjectWithPrefabParent(out GameObject prefab) { prefab = null; PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject); if (prefabType == PrefabType.None) { return(false); } prefab = (GameObject)PrefabUtility.GetPrefabParent(gameObject); if (prefab == null) { if (LogFilter.logError) { Debug.LogError("Failed to find prefab parent for scene object [name:" + gameObject.name + "]"); } return(false); } return(true); }
// We cannot allow a GUID to be saved into a prefab, and we need to convert to byte[] public void OnBeforeSerialize() { #if UNITY_EDITOR // This lets us detect if we are a prefab instance or a prefab asset. // A prefab asset cannot contain a GUID since it would then be duplicated when instanced. PrefabType prefabType = PrefabUtility.GetPrefabType(this); if (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab) { serializedGuid = new byte[0]; guid = Guid.Empty; } else #endif { if (guid != Guid.Empty) { serializedGuid = guid.ToByteArray(); } } }
public static void CreatePrefab(string name, GameObject go) { PrefabType prefabType = PrefabUtility.GetPrefabType(go); if (prefabType == PrefabType.Prefab || prefabType == PrefabType.PrefabInstance) { Object prefabParent = PrefabUtility.GetPrefabParent(go); string path = AssetDatabase.GetAssetPath(prefabParent); PrefabUtility.ReplacePrefab(go, prefabParent, ReplacePrefabOptions.ConnectToPrefab); Debug.Log("Prefab replaced: " + path); } else { string path = "Assets/" + root + "Prefabs/" + name; PrefabUtility.CreatePrefab(path, go, ReplacePrefabOptions.Default); PrefabUtility.ReconnectToLastPrefab(go); Debug.Log("Prefab created: " + path); } }
/// <summary> /// Create a body with a circular shape /// </summary> /// <param name="world">World</param> /// <param name="position">Position in sim-units</param> /// <param name="spriteName">Sprite name to render with</param> /// <param name="radius">radius of the body in sim-units</param> /// <returns>new instance of a Body</returns> private static Body CreateCircle(World world, Vector2 position, PrefabType prefabType, float radius) { Body body = BodyFactory.CreateCircle(world, radius, 1f, position); body.UserData = new PrefabUserData { Origin = new Vector2(radius), PrefabType = prefabType }; body.AngularDamping = 2f; //without this, our ball would keep on rolling regardless of friction body.BodyType = BodyType.Dynamic; return body; }
/// <summary> /// Create a body with a rectangular shape /// </summary> /// <param name="world">World</param> /// <param name="position">Position in sim-units</param> /// <param name="spriteName">Sprite name to render with</param> /// <param name="width">width of the body in sim-units</param> /// <param name="height">height of the body in sim-units</param> /// <returns>new instance of a Body</returns> private static Body CreateRectangle(World world, Vector2 position, PrefabType prefabType, float width, float height, int hitPoints) { Body body = BodyFactory.CreateRectangle (world, width, height, 1f, position); body.UserData = new PrefabUserData { Origin = new Vector2(width/2f, height/2f), PrefabType = prefabType, HitPoints = hitPoints, }; body.BodyType = BodyType.Dynamic; return body; }
public static void Load(GameScreen gameScreen, PrefabType prefabType) { if(textures.ContainsKey(prefabType)) return; textures.Add(prefabType, gameScreen.Load<Texture2D>(GetTextureName(prefabType))); }
private static Body CreateTriangleR(World world, Vector2 position, PrefabType prefabType,float width,float height,int hitPoints) { /* 13,25 25,13 -4,13 -9,12 -12,13 -13,-6 */ var w = width /2; var h = height / 2; Vertices vertices = new Vertices(6); vertices.Add(new Vector2(-w,-h)); vertices.Add(new Vector2(w,h)); vertices.Add(new Vector2(-w,h)); //vertices.Add(new Vector2(-.10f,.00f)); PolygonShape chassis = new PolygonShape(vertices, 1); Body body = new Body(world); body.BodyType = BodyType.Dynamic; body.CreateFixture(chassis); body.Position = position; body.UserData = new PrefabUserData { Origin = new Vector2(width/2f, height/2f), PrefabType = prefabType, HitPoints = hitPoints, }; return body; }
public static Texture2D GetTexture(PrefabType prefabType) { return textures[prefabType]; }
/// <summary> /// Create Body of certain prefab type /// </summary> /// <param name="type">prefab type</param> /// <param name="world">Farseer world</param> /// <param name="position">position of the body in the physics world (using simulation units)</param> /// <returns>a new instance of a Body</returns> public static Body CreateBody(PrefabType type, World world, Vector2 position) { //will lookup the correct delegate in our prefab library and execute the delegate in order to create a new instance return Library [type] (world, position); }
public void Reset() { if (!entity) return; entity.SetActive(true); entity.transform.localScale = Vector3.one; entity.transform.localPosition = Vector3.zero; entity.transform.localRotation = Quaternion.identity; if (particle != null) { type = PrefabType.Particle; pool.StartCoroutine(pool.AutoReleaseParticle(entity.name, particle, this)); } }
private void DoPrefabButtons(PrefabType prefabType, GameObject go) { if (this.m_HasInstance) { using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode)) { EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIContent content = (base.targets.Length <= 1) ? s_Styles.goTypeLabel[(int) prefabType] : s_Styles.goTypeLabelMultiple; if (content != null) { GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(24f + s_Styles.tagFieldWidth) }; EditorGUILayout.BeginHorizontal(options); GUILayout.FlexibleSpace(); if (((prefabType == PrefabType.DisconnectedModelPrefabInstance) || (prefabType == PrefabType.MissingPrefabInstance)) || (prefabType == PrefabType.DisconnectedPrefabInstance)) { GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.ExpandWidth(false) }; GUILayout.Label(content, EditorStyles.whiteLabel, optionArray2); GUI.contentColor = Color.white; } else { GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.ExpandWidth(false) }; GUILayout.Label(content, optionArray3); } EditorGUILayout.EndHorizontal(); } if (base.targets.Length > 1) { GUILayout.Label("Instance Management Disabled", s_Styles.instanceManagementInfo, new GUILayoutOption[0]); } else { if ((prefabType != PrefabType.MissingPrefabInstance) && GUILayout.Button("Select", "MiniButtonLeft", new GUILayoutOption[0])) { Selection.activeObject = PrefabUtility.GetPrefabParent(base.target); EditorGUIUtility.PingObject(Selection.activeObject); } if (((prefabType == PrefabType.DisconnectedModelPrefabInstance) || (prefabType == PrefabType.DisconnectedPrefabInstance)) && GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0])) { List<Object> hierarchy = new List<Object>(); this.GetObjectListFromHierarchy(hierarchy, go); Undo.RegisterFullObjectHierarchyUndo(go, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(go); Undo.RegisterCreatedObjectUndo(PrefabUtility.GetPrefabObject(go), "Revert to prefab"); PrefabUtility.RevertPrefabInstance(go); this.CalculatePrefabStatus(); List<Object> list2 = new List<Object>(); this.GetObjectListFromHierarchy(list2, go); this.RegisterNewComponents(list2, hierarchy); } using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode())) { if (((prefabType == PrefabType.ModelPrefabInstance) || (prefabType == PrefabType.PrefabInstance)) && GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0])) { List<Object> list3 = new List<Object>(); this.GetObjectListFromHierarchy(list3, go); Undo.RegisterFullObjectHierarchyUndo(go, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(go); this.CalculatePrefabStatus(); List<Object> list4 = new List<Object>(); this.GetObjectListFromHierarchy(list4, go); this.RegisterNewComponents(list4, list3); } if ((prefabType == PrefabType.PrefabInstance) || (prefabType == PrefabType.DisconnectedPrefabInstance)) { GameObject source = PrefabUtility.FindValidUploadPrefabInstanceRoot(go); GUI.enabled = (source != null) && !AnimationMode.InAnimationMode(); if (GUILayout.Button("Apply", "MiniButtonRight", new GUILayoutOption[0])) { Object prefabParent = PrefabUtility.GetPrefabParent(source); string assetPath = AssetDatabase.GetAssetPath(prefabParent); string[] assets = new string[] { assetPath }; if (Provider.PromptAndCheckoutIfNeeded(assets, "The version control requires you to check out the prefab before applying changes.")) { PrefabUtility.ReplacePrefab(source, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); EditorSceneManager.MarkSceneDirty(source.scene); GUIUtility.ExitGUI(); } } } } if (((prefabType == PrefabType.DisconnectedModelPrefabInstance) || (prefabType == PrefabType.ModelPrefabInstance)) && GUILayout.Button("Open", "MiniButtonRight", new GUILayoutOption[0])) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(base.target)); GUIUtility.ExitGUI(); } } EditorGUILayout.EndHorizontal(); } } }
public GameObject InstantiatePrefabType(PrefabType prefabType, int index) { GameObject nextGameObject; nextGameObject = PrefabManager.Instance.InstantiatePrefabType (prefabType); nextGameObject.transform.position = _gameManager.GetRandomPositionWithinGameBounds(); nextGameObject.transform.parent = _gameManager.transform; nextGameObject.name += index; _gameObjects.Add (nextGameObject); return nextGameObject; }