Exemple #1
0
    //Links the variables component instance
    protected void LinkComponentInstance()
    {
        //If the instance tag is valid
        if (!string.IsNullOrEmpty(instanceTag))
        {
            //Query list of GameObjects with the instance tag
            GameObject[] searchList = GameObject.FindGameObjectsWithTag(instanceTag);

            //For each GameObject in the search list
            for (int gameObjectIndex = 0; gameObjectIndex < searchList.Length; gameObjectIndex++)
            {
                //If the GameObjects name matches the instance name
                if (searchList[gameObjectIndex].name == instanceName)
                {
                    //Create reference  to the GameObjects blueprint UID
                    BlueprintUID gameObjectUID = searchList[gameObjectIndex].GetComponent <BlueprintUID>();

                    //If the GameObjects blueprint UID matches the instance ID
                    if (gameObjectUID != null && gameObjectUID.ID == instanceID)
                    {
                        //Link the variables component
                        component = searchList[gameObjectIndex].GetComponent <T1>();
                        break;
                    }
                }
            }
        }
    }
    //Links the gameobject
    private void LinkGameObjectInstance()
    {
        //If the gameobject is a prefab
        if (isPrefab)
        {
            //If the prefab filepath is valid
            if (!string.IsNullOrEmpty(prefabFilepath))
            {
                //Link the gameobject to the attribute value
                attributeValue = Resources.Load <GameObject>(BlueprintPathHelper.ConvertToAssetResourcePath(prefabFilepath));
            }
        }
        //Otherwise, if the instance tag is valid
        if (!string.IsNullOrEmpty(instanceTag))
        {
            //Find all GameObjects with the instance tag
            GameObject[] searchList = GameObject.FindGameObjectsWithTag(instanceTag);

            //For each gameobject in the search list
            for (int objectIndex = 0; objectIndex < searchList.Length; objectIndex++)
            {
                //If the GameObjects name matches the instance name
                if (searchList[objectIndex].name == instanceName)
                {
                    //Create reference to the GameObjects blueprint ID
                    BlueprintUID gameObjectID = searchList[objectIndex].GetComponent <BlueprintUID>();

                    //If the GameObjects blueprint ID is valid
                    if (gameObjectID != null)
                    {
                        //If the GameObjects blueprint ID matches the instance ID
                        if (gameObjectID.ID == instanceID)
                        {
                            //Link the GameObject to the attribute value
                            attributeValue = searchList[objectIndex];
                            return;
                        }
                    }
                }
            }
        }
    }
    //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);
    }
Exemple #4
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);
    }