//Links the specified GameObject to the blueprint node variable GameObject and returns true if successful
    private bool LinkGameObjectToBlueprint(GameObject gameObject)
    {
        //If the GameObject is not valid
        if (gameObject == null)
        {
            //Reset attributes
            isPrefab       = false;
            prefabFilepath = "";
            instanceTag    = "";
            instanceName   = "";
            instanceID     = "";

            //Update the attribute value
            attributeValue = gameObject;

            //Successfully linked the GameObject to the blueprint
            return(true);
        }

        //If the GameObject is a prefab
        if (gameObject.scene.name == null)
        {
            //Update attributes
            isPrefab       = true;
            prefabFilepath = AssetDatabase.GetAssetPath(gameObject);
            instanceTag    = "";
            instanceName   = "";
            instanceID     = "";

            //Update the attribute value
            attributeValue = gameObject;

            //Successfully linked the GameObject to the blueprint
            return(true);
        }
        //Otherwise, if the GameObject is not the blueprints parent GameObject
        else if (Selection.activeGameObject != gameObject)
        {
            //If the tag is valid
            if (!string.IsNullOrEmpty(gameObject.tag) && gameObject.tag != "Untagged")
            {
                //Create a reference to the GameObjects blueprint UID
                BlueprintUID gameObjectID = gameObject.GetComponent <BlueprintUID>();

                //If the GameObjects blueprint ID is not valid
                if (gameObjectID == null)
                {
                    //Create and initialize blueprint UID for the GameObject
                    gameObjectID    = gameObject.AddComponent <BlueprintUID>();
                    gameObjectID.ID = BlueprintIdentificationHelper.GenerateID();
                }

                //Update attributes for instance
                isPrefab       = false;
                prefabFilepath = "";
                instanceTag    = gameObject.tag;
                instanceName   = gameObject.name;
                instanceID     = gameObjectID.ID;

                //Update the attribute value
                attributeValue = gameObject;

                //Successfully linked the GameObject to the blueprint
                return(true);
            }
            //Otherwise
            else
            {
                //Log warning
                Debug.LogWarning("WARNING: Linking an untagged GameObject in the scene hierachy is not allowed, set the GameObjects tag and try again.");

                //Reset attribute value
                attributeValue = null;
            }
        }
        //Otherwise
        else
        {
            //Log warning
            Debug.LogWarning("WARNING: Linking the parent GameObject is not allowed, try linking a different GameObject.");

            //Reset attribute value
            attributeValue = null;
        }

        //Failed to link the GameObject to the blueprint
        return(false);
    }
Esempio n. 2
0
    //Links the specified component to the blueprint node variable component and returns true if successful
    private bool LinkComponentToBlueprint(T1 component)
    {
        //If the Component is not valid
        if (component == null)
        {
            //Update attributes
            instanceTag  = "";
            instanceName = "";
            instanceID   = "";

            //Update the component
            this.component = component;

            //Successfully linked the component to the blueprint
            return(true);
        }
        //Otherwise, if the component is attached to the blueprints parent GameObject
        else if (Selection.activeGameObject == component.gameObject)
        {
            //Log warning
            Debug.LogWarning("WARNING: Linking a Component attached to the parent GameObject is not allowed, try linking a Component on a different GameObject.");

            //Reset component value
            this.component = null;
        }
        //Otherwise, if the component is on a prefab
        else if (component.gameObject.scene.name == null)
        {
            //Log warning
            Debug.LogWarning("WARNING: Linking a Component from a prefab is not allowed, try linking a Component from a GameObject instance.");

            //Reset component value
            this.component = null;
        }
        //Otherwise, if the tag is valid
        else if (!string.IsNullOrEmpty(component.gameObject.tag) && component.gameObject.tag != "Untagged")
        {
            //Create reference to the components parent GameObjects blueprint UID
            BlueprintUID gameObjectUID = component.gameObject.GetComponent <BlueprintUID>();

            //If the components parent GameObjects blueprint UID is not valid
            if (gameObjectUID == null)
            {
                //Create and initialize blueprint UID for the components parent GameObject
                gameObjectUID    = component.gameObject.AddComponent <BlueprintUID>();
                gameObjectUID.ID = BlueprintIdentificationHelper.GenerateID();
            }

            //Update attributes
            instanceTag  = component.gameObject.tag;
            instanceName = component.gameObject.name;
            instanceID   = gameObjectUID.ID;

            //Update the component
            this.component = component;

            //Successfully linked the component to the blueprint
            return(true);
        }
        //Otherwise
        else
        {
            //Log warning
            Debug.LogWarning("WARNING: Linking a Component from an untagged GameObject is not allowed, set the GameObjects tag and try again.");

            //Reset component value
            this.component = null;
        }

        //Failed to link the component to the blueprint
        return(false);
    }