public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object for which the static flags should be changed.", this);
        }

        var theStaticFlags = staticFlags.EvaluateIn(context);

        var theCurrentStaticFlags = GameObjectUtility.GetStaticEditorFlags(theGameObject);

        switch (changeType.EvaluateIn(context))
        {
        case UTSetOperation.Add:
            theStaticFlags = theStaticFlags | theCurrentStaticFlags;
            break;

        case UTSetOperation.Replace:
            break;

        case UTSetOperation.Subtract:
            theStaticFlags = theCurrentStaticFlags & ~theStaticFlags;
            break;

        default:
            throw new UTFailBuildException("Change type is unsupported.", this);              // should never happen(tm)
        }
        GameObjectUtility.SetStaticEditorFlags(theGameObject, theStaticFlags);

        yield return("");
    }
Esempio n. 2
0
    public override IEnumerator Execute(UTContext context)
    {
        var thePrefab = prefab.EvaluateIn(context);

        if (thePrefab == null)
        {
            throw new UTFailBuildException("You need to specify a prefab to instantiate.", this);
        }

        var theObjectName = objectName.EvaluateIn(context);

        if (UTPreferences.DebugMode)
        {
            Debug.Log("Instantiating prefab: " + thePrefab);
        }

        var theObject = (GameObject)PrefabUtility.InstantiatePrefab(thePrefab);

        if (!string.IsNullOrEmpty(theObjectName))
        {
            theObject.name = theObjectName;
        }


        var theProperty = outputProperty.EvaluateIn(context);

        if (!string.IsNullOrEmpty(theProperty))
        {
            context [theProperty] = theObject;
        }

        yield return("");
    }
Esempio n. 3
0
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object to tag.", this);
        }

        var theTagName = tagName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theTagName))
        {
            theGameObject.tag = string.Empty;
        }
        else
        {
            if (Array.IndexOf(InternalEditorUtility.tags, theTagName) == -1)
            {
                throw new UTFailBuildException("There is currently no tag '" + theTagName +
                                               "' defined. Please define it in the tag manager and then run this action again.", this);
            }
            theGameObject.tag = theTagName;
        }

        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("Game object is required", this);
        }
        Selection.activeObject = theGameObject;

        yield return("");
    }
Esempio n. 5
0
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object to revert.", this);
        }

        PrefabUtility.RevertPrefabInstance(theGameObject);

        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object.", this);
        }

        UTTypeInfo theComponentInfo = component.EvaluateIn(context);

        if (theComponentInfo == null)
        {
            throw new UTFailBuildException("You need to specify a component that should be removed.", this);
        }

        Type theComponent = theComponentInfo.Type;

        if (theComponent == null)
        {
            throw new UTFailBuildException("There is no component of type " + theComponentInfo.TypeName + " in the current project. Did you delete it accidently?", this);
        }

        var doRemoveAll = removeAll.EvaluateIn(context);


        Component[] toRemove;
        if (doRemoveAll)
        {
            toRemove = theGameObject.GetComponents(theComponent);
        }
        else
        {
            toRemove = new Component[] { theGameObject.GetComponent(theComponent) };
        }

        foreach (var comp in toRemove)
        {
            if (comp != null)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Removing component " + comp.name + ".", this);
                }
                UObject.DestroyImmediate(comp);
            }
        }

        yield return("");
    }
Esempio n. 7
0
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object to tag.", this);
        }

        var theLayer = layer.EvaluateIn(context);

        theGameObject.layer = theLayer;

        yield return("");
    }
Esempio n. 8
0
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object for which the status should be changed.", this);
        }

#if UNITY_3_5
        theGameObject.SetActiveRecursively(active.EvaluateIn(context));
#else
        theGameObject.SetActive(active.EvaluateIn(context));
#endif
        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object.", this);
        }

        UTTypeInfo theComponentInfo = component.EvaluateIn(context);

        if (theComponentInfo == null)
        {
            throw new UTFailBuildException("You need to specify a component that should be added.", this);
        }

        Type theComponent = theComponentInfo.Type;

        if (theComponent == null)
        {
            throw new UTFailBuildException("There is no component of type " + theComponentInfo.TypeName + " in the current project. Did you delete it accidently?", this);
        }

        var doOnlyIfNotExists = onlyIfNotExists.EvaluateIn(context);
        var doAdd             = true;

        if (doOnlyIfNotExists)
        {
            if (theGameObject.GetComponent(theComponent) != null)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Component of type " + theComponent.Name + " already exists at game object " + theGameObject);
                }
                doAdd = false;
            }
        }

        if (doAdd)
        {
            theGameObject.AddComponent(theComponent);
        }

        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object to rename.", this);
        }

        var theName = newName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theName))
        {
            throw new UTFailBuildException("You need to specify a new name for the game object.", this);
        }

        theGameObject.name = theName;
        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object to transform.", this);
        }

        if (positionAbsolute.EvaluateIn(context))
        {
            theGameObject.transform.position = position.EvaluateIn(context);
        }
        else
        {
            theGameObject.transform.position += position.EvaluateIn(context);
        }

        if (rotationAbsolute.EvaluateIn(context))
        {
            theGameObject.transform.localRotation = Quaternion.Euler(rotation.EvaluateIn(context));
        }
        else
        {
            theGameObject.transform.localRotation = Quaternion.Euler(theGameObject.transform.localEulerAngles + rotation.EvaluateIn(context));
        }

        if (scaleAbsolute.EvaluateIn(context))
        {
            theGameObject.transform.localScale = scale.EvaluateIn(context);
        }
        else
        {
            theGameObject.transform.localScale = Vector3.Scale(theGameObject.transform.localScale, scale.EvaluateIn(context));
        }

        yield return("");
    }
Esempio n. 12
0
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object to delete.", this);
        }

        if (dryRun.EvaluateIn(context))
        {
            Debug.Log("Would delete game object " + theGameObject.name, theGameObject);
        }
        else
        {
            if (UTPreferences.DebugMode)
            {
                Debug.Log("Deleting game object " + theGameObject.name);
            }
            GameObject.DestroyImmediate(theGameObject);
        }

        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You must specify the game object htat holds the component.", this);
        }

        var theProperty = property.EvaluateIn(context);

        if (theProperty == null || !theProperty.FullyDefined)
        {
            throw new UTFailBuildException("You must specify the component type and its property you want to change.", this);
        }

        var propertyPath = UTComponentScanner.FindPropertyPath(theProperty.Type, theProperty.FieldPath);

        if (propertyPath == null)
        {
            throw new UTFailBuildException("The component type or the property path is no longer valid.", this);
        }

        var theComponent = theGameObject.GetComponent(theProperty.Type);

        if (theComponent == null)
        {
            // nothing to do
            if (UTPreferences.DebugMode)
            {
                Debug.Log("Component " + theProperty.Type.Name + " not found at game object " + theGameObject, this);
            }
        }
        else
        {
            Type   propertyType = UTInternalCall.GetMemberType(propertyPath[propertyPath.Length - 1]);
            object propertyValue;
            if (typeof(string).IsAssignableFrom(propertyType))
            {
                propertyValue = stringPropertyValue.EvaluateIn(context);
            }
            else if (typeof(bool).IsAssignableFrom(propertyType))
            {
                propertyValue = boolPropertyValue.EvaluateIn(context);
            }
            else if (typeof(int).IsAssignableFrom(propertyType))
            {
                propertyValue = intPropertyValue.EvaluateIn(context);
            }
            else if (typeof(float).IsAssignableFrom(propertyType))
            {
                propertyValue = floatPropertyValue.EvaluateIn(context);
            }
            else if (typeof(Texture).IsAssignableFrom(propertyType))
            {
                propertyValue = texturePropertyValue.EvaluateIn(context);
            }
            else if (typeof(Vector3).IsAssignableFrom(propertyType))
            {
                propertyValue = vector3PropertyValue.EvaluateIn(context);
            }
            else if (typeof(Vector2).IsAssignableFrom(propertyType))
            {
                propertyValue = vector2PropertyValue.EvaluateIn(context);
            }
            else if (typeof(Rect).IsAssignableFrom(propertyType))
            {
                propertyValue = rectPropertyValue.EvaluateIn(context);
            }
            else if (typeof(Quaternion).IsAssignableFrom(propertyType))
            {
                propertyValue = quaternionPropertyValue.EvaluateIn(context);
            }
            else if (typeof(Material).IsAssignableFrom(propertyType))
            {
                propertyValue = materialPropertyValue.EvaluateIn(context);
            }
            else if (typeof(Color).IsAssignableFrom(propertyType))
            {
                propertyValue = colorPropertyValue.EvaluateIn(context);
            }
            else if (typeof(GameObject).IsAssignableFrom(propertyType))
            {
                propertyValue = gameObjectPropertyValue.EvaluateIn(context);
            }
            else if (typeof(UObject).IsAssignableFrom(propertyType))
            {
                propertyValue = unityObjectPropertyValue.EvaluateIn(context);
            }
            else
            {
                propertyValue = objectPropertyValue.EvaluateIn(context);
            }

            // TODO: we need a lot more validation here.
            // e.g. is the value assignable?

            // Tested with Vector3 -> BoxCollider:center
            // and float -> BoxCollider:center.y
            UTInternalCall.SetMemberValue(theComponent, propertyPath, propertyValue);
        }
        yield return("");
    }