Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using AC;
  5.  
  6. public class FixConstantIDs : MonoBehaviour {
  7.  
  8. public int constantID;
  9. // Use this for initialization
  10. void Start () {
  11.  
  12. }
  13.  
  14. // Update is called once per frame
  15. void Update () {
  16.  
  17. }
  18.  
  19. void FixIDs()
  20. {
  21. ConstantID[] allIDScripts = Object.FindObjectsOfType <ConstantID>();
  22. foreach(ConstantID idScript in allIDScripts)
  23. {
  24. //idScript.gameObject.SendMessage ("CheckForDuplicateIDs", SendMessageOptions.DontRequireReceiver);
  25.  
  26. if (idScript.constantID == constantID && idScript.gameObject != this.gameObject && constantID != 0)
  27. {
  28. ACDebug.Log ("Duplicate ID found: " + idScript.gameObject.name + " and " + this.name + " : " + constantID, gameObject);
  29. SetNewID (true);
  30. break;
  31. }
  32. }
  33. }
  34.  
  35.  
  36.  
  37.  
  38. private ConstantID[] GetAllIDScriptsInHierarchy ()
  39. {
  40. ConstantID[] idScripts = null;
  41.  
  42.  
  43.  
  44. if (UnityVersionHandler.IsPrefabEditing (gameObject))
  45. {
  46. GameObject rootObject = (transform.root != null) ? transform.root.gameObject : gameObject;
  47. idScripts = rootObject.GetComponentsInChildren <ConstantID>();
  48. }
  49. else
  50. {
  51. idScripts = FindObjectsOfType (typeof (ConstantID)) as ConstantID[];
  52. }
  53. return idScripts;
  54. }
  55.  
  56. private void SetNewID (bool ignoreOthers = false)
  57. {
  58. // Share ID if another ID script already exists on object
  59. ConstantID[] idScripts = GetComponents <ConstantID>();
  60.  
  61. foreach (ConstantID idScript in idScripts)
  62. {
  63. if (idScript != this && idScript.constantID != 0)
  64. {
  65. if (ignoreOthers && idScript.constantID == constantID)
  66. {
  67. continue;
  68. }
  69.  
  70. constantID = idScript.constantID;
  71. UnityVersionHandler.CustomSetDirty (this, true);
  72. return;
  73. }
  74. }
  75.  
  76. constantID = GetInstanceID ();
  77. if (constantID < 0)
  78. {
  79. constantID *= -1;
  80. }
  81.  
  82. UnityVersionHandler.CustomSetDirty (this, true);
  83. ACDebug.Log ("Set new ID for " + this.name + ": " + constantID, gameObject);
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement