예제 #1
0
    private void CreateObstaclePrefab()
    {
        Object newPrefab = PrefabUtility.CreateEmptyPrefab("Assets/Prefabs/Obstacles/" + objectName + ".prefab");

        GameObject newObject = new GameObject();

        SpriteRenderer sr = newObject.AddComponent <SpriteRenderer>() as SpriteRenderer;

        sr.sprite = singleSprite;

        BoxCollider2D bc = newObject.AddComponent <BoxCollider2D>() as BoxCollider2D;

        bc.size = singleSprite.bounds.size;

        GameObject path = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Path.prefab", typeof(GameObject));

        GameObject pathInstance = (GameObject)Instantiate(path, newObject.transform.position, Quaternion.identity);

        pathInstance.transform.parent = newObject.transform;

        followPath fp = newObject.AddComponent <followPath>() as followPath;

        fp.path = pathInstance.GetComponent <definePath>();

        obstacleAI ai = newObject.AddComponent <obstacleAI>() as obstacleAI;

        PrefabUtility.ReplacePrefab(newObject, newPrefab, ReplacePrefabOptions.ConnectToPrefab);

        DestroyImmediate(newObject);

        this.Close();
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        _AI = (obstacleAI)target;

        _AI.parameters.isIndestructible = EditorGUILayout.Toggle("Is Indestructable", _AI.parameters.isIndestructible);

        if (!_AI.parameters.isIndestructible)
        {
            _AI.parameters.hp = EditorGUILayout.FloatField("HP", _AI.parameters.hp);
        }

        _AI.parameters.whenFire = (Obstacle.fireOn)EditorGUILayout.EnumPopup("Fire On", _AI.parameters.whenFire);

        if (_AI.parameters.whenFire == Obstacle.fireOn.timeInterval)
        {
            TimeIntervalOptions();
        }

        if (_AI.parameters.whenFire == Obstacle.fireOn.onClearShot)
        {
            OnClearShotOptions();
        }

        if (_AI.parameters.whenFire == Obstacle.fireOn.onCollision)
        {
            OnCollisionOptions();
        }

        if (_AI.parameters.whereAim == Obstacle.aimTowards.fixedPoint)
        {
            if (!fixedPointCreated)
            {
                CreateFixedPoint();
            }
        }

        if (_AI.parameters.whereAim != Obstacle.aimTowards.fixedPoint && fixedPointCreated)
        {
            DestroyFixedPoint();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty((obstacleAI)target);
        }
    }