Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using AC;
- public class FixConstantIDs : MonoBehaviour {
- public int constantID;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- void FixIDs()
- {
- ConstantID[] allIDScripts = Object.FindObjectsOfType <ConstantID>();
- foreach(ConstantID idScript in allIDScripts)
- {
- //idScript.gameObject.SendMessage ("CheckForDuplicateIDs", SendMessageOptions.DontRequireReceiver);
- if (idScript.constantID == constantID && idScript.gameObject != this.gameObject && constantID != 0)
- {
- ACDebug.Log ("Duplicate ID found: " + idScript.gameObject.name + " and " + this.name + " : " + constantID, gameObject);
- SetNewID (true);
- break;
- }
- }
- }
- private ConstantID[] GetAllIDScriptsInHierarchy ()
- {
- ConstantID[] idScripts = null;
- if (UnityVersionHandler.IsPrefabEditing (gameObject))
- {
- GameObject rootObject = (transform.root != null) ? transform.root.gameObject : gameObject;
- idScripts = rootObject.GetComponentsInChildren <ConstantID>();
- }
- else
- {
- idScripts = FindObjectsOfType (typeof (ConstantID)) as ConstantID[];
- }
- return idScripts;
- }
- private void SetNewID (bool ignoreOthers = false)
- {
- // Share ID if another ID script already exists on object
- ConstantID[] idScripts = GetComponents <ConstantID>();
- foreach (ConstantID idScript in idScripts)
- {
- if (idScript != this && idScript.constantID != 0)
- {
- if (ignoreOthers && idScript.constantID == constantID)
- {
- continue;
- }
- constantID = idScript.constantID;
- UnityVersionHandler.CustomSetDirty (this, true);
- return;
- }
- }
- constantID = GetInstanceID ();
- if (constantID < 0)
- {
- constantID *= -1;
- }
- UnityVersionHandler.CustomSetDirty (this, true);
- ACDebug.Log ("Set new ID for " + this.name + ": " + constantID, gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement